void bounce(double v = 90) { double n = movingDirectionH; setMovingDirection(2 * n - v - 180); if (n == movingDirectionH) { movingDirectionH = v; } }
void TankAIStrategy::init() { QList<QString> tanksList = _board->getObjectIdsByType(AnimatedBoardObject::TYPE_ENEMYTANK); for(auto tankId : tanksList) { int positionX, positionY, rotation; _board->getObjectPositionAndRotationById(tankId, positionX, positionY, rotation); AnimatedBoardObject::MovingDirectionType movingDirection = getMovingDirectionByRotation(rotation); setMovingDirection(tankId, movingDirection); } }
void TankAIStrategy::advance() { BoardObjectAIStrategy::advance(); QList<QString> tanksList = _board->getObjectIdsByType(AnimatedBoardObject::TYPE_ENEMYTANK); for(auto tankId : tanksList) { AnimatedBoardObject::MovingDirectionType movingDirection = _board->getObjectMovingDirectionById(tankId); if (moveToDirection(tankId, movingDirection)) { setMovingDirection(tankId, getMovingDirectionNotEqualTo(movingDirection)); } if (qrand() % 50 == 0) { _lastFiredObject = AnimatedBoardObject::TYPE_ENEMYTANK; _stage->sendObjectFired(tankId); ResourceSound::play(kShotSoundFileName); } } QList<QString> userTankList = _board->getObjectIdsByType(AnimatedBoardObject::TYPE_USERTANK); if (userTankList.count()) { QString userTankId = userTankList.first(); // If user pressed control key propagate fire event to mediator // Use constant to tune firing speed if (_isUserTankFiring && _gameLoopIterationCount % kFiringSpeedFactor == 0) { _isUserTankFiring = false; _stage->sendObjectFired(userTankId); ResourceSound::play(kShotSoundFileName); } AnimatedBoardObject::MovingDirectionType movingDirection = _board->getObjectMovingDirectionById(userTankId); if (movingDirection != AnimatedBoardObject::MOVING_NONE) { moveToDirection(userTankId, movingDirection); if (_userMovingSound->isFinished()) { _userMovingSound->play(); } if (_userMovingSoundTimer) { delete _userMovingSoundTimer; _userMovingSoundTimer = nullptr; } // Start timer to stop the moving sound _userMovingSoundTimer = new QTimer(this); connect(_userMovingSoundTimer, SIGNAL(timeout()), SLOT(stopUserMovingSound())); _userMovingSoundTimer->start(100); _userMovingSoundTimer->setSingleShot(true); } } }
void setVelocity(double speed, double hDegrees, double vDegrees, double sDegrees) { setMovingDirection(hDegrees, vDegrees, sDegrees); this->speed = speed; }