Esempio n. 1
0
// Machinegun
void actorMachineGun (edict_t *self)
{
	vec3_t	start, target;
	vec3_t	forward, right, up;
	int		damage;

	if(!self->enemy || !self->enemy->inuse) {
		self->monsterinfo.pausetime = 0;
		return;
	}

	AngleVectors (self->s.angles, forward, right, up);
	G_ProjectSource2 (self->s.origin, self->muzzle, forward, right, up, start);
	ActorTarget(self,target);
	VectorSubtract (target, start, forward);
	VectorNormalize (forward);

	if(self->monsterinfo.aiflags & AI_TWO_GUNS)
		damage = 2;
	else
		damage = 4;

	fire_bullet (self, start, forward, damage, 2, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);

	gi.WriteByte(svc_temp_entity);
	gi.WriteByte(TE_CHAINFIST_SMOKE);
	gi.WritePosition(start);
	gi.multicast(start, MULTICAST_PVS);
	gi.positioned_sound(start,self,CHAN_WEAPON,gi.soundindex(va("weapons/machgf%db.wav",self->actor_gunframe % 5 + 1)),1,ATTN_NORM,0);

	if(self->flash)
	{
		VectorCopy(start,self->flash->s.origin);
		self->flash->think = muzzleflash_think;
		self->flash->wait  = level.time + FRAMETIME;
		self->flash->think(self->flash);
	}

	if(developer->value)
		TraceAimPoint(start,target);

	if(self->monsterinfo.aiflags & AI_TWO_GUNS)
	{
		G_ProjectSource2 (self->s.origin, self->muzzle2, forward, right, up, start);
		ActorTarget(self,target);
		VectorSubtract (target, start, forward);
		VectorNormalize (forward);
		fire_bullet (self, start, forward, damage, 2, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
		gi.WriteByte(svc_temp_entity);
		gi.WriteByte(TE_CHAINFIST_SMOKE);
		gi.WritePosition(start);
		gi.multicast(start, MULTICAST_PVS);
	}
}
Esempio n. 2
0
void fire_bullet_ang(struct moag *m, char type, int x, int y, float angle, float vel)
{
    fire_bullet(m, type, (float)x + 5.0 * cosf(DEG2RAD(angle)),
                         (float)y - 5.0 * sinf(DEG2RAD(angle)),
                         vel * cosf(DEG2RAD(angle)),
                        -vel * sinf(DEG2RAD(angle)));
}
Esempio n. 3
0
//FIXME mosnters should call these with a totally accurate direction
// and we can mess it up based on skill.  Spread should be for normal
// and we can tighten or loosen based on skill.  We could muck with
// the damages too, but I'm not sure that's such a good idea.
void monster_fire_bullet (edict_t *self, vec3_t start, vec3_t dir, int damage, int kick, int hspread, int vspread, int flashtype)
{
	float chance;

	// holy freeze reduces firing rate by 50%
	if (que_typeexists(self->curses, AURA_HOLYFREEZE))
	{
		if (random() <= 0.5)
			return;
	}

	// chill effect reduces attack rate/refire
	if (self->chill_time > level.time)
	{
		chance = 1 / (1 + CHILL_DEFAULT_BASE + CHILL_DEFAULT_ADDON * self->chill_level);
		if (random() > chance)
			return;
	}

	damage = monster_increaseDamageByTalent(self->activator, damage);	
	fire_bullet (self, start, dir, damage, kick, hspread, vspread, MOD_UNKNOWN);

	gi.WriteByte (svc_muzzleflash2);
	gi.WriteShort (self - g_edicts);
	gi.WriteByte (flashtype);
	gi.multicast (start, MULTICAST_PVS);
}
Esempio n. 4
0
//FIXME mosnters should call these with a totally accurate direction
// and we can mess it up based on skill.  Spread should be for normal
// and we can tighten or loosen based on skill.  We could muck with
// the damages too, but I'm not sure that's such a good idea.
void monster_fire_bullet(edict_t *self, vec3_t start, vec3_t dir, int damage, int kick, int hspread, int vspread, int flashtype){
	fire_bullet(self, start, dir, damage, kick, hspread, vspread, MOD_UNKNOWN);
	
	gi.WriteByte(svc_muzzleflash2);
	gi.WriteShort(self - g_edicts);
	gi.WriteByte(flashtype);
	gi.multicast(start, MULTICAST_PVS);
}
Esempio n. 5
0
void teclado(char **nomes, int side)
{
   int c;

   /**Contador para respeitar mintshoot**/
   contador=0;

   /**ponderar verificar check dead no servidor*/
   while (!quit)
   {
      /**SE DEAD, espera por confirmacao do servidor(?)*/
      lock(&actualiza);
      lock(&ecra);
      c = getch();
      switch(c)
      {
         case 'w':
         case KEY_UP:
            move_cowboy_up(nomes, side, &cowboys[side].sfd);
            break;

         case 's':
         case KEY_DOWN:
            move_cowboy_down(nomes, side, &cowboys[side].sfd);
            break;

         case ' ':
         /**So envio se tiver balas disponiveis*/
            /**BLOQUEAR ACESSO!*/
            if (cowboys[side].bulletsleft && !contador)
            {
               /**Para se dar inicio à contagem*/
               contador++;
               fire_bullet( nomes, side, &cowboys[side].sfd);
            }
            break;

         case 'q':
            inicia_saida(nomes[PID], &cowboys[side].sfd, side);
            quit = 1;
            break;
         case 'a':

            break;

         break;
      }

      /**Assim que atinge mintshoot para contagem e mantem valor zero*/
      if(contador)
         contador=(contador+1)%mintshoot;

      unlock(&actualiza);
      unlock(&ecra);
   }

}
Esempio n. 6
0
void timer_update(struct moag *m, int id)
{
    struct timer *t = &m->timers[id];
    if (t->frame && t->frame <= m->frame)
    {
        fire_bullet(m, t->type, t->x, t->y, t->vx, t->vy);
        t->frame = 0;
    }
}
Esempio n. 7
0
// Willi
void Shrapnel_Explode (edict_t *ent)
{
    vec3_t origin;     
    vec3_t grenade1;
    vec3_t grenade2;
    vec3_t grenade3;
    vec3_t grenade4;
    vec3_t grenade5;
    vec3_t grenade6;
    vec3_t grenade7;
    vec3_t grenade8;
    int    mod;
    int    i;
    vec3_t offset;

    if (ent->owner->client)
        PlayerNoise(ent->owner, ent->s.origin, PNOISE_IMPACT);

    VectorSet(offset,0,0,32);
    VectorAdd(offset,ent->s.origin,offset);
    VectorCopy (offset, ent->s.origin);
    VectorSet(grenade1,20,20,5);
    VectorSet(grenade2,20,-20,5);
    VectorSet(grenade3,-20,20,5);
    VectorSet(grenade4,-20,-20,5);
    VectorSet(grenade5,0,20,5);
    VectorSet(grenade6,0,-20,5);
    VectorSet(grenade7,-20,0,5);
    VectorSet(grenade8,20,0,5);
    for (i = 0; i < 6; i++) 
    {
        fire_bullet (ent, offset, grenade1, 2, 2, 4500, 4500, MOD_G_SPLASH);
        fire_bullet (ent, offset, grenade2, 2, 2, 4500, 4500, MOD_G_SPLASH);
        fire_bullet (ent, offset, grenade3, 2, 2, 4500, 4500, MOD_G_SPLASH);
        fire_bullet (ent, offset, grenade4, 2, 2, 4500, 4500, MOD_G_SPLASH);
        fire_bullet (ent, offset, grenade5, 2, 2, 4500, 4500, MOD_G_SPLASH);
        fire_bullet (ent, offset, grenade6, 2, 2, 4500, 4500, MOD_G_SPLASH);
        fire_bullet (ent, offset, grenade7, 2, 2, 4500, 4500, MOD_G_SPLASH);
        fire_bullet (ent, offset, grenade8, 2, 2, 4500, 4500, MOD_G_SPLASH);
    }

	Grenade_Explode (ent);
}
Esempio n. 8
0
void monster_autocannon_fire(edict_t *self)
{
	vec3_t forward, right, start;

	// fire straight ahead
	AngleVectors (self->s.angles, forward, right, NULL);
	if (self->onFloor)
		VectorNegate(right, right);
	VectorMA(self->s.origin, 24, forward, start);
	G_ProjectSource (self->s.origin, fireOffset[self->style], forward, right, start);

	if(EMPNukeCheck(self, start))
	{
		gi.sound (self, CHAN_AUTO, gi.soundindex("items/empnuke/emp_missfire.wav"), 1, ATTN_NORM, 0);
		return;
	}

	// what to fire?
	switch(self->style)
	{
	case 1:
	default:
		fire_bullet(self, start, forward, AC_BULLET_DMG, AC_BULLET_KICK, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_AUTOCANNON);
		gi.WriteByte (svc_muzzleflash);
		gi.WriteShort (self - g_edicts);
		gi.WriteByte (MZ_CHAINGUN2);
		gi.multicast (self->s.origin, MULTICAST_PVS);
		break;
	case 2:
		fire_rocket(self, start, forward, AC_ROCKET_DMG, AC_ROCKET_SPEED, AC_ROCKET_RADIUS_DMG, AC_ROCKET_DMG_RADIUS);
		gi.WriteByte (svc_muzzleflash);
		gi.WriteShort (self - g_edicts);
		gi.WriteByte (MZ_ROCKET);
		gi.multicast (self->s.origin, MULTICAST_PVS);
		break;
	case 3:
	case 4:
		fire_blaster (self, start, forward, AC_BLASTER_DMG, AC_BLASTER_SPEED, EF_HYPERBLASTER, true);
		gi.WriteByte (svc_muzzleflash);
		gi.WriteShort (self - g_edicts);
		gi.WriteByte (MZ_HYPERBLASTER);
		gi.multicast (self->s.origin, MULTICAST_PVS);
		break;
	}
}
Esempio n. 9
0
void Machinegun_Fire (edict_t *ent)
{
	int	i;
	vec3_t		start;
	vec3_t		forward, right;
	vec3_t		angles;
	int			damage = 8;
	int			kick = 2;
	vec3_t		offset;

	if (!(ent->client->buttons & BUTTON_ATTACK))
	{
		ent->client->machinegun_shots = 0;
		ent->client->ps.gunframe++;
		return;
	}

	if (ent->client->ps.gunframe == 5)
		ent->client->ps.gunframe = 4;
	else
		ent->client->ps.gunframe = 5;

	if (ent->client->inventory[ent->client->ammo_index] < 1)
	{
		ent->client->ps.gunframe = 6;
		if (level.framenum >= ent->pain_debounce_framenum)
		{
			gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
			ent->pain_debounce_framenum = level.framenum + SECS_TO_FRAMES(1);
		}
		NoAmmoWeaponChange (ent);
		return;
	}

	if (is_quad == ent)
	{
		damage *= 4;
		kick *= 4;
	}

	for (i=1 ; i<3 ; i++)
	{
		ent->client->kick_origin_final[i] = crandom() * 0.35f;
		ent->client->kick_angles_final[i] = crandom() * 0.7f;
	}
	ent->client->kick_origin_final[0] = crandom() * 0.35f;
	ent->client->kick_angles_final[0] = ent->client->machinegun_shots * -1.5f;

	ent->client->kick_origin_start = 0;
	ent->client->kick_origin_end = 0.1f * SERVER_FPS;

	// get start / end positions
	VectorAdd (ent->client->v_angle, ent->client->kick_angles_final, angles);
	AngleVectors (angles, forward, right, NULL);
	VectorSet(offset, 0, 8, ent->viewheight-8);
	P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
	fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
	TDM_WeaponFired (ent);

	gi.WriteByte (svc_muzzleflash);
	gi.WriteShort (ent-g_edicts);
	gi.WriteByte (MZ_MACHINEGUN | is_silenced);
	gi.multicast (ent->s.origin, MULTICAST_PVS);

	if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
		ent->client->inventory[ent->client->ammo_index]--;

	ent->client->anim_priority = ANIM_ATTACK;
	if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
	{
		ent->s.frame = FRAME_crattak1 - (int) (random()+0.25f);
		ent->client->anim_end = FRAME_crattak9;
	}
	else
	{
		ent->s.frame = FRAME_attack1 - (int) (random()+0.25f);
		ent->client->anim_end = FRAME_attack8;
	}
}
Esempio n. 10
0
void Chaingun_Fire (edict_t *ent)
{
	int			shots, flash_shots = 1;
	vec3_t		start;
	vec3_t		forward, right, up;
	float		r, u;
	vec3_t		offset;
	int			damage;
	int			kick = 0;
	int item = getWornItem(ent, GIEX_ITEM_WEAPON);
	iteminfo_t	*info = getWornItemInfo(ent, 0);
	int	i, spread = getMachinegunSpread(ent, item, info);

//	damage = info->arg1 + info->arg2 * ent->client->pers.skill[1];
	damage = getChaingunDamage(ent, item, info);

	if (ent->client->ps.gunframe == 5) {
		if ((ent->client->silencer_shots > 0) && (ent->client->pers.skill[58] > 6)) {
			ent->client->silencer_shots -= 1;
		} else {
			gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnu1a.wav"), 1, ATTN_IDLE, 0);
		}
		ent->client->ps.gunframe += ent->client->pers.skill[5];
	}

	if ((ent->client->ps.gunframe == 14) && !(ent->client->buttons & BUTTON_ATTACK)) {
		ent->client->ps.gunframe = 32; // End firing
		ent->client->weapon_sound = 0;
		return;
	} else if ((ent->client->ps.gunframe == 21) && (ent->client->buttons & BUTTON_ATTACK)
		&& ent->client->pers.inventory[ent->client->ammo_index]) {
		ent->client->ps.gunframe = 15; // Loop back
	} else {
		ent->client->ps.gunframe++;
	}

	if (ent->client->ps.gunframe == 22) {
		ent->client->weapon_sound = 0;
		if ((ent->client->silencer_shots > 0) && (ent->client->pers.skill[58] > 6)) {
			ent->client->silencer_shots -= 1;
		} else {
			gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnd1a.wav"), 1, ATTN_IDLE, 0);
		}
		ent->client->ps.gunframe += ent->client->pers.skill[5];
	} else {
		if ((ent->client->silencer_shots > 0) && (ent->client->pers.skill[58] > 6)) {
			ent->client->silencer_shots -= 1;
		} else {
			ent->client->weapon_sound = gi.soundindex("weapons/chngnl1a.wav");
		}
	}

	ent->client->anim_priority = ANIM_ATTACK;
	if (ent->client->ps.pmove.pm_flags & PMF_DUCKED) {
		ent->s.frame = FRAME_crattak1 - (ent->client->ps.gunframe & 1);
		ent->client->anim_end = FRAME_crattak9;
	} else {
		ent->s.frame = FRAME_attack1 - (ent->client->ps.gunframe & 1);
		ent->client->anim_end = FRAME_attack8;
	}

	if (ent->client->ps.gunframe <= 9) {
		shots = info->arg4;
	} else if (ent->client->ps.gunframe <= 14) {
		if (ent->client->buttons & BUTTON_ATTACK) {
			shots = info->arg4 + 1; flash_shots = 2;
		} else {
			shots = info->arg4; flash_shots = 1;
		}
	}
	else { // 15 - 20
		if ((ent->client->ps.gunframe == 18) || (ent->client->ps.gunframe == 20)) {
			shots = info->arg4 + 2; flash_shots = 2;
		} else {
			shots = info->arg4 + 1; flash_shots = 1;
		}
	}

	if (shots < 1)
		shots = 1;
	if (ent->client->pers.inventory[ent->client->ammo_index] < shots) {
		shots = ent->client->pers.inventory[ent->client->ammo_index];
	}

	if (!shots) {
		if (level.time >= ent->pain_debounce_time) {
			gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
			ent->pain_debounce_time = level.time + 1;
		}
		NoAmmoWeaponChange (ent);
		return;
	}

	damage = applyWeaponBonuses(ent, damage, 1);
//	if (is_quad)
//		kick *= 4;

	for (i=0 ; i<3 ; i++) {
		ent->client->kick_origin[i] = crandom() * 0.35;
		ent->client->kick_angles[i] = crandom() * 0.7;
	}

	for (i=0 ; i<shots ; i++) {
		// get start / end positions
		AngleVectors (ent->client->v_angle, forward, right, up);
		r = 7 + crandom()*4;
		u = crandom()*4;
		VectorSet(offset, 0, r, u + ent->viewheight-8);
		P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);

		fire_bullet (ent, start, forward, damage, kick, spread, spread, MOD_CHAINGUN);
	}

	// send muzzle flash
	if ((ent->client->silencer_shots > 0) && (ent->client->pers.skill[58] > 7)) {
		ent->client->silencer_shots -= shots;
	} else {
		gi.WriteByte (svc_muzzleflash);
		gi.WriteShort (ent-g_edicts);
		gi.WriteByte ((MZ_CHAINGUN1 + flash_shots) | is_silenced);
		gi.multicast (ent->s.origin, MULTICAST_PVS);
	}

	ent->client->silencer_shots-=3;
	PlayerNoise(ent, start, PNOISE_WEAPON);

//	if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
		ent->client->pers.inventory[ent->client->ammo_index] -= shots;
}
Esempio n. 11
0
void Machinegun_Fire (edict_t *ent)
{
	vec3_t		start;
	vec3_t		forward, right;
	vec3_t		angles;
	int			damage;
	int			kick = 0;
	vec3_t		offset;
	int item = getWornItem(ent, GIEX_ITEM_WEAPON);
	iteminfo_t	*info = getWornItemInfo(ent, GIEX_ITEM_WEAPON);
	int	i, spread = getMachinegunSpread(ent, item, info);

//	damage = info->arg1 + info->arg2 * ent->client->pers.skill[1];
	damage = getMachinegunDamage(ent, item, info);

	if (!(ent->client->buttons & BUTTON_ATTACK))
	{
		ent->client->ps.gunframe++;
		return;
	}

	if (ent->client->ps.gunframe == 5)
		ent->client->ps.gunframe = 4;
	else
		ent->client->ps.gunframe = 5;

	if (ent->client->pers.inventory[ent->client->ammo_index] < 1)
	{
		ent->client->ps.gunframe = 6;
		if (level.time >= ent->pain_debounce_time)
		{
			gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
			ent->pain_debounce_time = level.time + 1;
		}
		NoAmmoWeaponChange (ent);
		return;
	}

	damage = applyWeaponBonuses(ent, damage, 1);
//	if (is_quad)
//		kick *= 4;

	for (i=1 ; i<3 ; i++) {
		ent->client->kick_origin[i] = crandom() * 0.35;
		ent->client->kick_angles[i] = crandom() * 0.7;
	}
	ent->client->kick_origin[0] = crandom() * 0.35;

	// get start / end positions
	VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);
	AngleVectors (angles, forward, right, NULL);
	VectorSet(offset, 0, 8, ent->viewheight-8);
	P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
	fire_bullet (ent, start, forward, damage, kick, spread, spread, MOD_MACHINEGUN);

	if ((ent->client->silencer_shots > 0) && (ent->client->pers.skill[58] > 7)) {
		ent->client->silencer_shots -= 1;
	} else {
		gi.WriteByte (svc_muzzleflash);
		gi.WriteShort (ent-g_edicts);
		gi.WriteByte (MZ_MACHINEGUN | is_silenced);
		gi.multicast (ent->s.origin, MULTICAST_PVS);
	}

	PlayerNoise(ent, start, PNOISE_WEAPON);

//	if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
		ent->client->pers.inventory[ent->client->ammo_index]--;

	ent->client->anim_priority = ANIM_ATTACK;
	if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
	{
		ent->s.frame = FRAME_crattak1 - (int) (random()+0.25);
		ent->client->anim_end = FRAME_crattak9;
	}
	else
	{
		ent->s.frame = FRAME_attack1 - (int) (random()+0.25);
		ent->client->anim_end = FRAME_attack8;
	}
}
Esempio n. 12
0
File: Ship.cpp Progetto: jamtot/CPP
void Ship::update(){

    sf::Vector2f accel(0,0);

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::A))
    {
        m_rotation-=m_rotation_speed;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D))
    {
        m_rotation+=m_rotation_speed;
    }

        m_shape->setRotation(m_rotation);
        float theta = DEGREES_TO_RADIANS(m_rotation);
        float cs = cos(theta);
        float sn = sin(theta);

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::W))
    {
        sf::Vector2f thrust = *m_acceleration;
        accel+=thrust;
        // rotate the vector
        sf::Vector2f newAccel;
        newAccel.x = accel.x * cs - accel.y * sn;
        newAccel.y = accel.x * sn + accel.y * cs;
        *m_velocity+=newAccel;

        if (Funcs::GetVecLen(*m_velocity) > m_max_speed)
            *m_velocity=Funcs::Normalise(*m_velocity)*m_max_speed;
    }
    else
    {
        if (Funcs::GetVecLen(*m_velocity) > 0.01f)
        {
            //slow by using reverse vector
            sf::Vector2f negVel = *m_velocity * 0.05f;
            *m_velocity = *m_velocity - negVel;
        }
        else
        {
            *m_velocity=sf::Vector2f(0.f,0.f);
        }
    }


    //bounds checking
    /*if (m_pos->x > m_windowsize[0] - m_length/2) m_pos->x = (m_windowsize[0] - m_length/2);
    else if (m_pos->x < m_length/2) m_pos->x = m_length/2;
    if (m_pos->y > m_windowsize[1] - m_length/2) m_pos->y = (m_windowsize[1] - m_length/2);
    else if (m_pos->y < m_length/2) m_pos->y = m_length/2;*/

    if (m_pos->x < 0-m_length/2)
        m_pos->x = m_windowsize[0]+m_length/2;
    else if (m_pos->x > m_windowsize[0]+m_length/2)
        m_pos->x = 0-m_length/2;

    if (m_pos->y < 0-m_length/2)
        m_pos->y = m_windowsize[1]+m_length/2;
    else if (m_pos->y > m_windowsize[1]+m_length/2)
        m_pos->y = 0-m_length/2;

    //set position
    *m_pos+=*m_velocity;
    m_shape->setPosition(*m_pos);

    if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && !m_firing)
    { // if the mouse is clicked, use mouse position for shot
        sf::Vector2f position = (sf::Vector2f)sf::Mouse::getPosition(*m_window);
        position-=*m_pos;
        fire_bullet(position);
        m_firing = true;
        m_timer = m_shoot_time;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && !m_firing)
    { // if space is pressed, use ship direction for shot
        sf::Vector2f dir(0,1);
        sf::Vector2f rotdir;
        rotdir.x = dir.x * cs - dir.y * sn;
        rotdir.y = dir.x * sn + dir.y * cs;
        fire_bullet(rotdir);
        m_firing = true;
        m_timer = m_shoot_time;
    }
    if (!sf::Mouse::isButtonPressed(sf::Mouse::Left) && !sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
    {
        m_firing = false;
    }


    if (m_timer > 0)
    { m_timer--; }
    else if (m_timer == 0)
    {
        m_firing = false;
    }

    vector<Bullet>::iterator it;
    for (it = m_bullet_vec->begin(); it != m_bullet_vec->end(); ++it)
    {
        if ((*it).isAlive())
            (*it).update();
        else
        {
            //remove dead bullets, decrement the iterator
            m_bullet_vec->erase(it);
            --it;
        }

    }
}
Esempio n. 13
0
int main(int argc, char const *argv[])
{
	const int FPS = 60;
	const int MAX_BULLETS = 10;
	const int MAX_ASTEROIDS = 10;
	const int MAX_EXPLOSIONS = 10;
	srand(time(NULL));
	int done = 0;
	int redraw = 1;

	if(!al_init())
	{
		al_show_native_message_box(NULL, "Error", "Error", 
			"Could not initialize Allegro 5.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	ALLEGRO_DISPLAY *display = al_create_display(screen_width, screen_height);
	if(!display)
	{
		al_show_native_message_box(NULL, "Error", "Error", 
			"Could not create display.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	if(!event_queue)
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not create event queue.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	ALLEGRO_TIMER *timer = al_create_timer(1.0/FPS);
	if(!timer)
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not create timer.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	if(!al_install_keyboard())
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not install keyboard.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	if(!al_install_mouse())
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not install mouse.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	if(!al_init_image_addon())
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not initialize image addon.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	if(!al_init_primitives_addon())
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not initialize primitives addon.", 0, ALLEGRO_MESSAGEBOX_ERROR);
	}

	al_init_font_addon(); // for whatever reason this function is void returning

	if(!al_init_ttf_addon())
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not initialize ttf addon.", 0, ALLEGRO_MESSAGEBOX_ERROR);
	}
	
	al_hide_mouse_cursor(display);

	al_register_event_source(event_queue, al_get_mouse_event_source());
	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_display_event_source(display));
	al_register_event_source(event_queue, al_get_timer_event_source(timer));

	ALLEGRO_FONT *font18 = al_load_font("Arial.ttf", 18, 0);

	int prev_x = screen_width, prev_y = screen_height;
	int fps_counter = 0;
	int fps_counter2 = 0;
	int i, j, k;

	struct spaceship ship;
	init_ship(&ship);

	struct bullet bullets[MAX_BULLETS];
	for(i = 0; i < MAX_BULLETS; i++)
	{
		init_bullet(&bullets[i]);
	}

	struct asteroid asteroids[MAX_ASTEROIDS];
	for(i = 0; i < MAX_ASTEROIDS; i++)
	{
		init_asteroid(&asteroids[i]);
	}

	struct explosion explosions[MAX_EXPLOSIONS];
	for(i = 0; i < MAX_EXPLOSIONS; i++)
	{
		init_explosion(&explosions[i]);
	}

	al_start_timer(timer);

	while(!done)
	{
		ALLEGRO_EVENT event;
		al_wait_for_event(event_queue, &event);

		if(event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			done = 1;
		}
		if(event.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			switch(event.keyboard.keycode)
			{
				case ALLEGRO_KEY_Q: 
					done = 1;
					break;
				case ALLEGRO_KEY_ESCAPE:
					done = 1;
					break;
			}
		}
		if(event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
		{
			if(event.mouse.button & 1)
			{
				for(i = 0; i < MAX_BULLETS; i++)
				{
					if(!bullets[i].live)
					{
						fire_bullet(&bullets[i], ship);
						break;
					}
				}
			}
		}
		if(event.type == ALLEGRO_EVENT_MOUSE_AXES ||
              event.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY)
		{
			set_ship_coordinates(&ship, event.mouse.x, event.mouse.y);
		}
		if(event.type == ALLEGRO_EVENT_TIMER)
		{	
			if(ship.x > prev_x)
			{	
				ship.sprite.dir_horizontal = RIGHT;
			}
			else if(ship.x == prev_x)
			{
				ship.sprite.dir_horizontal = CENTER;
			}
			else if(ship.x < prev_x) 
			{
				ship.sprite.dir_horizontal = LEFT;
			}

			if(ship.y > prev_y)
			{
				ship.sprite.dir_vertical = BACK;
			}
			else if(ship.y == prev_y)
			{
				ship.sprite.dir_vertical = NEUTRAL;
			}
			else if(ship.y < prev_y)
			{
				ship.sprite.dir_vertical = FORWARD;
			}

			if(++fps_counter >= FPS / 5)
			{
				fps_counter = 0;
				prev_x = ship.x;
				prev_y = ship.y;	
			}

			if(++fps_counter2 >= 2 * FPS)
			{
				for(i = 0; i < MAX_ASTEROIDS; i++)
				{
					if(!asteroids[i].live)
					{
						start_asteroid(&asteroids[i]);
						break;
					}
				}
				fps_counter2 = 0;
			}

			for(i = 0; i < MAX_BULLETS; i++)
			{
				if(bullets[i].live)
				{
					update_bullet(&bullets[i]);
				}
			}

			for(i = 0; i < MAX_ASTEROIDS; i++)
			{
				if(asteroids[i].live)
				{
					update_asteroid(&asteroids[i], &ship);
				}
			}

			for(i = 0; i < MAX_EXPLOSIONS; i++)
			{
				if(explosions[i].live)
				{
					update_explosion(&explosions[i]);
				}
			}

			update_ship_boundaries(&ship);

			for(i = 0; i < MAX_BULLETS; i++)
			{
				if(bullets[i].live)
				{
					for(j = 0; j < MAX_ASTEROIDS; j++)
					{
						if(asteroids[j].live)
						{
							if(bullet_and_asteroid_collision(bullets[i], asteroids[j]))
							{
								bullets[i].live = 0;
								asteroids[j].live = 0;
								ship.score += 20;
								for(k = 0; k < MAX_EXPLOSIONS; k++)
								{
									if(!explosions[k].live)
									{
										start_explosion(&explosions[k], bullets[i].x, bullets[i].y);
										break;
									}
								}
							}
						}
					}
				}
			}

			for(i = 0; i < MAX_ASTEROIDS; i++)
			{
				if(asteroids[i].live)
				{
					if(ship_and_asteroid_collision(ship, asteroids[i]))
					{
						asteroids[i].live = 0;
						for(k = 0; k < MAX_EXPLOSIONS; k++)
						{
							if(!explosions[k].live)
							{
								start_explosion(&explosions[k], ship.x, ship.y);
								break;
							}
						}
						
						ship.lives--;
					}
				}
			}

			if(!ship.lives)
			{
				done = true;
			}

			redraw = 1;
		}

		if(redraw)
		{
			redraw = 0;
			draw_ship_sprite(ship.sprite, ship.x, ship.y);
			for(i = 0; i < MAX_BULLETS; i++)
			{
				if(bullets[i].live)
				{
					draw_bullet(bullets[i]);
				}
			}
			for(i = 0; i < MAX_ASTEROIDS; i++)
			{
				if(asteroids[i].live)
				{
					draw_asteroid(asteroids[i]);
				}
			}
			for(i = 0; i < MAX_EXPLOSIONS; i++)
			{
				if(explosions[i].live)
				{
					draw_explosion(explosions[i]);
				}
			}
			al_draw_textf(font18, al_map_rgb(255, 255, 255), 50, 5, 0, 
				"Score: %d ", ship.score); // I have no idea why it doesn't print the S...
			al_draw_textf(font18, al_map_rgb(255, 255, 255), 50, 25, 0, 
				"Lives: %d", ship.lives);
			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));
		}
	}

	for(i = 0; i < MAX_ASTEROIDS; i++)
	{
		destroy_asteroid(&asteroids[i]);
	}
	for(i = 0; i < MAX_EXPLOSIONS; i++)
	{
		destroy_explosion(&explosions[i]);
	}
	destroy_sprite(&ship.sprite);
	al_destroy_display(display);
	al_destroy_event_queue(event_queue);
	al_destroy_timer(timer);
	al_destroy_font(font18);

	return 0;
}
Esempio n. 14
0
// Chaingun
void actorChaingun (edict_t *self)
{
	vec3_t	start, target;
	vec3_t	forward, right, up;
	int		i;
	int		shots;
	int		damage;

	if(!self->enemy || !self->enemy->inuse)
		self->monsterinfo.pausetime = 0;

	if(level.time >= self->monsterinfo.pausetime) {
		self->s.sound = 0;
		gi.sound(self,CHAN_AUTO,gi.soundindex("weapons/chngnd1a.wav"),1,ATTN_IDLE,0);
		return;
	}

	if(self->actor_gunframe == 0)
		gi.sound(self, CHAN_AUTO, gi.soundindex("weapons/chngnu1a.wav"), 1, ATTN_IDLE, 0);

	if(self->actor_gunframe == 21 && level.time < self->monsterinfo.pausetime)
		self->actor_gunframe = 15;
	else
		self->actor_gunframe++;

	self->s.sound = gi.soundindex("weapons/chngnl1a.wav");
#ifdef LOOP_SOUND_ATTENUATION
	self->s.attenuation = ATTN_IDLE;
#endif

	if(self->actor_gunframe <= 9)
		shots = 1;
	else if(self->actor_gunframe <= 14)
		shots = 2;
	else
		shots = 3;

	AngleVectors (self->s.angles, forward, right, up);
	G_ProjectSource2 (self->s.origin, self->muzzle, forward, right, up, start);
	ActorTarget(self,target);
	VectorSubtract (target, start, forward);
	VectorNormalize (forward);
	if(self->monsterinfo.aiflags & AI_TWO_GUNS)
		damage = 2;
	else
		damage = 4;

	for(i=0; i<shots; i++)
		fire_bullet (self, start, forward, damage, 2, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);

	gi.WriteByte(svc_temp_entity);
	gi.WriteByte(TE_CHAINFIST_SMOKE);
	gi.WritePosition(start);
	gi.multicast(start, MULTICAST_PVS);
	gi.positioned_sound(start,self,CHAN_WEAPON,gi.soundindex(va("weapons/machgf%db.wav",self->actor_gunframe % 5 + 1)),1,ATTN_NORM,0);

	if(self->flash)
	{
		VectorCopy(start,self->flash->s.origin);
		self->flash->think = muzzleflash_think;
		self->flash->wait  = level.time + FRAMETIME;
		self->flash->think(self->flash);
	}

	if(developer->value)
		TraceAimPoint(start,target);

	if(self->monsterinfo.aiflags & AI_TWO_GUNS)
	{
		G_ProjectSource2 (self->s.origin, self->muzzle2, forward, right, up, start);
		ActorTarget(self,target);
		VectorSubtract (target, start, forward);
		VectorNormalize (forward);
		for(i=0; i<shots; i++)
			fire_bullet (self, start, forward, damage, 2, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);
		gi.WriteByte(svc_temp_entity);
		gi.WriteByte(TE_CHAINFIST_SMOKE);
		gi.WritePosition(start);
		gi.multicast(start, MULTICAST_PVS);
	}
}
Esempio n. 15
0
File: p_weapon.c Progetto: ZwS/qudos
void Chaingun_Fire (edict_t *ent)
{
	int			i;
	int			shots;
	vec3_t		start;
	vec3_t		forward, right, up;
	float		r, u;
	vec3_t		offset;
	int			damage;
	int			kick = 2;

	if (deathmatch->value)
		damage = 6;
	else
		damage = 8;

	if (ent->client->ps.gunframe == 5)
		gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnu1a.wav"), 1, ATTN_IDLE, 0);

	if ((ent->client->ps.gunframe == 14) && !(ent->client->buttons & BUTTON_ATTACK))
	{
		ent->client->ps.gunframe = 32;
		ent->client->weapon_sound = 0;
		return;
	}
	else if ((ent->client->ps.gunframe == 21) && (ent->client->buttons & BUTTON_ATTACK)
		&& ent->client->pers.inventory[ent->client->ammo_index])
	{
		ent->client->ps.gunframe = 15;
	}
	else
	{
		ent->client->ps.gunframe++;
	}

	if (ent->client->ps.gunframe == 22)
	{
		ent->client->weapon_sound = 0;
		gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnd1a.wav"), 1, ATTN_IDLE, 0);
	}
	else
	{
		ent->client->weapon_sound = gi.soundindex("weapons/chngnl1a.wav");
	}

	ent->client->anim_priority = ANIM_ATTACK;
	if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
	{
		ent->s.frame = FRAME_crattak1 - (ent->client->ps.gunframe & 1);
		ent->client->anim_end = FRAME_crattak9;
	}
	else
	{
		ent->s.frame = FRAME_attack1 - (ent->client->ps.gunframe & 1);
		ent->client->anim_end = FRAME_attack8;
	}

	if (ent->client->ps.gunframe <= 9)
		shots = 1;
	else if (ent->client->ps.gunframe <= 14)
	{
		if (ent->client->buttons & BUTTON_ATTACK)
			shots = 2;
		else
			shots = 1;
	}
	else
		shots = 3;

	if (ent->client->pers.inventory[ent->client->ammo_index] < shots)
		shots = ent->client->pers.inventory[ent->client->ammo_index];

	if (!shots)
	{
		if (level.time >= ent->pain_debounce_time)
		{
			gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
			ent->pain_debounce_time = level.time + 1;
		}
		NoAmmoWeaponChange (ent);
		return;
	}

	if (is_quad)
	{
		damage *= 4;
		kick *= 4;
	}

	for (i=0 ; i<3 ; i++)
	{
		ent->client->kick_origin[i] = crandom() * 0.35;
		ent->client->kick_angles[i] = crandom() * 0.7;
	}

	for (i=0 ; i<shots ; i++)
	{
		// get start / end positions
		AngleVectors (ent->client->v_angle, forward, right, up);
		r = 7 + crandom()*4;
		u = crandom()*4;
		VectorSet(offset, 0, r, u + ent->viewheight-8);
		P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);

		fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);
	}

	// send muzzle flash
	gi.WriteByte (svc_muzzleflash);
	gi.WriteShort (ent-g_edicts);
	gi.WriteByte ((MZ_CHAINGUN1 + shots - 1) | is_silenced);
	gi.multicast (ent->s.origin, MULTICAST_PVS);

	PlayerNoise(ent, start, PNOISE_WEAPON);

	if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
		ent->client->pers.inventory[ent->client->ammo_index] -= shots;
}
Esempio n. 16
0
void update_ship(Ship *s)
{
    if (keys.left){
        if (s->vrot < 7)
            s->vrot += s->arot;
    }
    if (keys.right){
        if (s->vrot > -7)
            s->vrot -= s->arot;
    }
    if (keys.space){
        fire_bullet(s);
        keys.space = 0;
    }
    if (keys.up){
        Vector *v = get_unit_vector(s->rot);
        s->v->x += v->x / 10;
        s->v->y += v->y / 10;
        free(v);
        add_smoke(s);
    }
    //update ship
    if (s->vrot){
        s->vrot *= 0.95;
        s->rot += s->vrot;
        s->rot %= 360;
        if (s->rot < 0) s->rot +=360;
        rotate_sprite(s->sprite, s->rot_buffer, s->rot);
    }
    s->v->x *= 0.95;
    s->v->y *= 0.95;
    s->pos->x += s->v->x;
    s->pos->y += s->v->y;
    if (s->pos->x < 0) s->pos->x = 0;
    if (s->pos->x + s->sprite.w > s->rainbow->w) s->pos->x = s->rainbow->w - s->sprite.w;
    if (s->pos->y < 0) s->pos->y = 0;
    if (s->pos->y + s->sprite.h > s->rainbow->h) s->pos->y = s->rainbow->h - s->sprite.h;

    //update bullets
    int i;
    for (i = 0; i < vl_array_length(s->bullets); ++i){
        Bullet* b = ((Bullet*) get_element(s->bullets, i));
        b->x += (int)b->vx;
        b->y += (int)b->vy;
        if (point_offscreen (s->rainbow, b->x, b->y) || point_offscreen(s->rainbow, b->x + b->w, b->y + b->h)){
            remove_element(s->bullets, b);
            --i;
        }
    }
    // update particles
    for (i = 0; i < vl_array_length(s->particles); ++i){
        Particle *p = (Particle*) get_element(s->particles, i);
        --(p->life);
        p->pos->x += p->v->x;
        p->pos->y += p->v->y;
        if (p->life < 0 || point_offscreen(s->rainbow, p->pos->x, p->pos->y)) {
	    free(p->pos);
	    free(p->v);
            remove_element(s->particles, p);
            --i;
            continue;
        }
    }
}
Esempio n. 17
0
int main(void)
{
    bool done =false;
    bool redraw = true;
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_TIMER *timer =NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    SpaceShip ship;
    Bullet bullet[num_bullets];
    Commet commet[num_commets];
    if(!al_init())
    {
        fprintf(stderr,"allegro is not intialized");
        return -1;
    }
    display = al_create_display(SCREEN_W,SCREEN_H);
    if(!display)
    {
        fprintf(stderr,"failed to intialize the display");
        return -1;
    }
    
    timer  = al_create_timer(1.0/FPS);
    if(!timer)
    {
        fprintf(stderr,"failed to intialize timer");
        al_destroy_display(display);
        return -1;
    }
    event_queue = al_create_event_queue();
    if(!event_queue)
    {
        fprintf(stderr,"failed to create event queue");
        al_destroy_display(display);
        al_destroy_timer(timer);
        return -1;
    }
    al_install_keyboard();
    al_register_event_source(event_queue,al_get_timer_event_source(timer));
    al_register_event_source(event_queue,al_get_keyboard_event_source());
    al_register_event_source(event_queue,al_get_display_event_source(display));
    init_ship(&ship);
    init_bullet(&bullet);
    init_commet(&commet);
    al_start_timer(timer);
    while(!done)
    {
        
        ALLEGRO_EVENT ev;
        al_wait_for_event(event_queue,&ev);
        
        if(ev.type == ALLEGRO_EVENT_TIMER)
        {
            if(keys[KEY_UP])
            {
                move_ship_up(&ship);
            }
            if(keys[KEY_DOWN])
            {
                move_ship_down(&ship);
            }if(keys[KEY_LEFT])
            {
                move_ship_left(&ship);
            }
            if(keys[KEY_RIGHT])
            {
                move_ship_right(&ship);
            }
            if(keys[KEY_SPACEBAR])
            {
                fire_bullet(&bullet,&ship);
            }
            if(!GameOver)
            {
                update_bullet(&bullet);
                update_commet(&commet);
                bullet_collision(&bullet,&commet);
            }
            
            redraw = true;
        }
        else if(ev.type==ALLEGRO_EVENT_DISPLAY_CLOSE)
        {
            done = true;
        }
        else if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
        {
            switch(ev.keyboard.keycode)
            {
                case ALLEGRO_KEY_UP:
                {
                    keys[KEY_UP]=true;
                    break;
                }
                case ALLEGRO_KEY_DOWN:
                {
                    keys[KEY_DOWN]=true;
                    break;
                }
                case ALLEGRO_KEY_LEFT:
                {
                    keys[KEY_LEFT]=true;
                    break;
                }
                case ALLEGRO_KEY_RIGHT :
                {
                    keys[KEY_RIGHT]=true;
                    break;
                }
                case ALLEGRO_KEY_SPACE:
                {
                    keys[KEY_SPACEBAR] = true;
                    break;
                }
                    
            }
        }
        else if(ev.type == ALLEGRO_EVENT_KEY_UP)
        {
            switch(ev.keyboard.keycode)
            {
                case ALLEGRO_KEY_UP:
                {
                    keys[KEY_UP]=false;
                    break;
                }
                case ALLEGRO_KEY_DOWN:
                {
                    keys[KEY_DOWN]=false;
                    break;
                }
                case ALLEGRO_KEY_LEFT:
                {
                    keys[KEY_LEFT]=false;
                    break;
                }
                case ALLEGRO_KEY_RIGHT :
                {
                    keys[KEY_RIGHT]=false;
                    break;
                }
                case ALLEGRO_KEY_SPACE:
                {
                    keys[KEY_SPACEBAR]=false;
                    break;
                }
                    
            }
        }
        
        if(redraw && al_event_queue_is_empty(event_queue))
        {
            redraw = false ;
            al_clear_to_color(al_map_rgb(255,100,100));
            draw_ship(&ship);
            draw_bullet(bullet);
            draw_commet(commet);
            al_flip_display();
            al_clear_to_color(al_map_rgb(255,100,100));
            
            
        }
    }
    al_destroy_display(display);
    al_destroy_timer(timer);
    al_destroy_event_queue(event_queue);
    return 0;
}
Esempio n. 18
0
void bullet_update(struct moag *m, int id)
{
    struct bullet *b = &m->bullets[id];

    if (!b->active)
        return;

    if (b->type == LADDER)
    {
        b->active--;
        b->obj.pos = VEC2_ADD(b->obj.pos, b->obj.vel);
        b->x = (int)b->obj.pos.x;
        b->y = (int)b->obj.pos.y;

        if (get_land_at(m, b->x, b->y) == 1)
        {
            explode(m, b->x, b->y + LADDER_LENGTH - b->active, 1, E_SAFE_EXPLODE);
            bullet_detonate(m, id);
        }
        return;
    }

    b->obj.pos = VEC2_ADD(b->obj.pos, b->obj.vel);
    b->obj.vel = VEC2_ADD(b->obj.vel, VEC2(0, GRAVITY));
    b->x = (int)b->obj.pos.x;
    b->y = (int)b->obj.pos.y;
    if (get_land_at(m, b->x, b->y))
    {
        bullet_detonate(m, id);
        return;
    }

    if (b->active > 1)
    {
        b->active--;
        return;
    }

    if (b->type == BOUNCER && b->active == 1)
        b->active = -BOUNCER_BOUNCES;
    if (b->type == TUNNELER && b->active == 1)
        b->active = -TUNNELER_TUNNELINGS;

    for (int i = 0; i < MAX_PLAYERS; i++)
    {
        if(DIST(m->players[i].tank.x, m->players[i].tank.y - 3,
                b->x, b->y) < 8.5)
        {
            bullet_detonate(m, id);
            return;
        }
    }

    if (m->crate.active && DIST(m->crate.x, m->crate.y - 4, b->x, b->y) < 5.5)
    {
        if (m->crate.type == TRIPLER) {
            float angle = -RAD2DEG(atan2(b->obj.vel.y, b->obj.vel.x));
            float speed = VEC2_MAG(b->obj.vel);
            fire_bullet_ang(m, b->type, b->x, b->y, angle - 20.0, speed);
            fire_bullet_ang(m, b->type, b->x, b->y, angle + 20.0, speed);
        } else if (m->crate.type == SHOTGUN) {
            bullet_detonate(m, id);
            float angle = -RAD2DEG(atan2(b->obj.vel.y, b->obj.vel.x));
            float speed = VEC2_MAG(b->obj.vel);
            int shots = SHOTGUN_PELLETS;
            for (int i = 0; i < shots; i++)
                fire_bullet_ang(m, m->crate.type, m->crate.x, m->crate.y - 4,
                        angle - (shots-1)*2 + i*4, speed*0.5);
        } else {
            bullet_detonate(m, id);
            fire_bullet(m, m->crate.type, m->crate.x, m->crate.y - 4,
                           m->crate.type != BOUNCER ? 0 :
                           b->obj.vel.x < 0 ? -0.2 :
                                               0.2, -0.2);
        }
        m->crate.active = false;
        return;
    }

    if (b->type == MIRV && b->obj.vel.y > 0)
    {
        bullet_detonate(m, id);
        return;
    }

    if (b->active)
        broadcast_bullet_chunk(m, MOVE, id);
}
Esempio n. 19
0
void bullet_detonate(struct moag *m, int id)
{
    struct bullet *b = &m->bullets[id];
    float d = VEC2_MAG(b->obj.vel);

    if (d < 0.001 && d >- 0.001)
        d = d < 0 ? -1 : 1;

    const float dx = b->obj.vel.x / d;
    const float dy = b->obj.vel.y / d;

    float hitx = b->obj.pos.x;
    float hity = b->obj.pos.y;

    for (int i = 40; i > 0 && get_land_at(m, (int)hitx, (int)hity); i--)
    {
        hitx -= dx;
        hity -= dy;
    }

    switch (b->type)
    {
        case MISSILE:
            explode(m, b->x, b->y, 12, E_EXPLODE);
            break;

        case SHOTGUN:
            explode(m, b->x, b->y, 6, E_EXPLODE);
            break;

        case BABY_NUKE:
            explode(m, b->x, b->y, 55, E_EXPLODE);
            break;

        case NUKE:
            explode(m, b->x, b->y, 150, E_EXPLODE);
            break;

        case DIRT:
            explode(m, b->x, b->y, 55, E_DIRT);
            break;

        case SUPER_DIRT:
            explode(m, b->x, b->y, 300, E_DIRT);
            break;

        case COLLAPSE:
            explode(m, b->x, b->y, 120, E_COLLAPSE);
            break;

        case LIQUID_DIRT:
            for (int i = 0; i < 4; i++)
                set_timer(m, m->frame + 65*i, LIQUID_DIRT_WARHEAD,
                        b->x, b->y, 0, 0);
            break;

        case LIQUID_DIRT_WARHEAD:
            liquid(m, (int)hitx, (int)hity, 2000);
            break;

        case BOUNCER:
            if (b->active > 0)
                b->active = -BOUNCER_BOUNCES;
            b->active++;
            bounce_bullet(m, id, hitx, hity);
            b->obj.vel = VEC2_MUL_CONST(b->obj.vel, 0.9);
            explode(m, b->x, b->y, 12, E_EXPLODE);
            break;

        case TUNNELER:
            if (b->active > 0)
                b->active = -TUNNELER_TUNNELINGS;
            b->active++;
            explode(m, hitx, hity, 9, E_EXPLODE);
            explode(m, hitx + 8 * dx, hity + 8 * dy, 9, E_EXPLODE);
            break;

        case LADDER: {
            int x = b->x;
            int y = b->y;
            for (; y < LAND_HEIGHT; y++)
                if (get_land_at(m, x, y) == 0)
                    break;
            for (; y < LAND_HEIGHT; y++)
                if (get_land_at(m, x, y))
                    break;
            const int maxy = y + 1;
            y = b->y;
            for (; y > 0; y--)
                if (get_land_at(m, x, y) == 0)
                    break;
            const int miny = y;
            for(; y < maxy; y += 2)
            {
                set_land_at(m, x - 1, y,     0);
                set_land_at(m, x    , y,     1);
                set_land_at(m, x + 1, y,     0);
                set_land_at(m, x - 1, y + 1, 1);
                set_land_at(m, x    , y + 1, 1);
                set_land_at(m, x + 1, y + 1, 1);
            }
            broadcast_packed_land_chunk(m, x - 1, miny, 3, maxy - miny + 1);
            break;
        }

        case MIRV:
            bounce_bullet(m, id, hitx, hity);
            explode(m, b->x, b->y, 12, E_EXPLODE);
            for (int i = -3; i < 4; i++)
                fire_bullet(m, MIRV_WARHEAD,
                            b->x, b->y,
                            b->obj.vel.x + i, b->obj.vel.y);
            break;

        case MIRV_WARHEAD:
            explode(m, b->x, b->y, 30, E_EXPLODE);
            break;

        case CLUSTER_BOMB:
            bounce_bullet(m, id, hitx, hity);
            explode(m, b->x, b->y, 20, E_EXPLODE);
            for (int i = 0; i < 11; i++)
                fire_bullet(m, MISSILE, hitx, hity,
                            2.0 * cosf(i * M_PI / 5.5) + 0.50 * b->obj.vel.x,
                            2.0 * sinf(i * M_PI / 5.5) + 0.50 * b->obj.vel.y);
            break;

        case CLUSTER_BOUNCER:
            bounce_bullet(m, id, hitx, hity);
            explode(m, b->x, b->y, 20, E_EXPLODE);
            for (int i = 0; i < 11; i++)
                fire_bullet(m, BOUNCER, hitx, hity,
                            2.0 * cosf(i * M_PI / 5.5) + 0.50 * b->obj.vel.x,
                            2.0 * sinf(i * M_PI / 5.5) + 0.50 * b->obj.vel.y);
            break;

        default: break;
    }

    if (b->active >= 0)
    {
        b->active = 0;
        broadcast_bullet_chunk(m, KILL, id);
    }
}
Esempio n. 20
0
void minisentry_attack (edict_t *self)
{
	int			speed, dmg_radius;
	float		chance;
	vec3_t		forward, start, aim;
	qboolean	slowed=false;

	minisentry_lockon(self);
	if (self->light_level < 1)
		return; // out of ammo
	// are we affected by holy freeze?
	//if (HasActiveCurse(self, AURA_HOLYFREEZE))
	if (que_typeexists(self->curses, AURA_HOLYFREEZE))
		slowed = true;
	
	// calculate muzzle location
	AngleVectors(self->s.angles, forward, NULL, NULL);
	VectorCopy(self->s.origin, start);
	if (self->owner && self->owner->style == SENTRY_FLIPPED)
		start[2] -= abs(self->mins[2]);
	else
		start[2] += self->maxs[2];
	VectorMA(start, (self->maxs[0] + 16), forward, start);

	if ((level.time > self->wait) && infov(self, self->enemy, 30))
	{
		speed = 650 + 35*self->creator->myskills.abilities[BUILD_SENTRY].current_level;
		MonsterAim(self, -1, speed, true, 0, aim, start);
		dmg_radius = self->radius_dmg;
		if (dmg_radius > 150)
			dmg_radius = 150;
		fire_rocket (self, start, aim, self->radius_dmg, speed, dmg_radius, self->radius_dmg);
		if (slowed)
			self->wait = level.time + 2.0;
		else if (self->chill_time > level.time)
			self->wait = level.time + (1.0 * (1 + CHILL_DEFAULT_BASE + CHILL_DEFAULT_ADDON * self->chill_level));
		else
			self->wait = level.time + 1.0;
	
	}
	self->light_level--; // decrease ammo
	
	if (slowed && !(level.framenum%2))
		return;

	// chill effect reduces attack rate/refire
	if (self->chill_time > level.time)
	{
		chance = 1 / (1 + CHILL_DEFAULT_BASE + CHILL_DEFAULT_ADDON * self->chill_level);
		if (random() > chance)
			return;
	}

	fire_bullet (self, start, forward, self->dmg, 2*self->dmg, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_SENTRY);
	gi.sound(self, CHAN_WEAPON, gi.soundindex("weapons/plaser.wav"), 1, ATTN_NORM, 0);

	gi.WriteByte (svc_muzzleflash);
	gi.WriteShort (self-g_edicts);
	gi.WriteByte (MZ_IONRIPPER|MZ_SILENCED);
	gi.multicast (start, MULTICAST_PVS);
}
Esempio n. 21
0
File: p_weapon.c Progetto: ZwS/qudos
void Machinegun_Fire (edict_t *ent)
{
	int	i;
	vec3_t		start;
	vec3_t		forward, right;
	vec3_t		angles;
	int			damage = 8;
	int			kick = 2;
	vec3_t		offset;

	if (!(ent->client->buttons & BUTTON_ATTACK))
	{
		ent->client->machinegun_shots = 0;
		ent->client->ps.gunframe++;
		return;
	}

	if (ent->client->ps.gunframe == 5)
		ent->client->ps.gunframe = 4;
	else
		ent->client->ps.gunframe = 5;

	if (ent->client->pers.inventory[ent->client->ammo_index] < 1)
	{
		ent->client->ps.gunframe = 6;
		if (level.time >= ent->pain_debounce_time)
		{
			gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
			ent->pain_debounce_time = level.time + 1;
		}
		NoAmmoWeaponChange (ent);
		return;
	}

	if (is_quad)
	{
		damage *= 4;
		kick *= 4;
	}

	for (i=1 ; i<3 ; i++)
	{
		ent->client->kick_origin[i] = crandom() * 0.35;
		ent->client->kick_angles[i] = crandom() * 0.7;
	}
	ent->client->kick_origin[0] = crandom() * 0.35;
	ent->client->kick_angles[0] = ent->client->machinegun_shots * -1.5;

	// raise the gun as it is firing
	if (!deathmatch->value)
	{
		ent->client->machinegun_shots++;
		if (ent->client->machinegun_shots > 9)
			ent->client->machinegun_shots = 9;
	}

	// get start / end positions
	VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);
	AngleVectors (angles, forward, right, NULL);
	VectorSet(offset, 0, 8, ent->viewheight-8);
	P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
	fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);

	gi.WriteByte (svc_muzzleflash);
	gi.WriteShort (ent-g_edicts);
	gi.WriteByte (MZ_MACHINEGUN | is_silenced);
	gi.multicast (ent->s.origin, MULTICAST_PVS);

	PlayerNoise(ent, start, PNOISE_WEAPON);

	if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
		ent->client->pers.inventory[ent->client->ammo_index]--;

	ent->client->anim_priority = ANIM_ATTACK;
	if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
	{
		ent->s.frame = FRAME_crattak1 - (int) (random()+0.25);
		ent->client->anim_end = FRAME_crattak9;
	}
	else
	{
		ent->s.frame = FRAME_attack1 - (int) (random()+0.25);
		ent->client->anim_end = FRAME_attack8;
	}
}
Esempio n. 22
0
/* updates the player position */
int update_player()
{
   poll_input();

   /* quit game? */ 
   if (key[ALLEGRO_KEY_ESCAPE])
      return -1;

   /* safe period while initing */
   if (init_time)
      init_time--;

   /* blown up? */
   if (die_time) {
      die_time--;

      if (!die_time) {
	 lives--;
	 if (!lives)
	    return 1;

	 init_time = 128;
	 pos = 0.5;
	 vel = 0;

	 if (lives == 1)
	    message("This Is Your Final Life");
	 else
	    message("One Life Remaining");
      }
   }

   /* handle user left/right input */
   if (!die_time) {
      if ((joy_left) || (key[ALLEGRO_KEY_LEFT]))
	 vel -= 0.005;

      if ((joy_right) || (key[ALLEGRO_KEY_RIGHT]))
	 vel += 0.005;
   }

   /* move left and right */
   pos += vel;

   if (pos >= 1.0)
      pos -= 1.0;

   if (pos < 0.0)
      pos += 1.0;

   vel *= 0.67;

   /* fire bullets */
   if ((!die_time) && (!init_time) && (!fire_time)) {
      if ((key[ALLEGRO_KEY_SPACE]) || (joy_b1)) {
	 fire_bullet();
	 fire_time = 24;
      }
   }

   if (fire_time)
      fire_time--;

   return 0;
}