Example #1
0
static void kill_enemy( ENEMY *e )
{
  player_score += get_points( e->type );

  new_explosion( e->current->x, e->current->y, BIG ); 

  remove_enemy( e );
}
Example #2
0
static void
missile_explode_asteroid(MISSILE *missile, ASTEROID *asteroid)
{
  missile->active = false;
  score(asteroid->points);

  new_explosion(missile->position);
  explode_asteroid(asteroid);
}
Example #3
0
static void
check_saucer_asteroid_collisions(LEVEL *level)
{
  if(!level->saucer)
    return;

  LIST *head = list_first(level->asteroids);
  while(head && level->saucer) {
    ASTEROID *a = (ASTEROID *) head->data;

    if(saucer_asteroid_collision(level->saucer, a)) {
      new_explosion(a->position);
      explode_asteroid(a);
      saucer_free(level->saucer);
      level->saucer = NULL;
    }

    head = head->next;
  }
}
Example #4
0
static void
check_ship_missile_saucer_collisions(LEVEL *level, SHIP *ship)
{
  if(!level->saucer)
    return;

  LIST *head = list_first(ship->missiles);
  while(head) {
    MISSILE *m = (MISSILE *) head->data;

    if(ship_missile_saucer_collision(m, level->saucer)) {
      new_explosion(level->saucer->position);
      saucer_free(level->saucer);
      level->saucer = NULL;
      break;
    }

    head = head->next;
  }
}
Example #5
0
void ship_hit( SIDE side )
{
  static Uint32 last_hit = 0;

  if( last_hit == 0 ) {
    last_hit = SDL_GetTicks();

  } else {
    if( last_hit + SHIP_HIT_TIMEOUT > SDL_GetTicks() )
      return;
    else
      last_hit = SDL_GetTicks();
  }

  new_explosion( ship.current->x, ship.current->y, SMALL );
  ship.hp -= 2;

  if( ship.hp <= 0 ) {
    game_over();
  }
}
Example #6
0
// modify_scene modifies the global variables g_projectiles and g_explosions
// during the course of an attack sequence.  It takes a parameter dt which
// represents the amount of time between frames.
// Return: the number of items left to animate.
int modify_scene(float dt)
{
    int i, j, num_impacted;
    float t;
    struct Projectile *p;
    struct Explosion *e;
    struct Tank *tank;
    Vector v;
    float d;

    // Go through all the explosions and update them according to the
    // amount of time passed.
    for(j = 0; j < g_num_explosions; j++)
    {
        e = &g_explosions[j];
        t = update_explosion(e, dt);
    }

    // Go through all the projectiles and handle the ones that have not yet
    // been impacted.
    for(j = 0, num_impacted = 0; j < g_num_projectiles; j++)
    {
        p = &g_projectiles[j];
        if(p->o.state != STATE_IMPACTED)
        {
            t = update_projectile(p, dt);
            if(p->o.state == STATE_IMPACTED)
            {
                printf("Projectile %d has impacted.\n", j);
                // If the projectile has impacted, an explosion needs to be
                // created which is appropriate to the projectile which has
                // impacted, and which takes on properties of the former
                // projectile.
                e = new_explosion(p);

                // Now, using the remaining time that did not get used on the
                // projectile, update the new explosion.
                t = update_explosion(e, dt - t);

                // And play a sound to match
                sx3_play_sound(SX3_AUDIO_EXPLOSION);
            }
        }
        if(p->o.state == STATE_IMPACTED) num_impacted++;
    }

    // FIX ME!! These two checks don't work properly if we have a low
    // framerate.
    for(j = 0; j < g_num_explosions; j++)
    {
        e = &g_explosions[j];
        for(i = 0; i < g_num_tanks; i++)
        {
            tank = &g_tanks[i];
            // Don't check this tank if it's already been hit
            // FIX ME!! This should be on a per-projectile/explosion basis
            if(tank->s.temp_damage != 0.0) continue;

            // Find the distance between the tank and the explosion, and test
            vv_cpy(v, tank->o.props.position);
            vv_sub(v, e->props.position);
            d = v_mag(v);

            if(d < tank->o.props.radius + e->props.radius)
            {
                // A tank has been hit!
                sx3_play_sound(SX3_AUDIO_HIT);
                printf("Tank %d hit by explosion %d\n", i, j);
                // FIX ME!! This should not be constant damage.
                tank->s.temp_damage = 20.0;
            }
        }
    }

    for(j = 0; j < g_num_projectiles; j++)
    {
        p = &g_projectiles[j];
        if(p->o.state == STATE_IMPACTED) continue;
        for(i = 0; i < g_num_tanks; i++)
        {
            tank = &g_tanks[i];
            // Don't check this tank if it's already been hit
            // FIX ME!! This should be on a per-projectile/explosion basis
            if(tank->s.temp_damage != 0.0) continue;

            // Find the distance between the tank and the projectiles, and test
            vv_cpy(v, tank->o.props.position);
            vv_sub(v, p->o.props.position);
            d = v_mag(v);

            if(d < tank->o.props.radius + p->o.props.radius)
            {
                // A tank has been hit!
                sx3_play_sound(SX3_AUDIO_HIT);
                printf("Tank %d hit by projectile %d\n", i, j);
                // FIX ME!! This should not be constant damage.
                tank->s.temp_damage = 40.0;
            }
        }
    }
    return g_num_explosions + g_num_projectiles - num_impacted;
}