コード例 #1
0
ファイル: player.cpp プロジェクト: SpaceManiac/Lunatic
void PlayerFirePowerArmor(Guy *me, byte mode)
{
	int x, y, x2, y2;
	byte f;

	switch (mode) {
		case 1:
			MakeSound(SND_ARMORSHOOT, me->x, me->y, SND_CUTOFF, 1200);
			f = me->facing * 32 - 64;
			x = me->x + Cosine(me->facing * 32)*20;
			y = me->y + Sine(me->facing * 32)*20;

			x2 = x + Cosine(f)*32;
			y2 = y + Sine(f)*32;
			FireBullet(x2, y2, me->facing * 32, BLT_BIGSHELL, 1);
			x2 = x - Cosine(f)*32;
			y2 = y - Sine(f)*32;
			FireBullet(x2, y2, me->facing * 32, BLT_BIGSHELL, 1);
			if (player.ammo > 2)
				player.ammo -= 2;
			break;
		case 2:
			QuadMissile(me->x, me->y, me->facing, 1);
			if (player.ammo > 25)
				player.ammo -= 25;
			else
				player.ammo = 0;
			break;
	}
}
コード例 #2
0
ファイル: player.cpp プロジェクト: SpaceManiac/Lunatic
void PlayerThrowHammer(Guy *me)
{
	if (opt.playAs == PLAYAS_BOUAPHA)
	{
		HammerLaunch(me->x, me->y, me->facing, player.hammers, player.hammerFlags);
	}
	else if (opt.playAs == PLAYAS_LUNATIC)
	{
		MakeSound(SND_BALLLIGHTNING, me->x, me->y, SND_CUTOFF, 600);
		FireBullet(me->x, me->y, me->facing, BLT_BALLLIGHTNING, 1);
		if (player.hammerFlags & HMR_REVERSE)
			FireBullet(me->x, me->y, (byte) MGL_random(8), BLT_BALLLIGHTNING, 1);
	}
	else
	{
		HappyLaunch(me->x, me->y, me->facing, player.hammers, player.hammerFlags);
	}

	player.reload = player.hamSpeed + 2;
}
コード例 #3
0
ファイル: HelicopterWeapon.cpp プロジェクト: 2asoft/xray
void CHelicopter::OnShot		()
{
	Fvector fire_pos,fire_dir;
	fire_pos = get_CurrentFirePoint();
	fire_dir = m_fire_dir;

	float fire_trail_speed		= 15.0f;
	clamp						(fire_trail_speed,GetCurrVelocity(),300.0f);
	if(m_enemy.bUseFireTrail){
		Fvector enemy_pos = m_enemy.destEnemyPos;

		float	dt		= Device.fTimeGlobal - m_enemy.fStartFireTime; VERIFY(dt>=0);
		float	dist	= m_enemy.fire_trail_length_curr - dt*fire_trail_speed;
		if(dist<0)
		{
			MGunFireEnd	();
			return		;
		}

		Fvector fp		= fire_pos;
		fp.y			= enemy_pos.y;
		Fvector	fd;
		fd.sub(enemy_pos,fp).normalize_safe();
		if(dist > (m_enemy.fire_trail_length_curr/2.0f) ){
			fd.mul(-1.0f);
			dist = dist - (m_enemy.fire_trail_length_curr/2.0f);
		}else{
			dist = (m_enemy.fire_trail_length_curr/2.0f) - dist;
		}
		

		static float fire_trace_width = pSettings->r_float(*cNameSect(),"fire_trace_width");
		enemy_pos.mad(fd,dist);
		Fvector disp_dir;
		disp_dir.random_point(fire_trace_width);

		enemy_pos.add(disp_dir);
		fire_dir.sub(enemy_pos,fire_pos).normalize_safe();
	};

	FireBullet(fire_pos, fire_dir, fireDispersionBase, m_CurrentAmmo, ID(), ID(), OnServer());

	StartShotParticles	();
	if(m_bLightShotEnabled) 
		Light_Start			();


	StartFlameParticles		();
	StartSmokeParticles		(fire_pos, zero_vel);
	OnShellDrop				(fire_pos, zero_vel);

	HUD_SOUND_ITEM::PlaySound	(m_sndShot, fire_pos, this, false);

}
コード例 #4
0
ファイル: CarWeapon.cpp プロジェクト: NeoAnomaly/xray
void CCarWeapon::OnShot()
{
	FireBullet				(	m_fire_pos, m_fire_dir, fireDispersionBase, *m_Ammo, 
								m_object->ID(), m_object->ID(), SendHitAllowed(m_object));

	StartShotParticles		();
	
	if(m_bLightShotEnabled) 
		Light_Start			();

	StartFlameParticles		();
	StartSmokeParticles		(m_fire_pos, zero_vel);
//	OnShellDrop				(m_fire_pos, zero_vel);

	HUD_SOUND::PlaySound	(m_sndShot, m_fire_pos, m_object, false);
}
コード例 #5
0
ファイル: Spaceship.cpp プロジェクト: mwales/education
void Spaceship::Update()
{
   // Reset thrust vector
   if (theThrustOn)
   {
      XYPair accelDir = GameMath::GetUnitVector(theAngle);
      theAcceleration = (accelDir * THRUST_ACCELERATION);
   }
   else
   {
      theAcceleration = XYPair(0.0, 0.0);
   }

   if (theFireBullet)
   {
      FireBullet();
   }

   // Call parent update
   GraphicEntity::Update();
}
コード例 #6
0
int KHero::LuaFireBullet(Lua_State* L)
{
    int      nTopIndex    = 0;
    DWORD    dwTemplateID = ERROR_ID;
    KBullet* pBullet      = NULL;
    DWORD    dwBulletID   = ERROR_ID;

    nTopIndex = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nTopIndex == 1 || nTopIndex == 4 || nTopIndex == 7);

    dwTemplateID = (DWORD)Lua_ValueToNumber(L, 1);
    KGLOG_PROCESS_ERROR(dwTemplateID);

    pBullet = FireBullet(dwTemplateID);
    KGLOG_PROCESS_ERROR(pBullet);

    if (nTopIndex >= 4)
    {
        int nX = (int)Lua_ValueToNumber(L, 2);
        int nY = (int)Lua_ValueToNumber(L, 3);
        int nZ = (int)Lua_ValueToNumber(L, 4);
        pBullet->SetPosition(nX, nY, nZ);
    }

    if (nTopIndex == 7)
    {
        pBullet->m_nVelocityX = (int)Lua_ValueToNumber(L, 5);
        pBullet->m_nVelocityY = (int)Lua_ValueToNumber(L, 6);
        pBullet->m_nVelocityZ = (int)Lua_ValueToNumber(L, 7);
    }

    g_PlayerServer.DoNewBulletNotify(m_pScene, pBullet);

    dwBulletID = pBullet->m_dwID;
Exit0:
    Lua_PushNumber(L, dwBulletID);
    return 1;
}
コード例 #7
0
ファイル: WeaponStatMgunFire.cpp プロジェクト: 2asoft/xray
void CWeaponStatMgun::OnShot()
{
	VERIFY(Owner());

	FireBullet				(	m_fire_pos, m_fire_dir, fireDispersionBase, *m_Ammo, 
								Owner()->ID(),ID(), SendHitAllowed(Owner()));

	StartShotParticles		();
	
	if(m_bLightShotEnabled) 
		Light_Start			();

	StartFlameParticles		();
	StartSmokeParticles		(m_fire_pos, zero_vel);
	OnShellDrop				(m_fire_pos, zero_vel);

	bool b_hud_mode =		(Level().CurrentEntity() == smart_cast<CObject*>(Owner()));
	m_sounds.PlaySound		("sndShot", m_fire_pos, Owner(), b_hud_mode);

	AddShotEffector			();
	m_dAngle.set			(	::Random.randF(-fireDispersionBase,fireDispersionBase),
								::Random.randF(-fireDispersionBase,fireDispersionBase));
}
コード例 #8
0
ファイル: rage.cpp プロジェクト: SpaceManiac/Lunatic
void DoRage(Guy *me)
{
	int cx, cy, i;

	if (player.rageClock > 0)
		player.rageClock--;

	if (player.rageClock > 59)
		switch (rageWpn) {
			case WPN_NONE:
				switch (opt.playAs) {
					case PLAYAS_BOUAPHA:
						if (player.rageClock == (player.rageClock / 4)*4)
							HammerLaunch(me->x, me->y, me->facing, 5, HMR_REVERSE | HMR_REFLECT);
						break;
					case PLAYAS_LUNATIC:
						if (player.rageClock == (player.rageClock / 4)*4)
						{
							for (i = 0; i < 10; i++)
								FireBullet(me->x, me->y, (byte) MGL_random(8), BLT_BALLLIGHTNING, 1);
						}
						break;
					case PLAYAS_HAPPY:
						if (player.rageClock == (player.rageClock / 4)*4)
							HappyLaunch(me->x, me->y, me->facing, 5, HMR_REVERSE | HMR_REFLECT);
						break;
				}
				break;
			case WPN_MISSILES:
				FireBullet(me->x, me->y, (player.rageClock & 7), BLT_MISSILE, 1);
				break;
			case WPN_BOMBS:
				GetCamera(&cx, &cy);
				cx -= 320;
				cy -= 240;
				FireBullet((cx + MGL_random(640)) << FIXSHIFT, (cy + MGL_random(480)) << FIXSHIFT,
						0, BLT_BOOM, 1);
				ShakeScreen(10); // make the screen shake!
				break;
			case WPN_AK8087:
				FireBullet(me->x, me->y, (byte) MGL_random(8), BLT_LASER, 1);
				FireBullet(me->x, me->y, (byte) MGL_random(8), BLT_LASER, 1);
				FireBullet(me->x, me->y, (byte) MGL_random(8), BLT_LASER, 1);
				break;
			case WPN_FLAME:
				GetCamera(&cx, &cy);
				cx -= 320;
				cy -= 240;
				for (i = 0; i < 3; i++)
					FireBullet((cx + MGL_random(640)) << FIXSHIFT, (cy + MGL_random(480)) << FIXSHIFT,
						(byte) MGL_random(8), BLT_FLAME, 1);
				break;
			case WPN_BIGAXE:
				if (player.rageClock == (player.rageClock / 5)*5)
				{
					MakeSound(SND_BOMBTHROW, me->x, me->y, SND_CUTOFF, 1200);
					FireBullet(me->x, me->y, me->facing, BLT_BIGAXE, 1);
				}
				break;
			case WPN_LIGHTNING:
				GetCamera(&cx, &cy);
				cx -= 320;
				cy -= 240;
				FireBullet((cx + MGL_random(640)) << FIXSHIFT, (cy + MGL_random(480)) << FIXSHIFT,
						(byte) MGL_random(8), BLT_LIGHTNING, 1);
				break;
			case WPN_SPEAR:
				if (player.rageClock == (player.rageClock / 3)*3)
				{
					MakeSound(SND_BOMBTHROW, me->x, me->y, SND_CUTOFF, 1200);
					FireBullet(me->x, me->y, (me->facing + 7)&7, BLT_SPEAR, 1);
					FireBullet(me->x, me->y, me->facing, BLT_SPEAR, 1);
					FireBullet(me->x, me->y, (me->facing + 1)&7, BLT_SPEAR, 1);
				}
				break;
			case WPN_MACHETE:
				GetCamera(&cx, &cy);
				cx -= 320;
				cy -= 240;
				for (i = 0; i < 10; i++)
					FireBullet((cx + MGL_random(640)) << FIXSHIFT, (cy + MGL_random(480)) << FIXSHIFT,
						(byte) MGL_random(8), BLT_SLASH, 1);
				break;
			case WPN_MINES:
				if (player.rageClock == (player.rageClock / 8)*8)
				{
					cx = 32 / 8 - ((player.rageClock - 60) / 8) + 1;
					for (i = 0; i < 8; i++)
						FireBullet(me->x + Cosine(i * 32)*(cx * 32), me->y + Sine(i * 32)*(cx * 32),
							0, BLT_BOOM, 1);
				}
				break;
			case WPN_MINDCONTROL:
				if (player.rageClock & 1)
					for (i = 0; i < 8; i++)
						FireBullet(me->x, me->y, i, BLT_MINDWIPE, 1);
				break;
			case WPN_REFLECTOR:
				FireBullet(me->x, me->y, 0, BLT_REFLECT, 1);
				break;
			case WPN_TURRET:
			case WPN_SWAPGUN:
				for (i = 0; i < 4; i++)
					FireBullet(me->x, me->y, (i * 64 + player.rageClock)&255, BLT_GREEN, 1);
				break;
			case WPN_JETPACK:
				for (i = 0; i < 8; i++)
					FireBullet(me->x, me->y, i, BLT_FLAME, 1);
				break;
		}
}
コード例 #9
0
ファイル: FournoidWeapon.cpp プロジェクト: Roger7410/Fournoid
void AFournoidWeapon::OnFireStarted()
{
	// Not checking last fire time for simplicity, so players can
	// cheat if they have a finger that's quick enough...
	FireBullet();
}
コード例 #10
0
CBaseEntity *CTFWeaponBaseGun::FireProjectile( CTFPlayer *pPlayer )
{
	int iProjectile = TF_PROJECTILE_NONE;

	CALL_ATTRIB_HOOK_INT( iProjectile, override_projectile_type );

	if ( !iProjectile )
		iProjectile = m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_iProjectile;

	CBaseEntity *pProjectile = NULL;

	switch( iProjectile )
	{
	case TF_PROJECTILE_BULLET:
		FireBullet( pPlayer );
		break;

	case TF_PROJECTILE_ROCKET:
		pProjectile = FireRocket( pPlayer );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_SYRINGE:
	case TF_PROJECTILE_NAIL:
		pProjectile = FireNail( pPlayer, iProjectile );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_DART:
		pProjectile = FireNail(pPlayer, iProjectile);
		pPlayer->DoAnimationEvent(PLAYERANIMEVENT_ATTACK_PRIMARY);
		break;

	case TF_PROJECTILE_PIPEBOMB:
	case TF_PROJECTILE_CANNONBALL:
		pProjectile = FireGrenade( pPlayer, iProjectile );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_PIPEBOMB_REMOTE:
	case TF_PROJECTILE_PIPEBOMB_REMOTE_PRACTICE:
		pProjectile = FireGrenade( pPlayer, iProjectile );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_FLARE:
		pProjectile = FireFlare( pPlayer );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_MIRV:
		pProjectile = FireGrenade( pPlayer, iProjectile );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_JAR:
	case TF_PROJECTILE_JAR_MILK:
	case TF_PROJECTILE_CLEAVER:
	case TF_PROJECTILE_THROWABLE:
	case TF_PROJECTILE_FESTITIVE_URINE:
	case TF_PROJECTILE_BREADMONSTER_JARATE:
	case TF_PROJECTILE_BREADMONSTER_MADMILK:
		// TO-DO: Implement 'grenade' support
		break;

	case TF_PROJECTILE_ARROW:
	case TF_PROJECTILE_HEALING_BOLT:
	case TF_PROJECTILE_BUILDING_REPAIR_BOLT:
	case TF_PROJECTILE_FESTITIVE_ARROW:
	case TF_PROJECTILE_FESTITIVE_HEALING_BOLT:
	case TF_PROJECTILE_GRAPPLINGHOOK:
		pProjectile = FireArrow( pPlayer, iProjectile );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_NONE:
	default:
		// do nothing!
		DevMsg( "Weapon does not have a projectile type set\n" );
		break;
	}

	if ( UsesClipsForAmmo1() )
	{
		m_iClip1 -= m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_iAmmoPerShot;
	}
	else
	{
		if ( m_iWeaponMode == TF_WEAPON_PRIMARY_MODE )
		{
			pPlayer->RemoveAmmo( m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_iAmmoPerShot, m_iPrimaryAmmoType );
		}
		else
		{
			pPlayer->RemoveAmmo( m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_iAmmoPerShot, m_iSecondaryAmmoType );
		}
	}

	DoFireEffects();

	UpdatePunchAngles( pPlayer );

	return pProjectile;
}
コード例 #11
0
CBaseEntity *CTFWeaponBaseGun::FireProjectile( CTFPlayer *pPlayer )
{
	int iProjectile = m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_iProjectile;

	CBaseEntity *pProjectile = NULL;

	switch( iProjectile )
	{
	case TF_PROJECTILE_BULLET:
		FireBullet( pPlayer );
		break;

	case TF_PROJECTILE_ROCKET:
		pProjectile = FireRocket( pPlayer );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_SYRINGE:
		pProjectile = FireNail( pPlayer, iProjectile );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_NAIL:
		pProjectile = FireNail(pPlayer, iProjectile);
		pPlayer->DoAnimationEvent(PLAYERANIMEVENT_ATTACK_PRIMARY);
		break;

	case TF_PROJECTILE_DART:
		pProjectile = FireNail(pPlayer, iProjectile);
		pPlayer->DoAnimationEvent(PLAYERANIMEVENT_ATTACK_PRIMARY);
		break;

	case TF_PROJECTILE_PIPEBOMB:
		pProjectile = FirePipeBomb( pPlayer, false );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_PIPEBOMB_REMOTE:
		pProjectile = FirePipeBomb( pPlayer, true );
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
		break;

	case TF_PROJECTILE_FLARE:
		pProjectile = FireFlare(pPlayer);
		pPlayer->DoAnimationEvent(PLAYERANIMEVENT_ATTACK_PRIMARY);
		break;

	case TF_PROJECTILE_NONE:
	default:
		// do nothing!
		DevMsg( "Weapon does not have a projectile type set\n" );
		break;
	}

	if ( m_iClip1 != -1 )
	{
		m_iClip1 -= m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_iAmmoPerShot;
	}
	else
	{
		if ( m_iWeaponMode == TF_WEAPON_PRIMARY_MODE )
		{
			pPlayer->RemoveAmmo( m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_iAmmoPerShot, m_iPrimaryAmmoType );
		}
		else
		{
			pPlayer->RemoveAmmo( m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_iAmmoPerShot, m_iSecondaryAmmoType );
		}
	}

	DoFireEffects();

	UpdatePunchAngles( pPlayer );

	return pProjectile;
}
コード例 #12
0
ファイル: g_weapon.cpp プロジェクト: Xecantur/Unvanquished
void G_FireWeapon( gentity_t *self, weapon_t weapon, weaponMode_t weaponMode )
{
	// calculate muzzle
	if ( self->client )
	{
		AngleVectors( self->client->ps.viewangles, forward, right, up );
		G_CalcMuzzlePoint( self, forward, right, up, muzzle );
	}
	else
	{
		AngleVectors( self->buildableAim, forward, right, up );
		VectorCopy( self->s.pos.trBase, muzzle );
	}

	switch ( weaponMode )
	{
		case WPM_PRIMARY:
		{
			switch ( weapon )
			{
				case WP_ALEVEL1:
					FireLevel1Melee( self );
					break;

				case WP_ALEVEL3:
					FireMelee( self, LEVEL3_CLAW_RANGE, LEVEL3_CLAW_WIDTH, LEVEL3_CLAW_WIDTH,
					           LEVEL3_CLAW_DMG, MOD_LEVEL3_CLAW );
					break;

				case WP_ALEVEL3_UPG:
					FireMelee( self, LEVEL3_CLAW_UPG_RANGE, LEVEL3_CLAW_WIDTH, LEVEL3_CLAW_WIDTH,
					           LEVEL3_CLAW_DMG, MOD_LEVEL3_CLAW );
					break;

				case WP_ALEVEL2:
					FireMelee( self, LEVEL2_CLAW_RANGE, LEVEL2_CLAW_WIDTH, LEVEL2_CLAW_WIDTH,
					           LEVEL2_CLAW_DMG, MOD_LEVEL2_CLAW );
					break;

				case WP_ALEVEL2_UPG:
					FireMelee( self, LEVEL2_CLAW_U_RANGE, LEVEL2_CLAW_WIDTH, LEVEL2_CLAW_WIDTH,
					           LEVEL2_CLAW_DMG, MOD_LEVEL2_CLAW );
					break;

				case WP_ALEVEL4:
					FireMelee( self, LEVEL4_CLAW_RANGE, LEVEL4_CLAW_WIDTH, LEVEL4_CLAW_HEIGHT,
					           LEVEL4_CLAW_DMG, MOD_LEVEL4_CLAW );
					break;

				case WP_BLASTER:
					FireBlaster( self );
					break;

				case WP_MACHINEGUN:
					FireBullet( self, RIFLE_SPREAD, RIFLE_DMG, MOD_MACHINEGUN );
					break;

				case WP_SHOTGUN:
					FireShotgun( self );
					break;

				case WP_CHAINGUN:
					FireBullet( self, CHAINGUN_SPREAD, CHAINGUN_DMG, MOD_CHAINGUN );
					break;

				case WP_FLAMER:
					FireFlamer( self );
					break;

				case WP_PULSE_RIFLE:
					FirePrifle( self );
					break;

				case WP_MASS_DRIVER:
					FireMassdriver( self );
					break;

				case WP_LUCIFER_CANNON:
					FireLcannon( self, qfalse );
					break;

				case WP_LAS_GUN:
					FireLasgun( self );
					break;

				case WP_PAIN_SAW:
					FirePainsaw( self );
					break;

				case WP_LOCKBLOB_LAUNCHER:
					FireLockblob( self );
					break;

				case WP_HIVE:
					FireHive( self );
					break;

				case WP_TESLAGEN:
					FireTesla( self );
					break;

				case WP_MGTURRET:
					FireBullet( self, TURRET_SPREAD, self->turretCurrentDamage, MOD_MGTURRET );
					break;

				case WP_ABUILD:
				case WP_ABUILD2:
					FireBuild( self, MN_A_BUILD );
					break;

				case WP_HBUILD:
					FireBuild( self, MN_H_BUILD );
					break;

				default:
					break;
			}
			break;
		}
		case WPM_SECONDARY:
		{
			switch ( weapon )
			{
				case WP_LUCIFER_CANNON:
					FireLcannon( self, qtrue );
					break;

				case WP_ALEVEL2_UPG:
					FireAreaZap( self );
					break;

				case WP_ABUILD:
				case WP_ABUILD2:
				case WP_HBUILD:
					CancelBuild( self );
					break;

				default:
					break;
			}
			break;
		}
		case WPM_TERTIARY:
		{
			switch ( weapon )
			{
				case WP_ALEVEL3_UPG:
					FireBounceball( self );
					break;

				case WP_ABUILD2:
					FireSlowblob( self );
					break;

				default:
					break;
			}
			break;
		}
		default:
		{
			break;
		}
	}

}
コード例 #13
0
//-----------------------------------------------------------------------------
// Purpose: Fire a bullet in the specified direction
//-----------------------------------------------------------------------------
void CNPC_Portal_FloorTurret::InputFireBullet( inputdata_t &inputdata )
{
	FireBullet( inputdata.value.String() );
}
コード例 #14
0
ファイル: player.cpp プロジェクト: SpaceManiac/Lunatic
void PlayerFireWeapon(Guy *me)
{
	byte c;

	if (player.life == 0)
		return; // no shooting when you're dead

	switch (player.weapon) {
		case WPN_MISSILES:
			if (player.ammo)
			{
				FireBullet(me->x, me->y, me->facing, BLT_MISSILE, 1);
				player.ammo--;
			}
			player.wpnReload = 2;
			break;
		case WPN_BOMBS:
			if (player.ammo)
			{
				FireBullet(me->x, me->y, me->facing, BLT_BOMB, 1);
				player.ammo--;
			}
			player.wpnReload = 15;
			break;
		case WPN_AK8087:
			if (player.ammo)
			{
				FireBullet(me->x, me->y, me->facing, BLT_LASER, 1);
				player.ammo--;
			}
			me->z += FIXAMT * MGL_random(4);
			me->dx += FIXAMT / 2 - MGL_random(65535);
			me->dy += FIXAMT / 2 - MGL_random(65535);
			c = GetControls();
			if (c & CONTROL_B2) // fire is held
			{
				player.wpnReload = 1;
				me->frmTimer = 0;
			}
			else
			{
				player.wpnReload = 5;
			}
			DoPlayerFacing(c, me);
			break;
		case WPN_FLAME:
			if (player.ammo)
			{
				FireBullet(me->x, me->y, me->facing, BLT_FLAME, 1);
				player.ammo--;
			}
			c = GetControls();
			if (c & CONTROL_B2) // fire is held
			{
				player.wpnReload = 1;
				me->frmTimer = 0;
			}
			else
				player.wpnReload = 5;
			DoPlayerFacing(c, me);
			break;
		case WPN_BIGAXE:
			if (player.ammo)
			{
				FireBullet(me->x, me->y, me->facing, BLT_BIGAXE, 1);
				MakeSound(SND_BOMBTHROW, me->x, me->y, SND_CUTOFF, 1200);
				player.ammo--;
			}
			player.wpnReload = 10;
			break;
		case WPN_LIGHTNING:
			if (player.ammo)
			{
				// fire lightning
				FireBullet(me->x, me->y, me->facing, BLT_LIGHTNING, 1);
				player.ammo--;
			}
			c = GetControls();
			if (c & CONTROL_B2) // fire is held
			{
				player.wpnReload = 1;
				me->frmTimer = 0;
			}
			else
			{
				player.wpnReload = 5;
			}
			DoPlayerFacing(c, me);
			break;
		case WPN_SPEAR:
			if (player.ammo)
			{
				MakeSound(SND_BOMBTHROW, me->x, me->y, SND_CUTOFF, 1200);
				FireBullet(me->x, me->y, me->facing, BLT_SPEAR, 1);
				player.ammo--;
			}
			player.wpnReload = 5;
			break;
		case WPN_MACHETE:
			if (player.ammo)
			{
				MakeSound(SND_SLASH, me->x, me->y, SND_CUTOFF, 1200);
				FireBullet(me->x + Cosine(me->facing * 32)*32, me->y + Sine(me->facing * 32)*32,
						me->facing, BLT_SLASH, 1);
				player.ammo--;
			}
			player.wpnReload = 2;
			break;
		case WPN_MINES:
			if (player.ammo)
			{
				MakeSound(SND_MINELAY, me->x, me->y, SND_CUTOFF, 1200);
				FireBullet(me->x - Cosine(me->facing * 32)*32, me->y - Sine(me->facing * 32)*32,
						me->facing, BLT_MINE, 1);
				player.ammo--;
			}
			player.wpnReload = 15;
			break;
		case WPN_TURRET:
			if (player.ammo)
			{
				Guy *g;

				g = AddGuy(me->x + Cosine(me->facing * 32)*32, me->y + Sine(me->facing * 32)*32,
						FIXAMT * 10, MONS_GOODTURRET);
				if (g == NULL || !g->CanWalk(g->x, g->y, GameCurrentMap(), &curWorld))
				{
					MakeSound(SND_TURRETBZZT, me->x, me->y, SND_CUTOFF, 1200);
					if (g)
						g->type = MONS_NONE;
				}
				else
				{
					MakeSound(SND_MINELAY, me->x, me->y, SND_CUTOFF, 1200);
					player.ammo--;
				}
				player.wpnReload = 15;
			}
			break;
		case WPN_MINDCONTROL:
			if (player.ammo)
			{
				MakeSound(SND_MINDWIPE, me->x, me->y, SND_CUTOFF, 1200);
				FireBullet(me->x + Cosine(me->facing * 32)*32, me->y + Sine(me->facing * 32)*32,
						me->facing, BLT_MINDWIPE, 1);
				player.ammo--;
				player.wpnReload = 15;
			}
			break;
		case WPN_REFLECTOR:
			if (player.ammo)
			{
				MakeSound(SND_LIGHTSON, me->x, me->y, SND_CUTOFF, 1200);
				FireBullet(me->x, me->y, me->facing, BLT_REFLECT, 1);
				player.ammo--;
				c = GetControls();
				if (c & CONTROL_B2) // fire is held
				{
					player.wpnReload = 0;
					me->frmTimer = 0;
				}
				else
				{
					player.wpnReload = 10;
				}
			}
			break;
		case WPN_JETPACK:
			if (player.ammo)
			{
				player.jetting = 5;
				player.ammo--;
				player.wpnReload = 3;
			}
			break;
		case WPN_SWAPGUN:
			if (player.ammo)
			{
				MakeSound(SND_LIGHTSON, me->x, me->y, SND_CUTOFF, 1200);
				FireBullet(me->x, me->y, me->facing, BLT_SWAP, 1);
				player.ammo--;
				player.wpnReload = 10;
			}
			break;
	}
	if (!player.ammo)
		player.weapon = 0;
}
コード例 #15
0
ファイル: player.cpp プロジェクト: SpaceManiac/Lunatic
void PlayerControlMe(Guy *me, mapTile_t *mapTile, world_t *world)
{
	byte c;
	int x, y, i;

	player.life = me->hp;

	if (player.rage)
	{
		if (player.rage > 5)
			player.rage -= 6;
		else
			player.rage = 0;
	}
	if (player.rageClock)
		DoRage(me);

	if (player.invisibility)
		player.invisibility--;

	if (player.jetting && me->seq != ANIM_DIE && me->seq != ANIM_A3)
	{
		me->dx += Cosine(me->facing * 32)*6;
		me->dy += Sine(me->facing * 32)*6;
		Clamp(&me->dx, FIXAMT * 20);
		Clamp(&me->dy, FIXAMT * 20);

		if (me->z < FIXAMT * 20)
			me->z += FIXAMT * 4;
		me->dz = 0;

		MakeSound(SND_FLAMEGO, me->x, me->y, SND_CUTOFF, 1200);
		for (i = 0; i < 3; i++)
		{
			c = ((me->facing + 4)&7)*32;
			x = me->x + Cosine(c)*10 - FIXAMT * 10 + MGL_randoml(FIXAMT * 20);
			y = me->y + Sine(c)*10 - FIXAMT * 10 + MGL_randoml(FIXAMT * 20);
			FireBullet(x, y, (me->facing + 4)&7, BLT_FLAME, 1);
		}
		player.jetting--;
	}

	if (player.weapon == WPN_PWRARMOR)
	{
		PlayerControlPowerArmor(me, mapTile, world);
		return;
	}

	if (player.reload)
		player.reload--;
	if (player.wpnReload)
		player.wpnReload--;

	if (player.garlic)
	{
		player.garlic--;
		StinkySteam(me->x - FIXAMT * 20 + MGL_randoml(FIXAMT * 40), me->y - FIXAMT * 20 + MGL_randoml(FIXAMT * 40),
				me->z + FIXAMT * 40, FIXAMT * 2);
	}

	if (player.shield)
		player.shield--;

	if (player.pushPower)
		player.pushPower--;

	if (tportclock)
		tportclock--;

	// ice is slippery
	if (!(world->terrain[mapTile->floor].flags & TF_ICE))
	{
		if (player.jetting && me->mind1)
		{
			if (me->mind1 & 1)
			{
				me->dx = -me->dx;
				switch (me->facing) {
					case 0:
						me->facing = 4;
						break;
					case 1:
						me->facing = 3;
						break;
					case 2:
					case 6:
						break;
					case 3:
						me->facing = 1;
						break;
					case 4:
						me->facing = 0;
						break;
					case 5:
						me->facing = 7;
						break;
					case 7:
						me->facing = 5;
						break;
				}
			}
			if (me->mind1 & 2)
			{
				me->dy = -me->dy;
				switch (me->facing) {
					case 0:
					case 4:
						break;
					case 1:
						me->facing = 7;
						break;
					case 2:
						me->facing = 6;
						break;
					case 3:
						me->facing = 5;
						break;
					case 5:
						me->facing = 3;
						break;
					case 6:
						me->facing = 2;
						break;
					case 7:
						me->facing = 1;
						break;
				}
			}
		}
		Dampen(&me->dx, PLYR_DECEL);
		Dampen(&me->dy, PLYR_DECEL);
	}
	else
	{
		if (me->mind1) // bumped a wall while on ice
		{
			if (me->mind1 & 1)
				me->dx = -me->dx / 8;
			if (me->mind1 & 2)
				me->dy = -me->dy / 8;
		}
	}
	me->mind1 = 0;

	if (me->ouch == 4)
	{
		if (opt.playAs == PLAYAS_BOUAPHA)
		{
			if (me->hp > 0)
				MakeSound(SND_BOUAPHAOUCH, me->x, me->y, SND_CUTOFF | SND_ONE, 2000);
			else if (me->seq == ANIM_DIE) // so it doesn't do this if you're drowning
				MakeSound(SND_BOUAPHADIE, me->x, me->y, SND_CUTOFF | SND_ONE, 2000);
		}
		else if (opt.playAs == PLAYAS_LUNATIC)
		{
			if (me->hp > 0)
				MakeSound(SND_DRLOUCH, me->x, me->y, SND_CUTOFF | SND_ONE, 2000);
			else if (me->seq == ANIM_DIE) // so it doesn't do this if you're drowning
				MakeSound(SND_DRLDIE, me->x, me->y, SND_CUTOFF | SND_ONE, 2000);
		}
		else
		{
			if (me->hp > 0)
				MakeSound(SND_HAPPYOUCH, me->x, me->y, SND_CUTOFF | SND_ONE, 2000);
			else if (me->seq == ANIM_DIE) // so it doesn't do this if you're drowning
				MakeSound(SND_HAPPYDIE, me->x, me->y, SND_CUTOFF | SND_ONE, 2000);
		}
	}

	if (me->parent) // being grabbed by a Super Zombie or something
	{
		if (me->parent->type == MONS_SUPERZOMBIE)
		{
			me->dz = 0;
			if (me->parent->frm < 4)
				me->z += FIXAMT * 3;
			else if (me->parent->frm > 18)
			{
				me->z -= FIXAMT * 4;
				if (me->parent->frm == 21)
				{
					me->z = 0;
					me->parent = NULL;
					me->action = ACTION_IDLE;
					if (me->hp == 0)
					{
						me->seq = ANIM_DIE;
						me->frm = 0;
						me->frmTimer = 0;
						me->frmAdvance = 64;
						me->action = ACTION_BUSY;
					}
					return;
				}
			}
			if (me->seq != ANIM_MOVE)
			{
				me->seq = ANIM_MOVE;
				me->frm = 0;
				me->frmTimer = 0;
				me->frmAdvance = 512;
			}
			return;
		}
		else if (me->parent->type == MONS_MINECART)
		{
			me->x = me->parent->x;
			me->y = me->parent->y + 1;
			me->z = FIXAMT * 8;
		}
		else
		{
			me->parent = NULL;
		}
	}

	// triggering stuff
	if (me->action == ACTION_BUSY)
	{
		// throw hammer if need be, use item if need be
		if (me->seq == ANIM_A1 && me->frm == 2 && player.wpnReload == 0)
		{
			PlayerFireWeapon(me);
			return;
		}

		if (me->seq == ANIM_A3)
		{
			if (me->frm < 11)
			{
				me->z = FIXAMT * 8; // hover while spinning feet in the air before plunging into water
				me->dz = FIXAMT;
			}
			else
			{
				ExplodeParticles(PART_WATER, me->x, me->y, 0, 16);
			}
			return;
		}
		if (me->seq == ANIM_DIE)
		{
			me->facing = (me->facing + 1)&7;
			return;
		}
		if (me->seq == ANIM_A1)
			return;
	}

	// not busy, let's see if you want to do something
	c = GetControls();

	if (!player.jetting)
		DoPlayerFacing(c, me);

	if (me->action == ACTION_IDLE)
	{
		if ((c & (CONTROL_B1 | CONTROL_B2)) == (CONTROL_B1 | CONTROL_B2) && (player.rage / 256) >= player.life)
		{
			// RAGE!!!!!!!
			player.rage = 0;
			player.rageClock = 15;
			if (player.shield == 0)
				player.shield = 30;
			EnterRage();
		}
		if ((c & CONTROL_B1) && player.reload == 0) // pushed hammer throw button
		{
			me->action = ACTION_IDLE;
			if (!(c & (CONTROL_UP | CONTROL_DN | CONTROL_LF | CONTROL_RT)))
			{
				me->seq = ANIM_ATTACK; // even if unarmed
				me->frm = 0;
				me->frmTimer = 0;
				me->frmAdvance = 255;
				me->frm += 4 - (player.hamSpeed >> 2);
			}
			player.boredom = 0;
			if (player.hammers > 0)
				PlayerThrowHammer(me);
			player.reload += (10 - (4 - (player.hamSpeed >> 2)));
		}
コード例 #16
0
ファイル: player.cpp プロジェクト: SpaceManiac/Lunatic
byte PlayerGetItem(byte itm, int x, int y)
{
	int cx, cy;

	GetCamera(&cx, &cy);
	cx <<= FIXSHIFT;
	cy <<= FIXSHIFT;

	// won't pick up other weapons when in power armor
	if (player.weapon == WPN_PWRARMOR && (itm == ITM_MISSILES || itm == ITM_AK8087 ||
			itm == ITM_FLAME || itm == ITM_BOMBS || itm == ITM_BIGAXE || itm == ITM_SPEAR ||
			itm == ITM_MACHETE || itm == ITM_MINES || itm == ITM_LIGHTNING || itm == ITM_TURRETWPN ||
			itm == ITM_JETPACK || itm == ITM_MINDCONTROL || itm == ITM_REFLECTOR || itm == ITM_SWAPGUN))
		return 1;

	switch (itm) {
		case ITM_HAMMERUP:
			if (player.hammers < 5)
				player.hammers++;
			MakeNormalSound(SND_HAMMERUP);
			NewMessage("HAMMER UP!", 75, 0);
			player.score += 150;
			return 0;
			break;
		case ITM_PANTS:
			if (player.hamSpeed > 0)
				player.hamSpeed -= 4;
			NewMessage("PANTS OF POWER!", 75, 0);
			MakeNormalSound(SND_PANTS);
			player.score += 100;
			return 0;
			break;
		case ITM_REVERSE:
			player.hammerFlags |= HMR_REVERSE;
			NewMessage("REVERSE HAMMER!", 75, 0);
			MakeNormalSound(SND_REVERSE);
			player.score += 100;
			return 0;
			break;
		case ITM_REFLECT:
			player.hammerFlags |= HMR_REFLECT;
			NewMessage("REFLECT HAMMER!", 75, 0);
			MakeNormalSound(SND_REFLECT);
			player.score += 100;
			return 0;
			break;
		case ITM_MISSILES:
			if (player.weapon == WPN_MISSILES && player.ammo == 20) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("MISSILE PACK!", 75, 0);
			player.weapon = WPN_MISSILES;
			player.ammo = 20;
			player.score += 50;
			return 0;
			break;
		case ITM_FLAME:
			if (player.weapon == WPN_FLAME && player.ammo == 50) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("FLAMETHROWER!", 75, 0);
			player.weapon = WPN_FLAME;
			player.ammo = 50;
			player.score += 50;
			return 0;
			break;
		case ITM_BOMBS:
			if (player.weapon == WPN_BOMBS && player.ammo == 5) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("CHERRY BOMBS!", 75, 0);
			player.weapon = WPN_BOMBS;
			player.ammo = 5;
			player.score += 50;
			return 0;
			break;
		case ITM_AK8087:
			if (player.weapon == WPN_AK8087 && player.ammo == 99) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("AK-8087!", 75, 0);
			player.weapon = WPN_AK8087;
			player.ammo = 99;
			player.score += 50;
			return 0;
			break;
		case ITM_TAKEOUT:
			if (player.life == 128)
				return 1; // don't need the food

			MakeNormalSound(SND_FOOD);
			goodguy->poison = 0;
			switch (MGL_random(8)) {
				case 0:
					NewMessage("Just fried rice", 75, 0);
					PlayerHeal(5);
					break;
				case 1:
					NewMessage("Mmm, Kung Pao!", 75, 0);
					PlayerHeal(25);
					break;
				case 2:
					NewMessage("Szechwan Shredded Pork!!", 75, 0);
					PlayerHeal(50);
					break;
				case 3:
					NewMessage("Moo Shi Beef!", 75, 0);
					PlayerHeal(25);
					break;
				case 4:
					NewMessage("Ick, mostly veggies", 75, 0);
					PlayerHeal(1);
					break;
				case 5:
					NewMessage("Hmm, tastes kind of citrusy", 75, 0);
					PlayerHeal(15);
					break;
				case 6:
					NewMessage("Joy! Wontons!", 75, 0);
					PlayerHeal(20);
					break;
				case 7:
					NewMessage("GeneralTsao has outdone himself", 75, 0);
					PlayerHeal(40);
					break;
			}
			player.score += 50;
			return 0;
			break;
		case ITM_SHIELD:
			MakeNormalSound(SND_SHIELD);
			player.shield = 240;
			player.score += 50;
			NewMessage("Energy Barrier!", 30, 0);
			return 0;
			break;
		case ITM_BRAIN:
			MakeNormalSound(SND_GETBRAIN);
			player.brains++;
			if (player.brains >= TotalBrains())
			{
				player.brains = TotalBrains();
				if (opt.playAs == PLAYAS_BOUAPHA)
					MakeNormalSound(SND_KOOLKAT);
				else if (opt.playAs == PLAYAS_LUNATIC)
					MakeNormalSound(SND_DRLLAUGH);
				else
					MakeNormalSound(SND_HAPPYDIE);

				playerGlow = 127;
			}
			player.score += 25;
			return 0;
			break;
		case ITM_KEY:
			if (player.keys[0] < 3)
			{
				player.keys[0]++;
				MakeNormalSound(SND_GETKEY);
				return 0;
			}
			else
				return 1; // don't pick it up
			break;
		case ITM_KEYR:
			MakeNormalSound(SND_GETKEY);
			player.keys[1] = 1;
			return 0;
			break;
		case ITM_KEYG:
			MakeNormalSound(SND_GETKEY);
			player.keys[2] = 1;
			return 0;
			break;
		case ITM_KEYB:
			MakeNormalSound(SND_GETKEY);
			player.keys[3] = 1;
			return 0;
			break;
		case ITM_KEYCH1:
			MakeNormalSound(SND_GETKEYCHAIN);
			player.keychain[player.worldNum][0] = 1;
			KeyChainAllCheck();
			player.score += 50000;
			player.prevScore += 50000;
			NewMessage("Cool! A pumpkin keychain!", 75, 0);
			return 0;
			break;
		case ITM_KEYCH2:
			MakeNormalSound(SND_GETKEYCHAIN);
			player.keychain[player.worldNum][1] = 1;
			KeyChainAllCheck();
			player.score += 50000;
			player.prevScore += 50000;
			NewMessage("Cool! A hammer keychain!", 75, 0);
			return 0;
			break;
		case ITM_KEYCH3:
			MakeNormalSound(SND_GETKEYCHAIN);
			player.keychain[player.worldNum][2] = 1;
			KeyChainAllCheck();
			player.score += 50000;
			player.prevScore += 50000;
			NewMessage("Cool! A rocket keychain!", 75, 0);
			return 0;
			break;
		case ITM_KEYCH4:
			MakeNormalSound(SND_GETKEYCHAIN);
			player.keychain[player.worldNum][3] = 1;
			KeyChainAllCheck();
			player.score += 50000;
			player.prevScore += 50000;
			NewMessage("Cool! A squash keychain!", 75, 0);
			return 0;
			break;
		case ITM_LOONYKEY:
			MakeNormalSound(SND_LOONYKEY);
			player.lunacyKey[player.worldNum] = 1;
			player.score += 100000;
			player.prevScore += 100000;
			return 0;
			break;
#ifdef EXPANDO
		case ITM_PWRARMOR:
			MakeNormalSound(SND_ROBOBOUAPHAON);
			NewMessage("POWER ARMOR!!", 75, 0);
			player.weapon = WPN_PWRARMOR;
			player.ammo = 1000;
			player.score += 150;
			player.shield = 0;
			goodguy->seq = ANIM_A2;
			goodguy->frm = 0;
			goodguy->frmTimer = 0;
			goodguy->frmAdvance = 64;
			goodguy->action = ACTION_BUSY;
			return 0;
			break;
		case ITM_BIGAXE:
			if (player.weapon == WPN_BIGAXE && player.ammo == 15) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("BIG AXE!", 75, 0);
			player.weapon = WPN_BIGAXE;
			player.ammo = 15;
			player.score += 50;
			return 0;
			break;
		case ITM_LIGHTNING:
			if (player.weapon == WPN_LIGHTNING && player.ammo == 40) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("LIGHTNING ROD!", 75, 0);
			player.weapon = WPN_LIGHTNING;
			player.ammo = 40;
			player.score += 50;
			return 0;
			break;
		case ITM_SPEAR:
			if (player.weapon == WPN_SPEAR && player.ammo == 20) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("SPEARS!", 75, 0);
			player.weapon = WPN_SPEAR;
			player.ammo = 20;
			player.score += 50;
			return 0;
			break;
		case ITM_MACHETE:
			if (player.weapon == WPN_MACHETE && player.ammo == 30) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("MACHETE!", 75, 0);
			player.weapon = WPN_MACHETE;
			player.ammo = 30;
			player.score += 50;
			return 0;
			break;
		case ITM_MINES:
			if (player.weapon == WPN_MINES && player.ammo == 8) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("MINES!", 75, 0);
			player.weapon = WPN_MINES;
			player.ammo = 8;
			player.score += 50;
			return 0;
			break;
		case ITM_GARLIC:
			NewMessage("Fresh Garlic!", 75, 0);
			player.garlic = 255;
			return 0;
			break;
		case ITM_ORBITER:
			FireBullet(goodguy->x, goodguy->y, goodguy->facing, BLT_ORBITER, 1);
			NewMessage("ORBITER!", 75, 0);
			return 0;
			break;
		case ITM_ACCEL:
			MakeNormalSound(SND_SPEEDUP);
			NewMessage("PARTICLE ACCELERATOR!", 75, 0);
			player.speed = 255;
			return 0;
			break;
		case ITM_TURRETWPN:
			if (player.weapon == WPN_TURRET && player.ammo == 3) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("TURRETS!", 75, 0);
			player.weapon = WPN_TURRET;
			player.ammo = 3;
			player.score += 50;
			return 0;
			break;
		case ITM_MINDCONTROL:
			if (player.weapon == WPN_MINDCONTROL && player.ammo == 1) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("MIND CONTROL RAY!", 75, 0);
			player.weapon = WPN_MINDCONTROL;
			player.ammo = 1;
			player.score += 50;
			return 0;
			break;
		case ITM_REFLECTOR:
			if (player.weapon == WPN_REFLECTOR && player.ammo == 40) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("REFLECTOR SHIELD!", 75, 0);
			player.weapon = WPN_REFLECTOR;
			player.ammo = 40;
			player.score += 50;
			return 0;
			break;
		case ITM_INVIS:
			MakeNormalSound(SND_ROBOBOUAPHAON);
			NewMessage("THE CLOAK INVISIBLE!", 75, 0);
			player.score += 50;
			player.invisibility = 255;
			return 0;
			break;
		case ITM_JETPACK:
			if (player.weapon == WPN_JETPACK && player.ammo == 10) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("JETPACK!", 75, 0);
			player.weapon = WPN_JETPACK;
			player.ammo = 10;
			player.score += 50;
			return 0;
			break;
		case ITM_SWAPGUN:
			if (player.weapon == WPN_SWAPGUN && player.ammo == 3) // don't get it
				return 1;
			MakeNormalSound(SND_WEAPON);
			NewMessage("SWAPGUN!", 75, 0);
			player.weapon = WPN_SWAPGUN;
			player.ammo = 3;
			player.score += 50;
			return 0;
			break;
		case ITM_UNHAMMER:
			if (player.hammers > 0)
			{
				player.hammers--;
				player.score -= 150;
			}
			MakeNormalSound(SND_HAMMERDN);
			NewMessage("HAMMER DOWN!", 75, 0);
			return 0;
			break;
		case ITM_UNPANTS:
			if (player.hamSpeed < 16)
			{
				player.hamSpeed += 4;
				player.score -= 100;
			}
			NewMessage("PANTS OF SLOWNESS!", 75, 0);
			MakeNormalSound(SND_PANTSDN);
			return 0;
			break;
		case ITM_BADCHINESE:
			MakeNormalSound(SND_FOOD);
			goodguy->poison = 0;
			switch (MGL_random(6)) {
				case 0:
					NewMessage("Radioactive Energy!!", 75, 0);
					PlayerHeal(30);
					player.speed = 255;
					break;
				case 1:
					NewMessage("Szechwan Surprise!", 75, 0);
					PlayerHeal(128);
					break;
				case 2:
					NewMessage("Filling... with... RAGE!!", 75, 0);
					PlayerHeal(50);
					player.rage = 127 * 256;
					break;
				case 3:
					NewMessage("Toxic Mu Shu!", 75, 0);
					goodguy->poison = 255;
					break;
				case 4:
					NewMessage("Thermonuclear Heartburn!", 75, 0);
					goodguy->GetShot(0, 0, 50, GameCurrentMap(), &curWorld);
					break;
				case 5:
					NewMessage("Atomic Inviso-Power!", 75, 0);
					player.invisibility = 255;
					break;
			}
			player.score += 50;
			return 0;
			break;
#endif
	}
	return 1;
}
コード例 #17
0
ファイル: Game2.cpp プロジェクト: scheeloong/Cpp
int main(void)
{
	// primitive variables
	bool done = false; // for game loop
	bool redraw = true;  // for redraw. 
	const int FPS = 60;  // Frames Per Second
	bool isGameOver = false; 
	// initialize
	// object variables
	SpaceShip ship, ship2;
	Bullet bullet[NUM_BULLETS]; 
	Bullet bullet2[NUM_BULLETS]; 
	// Initialize 
	ALLEGRO_DISPLAY *display = NULL; 
	ALLEGRO_EVENT_QUEUE *event_queue = NULL ;
	ALLEGRO_TIMER *timer = NULL;
	ALLEGRO_FONT *font18 = NULL; 
	ALLEGRO_BITMAP *image1 = NULL , *image2 = NULL; 
	if(!al_init()) return -1; 
	display = al_create_display(WIDTH, HEIGHT); 
		if(!display) return -1; 

	// initializing primitives (for drawing ship) 
	al_init_primitives_addon(); 
	al_install_keyboard(); 
	al_init_font_addon();
	al_init_ttf_addon(); 
	al_init_image_addon(); 
	event_queue = al_create_event_queue(); 
	timer = al_create_timer(1.0/FPS); 
	// initialize objects
	srand(time(NULL)); // sees number generator with current time. 
						// as time changes, the random number changes too. 
	InitShip(ship); 
	InitShip2(ship2); 
	InitBullet(bullet, NUM_BULLETS); // array of bullets for ship
	InitBullet(bullet2, NUM_BULLETS); // array of bullets for ship2
	font18 = al_load_font("Arial.ttf", 18, 0); 
	image1 = al_load_bitmap("Ship1.bmp"); 
	image2 = al_load_bitmap("Ship2.bmp"); 
	// register keyboard. 
	al_register_event_source(event_queue, al_get_keyboard_event_source()); 
	al_register_event_source(event_queue, al_get_timer_event_source(timer)); 
	al_register_event_source(event_queue, al_get_display_event_source(display)); 
	// START TIMER
	al_start_timer(timer); 
	while(!done)
	{
		ALLEGRO_EVENT ev; 
		// wait for event to come in from queue. 
		al_wait_for_event(event_queue, &ev); 
		// only happens once every 60 seconds max. 
		if (ev.type == ALLEGRO_EVENT_TIMER)
		{
			redraw = true; 
			// update the position of the ship, depending if the keys are pressed. 
			if(keys[UP]) MoveShipUp(ship2);
			if(keys[DOWN]) MoveShipDown(ship2);
			if(keys[LEFT]) MoveShip2Left(ship2);
			if(keys[RIGHT]) MoveShip2Right(ship2);
			if(keys[W]) MoveShipUp(ship);
			if(keys[S]) MoveShipDown(ship);
			if(keys[A]) MoveShipLeft(ship);
			if(keys[D]) MoveShipRight(ship);

			if(!isGameOver)
			{
				UpdateBullet(bullet, NUM_BULLETS);  // update the position of the bullet
				UpdateBullet2(bullet2, NUM_BULLETS); 
				// test if all the objects collide after all the objects move. 
				CollideBullet(bullet, NUM_BULLETS, ship2, ship); 
				CollideBullet2(bullet2, NUM_BULLETS, ship, ship2); 
				if(ship.lives <= 0 || ship2.lives <=0) isGameOver = 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_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = true;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = true;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = true;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = true; 
				FireBullet2(bullet2, NUM_BULLETS, ship2); // break to fire one bullet only
				break; 
			case ALLEGRO_KEY_W:
				keys[W] = true;
				break;
			case ALLEGRO_KEY_A:
				keys[A] = true;
				break;
			case ALLEGRO_KEY_S:
				keys[S] = true;
				break;
			case ALLEGRO_KEY_D:
				keys[D] = true;
				break;
			case ALLEGRO_KEY_E:
				keys[E] = true; 
				FireBullet(bullet, NUM_BULLETS, ship); // break to fire one bullet only
				break; 
			}
		}

		else if(ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			switch(ev.keyboard.keycode)
			{
				case ALLEGRO_KEY_ESCAPE:
					done = true;
					break;
				case ALLEGRO_KEY_UP:
					keys[UP] = false;
					break;
				case ALLEGRO_KEY_DOWN:
					keys[DOWN] = false;
					break;
				case ALLEGRO_KEY_LEFT:
					keys[LEFT] = false;
					break;
				case ALLEGRO_KEY_RIGHT:
					keys[RIGHT] = false;
					break;
				case ALLEGRO_KEY_SPACE:
					keys[SPACE] = false; 
					break; 
				case ALLEGRO_KEY_W:
					keys[W] = false;
					break;
				case ALLEGRO_KEY_A:
					keys[A] = false;
					break;
				case ALLEGRO_KEY_S:
					keys[S] = false;
					break;
				case ALLEGRO_KEY_D:
					keys[D] = false;
					break;
				case ALLEGRO_KEY_E:
					keys[E] = false; 
					// break to fire one bullet only
					break; 
			}
		}

		// if redraw is true and no queue for event. 
		if ( redraw && al_is_event_queue_empty(event_queue))
		{
			redraw = false; 

			if (!isGameOver)
			{
				// draws the latest position of bullet and ship that has been updated. 
				DrawShip(ship, image1); // Draw ship
				DrawShip(ship2, image2); 
				DrawBullet(bullet, NUM_BULLETS); // draw bullets 
				DrawBullet(bullet2, NUM_BULLETS); 
				al_draw_textf(font18, al_map_rgb(255,0,255), 5, 5, 0, "Player 1 Lives left: %i \nScore: %i\n", ship.lives, ship.score); 
				al_draw_textf(font18, al_map_rgb(255,0,255), 50, 50, 0, "Player 2Lives left: %i \nScore: %i\n", ship2.lives, ship2.score);
			}
			else 
			{ al_draw_textf(font18, al_map_rgb(0,255,255), WIDTH/2, HEIGHT/2, ALLEGRO_ALIGN_CENTRE,
							"GAME OVER. P1 Final Score: %i\n P2 Final Score %i",ship.score, ship2.score); 

			}
			al_flip_display(); 
			al_clear_to_color(al_map_rgb(0, 0, 0)); 
		}
	}
	al_destroy_display(display); 
	return 0;
}
コード例 #18
0
ファイル: WeaponFire.cpp プロジェクト: 2asoft/xray
void CWeapon::FireTrace		(const Fvector& P, const Fvector& D)
{
	VERIFY		(m_magazine.size());

	CCartridge &l_cartridge = m_magazine.back();
//	Msg("ammo - %s", l_cartridge.m_ammoSect.c_str());
	VERIFY		(u16(-1) != l_cartridge.bullet_material_idx);
	//-------------------------------------------------------------	
	l_cartridge.m_flags.set				(CCartridge::cfTracer,(m_bHasTracers & !!l_cartridge.m_flags.test(CCartridge::cfTracer)));
	if (m_u8TracerColorID != u8(-1))
		l_cartridge.param_s.u8ColorID	= m_u8TracerColorID;
	//-------------------------------------------------------------
	//повысить изношенность оружия с учетом влияния конкретного патрона
//	float Deterioration = GetWeaponDeterioration();
//	Msg("Deterioration = %f", Deterioration);
	ChangeCondition(-GetWeaponDeterioration()*l_cartridge.param_s.impair);

	
	float fire_disp = 0.f;
	CActor* tmp_actor = NULL;
	if (!IsGameTypeSingle())
	{
		tmp_actor = smart_cast<CActor*>(Level().CurrentControlEntity());
		if (tmp_actor)
		{
			CEntity::SEntityState state;
			tmp_actor->g_State(state);
			if (m_first_bullet_controller.is_bullet_first(state.fVelocity))
			{
				fire_disp = m_first_bullet_controller.get_fire_dispertion();
				m_first_bullet_controller.make_shot();
			}
		}
	}
	if (fsimilar(fire_disp, 0.f))
	{
		//CActor* tmp_actor = smart_cast<CActor*>(Level().CurrentControlEntity());
		if (H_Parent() && (H_Parent() == tmp_actor))
		{
			fire_disp = tmp_actor->GetFireDispertion();
		} else
		{
			fire_disp = GetFireDispersion(true);
		}
	}
	

	bool SendHit = SendHitAllowed(H_Parent());
	//выстерлить пулю (с учетом возможной стрельбы дробью)
	for(int i = 0; i < l_cartridge.param_s.buckShot; ++i) 
	{
		FireBullet(P, D, fire_disp, l_cartridge, H_Parent()->ID(), ID(), SendHit);
	}

	StartShotParticles		();
	
	if(m_bLightShotEnabled) 
		Light_Start			();

	
	// Ammo
	m_magazine.pop_back	();
	--iAmmoElapsed;

	VERIFY((u32)iAmmoElapsed == m_magazine.size());
}
コード例 #19
0
int main(void)
{
	// don't forget to put allegro-5.0.10-monolith-md-debug.lib
	//primitive variable
	bool done = false;
	bool redraw = true;
	const int FPS = 60;
	bool isGameOver = false;

	//object variables
	spaceShip ship;
	Bullet bullets[NUM_BULLETS];
	Comet comets[NUM_COMETS];
	Explosion explosions[NUM_EXPLOSIONS];

	//Allegro variables
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_TIMER *timer = NULL;
	ALLEGRO_FONT *font18 = NULL;
	ALLEGRO_BITMAP *shipImage;
	ALLEGRO_BITMAP *cometImage;
	ALLEGRO_BITMAP *expImage;
	ALLEGRO_SAMPLE * sample = NULL;
	ALLEGRO_SAMPLE * sample2 = NULL;
	ALLEGRO_SAMPLE * sample3 = NULL;
	ALLEGRO_SAMPLE_INSTANCE * instance1 = NULL;
	ALLEGRO_SAMPLE_INSTANCE * instance2 = NULL;
	ALLEGRO_SAMPLE_INSTANCE * instance3 = NULL;

	//Initialization Functions
	if(!al_init())										//initialize Allegro
		return -1;

	display = al_create_display(WIDTH, HEIGHT);			//create our display object

	if(!display)										//test display object
		return -1;

	al_init_primitives_addon();
	al_install_keyboard();
	al_init_font_addon();
	al_init_ttf_addon();
	al_init_image_addon();
	al_install_audio(); // always initialize audio before the codecs
	al_init_acodec_addon();
	
	al_reserve_samples(10); // reserves numbers of samples/ channels or voices

	sample = al_load_sample("chirp.ogg");
	sample2 = al_load_sample("static.ogg");
	sample3 = al_load_sample("JSS - Our Song.ogg");

	instance1 = al_create_sample_instance(sample);
	instance2 = al_create_sample_instance(sample2);
	instance3 = al_create_sample_instance(sample3);	

	al_set_sample_instance_playmode(instance3, ALLEGRO_PLAYMODE_LOOP);

	al_attach_sample_instance_to_mixer(instance1, al_get_default_mixer());
    al_attach_sample_instance_to_mixer(instance2, al_get_default_mixer());
	al_attach_sample_instance_to_mixer(instance3, al_get_default_mixer());

	event_queue = al_create_event_queue();
	timer = al_create_timer(1.0 / FPS);

	cometImage = al_load_bitmap("asteroid-1-96.png");
	//above does not need convert_mask_to_alpha because it is tranparent background in sprite sheet
	shipImage = al_load_bitmap("Spaceship_by_arboris.png");
	al_convert_mask_to_alpha(shipImage,al_map_rgb(255,0,255));

	expImage = al_load_bitmap("explosion_3_40_128.png");

	srand(time(NULL));
	InitShip(ship, shipImage);
	InitBullet(bullets, NUM_BULLETS);
	InitComet(comets, NUM_COMETS, cometImage);
	InitExplosions(explosions, NUM_EXPLOSIONS, expImage);

	font18 = al_load_font("arial.ttf", 18, 0);

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

	al_play_sample_instance(instance3);

	al_start_timer(timer);
	while(!done)
	{
		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev);

		if(ev.type == ALLEGRO_EVENT_TIMER)
		{
			redraw = true;
			int soundX = ship.x;
			int soundY = ship.y;
			
			if(keys[UP])
				MoveShipUp(ship);
			else if(keys[DOWN])
				MoveShipDown(ship);
			else
				ResetShipAnimation(ship,1);
			if(keys[LEFT])
				MoveShipLeft(ship);
			else if(keys[RIGHT])
				MoveShipRight(ship);
			else
				ResetShipAnimation(ship, 2);
			
			if(soundX != ship.x || soundY != ship.y){
				//al_play_sample(sample, 1,0,1, ALLEGRO_PLAYMODE_ONCE, NULL);
				al_play_sample_instance(instance1);
			}
			if (ship.x -10 < 0 || ship.x + 10 > WIDTH || ship.y - 10 < 0 || ship.y + 10 > HEIGHT){
				al_play_sample_instance(instance2);
			}

			if(!isGameOver)
			{
				UpdateExplosions(explosions, NUM_EXPLOSIONS);
				UpdateBullet(bullets, NUM_BULLETS);
				StartComet(comets, NUM_COMETS);
				UpdateComet(comets, NUM_COMETS);
				CollideBullet(bullets, NUM_BULLETS, comets, NUM_COMETS, ship, explosions, NUM_EXPLOSIONS);
				CollideComet(comets, NUM_COMETS, ship, explosions, NUM_BULLETS);

				if(ship.lives <= 0)
					isGameOver = 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_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = true;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = true;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = true;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = true;
				FireBullet(bullets, NUM_BULLETS, ship);
				break;
			}
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			switch(ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = false;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = false;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = false;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = false;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = false;
				break;
			}
		}

		if(redraw && al_is_event_queue_empty(event_queue))
		{
			redraw = false; 

			if(!isGameOver)
			{
				DrawShip(ship);
				if(al_get_sample_instance_playing(instance1)){
					al_draw_text(font18, al_map_rgb(255,255,255),5,30,0, "Instance 1 is playing");
				}
				if(al_get_sample_instance_playing(instance2)){
					al_draw_text(font18, al_map_rgb(255,255,255),WIDTH - 5,30,ALLEGRO_ALIGN_RIGHT, "Instance 2 is playing");
				}
				if(al_get_sample_instance_playing(instance3)){
					al_draw_textf(font18, al_map_rgb(255,255,255),5,HEIGHT - 30,0, "Instance 3 is playing: %.1f %%", al_get_sample_instance_position(instance3) / (float)al_get_sample_instance_length(instance3) * 100);
				}

				DrawBullet(bullets, NUM_BULLETS);
				DrawComet(comets, NUM_COMETS);
				DrawExplosions(explosions, NUM_EXPLOSIONS);

				al_draw_textf(font18, al_map_rgb(255, 0, 255), 5, 5, 0, "Player has %i lives left. Player has destroyed %i objects", ship.lives, ship.score);
			}
			else
			{
				al_draw_textf(font18, al_map_rgb(0, 255, 255), WIDTH / 2, HEIGHT / 2, ALLEGRO_ALIGN_CENTRE, "Game Over. Final Score: %i", ship.score);
			}
		
			al_flip_display();
			al_clear_to_color(al_map_rgb(0,0,0));
		}
	}

	al_destroy_sample_instance(instance1);
	al_destroy_sample_instance(instance2);
	al_destroy_sample_instance(instance3);
	al_destroy_sample(sample);
	al_destroy_sample(sample2);
	al_destroy_sample(sample3);
	al_destroy_bitmap(expImage);
	al_destroy_bitmap(shipImage);
	al_destroy_bitmap(cometImage);
	al_destroy_event_queue(event_queue);
	al_destroy_timer(timer);
	al_destroy_font(font18);
	al_destroy_display(display);						//destroy our display object

	return 0;
}
コード例 #20
0
//---------------------------------------------------------
//---------------------------------------------------------
void CNPC_Combine_Cannon::RunTask( const Task_t *pTask )
{
	switch( pTask->iTask )
	{
	case TASK_CANNON_ATTACK_CURSOR:
		if( FireBullet( m_vecPaintCursor, true ) )
		{
			TaskComplete();
		}
		break;

	case TASK_RANGE_ATTACK1:
		{
			// Where we're focusing our fire
			Vector vecTarget = ( m_hBarrageTarget == NULL ) ? m_vecPaintCursor : LeadTarget( m_hBarrageTarget );

			// Fire at enemy
			if ( FireBullet( vecTarget, true ) )
			{
				bool bPlayerIsEnemy = ( m_hBarrageTarget && m_hBarrageTarget->IsPlayer() );
				bool bBarrageFinished = m_flBarrageDuration < gpGlobals->curtime;
				bool bNoShot = ( QuerySeeEntity( m_hBarrageTarget ) == false );	// FIXME: Store this info off better
				bool bSeePlayer = HasCondition( COND_SEE_PLAYER	);
				
				// Treat the player differently to normal NPCs
				if ( bPlayerIsEnemy )
				{
					// Store the last time we shot for doing an abbreviated attack telegraph
					m_flTimeLastAttackedPlayer = gpGlobals->curtime;

					// If we've got no shot and we're done with our current barrage
					if ( bNoShot && bBarrageFinished )
					{
						TaskComplete();
					}
				}
				else if ( bBarrageFinished || bSeePlayer )
				{
					// Done with the barrage or we saw the player as a better target
					TaskComplete();
				}
			}
		}
		break;

	case TASK_CANNON_PAINT_ENEMY:
		{
			// See if we're done painting our target
			if ( IsWaitFinished() )
			{			
				TaskComplete();
			}

			// Continue to paint the target
			PaintTarget( LeadTarget( GetEnemy() ), m_flPaintTime );
		}
		break;

	default:
		BaseClass::RunTask( pTask );
		break;
	}
}
コード例 #21
0
int main(void)
{
	//primitive variable
	bool done = false;
	bool redraw = true;
	const int FPS = 60;
	bool isGameOver = false;

	//object variables
	SpaceShip ship;
	Bullet bullets[NUM_BULLETS];
	Comet comets[NUM_COMETS];

	//Allegro variables
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_TIMER *timer = NULL;
	ALLEGRO_FONT *font18 = NULL;

	//Initialization Functions
	if(!al_init())										//initialize Allegro
		return -1;

	display = al_create_display(WIDTH, HEIGHT);			//create our display object

	if(!display)										//test display object
		return -1;

	al_init_primitives_addon();
	al_install_keyboard();
	al_init_font_addon();
	al_init_ttf_addon();

	event_queue = al_create_event_queue();
	timer = al_create_timer(1.0 / FPS);

	srand(time(NULL));
	InitShip(ship);
	InitBullet(bullets, NUM_BULLETS);
	InitComet(comets, NUM_COMETS);
	
	font18 = al_load_font("arial.ttf", 18, 0);

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

	al_start_timer(timer);
	while(!done)
	{
		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev);

		if(ev.type == ALLEGRO_EVENT_TIMER)
		{
			redraw = true;
			if(keys[UP])
				MoveShipUp(ship);
			if(keys[DOWN])
				MoveShipDown(ship);
			if(keys[LEFT])
				MoveShipLeft(ship);
			if(keys[RIGHT])
				MoveShipRight(ship);

			if(!isGameOver)
			{
				UpdateBullet(bullets, NUM_BULLETS);
				StartComet(comets, NUM_COMETS);
				UpdateComet(comets, NUM_COMETS);
				CollideBullet(bullets, NUM_BULLETS, comets, NUM_COMETS, ship);
				CollideComet(comets, NUM_COMETS, ship);

				if(ship.lives <= 0)
					isGameOver = 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_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = true;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = true;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = true;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = true;
				FireBullet(bullets, NUM_BULLETS, ship);
				break;
			}
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			switch(ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = false;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = false;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = false;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = false;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = false;
				break;
			}
		}

		if(redraw && al_is_event_queue_empty(event_queue))
		{
			redraw = false; 

			if(!isGameOver)
			{
				DrawShip(ship);
				DrawBullet(bullets, NUM_BULLETS);
				DrawComet(comets, NUM_COMETS);

				al_draw_textf(font18, al_map_rgb(255, 0, 255), 5, 5, 0, "Player has %i lives left. Player has destroyed %i objects", ship.lives, ship.score);
			}
			else
			{
				al_draw_textf(font18, al_map_rgb(0, 255, 255), WIDTH / 2, HEIGHT / 2, ALLEGRO_ALIGN_CENTRE, "Game Over. Final Score: %i", ship.score);
			}
		
			al_flip_display();
			al_clear_to_color(al_map_rgb(0,0,0));
		}
	}

	al_destroy_event_queue(event_queue);
	al_destroy_timer(timer);
	al_destroy_font(font18);
	al_destroy_display(display);						//destroy our display object

	return 0;
}
コード例 #22
0
int main(void)
{
    bool done = false; // Variavel booleana para identificar se o programa terminou de ser executado
    bool redraw = true; // Enquanto essa variavel for verdadeira, ira ser desenhado algo na tela
    bool desenha = true;
    int draw[5]= {0, 0, 0, 0, 0};
    int pos_x = WIDTH / 2;
    int pos_y = HEIGHT / 2;
    int timer_tiros = 0;
    int timer_energy = 0;
    int timer_heats = 0;
    int timer_tamenho_heat = 0;
    int timer_componente = 0;
    int count = 0;


    Gamer(gamer);
    Zone zone[LINHAS][COLUNAS];
    Bullet bullets[NUM_BULLETS+1];
    Energy energy[NUM_ENERGYS+1];
    Heat heats[NUM_HEAT+1];
    Zombie zombie[NUM_ZOMBIES];
    Battery battery[NUM_BATTERY];


    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;
    ALLEGRO_FONT *font18 = NULL;
    ALLEGRO_FONT *font_maior = NULL;
    ALLEGRO_BITMAP *resistor = NULL;
    ALLEGRO_BITMAP *capacitor = NULL;
    ALLEGRO_BITMAP *indutor = NULL;
    ALLEGRO_BITMAP *diodo = NULL;
    ALLEGRO_BITMAP *bateria = NULL;
    ALLEGRO_BITMAP *protoboard = NULL;
    ALLEGRO_BITMAP *fogo = NULL;
    ALLEGRO_BITMAP *zombie_bitmap = NULL;
    ALLEGRO_BITMAP *ataque_eletromagnetico = NULL;
    ALLEGRO_BITMAP *energia_capacitor = NULL;
    ALLEGRO_BITMAP *logo = NULL;


    if(!al_init())										//initialize Allegro
        return -1;

    display = al_create_display(WIDTH, HEIGHT);			//create our display object

    if(!display)										//test display object
        return -1;

    al_init_primitives_addon();
    al_install_keyboard();
    al_init_font_addon();
    al_init_ttf_addon();
    al_install_mouse();
    al_init_image_addon();

    resistor = al_load_bitmap("Resistor.png");
    capacitor = al_load_bitmap("Capacitor.png");
    indutor = al_load_bitmap("Indutor.png");
    diodo = al_load_bitmap("Diodo.png");
    bateria = al_load_bitmap("Bateria.png");
    protoboard = al_load_bitmap("Protoboard.png");
    fogo = al_load_bitmap("fogo_resistor/fire1.png");
    zombie_bitmap = al_load_bitmap("Zombie.png");
    ataque_eletromagnetico = al_load_bitmap("eletromagnetismo.jpg");
    energia_capacitor = al_load_bitmap("energia_capacitor.png");
    logo = al_load_bitmap("logo_EvsZ.jpg");

    al_convert_mask_to_alpha(resistor, al_map_rgb(255, 0, 255));
    al_convert_mask_to_alpha(capacitor, al_map_rgb(255, 0, 255));
    al_convert_mask_to_alpha(indutor, al_map_rgb(255, 0, 255));
    al_convert_mask_to_alpha(diodo, al_map_rgb(255, 0, 255));
    al_convert_mask_to_alpha(bateria, al_map_rgb(255, 0, 255));
    al_convert_mask_to_alpha(zombie_bitmap, al_map_rgb(255, 255, 255));
    al_convert_mask_to_alpha(ataque_eletromagnetico, al_map_rgb(255, 255, 255));


    event_queue = al_create_event_queue();
    timer = al_create_timer(1.0 / FPS);

    InitGamer(gamer);
    InitZone(zone, LINHAS, COLUNAS);
    InitBullet(bullets, NUM_BULLETS+1);
    InitHeat(heats, NUM_HEAT+1);
    InitZombie(zombie, NUM_ZOMBIES);
    InitEnergy(energy, NUM_ENERGYS+1);
    InitBattery(battery, NUM_BATTERY);

    font18 = al_load_font("arial.ttf", 18, 0);
    font_maior = al_load_font("arial.ttf", 24, 0);

    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_timer_event_source(timer));
    al_register_event_source(event_queue, al_get_display_event_source(display));

    al_hide_mouse_cursor(display);
    al_start_timer(timer);

    while(!done)
    {
        ALLEGRO_EVENT ev;
/*===============================================================================================================================================*/
        if(state == MENU)
        {
            al_wait_for_event(event_queue, &ev);

            al_draw_bitmap(logo, WIDTH / 2 - 145, HEIGHT - 500, 0);
            al_draw_text(font18, al_map_rgb(255, 255, 255), WIDTH / 2, HEIGHT / 2, ALLEGRO_ALIGN_CENTRE, "Os Zombies querem roubar seu diploma, proteja-o");
            al_draw_text(font18, al_map_rgb(0, 255, 255), WIDTH / 2, HEIGHT / 2 + 100, ALLEGRO_ALIGN_CENTRE, "Pressione Space para jogar");
            al_draw_text(font_maior, al_map_rgb(0, 255, 0), WIDTH / 2, HEIGHT / 2 + 150, ALLEGRO_ALIGN_CENTRE, "Tecla 1 = Resistor Tecla 2 = Capacitor  Tecla 3 = Indutor  Tecla 4 = Diodo");
            if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
                if(ev.keyboard.keycode == ALLEGRO_KEY_SPACE)
                    state = PLAYING;

            if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
                done = true;

            al_flip_display();

        }
/*===============================================================================================================================================*/
        if(state == PLAYING)
        {
            al_wait_for_event(event_queue, &ev);

            if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
                done = true;

            if(ev.type == ALLEGRO_EVENT_TIMER)
            {
                redraw = true;


                    for(int i = 0; i < LINHAS; i++)
                        for(int j=0; j<COLUNAS; j++)
                            if(zone[i][j].x < pos_x &&
                                    zone[i][j].x + ZONEX > pos_x &&
                                    zone[i][j].y < pos_y &&
                                    zone[i][j].y + ZONEY > pos_y)
                                if(desenha)
                                    if(zone[i][j].draw == 0)
                                    {
                                        if(keys[KEY_1] && gamer.energy >= 100)
                                        {
                                            zone[i][j].draw = draw[1];
                                            gamer.energy -=100;
                                            draw[1] = 0;
                                        }
                                        if(keys[KEY_2] && gamer.energy >= 50)
                                        {
                                            zone[i][j].draw = draw[2];
                                            gamer.energy -=50;
                                            draw[2] = 0;
                                        }
                                        if(keys[KEY_3] && gamer.energy >= 100)
                                        {
                                            zone[i][j].draw = draw[3];
                                            gamer.energy -=100;
                                            draw[3] = 0;
                                        }
                                        if(keys[KEY_4] && gamer.energy >= 100)
                                        {
                                            zone[i][j].draw = draw[4];
                                            gamer.energy -=100;
                                            draw[4] = 0;
                                        }
                                    }
                timer_battery_speed++;
                timer_battery_start++;
                if(timer_battery_start >= 360) // diminui a frequencia com que nasce uma bateria nova
                {
                    StartBattery(battery, NUM_BATTERY);
                    timer_battery_start = 0;
                }

                if(timer_battery_speed >= 2) // reduz um pouco a velocidade da bateria
                {
                    UpdateBattery(battery, NUM_BATTERY);
                    timer_battery_speed = 0;
                }


                timer_heats++;

                for(int i=0; i<LINHAS; i++)
                    for(int j=0; j<COLUNAS; j++)
                        if(zone[i][j].draw == 1)
                            if(timer_heats >= 200)
                            {
                                FireHeat(heats, NUM_HEAT+1, zone);
                                timer_heats = 0;
                            }

                timer_energy++;
                timer_energy_cap_death++;

                for(int i=0; i<LINHAS; i++)
                    for(int j=0; j<COLUNAS; j++)
                        if(zone[i][j].draw == 2)
                        {
                            if(timer_energy >= 420)
                            {
                                CreateEnergy(energy, NUM_ENERGYS+1, zone);
                                timer_energy = 0;
                            }

                        }

                timer_tiros++;

                for(int i=0; i<LINHAS; i++)
                    for(int j=0; j<COLUNAS; j++)
                        if(zone[i][j].draw == 3)
                            if(timer_tiros >= 200) // faz os Electronics atirarem numa velocidade constante
                            {
                                FireBullet(bullets, NUM_BULLETS+1, zone);
                                timer_tiros = 0;
                            }
                timer_zombie_start++;
                timer_zombie_speed++;
                timer_dificuldade++;
                if(timer_zombie_start >= 3)
                {
                    StartZombie(zombie, NUM_ZOMBIES);
                    timer_zombie_start = 0;
                }
                if(dificuldade >20 && dificuldade <=500)
                {
                if(timer_dificuldade >= 300)
                    {
                        dificuldade -= 30;
                        timer_dificuldade = 0;
                    }
                }
                if(timer_zombie_speed >= 3)
                {
                    UpdateZombie(zombie, NUM_ZOMBIES);
                    timer_zombie_speed = 0;
                }


                UpdateBullet(bullets, NUM_BULLETS+1);
                CollideBullet(bullets, NUM_BULLETS, zombie, NUM_ZOMBIES, gamer);
                CollideHeat(heats, NUM_HEAT, zombie, NUM_ZOMBIES, gamer, timer_tamenho_heat);
                CollideZone(zone, LINHAS, COLUNAS, zombie, NUM_ZOMBIES);
                CollideZoneDiodo(zone, LINHAS, COLUNAS, zombie, NUM_ZOMBIES);


                for(int i = 0; i < NUM_ENERGYS; i++)
                    if(energy[i].live)
                        if(energy[i].x - energy[i].boundx < pos_x &&
                                energy[i].x + energy[i].boundx > pos_x &&
                                energy[i].y - energy[i].boundy < pos_y &&
                                energy[i].y + energy[i].boundy > pos_y)
                        {
                            energy[i].live = false;
                            gamer.energy += 25;
                        }


            }
            else if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
            {
                switch(ev.keyboard.keycode)
                {
                case ALLEGRO_KEY_ESCAPE:
                    done = true;
                    break;
                case ALLEGRO_KEY_1:
                    keys[KEY_1] = true;
                    break;
                case ALLEGRO_KEY_2:
                    keys[KEY_2] = true;
                    break;
                case ALLEGRO_KEY_3:
                    keys[KEY_3] = true;
                    break;
                case ALLEGRO_KEY_4:
                    keys[KEY_4] = true;
                    break;
                }
            }
            else if(ev.type == ALLEGRO_EVENT_KEY_UP)
            {
                switch(ev.keyboard.keycode)
                {
                case ALLEGRO_KEY_ESCAPE:
                    done = true;
                    break;
                case ALLEGRO_KEY_1:
                    keys[KEY_1] = false;
                    break;
                case ALLEGRO_KEY_2:
                    keys[KEY_2] = false;
                    break;
                case ALLEGRO_KEY_3:
                    keys[KEY_3] = false;
                    break;
                case ALLEGRO_KEY_4:
                    keys[KEY_4] = false;
                    break;
                }
            }
            else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
            {
                if (ev.mouse.button & 2)
                    done = true;
            }
            else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES)
            {
                pos_x = ev.mouse.x;
                pos_y = ev.mouse.y;
                CaptureBattery(battery, NUM_BATTERY, ev.mouse.x, ev.mouse.y, gamer);
            }

            timer_componente++;

            if(timer_componente >= 10)
            {
                if(keys[KEY_1])
                    draw[1] = 1;
                if(keys[KEY_2])
                    draw[2] = 2;
                if(keys[KEY_3])
                    draw[3] = 3;
                if(keys[KEY_4])
                    draw[4] = 4;
            }

            if(redraw && al_is_event_queue_empty(event_queue))
            {
                redraw = false;


                DrawZone(zone, LINHAS, COLUNAS, resistor, capacitor, indutor, diodo);
                DrawBullet(bullets, NUM_BULLETS+1, ataque_eletromagnetico);
                DrawEnergy(energy, NUM_ENERGYS+1, energia_capacitor);
                DrawZombie(zombie, NUM_ZOMBIES, zombie_bitmap);
                DrawBattery(battery, NUM_BATTERY, bateria);
                timer_tamenho_heat++;
                DrawHeat(heats, NUM_HEAT+1, timer_tamenho_heat, fogo);
                if(timer_tamenho_heat > 80)
                    for(int i=0; i<NUM_HEAT; i++)
                    {
                        heats[i].live = false;
                        timer_tamenho_heat = 0;
                    }


                al_draw_filled_rectangle(pos_x, pos_y, pos_x + 10, pos_y + 10, al_map_rgb(0, 0, 0));
                count++;
                al_draw_textf(font18, al_map_rgb(255, 0, 0), WIDTH*13/16, 85, 0, "Time: %i", count/60);
                al_draw_textf(font18, al_map_rgb(255, 0, 0), WIDTH*13/300, 85, 0, "Energy: %i", gamer.energy);
                al_draw_textf(font18, al_map_rgb(255, 0, 0), WIDTH*13/25, 85, 0, "Score: %i", gamer.score);
                al_flip_display();
                al_draw_bitmap(protoboard, 0, 0, 0);
            }

        }
    /*================================================================================================================================================*/
        if(state == GAMEOVER)
        {
            al_wait_for_event(event_queue, &ev);
            al_clear_to_color(al_map_rgb(0,0,0));
            al_draw_text(font18, al_map_rgb(255, 168, 255), WIDTH / 2, HEIGHT / 2, ALLEGRO_ALIGN_CENTRE, "Os Zombies roubaram seu diploma");
            al_draw_text(font18, al_map_rgb(255, 255, 255), WIDTH / 2, HEIGHT / 2 +40, ALLEGRO_ALIGN_CENTRE, "Pressione Space para sair");
            al_draw_textf(font_maior, al_map_rgb(255, 0, 0), WIDTH*13/28, 85, 0, "Score: %i", gamer.score);
            al_flip_display();

            if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
                done = true;

            if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
                if(ev.keyboard.keycode == ALLEGRO_KEY_SPACE)
            {
                al_destroy_event_queue(event_queue);
                al_destroy_timer(timer);
                al_destroy_font(font18);
                al_destroy_bitmap(resistor);
                al_destroy_bitmap(capacitor);
                al_destroy_bitmap(indutor);
                al_destroy_bitmap(diodo);
                al_destroy_bitmap(bateria);
                al_destroy_bitmap(protoboard);
                al_destroy_bitmap(zombie_bitmap);
                al_destroy_display(display);

            }




        }
    }


    return 0;
}
コード例 #23
0
ファイル: copy of main.c プロジェクト: BADSA/GALAGA
int main(void){
	//allegro variables
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_BITMAP *bg = NULL;
	ALLEGRO_TIMER *timer;

	//program init
	if(!al_init())										//initialize Allegro
		return -1;

	display = al_create_display(WIDTH, HEIGHT);			//create our display object

	if(!display)										//test display object
		return -1;

	//==============================================
	//ADDON INSTALL
	//==============================================
	al_install_keyboard();
	al_init_image_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	al_init_primitives_addon();

    // FONT DEL PROGRAMA.
	ALLEGRO_FONT *font = al_load_ttf_font("Sarpanch-SemiBold.ttf",30,0 );

    // VARIABLES DEL JUEGO ========================
    bg = al_load_bitmap("img/sp1.jpg");

    SpaceShip nave_jugador;
    Enemy enemies1[10];
    Enemy enemies2[10];
    Enemy enemies3[10];
    Enemy enemies4[10];
    Enemy jefe1[10];
    Bullet bullets[5];


    char vidas_char[2];


    // INICIALIZAR OBJETOS====================
    InitShip(nave_jugador);
    InitBullet(bullets, NUM_BULLETS);
    InitEnemies(enemies1,ENM1,10,0,220,WIDTH/2);
    InitEnemies(enemies2,ENM2,8,50,180,WIDTH/2+100);
    InitEnemies(enemies3,ENM3,6,100,140,WIDTH);
    InitEnemies(enemies4,ENM4,4,150,100,(WIDTH/2)+100);
    InitEnemies(jefe1,JEFE,2,200,60);
    //DrawEnemies(enemies,NUM_ENEMIES);

	//==============================================
	//TIMER INIT AND STARTUP
	//==============================================
	event_queue = al_create_event_queue();
	timer = al_create_timer(1.0 / 60);

	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_keyboard_event_source());

	al_start_timer(timer);

    //AnimacionEntrada(enemies,NUM_ENEMIES);
    printf("ya");
    int animacion=1;
    int movimientos=0;
	while(!done){

		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev);

        // INFORMACION DEL JUEGO Y BG
        // DrawWindowStatus();
		al_draw_bitmap(bg, 0, 0, 0);
        al_draw_bitmap(nave_jugador.image, 5,440,0);
        al_draw_text(font, al_map_rgb(255,255,255), 40,430, 0, "X");
        sprintf(vidas_char,"%d",vidas);
        al_draw_text(font, al_map_rgb(255,255,255), 60,430, 0, vidas_char);
        al_draw_text(font, al_map_rgb(255,255,255), WIDTH/2 - 30, 0,ALLEGRO_ALIGN_CENTRE, "Score");
        char vartext[10];
        sprintf(vartext,"%d",score);
        al_draw_text(font, al_map_rgb(255,255,255), WIDTH/2 + 40, 0, 0, vartext);


		//==============================================
		//INPUT
		//==============================================
        if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			done = true;
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_DOWN){
			switch(ev.keyboard.keycode){
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = true;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = true;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = true;
				FireBullet(bullets, NUM_BULLETS, nave_jugador);
				break;
			}
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_UP)
        {
			switch(ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = false;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = false;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = false;
				break;
			}
		}


		//==============================================
		//GAME UPDATE
		//==============================================
		else if(ev.type == ALLEGRO_EVENT_TIMER){
			render = true;

			if(keys[LEFT])
				MoveShipLeft(nave_jugador);
			else if(keys[RIGHT])
				MoveShipRight(nave_jugador);

            UpdateBullet(bullets, NUM_BULLETS);

            CollideBullet(bullets,NUM_BULLETS,enemies1,NUM_ENEMIES);
            CollideBullet(bullets,NUM_BULLETS,enemies2,8);
            CollideBullet(bullets,NUM_BULLETS,enemies3,6);
            CollideBullet(bullets,NUM_BULLETS,enemies4,4);
            CollideBullet(bullets,NUM_BULLETS,jefe1,2);
		}

		//==============================================
		//RENDER
		//==============================================
		if(render && al_is_event_queue_empty(event_queue))
		{
			if (animacion==1){
                printf("si primero");
                movEnemies(enemies1,10,1);
                movEnemies(enemies2, 8,1);
                movEnemies(enemies3,6,1);
                movEnemies(enemies4,4,1);
                movEnemies(jefe1,2,1);
                animacion=0;
                movimientos=1;
			}


			render = false;

            // Dibujar nave
			al_draw_bitmap(nave_jugador.image, nave_jugador.x - nave_jugador.w / 2, nave_jugador.y - nave_jugador.h / 2, 0);
			// Dibujar Balas
			DrawBullet(bullets, NUM_BULLETS);

            // Dibuja los enemigos.
            DrawEnemies(enemies1,10);
            DrawEnemies(enemies2,8);
            DrawEnemies(enemies3,6);
            DrawEnemies(enemies4,4);
            DrawEnemies(jefe1,2);

			al_flip_display();
			al_clear_to_color(al_map_rgb(0,0,0));
			if (movimientos){
                movimientos=0;
                movEnemies(enemies1,10,2);
                movEnemies(enemies2,8,3);
			}
		}

	}


    for (int i =0;i<10;i++)

    al_destroy_bitmap(enemies1[i].image);

	al_destroy_event_queue(event_queue);
	al_destroy_timer(timer);
	al_destroy_display(display);						//destroy our display object

	return 0;
}