Simplify spread bullet code.

There were three flags, WF_STRAIGHT, WF_THIN_SPREAD and WF_WIDE_SPREAD,
when only one flag, WF_SPREAD suffices. This makes the code simpler and
gets rid of some duplication.
This commit is contained in:
Guus Sliepen 2011-09-04 18:24:54 +02:00
parent 45664437e1
commit e7f5c3825b
6 changed files with 71 additions and 117 deletions

View File

@ -170,7 +170,22 @@ void fireBullet(object *attacker, int weaponType)
break; break;
} }
if (theWeapon->flags & WF_STRAIGHT) if (theWeapon->flags & WF_SPREAD && theWeapon->ammo[0] >= 3)
{
addBullet(theWeapon, attacker, y * 1, -2);
if(theWeapon->ammo[0] != 4)
addBullet(theWeapon, attacker, y * 3, 0);
if(theWeapon->ammo[0] != 3)
{
addBullet(theWeapon, attacker, y * 2, -1);
addBullet(theWeapon, attacker, y * 4, 1);
}
addBullet(theWeapon, attacker, y * 5, 2);
}
else
{ {
switch (theWeapon->ammo[0]) switch (theWeapon->ammo[0])
{ {
@ -198,28 +213,6 @@ void fireBullet(object *attacker, int weaponType)
break; break;
} }
} }
else if (theWeapon->flags & WF_THIN_SPREAD)
{
addBullet(theWeapon, attacker, y * 2, -1);
if (theWeapon->ammo[0] == 3)
{
addBullet(theWeapon, attacker, y * 3, 0);
}
else
{
addBullet(theWeapon, attacker, y * 2, 0);
addBullet(theWeapon, attacker, y * 4, 0);
}
addBullet(theWeapon, attacker, y * 4, 1);
}
else if (theWeapon->flags & WF_WIDE_SPREAD)
{
addBullet(theWeapon, attacker, y * 1, -2);
addBullet(theWeapon, attacker, y * 2, -1);
addBullet(theWeapon, attacker, y * 3, 0);
addBullet(theWeapon, attacker, y * 4, 1);
addBullet(theWeapon, attacker, y * 5, 2);
}
// Reset the weapon reload time. Double it if it is not friendly or a boss or Kline // Reset the weapon reload time. Double it if it is not friendly or a boss or Kline
attacker->reload[weaponType] = theWeapon->reload[0]; attacker->reload[weaponType] = theWeapon->reload[0];
@ -539,7 +532,7 @@ void doBullets()
addExplosion(bullet->x, bullet->y, E_TINY_EXPLOSION); addExplosion(bullet->x, bullet->y, E_TINY_EXPLOSION);
} }
if ((bullet->flags & WF_AIMED) || (bullet->flags & WF_THIN_SPREAD)) if ((bullet->flags & WF_AIMED) || (bullet->flags & WF_SPREAD))
{ {
blit(bullet->image[0], (int)(bullet->x - bullet->dx), (int)(bullet->y - bullet->dy)); blit(bullet->image[0], (int)(bullet->x - bullet->dx), (int)(bullet->y - bullet->dy));
} }

View File

@ -327,8 +327,7 @@ void doCollectables()
weapon[1].damage = 5; weapon[1].damage = 5;
weapon[1].reload[0] = 7; weapon[1].reload[0] = 7;
weapon[1].flags &= ~(WF_STRAIGHT | WF_THIN_SPREAD); weapon[1].flags |= WF_SPREAD;
weapon[1].flags |= WF_WIDE_SPREAD;
sprintf(temp, "Picked up a Super Charge!!"); sprintf(temp, "Picked up a Super Charge!!");

View File

@ -135,9 +135,7 @@ enum {
}; };
// Weapon flags // Weapon flags
#define WF_STRAIGHT 1 #define WF_SPREAD 4
#define WF_THIN_SPREAD 2
#define WF_WIDE_SPREAD 4
#define WF_SCATTER 8 #define WF_SCATTER 8
#define WF_VARIABLE_SPEED 16 #define WF_VARIABLE_SPEED 16
#define WF_HOMING 32 #define WF_HOMING 32

View File

@ -130,58 +130,22 @@ void doPlayer()
if ((engine.keyState[SDLK_LSHIFT]) || (engine.keyState[SDLK_RSHIFT])) if ((engine.keyState[SDLK_LSHIFT]) || (engine.keyState[SDLK_RSHIFT]))
{ {
if (player.ammo[0] < 1) int w = player.ammo[0] > 0;
if(weapon[w].ammo[0] >= 3)
{ {
if (weapon[0].ammo[0] == 3) weapon[w].flags ^= WF_SPREAD;
if(weapon[w].flags & WF_SPREAD)
{ {
if (weapon[0].flags & WF_THIN_SPREAD) setInfoLine("Weapon set to Spread", FONT_WHITE);
{ }
weapon[0].flags &= ~WF_THIN_SPREAD; else
weapon[0].flags |= WF_STRAIGHT; {
setInfoLine("Weapon set to Concentrate", FONT_WHITE); setInfoLine("Weapon set to Concentrate", FONT_WHITE);
}
else
{
weapon[0].flags &= ~WF_STRAIGHT;
weapon[0].flags |= WF_THIN_SPREAD;
setInfoLine("Weapon set to Spread", FONT_WHITE);
}
} }
} }
else
{
if (weapon[1].ammo[0] == 3 || weapon[1].ammo[0] == 4)
{
if (weapon[1].flags & WF_THIN_SPREAD)
{
weapon[1].flags &= ~WF_THIN_SPREAD;
weapon[1].flags |= WF_STRAIGHT;
setInfoLine("Weapon set to Concentrate", FONT_WHITE);
}
else
{
weapon[1].flags &= ~WF_STRAIGHT;
weapon[1].flags |= WF_THIN_SPREAD;
setInfoLine("Weapon set to Spread", FONT_WHITE);
}
}
else if (weapon[1].ammo[0] == 5)
{
if (weapon[1].flags & WF_WIDE_SPREAD)
{
weapon[1].flags &= ~(WF_THIN_SPREAD | WF_WIDE_SPREAD);
weapon[1].flags |= WF_STRAIGHT;
setInfoLine("Weapon set to Concentrate", FONT_WHITE);
}
else
{
weapon[1].flags &= (WF_THIN_SPREAD | WF_STRAIGHT);
weapon[1].flags |= WF_WIDE_SPREAD;
setInfoLine("Weapon set to Spread", FONT_WHITE);
}
}
}
engine.keyState[SDLK_LSHIFT] = engine.keyState[SDLK_RSHIFT] = 0; engine.keyState[SDLK_LSHIFT] = engine.keyState[SDLK_RSHIFT] = 0;
} }

View File

@ -114,7 +114,7 @@ void initWeapons()
weapon[W_PLAYER_WEAPON].speed = 10; weapon[W_PLAYER_WEAPON].speed = 10;
weapon[W_PLAYER_WEAPON].imageIndex[0] = 0; weapon[W_PLAYER_WEAPON].imageIndex[0] = 0;
weapon[W_PLAYER_WEAPON].imageIndex[1] = 0; weapon[W_PLAYER_WEAPON].imageIndex[1] = 0;
weapon[W_PLAYER_WEAPON].flags = WF_STRAIGHT; weapon[W_PLAYER_WEAPON].flags = 0;
// Nor is this one! // Nor is this one!
weapon[W_PLAYER_WEAPON2] = weapon[W_PLAYER_WEAPON]; weapon[W_PLAYER_WEAPON2] = weapon[W_PLAYER_WEAPON];
@ -127,7 +127,7 @@ void initWeapons()
weapon[W_SINGLE_SHOT].speed = 10; weapon[W_SINGLE_SHOT].speed = 10;
weapon[W_SINGLE_SHOT].imageIndex[0] = 0; weapon[W_SINGLE_SHOT].imageIndex[0] = 0;
weapon[W_SINGLE_SHOT].imageIndex[1] = 1; weapon[W_SINGLE_SHOT].imageIndex[1] = 1;
weapon[W_SINGLE_SHOT].flags = WF_STRAIGHT; weapon[W_SINGLE_SHOT].flags = 0;
// Double Shot // Double Shot
weapon[W_DOUBLE_SHOT] = weapon[W_SINGLE_SHOT]; weapon[W_DOUBLE_SHOT] = weapon[W_SINGLE_SHOT];
@ -143,8 +143,8 @@ void initWeapons()
weapon[W_ROCKETS].damage = 15; weapon[W_ROCKETS].damage = 15;
weapon[W_ROCKETS].reload[0] = 45; weapon[W_ROCKETS].reload[0] = 45;
weapon[W_ROCKETS].speed = 20; weapon[W_ROCKETS].speed = 20;
weapon[W_ROCKETS].flags = WF_STRAIGHT; weapon[W_ROCKETS].flags = 0;
weapon[W_ROCKETS].imageIndex[0] = 2; weapon[W_ROCKETS].imageIndex[0] = 2;
weapon[W_ROCKETS].imageIndex[1] = 3; weapon[W_ROCKETS].imageIndex[1] = 3;
// Double Rockets (uses ROCKETS as base) // Double Rockets (uses ROCKETS as base)
@ -158,7 +158,7 @@ void initWeapons()
weapon[W_MICRO_ROCKETS].damage = 3; weapon[W_MICRO_ROCKETS].damage = 3;
weapon[W_MICRO_ROCKETS].reload[0] = 30; weapon[W_MICRO_ROCKETS].reload[0] = 30;
weapon[W_MICRO_ROCKETS].speed = 15; weapon[W_MICRO_ROCKETS].speed = 15;
weapon[W_MICRO_ROCKETS].flags = WF_STRAIGHT | WF_VARIABLE_SPEED; weapon[W_MICRO_ROCKETS].flags = WF_VARIABLE_SPEED;
weapon[W_MICRO_ROCKETS].imageIndex[0] = 2; weapon[W_MICRO_ROCKETS].imageIndex[0] = 2;
weapon[W_MICRO_ROCKETS].imageIndex[1] = 3; weapon[W_MICRO_ROCKETS].imageIndex[1] = 3;
@ -168,7 +168,7 @@ void initWeapons()
weapon[W_ENERGYRAY].damage = 1; weapon[W_ENERGYRAY].damage = 1;
weapon[W_ENERGYRAY].reload[0] = 25; // reload for energy ray is never used weapon[W_ENERGYRAY].reload[0] = 25; // reload for energy ray is never used
weapon[W_ENERGYRAY].speed = 15; weapon[W_ENERGYRAY].speed = 15;
weapon[W_ENERGYRAY].flags = WF_STRAIGHT; weapon[W_ENERGYRAY].flags = 0;
// Laser // Laser
weapon[W_LASER].id = WT_LASER; weapon[W_LASER].id = WT_LASER;
@ -178,7 +178,7 @@ void initWeapons()
weapon[W_LASER].speed = 10; weapon[W_LASER].speed = 10;
weapon[W_LASER].imageIndex[0] = 1; weapon[W_LASER].imageIndex[0] = 1;
weapon[W_LASER].imageIndex[1] = 1; weapon[W_LASER].imageIndex[1] = 1;
weapon[W_LASER].flags = WF_STRAIGHT; weapon[W_LASER].flags = 0;
// Beam up weapon // Beam up weapon
weapon[W_CHARGER].id = WT_CHARGER; weapon[W_CHARGER].id = WT_CHARGER;
@ -186,25 +186,25 @@ void initWeapons()
weapon[W_CHARGER].damage = 1; weapon[W_CHARGER].damage = 1;
weapon[W_CHARGER].reload[0] = 0; weapon[W_CHARGER].reload[0] = 0;
weapon[W_CHARGER].speed = 12; weapon[W_CHARGER].speed = 12;
weapon[W_CHARGER].flags = WF_STRAIGHT; weapon[W_CHARGER].flags = 0;
weapon[W_CHARGER].imageIndex[0] = 33; weapon[W_CHARGER].imageIndex[0] = 33;
weapon[W_CHARGER].imageIndex[1] = 34; weapon[W_CHARGER].imageIndex[1] = 34;
// Homing missile // Homing missile
weapon[W_HOMING_MISSILE].id = WT_ROCKET; weapon[W_HOMING_MISSILE].id = WT_ROCKET;
weapon[W_HOMING_MISSILE].ammo[0] = 1; weapon[W_HOMING_MISSILE].ammo[0] = 1;
weapon[W_HOMING_MISSILE].damage = 15; weapon[W_HOMING_MISSILE].damage = 15;
weapon[W_HOMING_MISSILE].reload[0] = 35; weapon[W_HOMING_MISSILE].reload[0] = 35;
weapon[W_HOMING_MISSILE].speed = 10; weapon[W_HOMING_MISSILE].speed = 10;
weapon[W_HOMING_MISSILE].flags = WF_STRAIGHT | WF_HOMING; weapon[W_HOMING_MISSILE].flags = WF_HOMING;
weapon[W_HOMING_MISSILE].imageIndex[0] = 4; weapon[W_HOMING_MISSILE].imageIndex[0] = 4;
weapon[W_HOMING_MISSILE].imageIndex[1] = 4; weapon[W_HOMING_MISSILE].imageIndex[1] = 4;
// Double homing missile // Double homing missile
weapon[W_DOUBLE_HOMING_MISSILES] = weapon[W_HOMING_MISSILE]; weapon[W_DOUBLE_HOMING_MISSILES] = weapon[W_HOMING_MISSILE];
weapon[W_DOUBLE_HOMING_MISSILES].ammo[0] = 2; weapon[W_DOUBLE_HOMING_MISSILES].ammo[0] = 2;
weapon[W_DOUBLE_HOMING_MISSILES].reload[0] = 65; weapon[W_DOUBLE_HOMING_MISSILES].reload[0] = 65;
weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[0] = 4; weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[0] = 4;
weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[1] = 4; weapon[W_DOUBLE_HOMING_MISSILES].imageIndex[1] = 4;
// Micro homing missiles // Micro homing missiles
@ -213,8 +213,8 @@ void initWeapons()
weapon[W_MICRO_HOMING_MISSILES].damage = 12; weapon[W_MICRO_HOMING_MISSILES].damage = 12;
weapon[W_MICRO_HOMING_MISSILES].reload[0] = 65; weapon[W_MICRO_HOMING_MISSILES].reload[0] = 65;
weapon[W_MICRO_HOMING_MISSILES].speed = 3; weapon[W_MICRO_HOMING_MISSILES].speed = 3;
weapon[W_MICRO_HOMING_MISSILES].flags = WF_STRAIGHT | WF_HOMING; weapon[W_MICRO_HOMING_MISSILES].flags = WF_HOMING;
weapon[W_MICRO_HOMING_MISSILES].imageIndex[0] = 4; weapon[W_MICRO_HOMING_MISSILES].imageIndex[0] = 4;
weapon[W_MICRO_HOMING_MISSILES].imageIndex[1] = 4; weapon[W_MICRO_HOMING_MISSILES].imageIndex[1] = 4;
// Aimed plasma bolt (2x damage) // Aimed plasma bolt (2x damage)
@ -223,7 +223,7 @@ void initWeapons()
weapon[W_AIMED_SHOT].damage = 2; weapon[W_AIMED_SHOT].damage = 2;
weapon[W_AIMED_SHOT].reload[0] = 15; weapon[W_AIMED_SHOT].reload[0] = 15;
weapon[W_AIMED_SHOT].speed = 0; weapon[W_AIMED_SHOT].speed = 0;
weapon[W_AIMED_SHOT].flags = WF_STRAIGHT | WF_AIMED; weapon[W_AIMED_SHOT].flags = WF_AIMED;
weapon[W_AIMED_SHOT].imageIndex[0] = 33; weapon[W_AIMED_SHOT].imageIndex[0] = 33;
weapon[W_AIMED_SHOT].imageIndex[1] = 34; weapon[W_AIMED_SHOT].imageIndex[1] = 34;
@ -233,7 +233,7 @@ void initWeapons()
weapon[W_SPREADSHOT].damage = 1; weapon[W_SPREADSHOT].damage = 1;
weapon[W_SPREADSHOT].reload[0] = 10; weapon[W_SPREADSHOT].reload[0] = 10;
weapon[W_SPREADSHOT].speed = 10; weapon[W_SPREADSHOT].speed = 10;
weapon[W_SPREADSHOT].flags = WF_THIN_SPREAD; weapon[W_SPREADSHOT].flags = WF_SPREAD;
weapon[W_SPREADSHOT].imageIndex[0] = 0; weapon[W_SPREADSHOT].imageIndex[0] = 0;
weapon[W_SPREADSHOT].imageIndex[1] = 1; weapon[W_SPREADSHOT].imageIndex[1] = 1;
@ -243,7 +243,7 @@ void initWeapons()
weapon[W_IONCANNON].damage = 1; weapon[W_IONCANNON].damage = 1;
weapon[W_IONCANNON].reload[0] = 2; weapon[W_IONCANNON].reload[0] = 2;
weapon[W_IONCANNON].speed = 10; weapon[W_IONCANNON].speed = 10;
weapon[W_IONCANNON].flags = WF_STRAIGHT | WF_DISABLE | WF_AIMED; weapon[W_IONCANNON].flags = WF_DISABLE | WF_AIMED;
weapon[W_IONCANNON].imageIndex[0] = 35; weapon[W_IONCANNON].imageIndex[0] = 35;
weapon[W_IONCANNON].imageIndex[1] = 35; weapon[W_IONCANNON].imageIndex[1] = 35;
@ -253,7 +253,7 @@ void initWeapons()
weapon[W_DIRSHOCKMISSILE].damage = 20; weapon[W_DIRSHOCKMISSILE].damage = 20;
weapon[W_DIRSHOCKMISSILE].reload[0] = 60; weapon[W_DIRSHOCKMISSILE].reload[0] = 60;
weapon[W_DIRSHOCKMISSILE].speed = 0; weapon[W_DIRSHOCKMISSILE].speed = 0;
weapon[W_DIRSHOCKMISSILE].flags = WF_STRAIGHT | WF_AIMED | WF_TIMEDEXPLOSION; weapon[W_DIRSHOCKMISSILE].flags = WF_AIMED | WF_TIMEDEXPLOSION;
weapon[W_DIRSHOCKMISSILE].imageIndex[0] = 4; weapon[W_DIRSHOCKMISSILE].imageIndex[0] = 4;
weapon[W_DIRSHOCKMISSILE].imageIndex[1] = 4; weapon[W_DIRSHOCKMISSILE].imageIndex[1] = 4;

View File

@ -1,21 +1,21 @@
1 1 1 15 10 0 0 1 1 1 1 15 10 0 0 0
1 1 1 15 10 0 0 1 1 1 1 15 10 0 0 0
1 1 1 15 10 0 1 1 1 1 1 15 10 0 1 0
1 2 1 15 10 0 1 1 1 2 1 15 10 0 1 0
1 3 1 15 10 0 1 1 1 3 1 15 10 0 1 0
2 1 15 45 20 2 3 1 2 1 15 45 20 2 3 0
2 2 15 80 20 2 3 1 2 2 15 80 20 2 3 0
2 5 3 30 15 2 3 17 2 5 3 30 15 2 3 16
3 255 1 25 15 0 0 1 3 255 1 25 15 0 0 0
4 1 3 1 10 1 1 1 4 1 3 1 10 1 1 0
6 1 1 0 12 33 34 1 6 1 1 0 12 33 34 0
2 1 15 35 10 4 4 33 2 1 15 35 10 4 4 32
2 2 15 65 10 4 4 33 2 2 15 65 10 4 4 32
2 5 12 65 3 4 4 33 2 5 12 65 3 4 4 32
7 1 2 15 0 33 34 513 7 1 2 15 0 33 34 512
8 3 1 10 10 0 1 2 8 3 1 10 10 0 1 4
1 1 1 2 10 35 35 1537 1 1 1 2 10 35 35 1536
2 5 20 60 0 4 4 2561 2 5 20 60 0 4 4 2560
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0