void LocalPlayer::walk(const Position& oldPos, const Position& newPos) { // a prewalk was going on if(m_preWalking) { if(m_waitingWalkPong) { if(newPos == m_lastPrewalkDestionation) m_lastWalkPing = m_walkPingTimer.ticksElapsed(); m_waitingWalkPong = false; } // switch to normal walking m_preWalking = false; m_lastPrewalkDone = true; // if is to the last prewalk destination, updates the walk preserving the animation if(newPos == m_lastPrewalkDestionation) { updateWalk(); // was to another direction, replace the walk } else Creature::walk(oldPos, newPos); } // no prewalk was going on, this must be an server side automated walk else { m_walkPingTimer.restart(); m_autoWalking = true; if(m_autoWalkEndEvent) m_autoWalkEndEvent->cancel(); Creature::walk(oldPos, newPos); } }
void LocalPlayer::walk(const Position& oldPos, const Position& newPos) { Otc::Direction direction = oldPos.getDirectionFromPosition(newPos); // a prewalk was going on if(m_preWalking) { // switch to normal walking m_preWalking = false; m_lastPrewalkDone = true; // if is to the last prewalk destination, updates the walk preserving the animation if(newPos == m_lastPrewalkDestionation) { updateWalk(); // was to another direction, replace the walk } else Creature::walk(oldPos, newPos); } else Creature::walk(oldPos, newPos); }
void Creature::nextWalkUpdate() { // remove any previous scheduled walk updates if(m_walkUpdateEvent) m_walkUpdateEvent->cancel(); // do the update updateWalk(); // schedules next update if(m_walking) { auto self = static_self_cast<Creature>(); m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] { self->m_walkUpdateEvent = nullptr; self->nextWalkUpdate(); }, getStepDuration() / 32); } }
void Creature::nextWalkUpdate() { // remove any previous scheduled walk updates if(m_walkUpdateEvent) m_walkUpdateEvent->cancel(); // do the update updateWalk(); // schedules next update if(m_walking) { auto self = asCreature(); m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] { self->m_walkUpdateEvent = nullptr; self->nextWalkUpdate(); }, m_walkAnimationInterval / 32); } }
void Player::update(Game& game, Level& level) { processQueuedActions(game); if (hasValidState() == false) { return; } if (useAI == true) { updateAI(level); } if (playerStatus != PlayerStatus::Dead && LifeNow() <= 0) { playerStatus = PlayerStatus::Dead; playSound(dieSound); } switch (playerStatus) { default: case PlayerStatus::Stand: updateAnimation(game); break; case PlayerStatus::Walk: updateWalk(game, level); break; case PlayerStatus::Attack: updateAttack(game, level); break; case PlayerStatus::Dead: updateDead(game, level); break; } updateHover(game, level); }
//-------------------------------------------------------------------------------------------------- /// The window coordinates are in OpenGL style coordinates, which means a right handed /// coordinate system with the origin in the lower left corner of the window. //-------------------------------------------------------------------------------------------------- bool LocatorPanWalkRotate::update(int x, int y) { CVF_ASSERT(m_camera.notNull()); if (x == m_lastPosX && y == m_lastPosY) return false; const double vpPixSizeX = m_camera->viewport()->width(); const double vpPixSizeY = m_camera->viewport()->height(); if (vpPixSizeX <= 0 || vpPixSizeY <= 0) return false; // Normalized movement in screen plane const double tx = (x - m_lastPosX)/vpPixSizeX; const double ty = (y - m_lastPosY)/vpPixSizeY; Vec3d oldPos = m_pos; if (m_operation == PAN) { updatePan(tx, ty); } else if (m_operation == WALK) { updateWalk(ty); } m_lastPosX = x; m_lastPosY = y; if (m_pos == oldPos) { return false; } else { return true; } }
void Creature::walk(const Position& position, bool inverse) { // set walking state bool sameWalk = m_walking && !m_inverseWalking && inverse; m_walking = true; m_inverseWalking = inverse; int walkTimeFactor = 1; // set new direction if(m_position + Position(0, -1, 0) == position) { setDirection(Otc::North); m_walkOffset.y = 32; } else if(m_position + Position(1, 0, 0) == position) { setDirection(Otc::East); m_walkOffset.x = -32; } else if(m_position + Position(0, 1, 0) == position) { setDirection(Otc::South); m_walkOffset.y = -32; } else if(m_position + Position(-1, 0, 0) == position) { setDirection(Otc::West); m_walkOffset.x = 32; } else if(m_position + Position(1, -1, 0) == position) { setDirection(Otc::NorthEast); m_walkOffset.x = -32; m_walkOffset.y = 32; walkTimeFactor = 2; } else if(m_position + Position(1, 1, 0) == position) { setDirection(Otc::SouthEast); m_walkOffset.x = -32; m_walkOffset.y = -32; walkTimeFactor = 2; } else if(m_position + Position(-1, 1, 0) == position) { setDirection(Otc::SouthWest); m_walkOffset.x = 32; m_walkOffset.y = -32; walkTimeFactor = 2; } else if(m_position + Position(-1, -1, 0) == position) { setDirection(Otc::NorthWest); m_walkOffset.x = 32; m_walkOffset.y = 32; walkTimeFactor = 2; } else { // Teleport // we teleported, dont walk or change direction m_walking = false; m_walkOffset.x = 0; m_walkOffset.y = 0; m_animation = 0; } if(!m_inverseWalking) { m_walkOffset.x = 0; m_walkOffset.y = 0; } if(m_walking) { // get walk speed int groundSpeed = 100; ItemPtr ground = g_map.getTile(position)->getGround(); if(ground) groundSpeed = ground->getType()->parameters[ThingType::GroundSpeed]; float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed; walkTime = (walkTime == 0) ? 1000 : walkTime; m_walkTimePerPixel = walkTime / 32.0; if(!sameWalk) m_walkStartTicks = g_clock.ticks(); updateWalk(); } }
void Actor::update(uint frameTime) { // Snap actor to walkboxes if following them. This might be // necessary for example after activating/deactivating // walkboxes, etc. if (_constrain && !_walking) { g_grim->getCurrSet()->findClosestSector(_pos, NULL, &_pos); } if (_turning) { float turnAmt = g_grim->getPerSecond(_turnRate) * 5.f; Math::Angle dyaw = _moveYaw - _yaw; dyaw.normalize(-180); // If the actor won't turn because the rate is set to zero then // have the actor turn all the way to the destination yaw. // Without this some actors will lock the interface on changing // scenes, this affects the Bone Wagon in particular. if (turnAmt == 0 || turnAmt >= fabsf(dyaw.getDegrees())) { setYaw(_moveYaw); _turning = false; } else if (dyaw > 0) { setYaw(_yaw + turnAmt); } else { setYaw(_yaw - turnAmt); } _currTurnDir = (dyaw > 0 ? 1 : -1); } if (_walking) { updateWalk(); } if (_walkChore.isValid()) { if (_walkedCur) { if (!_walkChore.isPlaying()) { _walkChore.playLooping(true); } if (_restChore.isPlaying()) { _restChore.stop(true); } } else { if (_walkedLast && _walkChore.isPlaying()) { _walkChore.stop(true); if (!_restChore.isPlaying()) { _restChore.playLooping(true); } } } } if (_leftTurnChore.isValid()) { if (_walkedCur || _walkedLast) _currTurnDir = 0; if (_restChore.isValid()) { if (_currTurnDir != 0) { if (getTurnChore(_currTurnDir)->isPlaying() && _restChore.isPlaying()) { _restChore.stop(true, 500); } } else if (_lastTurnDir != 0) { if (!_walkedCur && getTurnChore(_lastTurnDir)->isPlaying()) { _restChore.playLooping(true); } } } if (_lastTurnDir != 0 && _lastTurnDir != _currTurnDir) { getTurnChore(_lastTurnDir)->stop(true); } if (_currTurnDir != 0 && _currTurnDir != _lastTurnDir) { getTurnChore(_currTurnDir)->playLooping(true, 500); } } else { _currTurnDir = 0; } // The rest chore might have been stopped because of a // StopActorChore(nil). Restart it if so. if (!_walkedCur && _currTurnDir == 0 && !_restChore.isPlaying()) { _restChore.playLooping(true); } _walkedLast = _walkedCur; _walkedCur = false; _lastTurnDir = _currTurnDir; _currTurnDir = 0; // Update lip syncing if (_lipSync) { int posSound; // While getPosIn60HzTicks will return "-1" to indicate that the // sound is no longer playing, it is more appropriate to check first if (g_grim->getSpeechMode() != GrimEngine::TextOnly && g_sound->getSoundStatus(_talkSoundName.c_str())) posSound = g_sound->getPosIn60HzTicks(_talkSoundName.c_str()); else posSound = -1; if (posSound != -1) { int anim = _lipSync->getAnim(posSound); if (_talkAnim != anim) { if (anim != -1) { if (_talkChore[anim].isValid()) { stopMumbleChore(); if (_talkAnim != -1) { _talkChore[_talkAnim].stop(); } // Run the stop_talk chore so that it resets the components // to the right visibility. stopTalking(); _talkAnim = anim; _talkChore[_talkAnim].play(); } else if (_mumbleChore.isValid() && !_mumbleChore.isPlaying()) { _mumbleChore.playLooping(); _talkAnim = -1; } } else { stopMumbleChore(); if (_talkAnim != -1) _talkChore[_talkAnim].stop(); _talkAnim = 0; stopTalking(); } } } } frameTime = (uint)(frameTime * _timeScale); for (Common::List<Costume *>::iterator i = _costumeStack.begin(); i != _costumeStack.end(); ++i) { Costume *c = *i; c->setPosRotate(_pos, _pitch, _yaw, _roll); int marker = c->update(frameTime); if (marker > 0) { costumeMarkerCallback(marker); } } for (Common::List<Costume *>::iterator i = _costumeStack.begin(); i != _costumeStack.end(); ++i) { Costume *c = *i; c->animate(); } for (Common::List<Costume *>::iterator i = _costumeStack.begin(); i != _costumeStack.end(); ++i) { Costume *c = *i; c->moveHead(_lookingMode, _lookAtVector); } }