void Stalfos::movement(std::vector<std::shared_ptr<GameObject>>* worldMap) { Point offsets(getXOffset(), getYOffset()); switch (dir){ case Direction::Down: { Point pt(position.x, position.y + minStep); if (!isColliding(worldMap, fullMask, offsets) && !isOutsideRoomBound(pt)) position.y += minStep; else getNextDirection(Direction::Down); break; } case Direction::Up: { Point pt(position.x, position.y - minStep); if (!isColliding(worldMap, fullMask, offsets) && !isOutsideRoomBound(pt)) position.y -= minStep; else getNextDirection(Direction::Up); break; } case Direction::Left: { Point pt(position.x - minStep, position.y); if (!isColliding(worldMap, fullMask, offsets) && !isOutsideRoomBound(pt)) position.x -= minStep; else getNextDirection(Direction::Left); break; } case Direction::Right: { Point pt(position.x + minStep, position.y); if (!isColliding(worldMap, fullMask, offsets) && !isOutsideRoomBound(pt)) position.x += minStep; else getNextDirection(Direction::Right); break; } } }
void Being::logic() { // Reduce the time that speech is still displayed if (mSpeechTime > 0) mSpeechTime--; // Remove text and speechbubbles if speech boxes aren't being used if (mSpeechTime == 0 && mText) { delete mText; mText = 0; } #ifdef TMWSERV_SUPPORT const Vector dest = (mPath.empty()) ? mDest : Vector(mPath.front().x * 32 + 16, mPath.front().y * 32 + 16); Vector dir = dest - mPos; const float length = dir.length(); // When we're over 2 pixels from our destination, move to it // TODO: Should be possible to make it even pixel exact, but this solves // the jigger caused by moving too far. if (length > 2.0f) { const float speed = mWalkSpeed / 100.0f; setPosition(mPos + (dir / (length / speed))); if (mAction != WALK) setAction(WALK); // Update the player sprite direction int direction = 0; const float dx = std::abs(dir.x); const float dy = std::abs(dir.y); if (dx > dy) direction |= (dir.x > 0) ? RIGHT : LEFT; else direction |= (dir.y > 0) ? DOWN : UP; setDirection(direction); } else if (!mPath.empty()) { // TODO: Pop as soon as there is a direct unblocked line to the next // point on the path. mPath.pop_front(); } else if (mAction == WALK) { setAction(STAND); } #else // Update pixel coordinates setPosition(mX * 32 + 16 + getXOffset(), mY * 32 + 32 + getYOffset()); #endif if (mEmotion != 0) { mEmotionTime--; if (mEmotionTime == 0) mEmotion = 0; } // Update sprite animations if (mUsedTargetCursor) mUsedTargetCursor->update(tick_time * 10); for (int i = 0; i < VECTOREND_SPRITE; i++) { if (mSprites[i]) mSprites[i]->update(tick_time * 10); } // Restart status/particle effects, if needed if (mMustResetParticles) { mMustResetParticles = false; for (std::set<int>::iterator it = mStatusEffects.begin(); it != mStatusEffects.end(); it++) { const StatusEffect *effect = StatusEffect::getStatusEffect(*it, true); if (effect && effect->particleEffectIsPersistent()) updateStatusEffect(*it, true); } } // Update particle effects mChildParticleEffects.moveTo(mPos.x, mPos.y); }