Esempio n. 1
0
// player death
void player_die(Player *p, Bullet *bullets)
{
	spawn_explosion(bullets, p->exact_pos.x, p->exact_pos.y, 300, 0xFF0000);
	spawn_explosion(bullets, p->exact_pos.x, p->exact_pos.y, 300, 0xFFFFFF);
	spawn_explosion(bullets, p->exact_pos.x, p->exact_pos.y, 300, 0xFFFF00);


	p->exact_pos.x = DISPLAY_WIDTH/2;
	p->exact_pos.y = DISPLAY_HEIGHT/2;
	p->hp = p->max_hp;

	// probably temp; calc some stats
	p->total_kills += p->kills;
	p->total_kills_squared += p->kills * p->kills;
	p->deaths++;
	float mean = (float)p->total_kills/(float)p->deaths;
	float stddev = sqrt(p->total_kills_squared/p->deaths - mean*mean);
	printf("\n*** Kills ***\nThis round: %i\nTotal: %i\nAverage: %f\nStandard Deviation: %f\n\n",p->kills,p->total_kills, mean, stddev);
	p->kills = 0;
}
Esempio n. 2
0
void game_state::check_collisions( void )
{
    for( size_t i = explosions.size(); i > 0; --i )
    {
        position explosion_pos = explosions[i-1]->getPos();
        float explosion_radius = explosions[i-1]->getRadius();
        for( size_t j = tanks.size(); j > 0; --j )
        {
            if( explosion_pos.dist( tanks[ j - 1 ]->getPos() ) < explosion_radius )
            {
                spawn_explosion( tanks[ j - 1 ]->getPos() );
                destroy_tank( j - 1 );
            }
        }
    }
}
Esempio n. 3
0
void game_state::check_bullets( void )
{
    for( size_t b = bullets.size(); b > 0; --b )
    {
        for( size_t t = tanks.size(); t > 0; --t )
        {
            if( collision( *bullets[b-1], *tanks[t-1] ) )
            {
                spawn_explosion( bullets[ b - 1 ]->getPos() );
                destroy_tank( t - 1 );
                destroy_bullet( b - 1 );
                break;
            }
        }
    }
}
Esempio n. 4
0
/*----------------------------------------------------------------------------*/
void  use_bomb_powerup(void)
{
    Mix_Volume(-1,(game.config.Audio_Sound_Volume/2));
    if (!boss_level())
    {
        for (int npc_count = 0; npc_count < MAX_NPCS; npc_count++) //kill all npcs
        {
            sound.explosion_005.play();
            if (game_o.npc[npc_count].active)
            {
                int random_temp = random_int();
                if (random_temp <= game_o.coin_spawn_rate) //spawn coin
                {
                    spawn_coin(game_o.npc[npc_count].x_pos,game_o.npc[npc_count].y_pos,(game_o.npc[npc_count].type_npc+1+random_dec()));
                }
                if ((random_temp > game_o.coin_spawn_rate) && (random_temp <= game_o.wexp_spawn_rate)) //spawn wexp
                {
                    spawn_wexp(game_o.npc[npc_count].x_pos,game_o.npc[npc_count].y_pos,(game_o.npc[npc_count].type_npc+1+random_dec()));
                }
                if (random_temp > game_o.wexp_spawn_rate) //spawn null
                {
                    ;
                }
                game_o.score += (game_o.npc[npc_count].type_npc + 1) * 10;
                game_o.level_score += (game_o.npc[npc_count].type_npc + 1) * 10;
                spawn_explosion(game_o.npc[npc_count].x_pos,game_o.npc[npc_count].y_pos,0.50f);
                kill_npc(npc_count);
                game_o.kills++;
                game_o.level_kills++;
            }
        }
    }
    if (boss_level())
    {
        for (int npc_count = 0; npc_count < MAX_NPCS; npc_count++) //damage all npcs
        {
            sound.explosion_005.play();
            if (game_o.npc[npc_count].active)
            {
                game_o.npc[npc_count].health -= (game_o.enemy[game_o.npc[npc_count].type_npc].health/10);
                if (game_o.npc[npc_count].health <= 0)
                {
                    kill_npc(npc_count);
                    game_o.kills++;
                    game_o.level_kills++;
                }
            }
        }
    }
    for (int npc_count = 0; npc_count < MAX_NPCS; npc_count++)//kill all npc bullets
    {
        for (int bullet_count = 0; bullet_count < MAX_BULLETS-1; bullet_count++)
        {
            if (game_o.npc[npc_count].bullet[bullet_count].active)
            {
                spawn_explosion(game_o.npc[npc_count].bullet[bullet_count].x_pos,game_o.npc[npc_count].bullet[bullet_count].y_pos,0.125f);
                kill_npc_bullet(npc_count,bullet_count);
                kill_npc_bullet(npc_count,bullet_count);
            }
        }
    }
    Mix_Volume(-1,game.config.Audio_Sound_Volume);
}
Esempio n. 5
0
void world::update(int dt)
{
    m_net_data_updated = false;

    if (m_network)
    {
        m_network->update();

        network_interface::msg_add_plane mp;
        while (m_network->get_add_plane_msg(mp))
            add_plane(mp.preset.c_str(), mp.player_name.c_str(), mp.color, false, m_network->add_plane(mp));

        network_interface::msg_add_missile mm;
        while (m_network->get_add_missile_msg(mm))
        {
            auto net = m_network->get_plane(mm.plane_id);
            if (!net)
                continue;

            for (auto &p: m_planes)
            {
                if(p->net != net)
                    continue;

                p->special_weapon_selected = mm.special;
                add_missile(p, m_network->add_missile(mm));
                break;
            }
        }

        network_interface::msg_game_data md;
        while (m_network->get_game_data_msg(md))
        {
            auto net = m_network->get_plane(md.plane_id);
            if (!net)
                continue;

            for (auto &p: m_planes)
            {
                if(p->net != net)
                    continue;

                p->net_game_data = md.data;
                break;
            }

            m_net_data_updated = true;
        }

        std::string str;
        while(m_network->get_general_msg(str))
        {
            std::istringstream is(str);
            std::string cmd;
            is >> cmd;

            if (cmd == "explosion")
            {
                vec3 pos; float r;
                read(is, pos), is >> r;
                spawn_explosion(pos, r, false);
            }

            if (is_host())
            {
                if (cmd == "plane_take_damage")
                {
                    unsigned int plane_id; int damage;
                    is >> plane_id, is >> damage;

                    auto net = m_network->get_plane(plane_id);
                    if (!net)
                        continue;

                    for (auto &p: m_planes)
                    {
                        if(p->net != net)
                            continue;

                        p->take_damage(damage, *this, false);
                        break;
                    }
                }
            }
            else
            {
                if (cmd == "respawn")