void CVarPlatform::process() { int xBlockPos = target.x - getXPosition(); int yBlockPos = target.y - getYPosition(); const int xBlockPosAbs = (xBlockPos<0) ? -xBlockPos : xBlockPos; const int yBlockPosAbs = (yBlockPos<0) ? -yBlockPos : yBlockPos; if( xBlockPosAbs < MOVE_SPEED && yBlockPosAbs < MOVE_SPEED ) { const Uint16 object = mpMap->getPlaneDataAt(2, target.x, target.y); Vector2D<int> speed(xBlockPos, yBlockPos); movePlat(speed); readDirection(object, xDirection, yDirection ); detectNextTarget(target, xDirection, yDirection); } if(yDirection == UP && blockedu) yDirection = DOWN; else if(yDirection == DOWN && blockedd) yDirection = UP; if(xDirection == RIGHT && blockedr) xDirection = LEFT; else if(xDirection == LEFT && blockedl) xDirection = RIGHT; Vector2D<int> speed; if(yDirection == UP) { speed.y = -MOVE_SPEED; } else if(yDirection == DOWN) { speed.y = MOVE_SPEED; } if(xDirection == RIGHT) { speed.x = MOVE_SPEED; } else if(xDirection == LEFT) { speed.x = -MOVE_SPEED; } movePlat(speed); CPlatform::process(); }
CRocket::CRocket(CMap* pmap, const Uint16 foeID, const Uint32 x, const Uint32 y) : CGalaxyActionSpriteObject(pmap, foeID, x, y, 0), CMoveTarget(m_Pos, xDirection, yDirection), mpCarriedPlayer(nullptr) { mActionMap[A_ROCKET_SIT] = (void (CGalaxyActionSpriteObject::*)()) &CRocket::processSitting; mActionMap[A_ROCKET_FLY] = (void (CGalaxyActionSpriteObject::*)()) &CRocket::processFlying; solid = false; setupGalaxyObjectOnMap(0x1B08, A_ROCKET_SIT); fetchInitialDir(xDirection, yDirection, *mp_Map); detectNextTarget(target, xDirection, yDirection); }
void CRocket::processFlying() { int xBlockPos = target.x - getXPosition(); int yBlockPos = target.y - getYPosition(); const int xBlockPosAbs = (xBlockPos<0) ? -xBlockPos : xBlockPos; const int yBlockPosAbs = (yBlockPos<0) ? -yBlockPos : yBlockPos; if( xBlockPosAbs < MOVE_SPEED && yBlockPosAbs < MOVE_SPEED ) { const Uint16 object = mp_Map->getPlaneDataAt(2, target.x, target.y); Vector2D<int> speed(xBlockPos, yBlockPos); moveDir(speed); playSound(SOUND_ROCKET_DRIVE); // Happens when the rocket find a place where to stop if(object == 0x6A || object == 0x69) { xDirection = CENTER; yDirection = UP; setAction(A_ROCKET_SIT); detectNextTarget(target, xDirection, yDirection); Vector2D<int> newPlayerPos = m_Pos; newPlayerPos.y = getYDownPos(); newPlayerPos.x = getXRightPos(); mpCarriedPlayer->moveToForce(newPlayerPos); mpCarriedPlayer->solid = true; mpCarriedPlayer->dontdraw = false; mpCarriedPlayer = nullptr; return; } readDirection(object, xDirection, yDirection ); // If there is an object that changes the direction of the rocket, apply it! detectNextTarget(target, xDirection, yDirection); } Vector2D<int> speed; if(yDirection == UP) { speed.y = -MOVE_SPEED; } else if(yDirection == DOWN) { speed.y = MOVE_SPEED; } if(xDirection == RIGHT) { speed.x = MOVE_SPEED; } else if(xDirection == LEFT) { speed.x = -MOVE_SPEED; } if(mpCarriedPlayer != nullptr) { mpCarriedPlayer->moveDir(speed); } moveDir(speed); }