/** * \fn int updateVision(sInterface *p_interface, sMap *p_map) * \brief Fonction de mise à jour de la position du joueur * * \param *p_interface pointeur vers une structure de type sInterface * \param *p_map pointeur vers une structure de type sMap * \return int représentant le déroulement de la fonction */ int updateVision(sInterface *p_interface, sMap *p_map) { if (!(p_interface->player.isSliding)) { SDL_RenderCopy(p_interface->renderer, p_interface->player.playerSprite[p_interface->player.direction], NULL, &(p_interface->player.realPosition)); return 0; } if (comparePositionRect(p_interface->player.realPosition, p_interface->player.realDestination)) { SDL_RenderCopy(p_interface->renderer, p_interface->player.playerSprite[p_interface->player.direction], NULL, &(p_interface->player.realPosition)); p_interface->solution = dijkstra(p_map, getMapPosition(p_interface->player.realPosition)); p_interface->player.isSliding = FALSE; }else { if(!(p_interface->effect.particle)) initParticleSystem(&(p_interface->effect.particle), PATRICLE_SYSTEM_LIFETIME, PARTICLE_AMOUNT, p_interface->player.realPosition, p_interface->player.direction); SDL_RenderCopy(p_interface->renderer, p_interface->player.playerSprite[p_interface->player.direction], NULL, &(p_interface->player.realPosition)); if(p_interface->player.direction == DUP) p_interface->player.realPosition.y -= ((WINDOW_HEIGHT / CASE_LINE_AMOUNT) / SDL_ANIMATION_SLIDE_FRAMEAMOUNT); if (p_interface->player.direction == DRIGHT) p_interface->player.realPosition.x += ((WINDOW_WIDTH / CASE_COLUMN_AMOUNT) / SDL_ANIMATION_SLIDE_FRAMEAMOUNT); if (p_interface->player.direction == DDOWN) p_interface->player.realPosition.y += ((WINDOW_HEIGHT / CASE_LINE_AMOUNT) / SDL_ANIMATION_SLIDE_FRAMEAMOUNT); if (p_interface->player.direction == DLEFT) p_interface->player.realPosition.x -= ((WINDOW_WIDTH / CASE_COLUMN_AMOUNT) / SDL_ANIMATION_SLIDE_FRAMEAMOUNT); } return 0; }
void SGSHero::moveOneStep(SGSPointList* path) { if (path->empty()) { SGSPoint point = getMapPosition(); log("%s finished move %d %d", this->getName().c_str(), point.x, point.y); SGSkirmishScene::getCurrentSkirmish()->startSkirmish(0.0f); return; } SGSPoint target_pos = path->front(); path->erase(path->begin()); faceTo(getRelativeDirection(target_pos)); log("%s move one step to %d %d", this->getName().c_str(), target_pos.x, target_pos.y); stopAllActions(); int actualDuration = SGS_HERO_MOVE_ONE_STEP_TIME; FiniteTimeAction *actionMove = MoveTo::create(actualDuration, SGSPoint::mapPos2OpenGLPos(target_pos)); __CCCallFuncND * funcall= __CCCallFuncND::create(this, callfuncND_selector(SGSHero::moveOneStepFinished, this), path); FiniteTimeAction* moveWithCallback = Sequence::create(actionMove, funcall, NULL); Animate* animate = getWalkAnimate(__direction); Repeat* walk = Repeat::create(animate, 300); Spawn * walk_one_step = Spawn::create(walk, moveWithCallback, NULL); this->runAction(walk_one_step); }
SGSHero::HERO_DIRECTION SGSHero::getRelativeDirection(SGSPoint& point) { return getRelativeDirectionFrom(point, getMapPosition()); }