/* ** decrementYOffset ** Decreases the yOffset on an eponential scale */ float ofxOscilloscope::decrementYOffset() { float inc = 2.71828/2; if (getYOffset() == 0) { setYOffset(-1); } else if (getYOffset() == 1) { setYOffset(0); } else if (getYOffset() > 0) { setYOffset(pow(inc, round(log(getYOffset())/log(inc)) - 1)); } else if (getYOffset() < 0) { setYOffset(-pow(inc, round(log(-getYOffset())/log(inc)) + 1)); } return getYOffset(); }
/* ** plot ** Plots the data in the buffer */ void ofxOscilloscope::plot(){ // Legend Background ofEnableAlphaBlending(); ofSetColor(_backgroundColor); ofPoint legendMax = ofPoint(_min.x + _legendWidth, _max.y); ofRect(ofRectangle(_min, legendMax)); ofDisableAlphaBlending(); for (int i=0; i<_scopePlot.getNumVariables(); i++) { // Legend Text ofSetColor(_scopePlot.getVariableColor(i)); _legendFont.drawString(getVariableName(i), _min.x + _legendPadding, _min.y + _legendPadding + _textSpacer*(i+1)); } // Sets the zero line width when called before plot() ofSetLineWidth(_outlineWidth); // Plot the Data _scopePlot.plot(); ofSetColor(_outlineColor); ofSetLineWidth(_outlineWidth); ofEnableAlphaBlending(); // Legend outline ofLine(_min.x, _min.y, _min.x, _max.y); ofLine(_min.x, _max.y, _min.x + _legendWidth, _max.y); ofLine(_min.x + _legendWidth, _max.y, _min.x + _legendWidth, _min.y); ofLine(_min.x + _legendWidth, _min.y, _min.x, _min.y); // Scope outline //ofLine(_min.x, _min.y, _min.x, _max.y); ofLine(_min.x + _legendWidth, _max.y, _max.x, _max.y); ofLine(_max.x, _max.y, _max.x, _min.y); ofLine(_max.x, _min.y, _min.x + _legendWidth, _min.y); // Timescale _legendFont.drawString(ofToString(_scopePlot.getTimeWindow()) + " sec," + " yScale=" + ofToString(getYScale()) + ", yOffset=" + ofToString(getYOffset(), 1), _min.x + _legendWidth + _legendPadding, _max.y - _legendPadding); ofDisableAlphaBlending(); }
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); }