Exemplo n.º 1
0
static void movement_calc(void *o)
{
	struct missile *m = o;
	float target_dist = FLT_MAX;
	if (m->target != NULL) {
		target_dist = vector_magnitude(m->pos, m->target->pos);
		target_dist -= m->hb[0].rad;
		target_dist -= m->target->hb[0].rad;
	}
	if (	(m->life_time != 0 && 
		get_tick_count() - m->init_time > m->life_time) ||
		(m->frag && target_dist < 0.05*world_scale)
		) {
		if (m->frag) {
			missile_frag(m);
		}
		if (m->target != NULL) {
			remove_reset_ptr((void*)m->target, &m->target);
		}
		m->is_alive = false;
		explode(m);
		return;
	}
	if (m->target == NULL) {
		remove_reset_ptr((void*)m->target, &m->target);
		if (!m->dumb) {
			m->target = acquire_target(m->firer);
			if (m->target != NULL) {
				puts("required target");
			}
		}
		return;
	}
	if (	!m->target->is_alive ||
		!timed_out_r(&m->last_ctrl_tick, CTRL_RATE)) {
		return;
	}
	float dx = -m->target->pos.x + m->pos.x;
	float dy = +m->target->pos.y - m->pos.y;
	float old_rot = m->rotation;
	m->rotation = rad_to_degd(atan2(dx, dy));
	const float MAX_ROT = 10;
	if (old_rot > m->rotation) {
		if (old_rot - m->rotation > MAX_ROT ||
			fmod(360 + old_rot - m->rotation, 360) > MAX_ROT) {
			m->rotation = old_rot - MAX_ROT;
		}
	} else {
		if (m->rotation - old_rot  > MAX_ROT ||
			fmod(360 + m->rotation - old_rot, 360) > MAX_ROT) {
			m->rotation = old_rot + MAX_ROT;
		}
	}
	float mag = xy_magnitude(m->vel.x, m->vel.y);
	m->vel.x = vector_x(mag, 180 + m->rotation);
	m->vel.y = vector_y(mag, m->rotation);
	m->accel = 0;
}
trafficlights::trafficlights(Subject * aVehicle, QGraphicsItem *parent): QObject(), QGraphicsPixmapItem(parent)
{
    setUp();
    QTimer * timer = new QTimer();
    connect(timer,SIGNAL(timeout()),this,SLOT(acquire_target()));
    timer->start(50);
    destination= QPointF(800,0);
    traffic_light_concurrency_timer();

}
Exemplo n.º 3
0
void missile_init(struct missile *m, struct phys_obj *p, double speed,
		  float accel, float rad, unsigned long long life_time,
		  int fragments, bool fins, bool frag, bool dumb,
		  enum explosion_type e)
{
	zero_missile_init(m, fins, frag, dumb, accel, rad);
	m->pos = p->pos;
	m->pos.y += vector_y(0.2*world_scale, p->rotation);
	m->pos.x -= vector_x(0.2*world_scale, p->rotation);
	m->vel = p->vel;
	m->vel.x -= vector_x(speed, p->rotation);
	m->vel.y += vector_y(speed, p->rotation);
	m->rotation = p->rotation;
	m->target = dumb ? NULL : acquire_target(p);
	if (m->target != NULL) {
		add_reset_ptr((void*)m->target, &m->target);
	}
	m->init_time = get_tick_count();
	m->last_ctrl_tick = get_tick_count();
	m->life_time = life_time;
	m->fragments = fragments;
	m->firer = p;
	m->explosion_type = e;
}
Exemplo n.º 4
0
void run_actors(void)
{
 int i;

 for (i = 0; i < NO_ACTORS; i ++)
 {
  if (actor[i].type == ACTORTYPE_NONE)
   continue;
  if (actor[i].in_play == 0)
  {
   
   actor[i].x_speed = 0;
   actor[i].y_speed = 0;
   if (actor[i].spawn_delay > 0)
   {
    actor[i].spawn_delay --;
    continue;
   }
   if (game.ships_left > 0)
   {
    if (arena.game_over == 0)
     spawn_actor(i); // ships_left will be non-zero for time attack games.
   } 
     else
      continue;
  }
//  actor[i].energy += actor[i].recharge;
//  if (actor[i].energy >= actor[i].max_energy)
//   actor[i].energy = actor[i].max_energy;

   if (actor[i].screen_shake_time > 0)
   {
    if (actor[i].screen_shake_time > 4)
    {
     player[actor[i].controller].screen_shake_x = grand(7501) - 3250;
     player[actor[i].controller].screen_shake_y = grand(7501) - 3250;
    }
     else
     {
      player[actor[i].controller].screen_shake_x = grand(3500) - 1750;
      player[actor[i].controller].screen_shake_y = grand(3500) - 1750;
     } 
    actor[i].screen_shake_time --;
   }
    else
    {
     player[actor[i].controller].screen_shake_x = 0;
     player[actor[i].controller].screen_shake_y = 0;
    }
// screen_shake needs to be first, as many things below can affect it and we don't want them wiped.
   
  if (actor[i].repairing > 0)
  {
   actor[i].repairing --;
   if (actor[i].armour < actor[i].max_armour)
    actor[i].armour += 5;
   if (actor[i].armour > actor[i].max_armour)
    actor[i].armour = actor[i].max_armour;
// + play a sound?
  }

  if (actor[i].ship == SHIP_ROUND && counter % 7 == 0)
  {
   if (actor[i].armour < actor[i].max_armour)
    actor[i].armour += 1;
  }


  if (actor[i].grace_period > 0)
   actor[i].grace_period --;
  if (actor[i].hurt_pulse > 0)
   actor[i].hurt_pulse --;
  if (actor[i].recycle1 > 0)
   actor[i].recycle1 --;
  if (actor[i].recycle2 > 0)
   actor[i].recycle2 --;
   
  if (actor[i].turret_recycle > 0)
   actor[i].turret_recycle --;
  if (actor[i].sidekick_recycle > 0)
   actor[i].sidekick_recycle --;
  if (actor[i].heavy_recycle > 0)
   actor[i].heavy_recycle --;
  if (actor[i].backfire_recycle > 0)
   actor[i].backfire_recycle --;
   
  if (actor[i].secondary_burst > 0)
   continue_secondary_burst(i); 
   
  if (actor[i].just_upgraded_timeout > 0)
   actor[i].just_upgraded_timeout --;
  if (actor[i].just_collided > 0)
   actor[i].just_collided --;
  move_actor(i);
  detect_collision_actor_enemies(i);
  detect_collision_actor_pickups(i);
  if (actor[i].upgraded_system [UPG_SEEKER] > 0)
   acquire_target(i);
//  if (actor[i].upgraded_system [UPG_TURRET] > 0)
//   acquire_turret_target(i);
//  if (actor[i].ship == SHIP_ORBITAL && actor[i].total_power > 0)
//   actor_orbital(i);
  if (actor[i].ability [ABILITY_DEFENCE] [SYMBOL_CIRCLE] > 0)
   actor_shield(i);
//  if (actor[i].upgraded_system [UPG_SIDEKICK] > 0)
//   actor_sidekicks(i);
  if (actor[i].drive_sound [DRIVE_THRUST] > 0)
   actor[i].drive_sound [DRIVE_THRUST] --;
  if (actor[i].drive_sound [DRIVE_SLIDE] > 0)
   actor[i].drive_sound [DRIVE_SLIDE] --;
  if (actor[i].drive_sound [DRIVE_RETRO] > 0)
   actor[i].drive_sound [DRIVE_RETRO] --;
 }

}