bool Hero::moveOutOfSolidEntities(){ std::vector<Entity*> entities; entities = mRoom->getSolidEntities(); bool ground = false; for(int i=0; i< entities.size();i++){ float2 sepVec = getSeparationVector(getCollisionRect(),entities[i]->getCollisionRect()); if(sepVec.y > 0.0f){ mVelocity.y = max(entities[i]->getVelocity().y * 0.5f, mVelocity.y); } if(sepVec.y < 0.0f){ mVelocity.y = min(entities[i]->getVelocity().y * 0.5f, mVelocity.y); ground=true; } if(sepVec.x > 0.0f){ mVelocity.x = max(entities[i]->getVelocity().x * 0.5f, mVelocity.x); } if(sepVec.x < 0.0f){ mVelocity.x = min(entities[i]->getVelocity().x * 0.5f, mVelocity.x); } setPosition(getPosition()+sepVec * 0.99f); } return ground; }
void Savepoint::update() { mFrame++; if (mTextCounter > 0) { mTextCounter--; } Hero *hero = getRoom()->getHero(); Entity::CollisionRect cr= hero->getCollisionRect(); bool heroOn = Collides(getCollisionRect(), cr); if (heroOn && !mHeroOn) { // SAVE GameState::put(GameState::LOCATION_X, getRoom()->getWorldOffsetX() * getRoom()->getTileWidth() + this->getPosition().x); GameState::put(GameState::LOCATION_Y, getRoom()->getWorldOffsetY() * getRoom()->getTileHeight() + this->getPosition().y + 10); GameState::saveToFile(); Sound::playSample("data/sounds/coin.wav"); mTextCounter = 50; } mHeroOn = heroOn; }
void Powerup::update() { if (GameState::getInt(mKind) != 0) { return; } Hero *hero = getRoom()->getHero(); Entity::CollisionRect cr = hero->getCollisionRect(); if (Collides(getCollisionRect(), cr)) { GameState::put(mKind, 1); std::string explanation; PowerUpScreen* screen; if (mKind == GameState::POWERUP_HIJUMP) { screen = new PowerUpScreen("HI JUMP SOCKS", "JUMP HIGHER"); } else if (mKind == GameState::POWERUP_GUN) { screen = new PowerUpScreen("POWER GUN", "USE Z"); } else if (mKind == GameState::POWERUP_GRENADE) { screen = new PowerUpScreen("GRAVITY GRANADE", "USE X"); } ScreenManager::add(screen); } mFrame++; }
void WallOfDeathStarter::update() { if (!myUsed && Collides(mRoom->getHero()->getCollisionRect(), getCollisionRect())) { mRoom->broadcastStartWallOfDeath(); myUsed = true; } }
void Spike::update() { Hero* hero = mRoom->getHero(); if (Collides(hero->getCollisionRect(), getCollisionRect())) { hero->kill(); } }
void Hero::checkEnemies(){ std::vector<Entity*> entities; entities=mRoom->getEnemies(); for (int i=0;i<entities.size();i++){ Entity::CollisionRect cr = entities[i]->getCollisionRect(); if(Collides(getCollisionRect(),cr)){ die(); } } }
void BossFloor::update() { myFrameCounter++; if (!myActive) return; if (Collides(mRoom->getHero()->getCollisionRect(), getCollisionRect())) { mRoom->getHero()->kill(); } if (myFrameCounter > 60) myActive = false; }
void BossSaw::update() { myFrameCounter++; if (myFrameCounter > myLifeTime) remove(); setPosition(getPosition() + mySpeed); if (Collides(mRoom->getHero()->getCollisionRect(), getCollisionRect())) { mRoom->getHero()->kill(); } }
void BouncyBee::draw() { setMapPosition(); if (flinching) { double elapsed = (getMs() - flinchTimer); if ((long)(elapsed / 100) % 2 == 0) { return; } } SDL_Rect rect = getCollisionRect(); //drawRect(rect); mapObjectDraw(); }
void SimpleWalkingMonster::update() { switch(mState) { case State_Walking: { mVelocity.y += 6.0f; mVelocity.x = 20.0f * ((mFacing==Facing_Left)?-1:1); setVelocity(mVelocity); int bumps = moveWithCollision(); if ((bumps & (Direction_Up | Direction_Down)) != 0) { mVelocity.y = 0; } if ((bumps & (Direction_Left)) != 0) { mFacing = Facing_Right; } if ((bumps & (Direction_Right)) != 0) { mFacing = Facing_Left; } int offsetX = (mState==Facing_Right)?-getHalfSize().x-2:getHalfSize().x+2; int offsetY = getHalfSize().y+2; float2 position = getPosition(); int x = (position.x+offsetX) / (float)mRoom->getTileWidth(); int y = (position.y+offsetY) / (float)mRoom->getTileHeight(); if (!mRoom->isCollidable(x, y)) { if (mFacing == Facing_Left) { mFacing = Facing_Right; } else { mFacing = Facing_Left; } } if (mRand.getFloat(1.0f) < WALK_TO_IDLE_CHANCE) { mState = State_Idling; } } break; case State_Idling: if (mRand.getFloat(1.0f) < IDLE_TO_WALK_CHANCE) { if (mRand.getFloat(1.0f) > 0.5) { mFacing = Facing_Left; } else { mFacing = Facing_Right; } mState = State_Walking; } break; } Hero* hero = mRoom->getHero(); if (Collides(hero->getCollisionRect(), getCollisionRect())) { hero->kill(); } mFrame++; }
void Boss::update() { myAnimFrameCounter++; myFrameCounter++; if (myState == State_Init) { myOriginalPos = getPosition(); myState = State_Sleeping; } if (myState != State_MoveUpwards && myState != State_Sleeping && myState != State_InitialBlow && myState != State_Dead && myState != State_Vulnerable) { if (Collides(mRoom->getHero()->getCollisionRect(), getCollisionRect())) { mRoom->getHero()->kill(); } } if (myState == State_InitialBlow) { if (myFrameCounter % 60 == 0) Sound::playSample("data/sounds/alarm.wav"); if (myFrameCounter >= INITIAL_BLOW_TIME) { Sound::playSample("data/sounds/reactor_explosion.wav"); Sound::playSample("data/sounds/start.wav"); ParticleSystem* ps = new ParticleSystem(Resource::getAnimation("data/images/debris.bmp", 4), 20, 200, 20, 1, 50, 50, -float2(0.0f, 150.0f), 5.0f); ps->setPosition(getPosition(), 10.0f); mRoom->addEntity(ps); myFrameCounter = 0; myState = State_Awakening; } } if (myState == State_Awakening) { if (myFrameCounter > 60 * 3) { myState = State_MoveUpwards; myFrameCounter = 0; setTilesCollidable(false); Music::pushSong(); Music::playSong("data/music/olof3.xm"); } } if (myState == State_MoveUpwards) { setPosition(getPosition() + float2(0, -1)); if (myOriginalPos.y - getPosition().y > 130) { myState = State_Float; mRoom->broadcastBoosWallActivate(); myFrameCounter = 0; } } if (myState == State_Float) { float y = sinf(myFrameCounter / 8) * 2.0f; if (myDirection == Direction_Right) { setPosition(getPosition() + float2(1.5f, y)); if (getPosition().x - myOriginalPos.x > 110) myDirection = Direction_Left; } if (myDirection == Direction_Left) { setPosition(getPosition() + float2(-1.5f, y)); if (myOriginalPos.x - getPosition().x > 110) myDirection = Direction_Right; } if (myFrameCounter > 60 * 7) { myState = State_Attack; myFrameCounter = 0; } } if (myState == State_Attack) { if (myFrameCounter < 40) { if (myFrameCounter % 2 == 0) setPosition(getPosition() + float2(-2, 0)); else setPosition(getPosition() + float2(2, 0)); } else { setPosition(getPosition() + float2(0, 6.0f)); if (myOriginalPos.y < getPosition().y) { mRoom->broadcastBoosWallDectivate(); setPosition(float2(getPosition().x, myOriginalPos.y)); myState = State_Vulnerable; mRoom->getCamera()->addShake(5.0f, 80); int numPs = rand() % 10 + 5; ParticleSystem* ps = new ParticleSystem(Resource::getAnimation("data/images/debris.bmp", 4), 10, 40, 10, 1, 50, numPs, -float2(0.0f, 20.0f), 2.0f); ps->setPosition(getPosition(), 10.0f); mRoom->addEntity(ps); mRoom->broadcastBoosFloorActivate(); Sound::playSample("data/sounds/reactor_explosion.wav"); Coin::SpawnDeathCoins(rand() % 5 + 3, getPosition(), 60 * 6, mRoom); } } } if (myState == State_Vulnerable) { if (myFrameCounter > 60 * 5) { myState = State_MoveUpwards; myFrameCounter = 0; } } if (myState == State_Dead) { if (myFrameCounter % 60 == 0) Sound::playSample("data/sounds/alarm.wav"); if (myFrameCounter >= BLOW_TIME) { Sound::playSample("data/sounds/reactor_explosion.wav"); Sound::playSample("data/sounds/start.wav"); ParticleSystem* ps = new ParticleSystem(Resource::getAnimation("data/images/debris.bmp", 4), 20, 200, 20, 1, 50, 50, -float2(0.0f, 150.0f), 5.0f); ps->setPosition(getPosition(), 10.0f); mRoom->addEntity(ps); ReactorCore* core = new ReactorCore; core->setPosition(getPosition()); core->setVelocity(float2(0, -50)); mRoom->addEntity(core); remove(); } } }
void Shot::update(){ if (++mLife > 180){ setCollided(true); } if (touchesDangerousTile()){ setCollided(true); } if(hasCollided()){ if (--mCollidedTimer < 0){ remove(); //remove } return; } // move int cur_x = getPosition().x; int cur_y = getPosition().y; int floor_y, edge_x; int bumps; /* floor_y= cur_y+getHalfSize().y+5; if (mFacingDirection == Direction_Left){ edge_x=cur_x-getHalfSize().x; } else { edge_x=cur_x+getHalfSize().x; } */ if(mGravity[mShotType] == ShotType_Bullet){ setVelocity(float2(mInitialVelocity[mShotType].x*getDirection(),mInitialVelocity[mShotType].y)); } else { setVelocity(float2(mInitialVelocity[mShotType].x*getDirection(),mInitialVelocity[mShotType].y+GRAVITY*mLife)); } //setVelocity(float2(12.0f,.0f)); bumps=moveWithCollision(); if((bumps & Direction_Left) != 0 || (bumps & Direction_Right) != 0 || (bumps & Direction_Up) != 0|| (bumps & Direction_Down) != 0 ){ setCollided(true); if (mShotType == ShotType_GravityGrenade || mShotType == ShotType_Fireball) { Sound::playSample("data/sounds/grenadeexplode.wav"); } } if(!mHurtPlayer){ std::vector<Entity*> collidedEntity = mRoom->checkEntitiesForCollision(this); if(collidedEntity.size() > 0){ setCollided(true); if (mShotType == ShotType_GravityGrenade || mShotType == ShotType_Fireball) { Sound::playSample("data/sounds/grenadeexplode.wav"); } for(int i=0;i<collidedEntity.size();i++){ attack(collidedEntity[i]); } } } else { Hero* h = mRoom->getHero(); Entity::CollisionRect cr= h->getCollisionRect(); if(Collides(getCollisionRect(),cr)){ setCollided(true); if (mShotType == ShotType_GravityGrenade || mShotType == ShotType_Fireball) { Sound::playSample("data/sounds/grenadeexplode.wav"); } if(mShotType == ShotType_Fireball || mShotType == ShotType_Bullet){ h->die(); return; } if(mShotType == ShotType_GravityGrenade){ attack(h); return; } } } mFrame++; }