示例#1
0
/**************************************************************************************
                                VERIFY WIN/LOSE CONDITION
 **************************************************************************************/
void verifyWinLose() {
    if(score_points >= WIN_CONDITION) {
        end_game = GL_TRUE;
    }
    
    if(end_game) {
        game_speed = 0.0f;
        move_text(score_txtLabel, -0.15, 0.2f);
        if(score_points >= WIN_CONDITION) {
            score = "You WIN!";
            hero.win(dt);
        } else {
            score = "You LOSE!";
            if(jumps == 0) {
                hero.setVelocity(60.0f);
                jumps++;
            }
            for(int i=0; i<NUMBER_OF_MONSTERS; i++)
                monster[i].stop = 0.0f;
            hero.die(dt);
            if(camera_loops < 1 && hero.died) {
                camera.setSpeedRotation(3.0f);
                camera.rotation360();
                camera_loops++;
            }
        }
    }
}
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++;
	

}