bool Unit::Update(float dt) { bool ret = true; bool collided = false; if (!targetReached) { if (UpdateVelocity(dt)) { if (!Move(dt)) targetReached = true; } } if (targetReached) { GetNewTarget(); } UpdateBarPosition(); UpdateBarTexture(); Draw(); return ret; }
void Unit::SetNewPath(C_DynArray<iPoint>& newPath) { path.Clear(); if (newPath.Count() > 0) { path += newPath; targetReached = false; currentNode = -1; GetNewTarget(); } }
void EntMobile::UpdateMovement(float dt) { if (movement) { if (!target_reached) { UpdateVelocity(dt); Move(dt); if (IsTargetReached()) target_reached = true; } else { GetNewTarget(); } } }
void EntMobile::SetNewPath(int x, int y) { iPoint start = App->map->WorldToMap(position.x, position.y); iPoint goal = { x, y }; if (App->game->em->EntityOnCoords(App->map->MapToWorld(GetMapPosition().x, GetMapPosition().y)) != NULL && App->game->em->EntityOnCoords(App->map->MapToWorld(GetMapPosition().x, GetMapPosition().y)) != this) { goal = FindClosestWalkable(goal); } int steps = App->pathfinding->GetNewPath(start, goal, path); if (steps > 0) { //StateMachine change current_input = ENTITY_INPUT_MOVE; movement = true; current_node = -1; GetNewTarget(); } }