void GameController::interpretBlockableCommand(){ if(gameState == GAMECONTROLLER_STATE_PLAYING){ //Penguin wants to go forward if (goForwardPressed){ //Then creates new movement to this penguin (only one position) std::pair<int, int> nextPosition = penguin->getNewPosition<int>(1); LinearMovement* newMove = new LinearMovement(penguin, nextPosition, true, penguinSpeed); blockingMovements.push_back(newMove); }else if(goBackwardsPressed){ //Penguin wants to go backwards, creates a movement for this std::pair<int, int> nextPosition = penguin->getNewPosition<int>(-1); LinearMovement* newMove = new LinearMovement(penguin, nextPosition, false, penguinSpeed); blockingMovements.push_back(newMove); }else if(turnClockwisePressed){ //Turn penguin right (clockwise) 90° double nextDirection = penguin->getNewDirection(-M_PI_2); AngularMovement* newMove = new AngularMovement(penguin, nextDirection, true); blockingMovements.push_back(newMove); }else if (turnCounterClockwisePressed){ //Turn penguin left (counter-clockwise) 90° double nextDirection = penguin->getNewDirection(M_PI_2); AngularMovement* newMove = new AngularMovement(penguin, nextDirection, false); blockingMovements.push_back(newMove); } //Penguin wants to push a block if (pushPressed){ //Take the position in front and verify if it is a block std::pair<int, int> frontPosition = penguin->getNewPosition<int>(1); if (!scenario.outOfMap(frontPosition)){ Block* block = dynamic_cast<Block*>(scenario.map[frontPosition.second][frontPosition.first]); if (block != NULL && block->mobile){ //It is a mobile block std::pair<int, int> twoPosAway = penguin->getNewPosition<int>(2); //If it is a push towards the wall, destroy the block if (scenario.outOfMap(twoPosAway)){ //Destroy it block->die(); delete block; block = NULL; } else { Modelable* other; //If there is another block in front of this one... if (((other = scenario.map[twoPosAway.second][twoPosAway.first]) != NULL) && (dynamic_cast<Block*>(other))) { //Destroy it block->die(); delete block; block = NULL; } else { //The way is free, push it to the bounds block->direction = penguin->direction; std::pair<int, int> blockDestiny = penguin->getNewPosition<int>(SCENARIO_MAP_SIZE+1); LinearMovement* newBlockMove = new LinearMovement(block, blockDestiny, true); normalMovements.push_back(newBlockMove); } } } } } //Create new Block if(createnewBlockPressed){ std::pair<int, int> nextPosition = penguin->getNewPosition<int>(1); if (scenario.conceptions.size() < maxConceivingBlocks && !scenario.outOfMap(nextPosition) && scenario.map[nextPosition.second][nextPosition.first] == NULL) scenario.createConceptionAt(nextPosition.second, nextPosition.first, GAMECONTROLLER_NUM_STEPS_CONCEPTION); } } }