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++;
}
Example #3
0
void Spike::update()
{
 	Hero* hero = mRoom->getHero();
	
	if (Collides(hero->getCollisionRect(), getCollisionRect()))
	{
		hero->kill();
	}
}
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 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++;
	

}