E_BEHAVIOR_ACTIONS CAggressiveBehaviorModule::playBehavior(const CGame& inGame) { E_BEHAVIOR_ACTIONS nextAction = E_ACTION_STAY; int opponentIdWithMaxMineCount = -1; int maxMineCount = 0; if (inGame.getOpponentIdWithMaxMineCount(opponentIdWithMaxMineCount, maxMineCount)) { const CHero &targetHero = inGame.getHero(opponentIdWithMaxMineCount); const CPosition targetHeroPos(targetHero.getPosition()); const int targetHeroCellId = inGame.get1DCoordOnBoard(targetHeroPos); const CHero &myHero = inGame.getMyHero(); path_t targetHeroPath; if (inGame.getPathTo(myHero.getId(), targetHeroCellId, false, targetHeroPath)) { // inGame.printPath(targetHeroPath, m_name); const CPosition nextPosition(inGame.get2DCoordOnBoard(*targetHeroPath.cbegin())); int deltaX = nextPosition.getX() - myHero.getPosition().getX(); int deltaY = nextPosition.getY() - myHero.getPosition().getY(); if (deltaX == 1) nextAction = E_ACTION_MOVE_EAST; else if (deltaX == -1) nextAction = E_ACTION_MOVE_WEST; else if (deltaY == 1) nextAction = E_ACTION_MOVE_SOUTH; else if (deltaY == -1) nextAction = E_ACTION_MOVE_NORTH; } else {} } else { // WAIT } // else return nextAction; } // playBehavior
void ALeft::execute(const sf::Int32 elapsed) { // TODO: Verif' they are existing components // #1 get all components CSpeed * speed; speed = (CSpeed *) parent->getComponent("Speed"); CAcceleration * acceleration; acceleration = (CAcceleration *) parent->getComponent("Acceleration"); CPosition * position; position = (CPosition *) parent->getComponent("Position"); if (speed->getHSpeed() > 1.2) { // #2a go back to 0 speed->setHSpeed((speed->getHSpeed())-((float)(speed->getHSpeed())/8.0)); position->setX((position->getX())+(speed->getHSpeed())); } else { // #2b increase speed speed->setHSpeed((speed->getHSpeed())-(acceleration->getHAcceleration())); position->setX((position->getX())+(speed->getHSpeed())); } // #3 change sprites TODO // example : if elapsed > modulotime/2 then ... }
void ARight::execute(const sf::Int64 elapsed) { // TODO: Verif' they are existing components // #1 get all components sf::Int64 tempElapsedSum = getElapsedSum() + elapsed; CAcceleration * acceleration; acceleration = (CAcceleration *) parent->getComponent("Acceleration"); CSpeed * speed = (CSpeed *) parent->getComponent("Speed"); CPosition * position = (CPosition *) parent->getComponent("Position"); CSprite * sprite = (CSprite *) parent->getComponent("Sprite"); if (speed->getHSpeed() < -1.2) { // #2a go back to 0 speed->setHSpeed((speed->getHSpeed())-((float)(speed->getHSpeed())/8.0)); position->setX((position->getX())+(speed->getHSpeed())); sprite->updatePosition(); } else { // #2b add values speed->setHSpeed((speed->getHSpeed())+ ((float)elapsed/acceleration->getHAcceleration()* speed->getHSpeedMax())); position->setX((position->getX())+ceil((speed->getHSpeed()))); // round sup sprite->updatePosition(); } // #3 change sprites sf::Int64 temp = 0; int k = 0; //index to read in tab while (temp < tempElapsedSum) { ++k; temp = temp + (getModuloTime()/getSubSprites().size()); } if ((k-1)>=getSubSprites().size()) {k=getSubSprites().size();} sprite->updateSubSprite(getSubSprites().at(k-1)); sprite->setDirection("right"); setElapsedSum(tempElapsedSum%getModuloTime()); }
void ALeft::execute(const sf::Int32 elapsed) { // TODO: Verif' they are existing components // #1 get all components CAcceleration * acceleration; acceleration = (CAcceleration *) parent->getComponent("Acceleration"); CSpeed * speed; speed = (CSpeed *) parent->getComponent("Speed"); CPosition * position; position = (CPosition *) parent->getComponent("Position"); // #2 add values speed->setHSpeed((speed->getHSpeed())-(acceleration->getHAcceleration())); position->setX((position->getX())+(speed->getHSpeed())); // #3 change sprites TODO // example : if elapsed > modulotime/2 then ... }
void AStand::execute(const sf::Int32 elapsed) { // TODO: Verif' they are existing components // #1 get all components CSpeed * speed; speed = (CSpeed *) parent->getComponent("Speed"); if ((float) std::abs(speed->getHSpeed()) > 1.2) { CAcceleration * acceleration; acceleration = (CAcceleration *) parent->getComponent("Acceleration"); CPosition * position; position = (CPosition *) parent->getComponent("Position"); // #2 add value speed->setHSpeed((speed->getHSpeed())-((float)(speed->getHSpeed())/8.0)); position->setX((position->getX())+(speed->getHSpeed())); } else { speed->setHSpeed(0.0); } // #3 change sprites TODO // example : if elapsed > modulotime/2 then ... }
// Call diz function implies an existing CPosition component void CSprite::updatePosition() { CPosition * position =(CPosition *) parent->getComponent("Position"); sprite.setPosition( position->getX() , position->getY()); }