Ejemplo n.º 1
0
/**
 * \brief Function called when the tnt exploses.
 * \param give_score Indicates if we give score.
 */
void rp::tnt::explose(bool give_score)
{ 
  if ( ! m_explosed  )
    {
      set_transportability(false);
      kill_interactive_item();

      if ( give_score ) 
        util::create_floating_score(*this,500);
      
      set_can_move_items(false);
      m_explosed = true;
      start_model_action("explose");
      set_mass(std::numeric_limits<double>::infinity());
      
      create_explosion(3,0); 
    }
} // tnt::explose()
Ejemplo n.º 2
0
// Marks an entity inactive so it's not updated
void destroy_entity(Entity *e) {
	// Allocate points and play sounds
	if (e->shot_by) {
		e->shot_by->points += e->points;

		int points = g_player1->points;
		if (points == FIRSTBLOOD_POINTS && points < MEGAKILL_POINTS) {
			play_sound(g_firstblood_snd, &g_firstblood_snd_played, false);
		} else if (points > MEGAKILL_POINTS && points < ULTRAKILL_POINTS) {
			play_sound(g_megakill_snd, &g_megakill_snd_played, false);
		} else if (points > ULTRAKILL_POINTS && points < RAMPAGE_POINTS) {
			play_sound(g_ultrakill_snd, &g_ultrakill_snd_played, false);
		} else if (points > RAMPAGE_POINTS && points < GODLIKE_POINTS) {
			play_sound(g_rampage_snd, &g_rampage_snd_played, false);
		} else if (points > GODLIKE_POINTS && e != g_boss) {
			play_sound(g_godlike_snd, &g_godlike_snd_played, false);
		}

		// Explosion
		if (e->type != E_EXPLOSION) {
			(void) create_explosion(e);
			if (e->type == E_BOSS_ENEMY) {
				printf("hi");
			}
		}
	}

	// Endgame state if player is hit or boss dies
	if ((!g_player1->lives && g_player1->active && !g_player2->lives && g_player2->active) || \
			(!g_player1->lives && !g_player2->active || !g_player2->lives && !g_player1->active)) {
		g_gameover = true;
		play_sound(g_die_snd, &g_die_snd_played, false);
	}
	if (e == g_boss) {
		g_gameover = true;
		play_sound(g_holyshit_snd, &g_holyshit_snd_played, false);
		// Disable both players
		g_player1->active = false;
		g_player2->active = false;
	}

	// Mark inactive
	e->active = false;
}
Ejemplo n.º 3
0
/**
 * \brief Create the third explosion.
 */
void rp::tnt::create_third_explosion()
{ 
  create_explosion(6,20);
} // tnt::create_third_explosion()
Ejemplo n.º 4
0
/**
 * \brief Create the second explosion.
 */
void rp::tnt::create_second_explosion()
{ 
  create_explosion(5,10);
  create_planks("tnt");
} // tnt::create_second_explosion()
Ejemplo n.º 5
0
int main(int argc, char* args[])
{
    bool loop = true;
    srand(time(0));
    SDL_Event event;
    int ticks;
    int mouseX, mouseY;
    init();
    SDL_Surface *text = NULL;
    stringstream ss;
    Block newBlock(0, 0, 16, 16);
    Block drawBlock(0, 0, 16, 16);
    list<Block> blockList;
    list<Block>::iterator it_Block;
    list<Bullet> bulletList;
    list<Bullet>::iterator it_Bullet;
    list<Explosion> explosionList;
    list<Explosion>::iterator it_Explosion;

    for (int i = 0; i < LEVEL_WIDTH / 16; i++)
    {
        newBlock.rect.y = SCREEN_HEIGHT - 16;
        newBlock.rect.x = i * 16;
        blockList.push_back(newBlock);
        if (i % 3 == 0)
        {
            newBlock.rect.y = SCREEN_HEIGHT - 32;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
        }
        if (i % 3 == 0)
        {
            newBlock.rect.y = SCREEN_HEIGHT - 48;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 64;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 80;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 96;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 112;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 128;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 144;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 160;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 176;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 192;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 208;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 224;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 240;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 256;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 272;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 288;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
            newBlock.rect.y = SCREEN_HEIGHT - 304;
            newBlock.rect.x = i * 16;
            blockList.push_back(newBlock);
        }

    }
    if (true) //load surfaces
    {
        playerImage = load_image("playerImage.bmp");
        bullet1Image = load_image("bullet1.bmp");
        bullet2Image = load_image("bullet2.bmp");
        bullet3Image = load_image("bullet3.bmp");
        explosion1 = load_image("explosion/01.bmp", true, 255, 255, 255);
        explosion2 = load_image("explosion/02.bmp", true, 255, 255, 255);
        explosion3 = load_image("explosion/03.bmp", true, 255, 255, 255);
        explosion4 = load_image("explosion/04.bmp", true, 255, 255, 255);
        blockImage = load_image("blockImage.bmp");
        inventoryImage = load_image("inventoryImage.bmp");
    }
    Player player(32, SCREEN_HEIGHT - 32, 16, 16);
    while (loop)
    {
        ticks = SDL_GetTicks();
        //Handle Events
        while (SDL_PollEvent(&event))
        {
            if (event.type == SDL_QUIT)
            {
                loop = false;
            }
            if (event.type == SDL_KEYDOWN)
            {
                if (event.key.keysym.sym == SDLK_w)
                {
                    bool jumped = false;
                    for (it_Block = blockList.begin(); it_Block != blockList.end(); it_Block++)
                    {
                        if (player.check_collision(it_Block->rect, 0, 1))
                        {
                            player.ySpeed = -8;
                            jumped = true;
                        }
                    }
                    if (!jumped)
                    {
                        for (it_Block = blockList.begin(); it_Block != blockList.end(); it_Block++)
                        {
                            if (player.check_collision(it_Block->rect, 1, 0))
                            {
                                player.ySpeed = -8;
                                player.xSpeed = -8;
                                jumped = true;
                            }
                        }
                    }
                    if (!jumped)
                    {
                        for (it_Block = blockList.begin(); it_Block != blockList.end(); it_Block++)
                        {
                            if (player.check_collision(it_Block->rect, -1, 0))
                            {
                                player.ySpeed = -8;
                                player.xSpeed = 8;
                                jumped = true;
                            }
                        }
                    }
                }
                if (event.key.keysym.sym == SDLK_SPACE)
                {
                    player.shoot(mouseX, mouseY, &bulletList);
                }
            }
            if (event.type == SDL_MOUSEBUTTONDOWN)
            {
                if (event.button.button == SDL_BUTTON_RIGHT)
                {
                    player.next_gun();
                }
                if (event.button.button == SDL_BUTTON_WHEELDOWN)
                {
                    if (player.power >= 6)
                        player.power -= 5;
                    else
                        player.power = 1;
                }
                if (event.button.button == SDL_BUTTON_WHEELUP)
                {
                    if (player.power == 1)
                        player.power = 5;
                    else if (player.power <= 95)
                        player.power += 5;
                    else
                        player.power = 100;
                }
            }
        }
        //Game Logic
        Uint8 *keyStates = SDL_GetKeyState(NULL);
        SDL_GetMouseState(&mouseX, &mouseY);

        player.move(keyStates);
        player.gravity();
        player.step();
        player.block_collision(blockList);

        for (it_Bullet = bulletList.begin(); it_Bullet != bulletList.end(); it_Bullet++)
        {
            it_Bullet->step();
            it_Bullet->gravity();
            for (it_Block = blockList.begin(); it_Block != blockList.end(); it_Block++)
            {
                if (it_Bullet->check_collision(it_Block->rect))
                {
                    if (it_Bullet->explode)
                    {
                        create_explosion(it_Bullet->rect.x - 8, it_Bullet->rect.y - 8, &explosionList);
                        it_Block = blockList.erase(it_Block);
                    }
                    it_Bullet = bulletList.erase(it_Bullet);
                }
            }
        }
        //Clear screen
        SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 255, 255, 255));
        //Draw to screen
        player.draw();
        bulletList.remove_if(bullet_dead);
        explosionList.remove_if(explosion_dead);
        for (it_Block = blockList.begin(); it_Block != blockList.end(); it_Block++)
        {
            it_Block->draw();
        }
        for (it_Bullet = bulletList.begin(); it_Bullet != bulletList.end(); it_Bullet++)
        {
            it_Bullet->draw();
        }
        for (it_Explosion = explosionList.begin(); it_Explosion != explosionList.end(); it_Explosion++)
        {
            it_Explosion->draw();
        }
        //Draw inventory and status bars
        draw_inventory(player);

        //Show screen
        SDL_Flip(screen);

        if (SDL_GetTicks() - ticks < 1000 / FPS)
        {
            SDL_Delay((1000 / FPS) - (SDL_GetTicks() - ticks));
        }
    }
    if (true) //free surfaces
    {
        SDL_FreeSurface(playerImage);
        SDL_FreeSurface(bullet1Image);
        SDL_FreeSurface(bullet2Image);
        SDL_FreeSurface(bullet3Image);
        SDL_FreeSurface(explosion1);
        SDL_FreeSurface(explosion2);
        SDL_FreeSurface(explosion3);
        SDL_FreeSurface(explosion4);
        SDL_FreeSurface(blockImage);
        SDL_FreeSurface(inventoryImage);
        SDL_FreeSurface(text);
        TTF_CloseFont(font);
    }

    //quit SDL
    TTF_Quit();
    SDL_Quit();
    return 0;
}