void create_bus_text_layers() { for( int i = 0; i < NUM_BUSES_PER_PAGE; ++i ) { common_create_text_layer( &s_bus_display_lines[ i ].line, s_bus_display_wnd, line_rect( i ), GColorWhite, GColorBlack, FONT_KEY_GOTHIC_14_BOLD, GTextAlignmentCenter ); common_create_text_layer( &s_bus_display_lines[ i ].dest, s_bus_display_wnd, dest_rect( i ), GColorWhite, GColorBlack, FONT_KEY_GOTHIC_14, GTextAlignmentLeft ); common_create_text_layer( &s_bus_display_lines[ i ].eta, s_bus_display_wnd, eta_rect( i ), GColorWhite, GColorBlack, FONT_KEY_GOTHIC_14_BOLD, GTextAlignmentRight ); } }
void main() { assert(line_line(line(vec2(0, 0), vec2(5, 5)), line(vec2(0, 5), vec2(5, 0))).result == true); assert(line_line(line(vec2(2.5, 0), vec2(2.5, 5)), line(vec2(0, 2.5), vec2(2.5, 5))).result == true); assert(line_rect(line(vec2(0,1),vec2(5,1)),rect(vec2(5,1),vec2(2,2))).result == true); assert(line_rect(line(vec2(1, 0), vec2(1, 5)), rect(vec2(1, 5), vec2(2, 2))).result == true); srand(time(NULL)); auto w = openContext(1280, 800); //size of window auto m = mat4::ortho(-25, 1280, -25, 800, 0, 100); //size of drawing area //drawing area is shrunk or stretchd to the size of the window Graph *g = Graph::genGrid(32,32,1280,800, 5); Solver dfs(g->getNumNodes(), g->getadjacencyMatrix(), g->getPos()); Entity e(200, g->getPos()[0]); Entity lala(100, vec2(400, 400)); float dt, current, total = 0; glfwSetTime(0); int lastGoal = 0; int newGoal = 0; bool newPath = true; std::vector<rect> obstacles; //used to keep track of the obstacles in the graph obstacles.push_back(rect(vec2( 165, 325), vec2( 50, 300))); //left side obstacles.push_back(rect(vec2(1115, 325), vec2( 50, 300))); //right top obstacles.push_back(rect(vec2( 640, 200), vec2(1000, 50))); //bottom obstacles.push_back(rect(vec2( 640, 800), vec2( 300, 300))); //top box obstacles.push_back(rect(vec2( 640, 0), vec2( 300, 150))); //bottom box for each(auto o in obstacles) g->addObstacle(o.min(), o.max()); //opens the game loop while (updateContext(w)) //calls the draw functions { current = glfwGetTime(); dt = current - total; total = current; if (dt > .16) dt = .16; if (newPath) { bool trying = true; lastGoal = newGoal; while (trying) { newGoal = rand() % g->getNumNodes(); //newGoal = 800; for (int i = 0; i < g->getNumNodes(); i++) if (g->getadjacencyMatrix()[newGoal][i] > 0) trying = false; } e.m_path = Solver::solve(g->getNumNodes(), g->getadjacencyMatrix(), g->getPos(), lastGoal, newGoal); e.m_path = dfs.smoothPath(e.m_path, obstacles); lala.m_path = Solver::solve(g->getNumNodes(), g->getadjacencyMatrix(), g->getPos(), lastGoal, newGoal); lala.m_path = dfs.smoothPath(e.m_path, obstacles); newPath = false; } e.update(dt); lala.update(dt); e.draw(m, 7, vec4(1,1,1,1)); lala.draw(m, 7, vec4(0,1,1,0)); for (int j = 0; j < obstacles.size(); j++) { draw_rect(m, rect(obstacles[j]), vec4(0, 0, 1, 0)); } for (int i = 1; i < e.m_path.size(); i++) //draw path { draw_line(m, line(e.m_path[i - 1], e.m_path[i]), vec4(0, 1, 0, 0)); } if (e.m_targetIndex == e.m_path.size()) { e.m_targetIndex = 0; newPath = true; } } //delete g; //closes the game loop closeContext(w); }