void CalculateDijkstra(Metrics &metrics, Pathfinding::Heuristic heuristic, int width, int height, Vec2D startPos, Vec2D goalPos, AStarNode** grid) { Dijkstra pathFinding(width, height, grid, heuristic); pathFinding.init(startPos, goalPos); if (pathFinding.findPath(metrics)) {} }
void CalculateHPAStar(Metrics &metrics, Pathfinding::Heuristic heuristic, int width, int height, Vec2D startPos, Vec2D goalPos, AStarNode** grid, int clusterSize) { HPAStar pathFinding(width, height, clusterSize, grid, heuristic); pathFinding.init(startPos, goalPos); if (pathFinding.findPath(metrics)) {} }
void Character::update(Tile my_map[][5], float timeElapsed) { //cout << "JOUEUR" << status << " " << tile_x << ":" << tile_y << " " << move_x << ":" << move_y << " " << m_goalX << ":" << m_goalY << endl; //system("PAUSE"); if (tile_x >= 5) { tile_x = 4; } if (tile_y >= 10) { tile_y = 9; } if (status == IDLE) { if (random_clock.getElapsedTime().asSeconds() > 5) { random_clock.restart(); int random = rand() % 10 + 0; if (random > 7) { if (direction == RIGHT) { direction = LEFT; } else if (direction == LEFT) { direction = RIGHT; } } } if (render_clock.getElapsedTime().asSeconds() > 0.1) { render_clock.restart(); if (direction == RIGHT) { walking_x += 2; } else if (direction == LEFT) { walking_x -= 2; } if (walking_x - sprite.get_w() < 0) { direction = RIGHT; walking_x = 0 + sprite.get_w(); } if (walking_x > tile_size) { direction = LEFT; walking_x = tile_size; } } } else if (status == DIGING) { if (my_map[m_digY][m_digX].addProgress(timeElapsed) == 0) { status == IDLE; m_digY = 0; m_digX = 0; } } else if (status == BUILDING) { if (my_map[m_buildY][m_buildX].addProgress(timeElapsed) == 0) { status == IDLE; m_buildY = 0; m_buildX = 0; } } if (life <= 0) { is_alive = false; } if (direction == RIGHT) { life_bar_background.flip_x(false); life_bar.flip_x(false); life_bar_heart.flip_x(false); sprite.flip_x(false); pike.flip_x(false); sword.flip_x(false); hammer.flip_x(false); } else if (direction == LEFT) { life_bar_background.flip_x(true); life_bar.flip_x(true); life_bar_heart.flip_x(true); sprite.flip_x(true); pike.flip_x(true); hammer.flip_x(true); sword.flip_x(true); } if ((tile_x == m_goalX) && (tile_y == m_goalY)) { if (status == MOVING) { cout << "1" << endl; status = IDLE; } } else { cout << "10" << endl; status = MOVING; pathFinding(my_map); m_moving += timeElapsed; // cout << " -->" << m_moving << endl; //} if (m_moving >= 2000) { (*this).setPosition(move_x, move_y); } } float new_life = life / 100.0f; life_bar.scale(new_life, 1.0f, false); }