void Astroid::update(sf::Time * delta_time) { Entity::update(); setXVelocity(cos(getAngle() * kDegreesToRadians) * delta_time->asSeconds()); setYVelocity(cos(getAngle() * kDegreesToRadians) * delta_time->asSeconds()); move(getXVelocity(), getYVelocity()); }
void Ghost::move_to_hero() { WorldManager &wm = WorldManager::getInstance(); Position pos = getPosition(); if (abs(pos.getX() - hero_pos.getX()) > abs(pos.getY() - hero_pos.getY())) { if (pos.getX() > hero_pos.getX()) { setXVelocity(-GHOST_VELOCITY); } else if (pos.getX() < hero_pos.getX()) { setXVelocity(GHOST_VELOCITY); } } else if (pos.getY() > hero_pos.getY()) { setYVelocity(-GHOST_VELOCITY); } else { setYVelocity(GHOST_VELOCITY); } }
// overloaded constructor to take in initial velocity and position Ball::Ball(float xVelocity, float yVelocity, df::Position pos){ setType("Ball"); setXVelocity(xVelocity); setYVelocity(yVelocity); setSolidness(df::HARD); setPosition(pos); }
Star::Star() { setKillsBottom(false); setKillsSide(false); setKillsTop(false); setPoints(0); setXVelocity(2.0); setYVelocity(0.0); }
Mushroom::Mushroom() { setKillsBottom(false); setKillsSide(false); setKillsTop(false); setPoints(0); setXVelocity(2.0); setYVelocity(0.0); }
EnemyFireball::EnemyFireball() { setKillsBottom(true); setKillsSide(true); setKillsTop(true); setPoints(0); setXVelocity(0.0); setYVelocity(0.0); }
Shell::Shell() { setKillsBottom(true); setKillsSide(true); setKillsTop(false); setPoints(0); setXVelocity(2.0); setYVelocity(0.0); }
Plant::Plant() { setKillsBottom(true); setKillsSide(true); setKillsTop(true); setPoints(0); setXVelocity(0.0); setYVelocity(1.0); count_ = 720; sprite(); }
Turtle::Turtle() { setKillsBottom(true); setKillsSide(true); setKillsTop(false); setPoints(0); setXVelocity(-0.5); setYVelocity(0.0); sprite(); }
void KbfxPlasmaCanvasItem::advance ( int phase ) { if ( phase == 0 ) { setXVelocity ( 0 ); setYVelocity ( yVelocity () * 1 - 0.001 ); } else { move ( x () + xVelocity (), y () + yVelocity () ); } }
void Platform::step(EventStep *p_s) { // move left and right if (move_countdown < 0) { setXVelocity(getXVelocity() * -1); setYVelocity(getYVelocity() * -1); move_countdown = 50; } move_countdown--; }
Bullet::Bullet(Position hero_pos, int velocityX, int velocityY, int typee) { // Set object properties. setType("Bullet"); setXVelocity(velocityX);// move 1 space right every frame setYVelocity(velocityY); type = typee; auto& resMgr = ResourceManager::getInstance(); if (type == 1) { setSprite(resMgr.getSprite("bullet1")); } else if (type == 2) { setSprite(resMgr.getSprite("bullet-left")); } else if (type == 3) { setSprite(resMgr.getSprite("bullet-right")); } setSpriteSlowdown(4); // Set object type. setBox(Box(Position(0, 0), getSprite()->getWidth(), getSprite()->getHeight())); Position pos1; // Set starting location, based on hero's position passed in. if (velocityY == 0) { Position pos(hero_pos.getX() + 3 * velocityX, hero_pos.getY()); pos1 = pos; } if (velocityX == 0 ) { Position pos(hero_pos.getX(), hero_pos.getY() + 3 * velocityY); pos1 = pos; } setPosition(pos1); }
Platform::Platform() { setType("Platform"); isItThick = false; size = 50; setSolidness(HARD); setXVelocity(0.0); setYVelocity(0.0); setAltitude(3); // Make them in the background. WorldManager &world_manager = WorldManager::getInstance(); //Position pos(random() % world_manager.getBoundary().getHorizontal(), // random() % world_manager.getBoundary().getVertical()); Position pos(0, 15); setPosition(pos); height = 5; setBox(Box(Position(), size, height)); thecolor = rand() % 7; }
Platform::Platform(bool thickness, int sizee, int heightt, int x, int y, float x_speed, float y_speed) { setType("Platform"); isItThick = thickness; size = sizee; setSolidness(HARD); setXVelocity(x_speed); move_countdown = 10; setYVelocity(y_speed); setAltitude(3); // Make them in the background. WorldManager &world_manager = WorldManager::getInstance(); //Position pos(random() % world_manager.getBoundary().getHorizontal(), // random() % world_manager.getBoundary().getVertical()); Position pos(x, y); setPosition(pos); height = heightt; setBox(Box(Position(), size, height)); thecolor = rand() % 7; }
void BallConfigItem::addParameter(std::string name, double value) { if (name == "xCoordinate") { setXCoordinate(value); } else if (name == "yCoordinate") { setYCoordinate(value); } else if (name == "radius") { setRadius(value); } else if (name == "xVelocity") { setXVelocity(value); } else if (name == "yVelocity") { setYVelocity(value); } else if (name == "colorHue") { if (value < 0 || value > 1) { std::cout << "Hue value out of bounds [0,1] when creating a ball." << std::endl; exit(0); } setHue(value); } else { // Unrecognised parameter. std::cout << "Unrecognised parameter when creating a ball: " + name << std::endl; exit(0); } }
void PMRendererTypography::update() { if (state != RENDERERSTATE_ON) return; PMBaseRenderer::update(); int _mode = myGUI->getMode(); if (oldMode != _mode) { oldMode = _mode; box2d.getWorld()->ClearForces(); } // IF ADDALETTER IS ENABLES IN ENERGY CHANGED ... if (addALetter) { float minVelocity = 0.01; float maxVelocity = 1.0; float velocityY = ofMap(pParams.smoothedPitch, 0.0, 1.0, minVelocity, maxVelocity, true); setYVelocity(velocityY); addLetter(); addALetter = false; } uint64_t maxAge = myGUI->getMaxAge() * uint64_t(1000); list<shared_ptr<PMLetterContainer>>::iterator letterIt; for (letterIt = activeLetters.begin(); letterIt != activeLetters.end(); ++letterIt) { if (((*letterIt)->getAge() >= maxAge) || ((*letterIt)->getNeedsToBeRemoved())) { (*letterIt).get()->destroy(); activeLetters.erase(letterIt++); } } switch (_mode) { case 1 : { box2d.setGravity(myGUI->getGravityX(), myGUI->getGravityY()); oldMode = 1; break; } case 2 : { float time = ofGetElapsedTimef(); float gX = sin(time * myGUI->getSinusFreq()) * myGUI->getSinusAmplitude(); float gY = cos(time * myGUI->getSinusFreq()) * myGUI->getSinusAmplitude(); myGUI->setGravityX(gX); myGUI->setGravityY(gY); box2d.setGravity(gX, gY); break; } case 3 : { box2d.setGravity(myGUI->getGravityX(), myGUI->getGravityY()); oldMode = 3; for (letterIt = activeLetters.begin(); letterIt != activeLetters.end(); ++letterIt) { ofVec2f mouse(ofGetMouseX(), ofGetMouseY()); ofVec2f v = ofVec2f(ofGetMouseX() / ofGetWidth(), ofGetMouseY() / ofGetHeight()); (*letterIt)->addAttractionPoint(mouse, myGUI->getAttractorForce()); } } case 4 : { box2d.setGravity(myGUI->getGravityX(), myGUI->getGravityY()); oldMode = 4; } default : break; } box2d.update(); }
void GLObject::setVelocity(GLfloat vx, GLfloat vy, GLfloat vz) { setXVelocity(vx); setYVelocity(vy); setZVelocity(vz); }