Moved fireRay to the ship module.
Also removed a really bad convention where a variable called "anEnemy" was used, rather than just "aliens[i]".
This commit is contained in:
parent
f58e15615b
commit
717d56755c
|
@ -1246,24 +1246,20 @@ any enemy craft that enter their line of sight.
|
||||||
*/
|
*/
|
||||||
int alien_enemiesInFront(object *alien)
|
int alien_enemiesInFront(object *alien)
|
||||||
{
|
{
|
||||||
object *anEnemy = aliens;
|
|
||||||
|
|
||||||
for (int i = 0 ; i < ALIEN_MAX ; i++)
|
for (int i = 0 ; i < ALIEN_MAX ; i++)
|
||||||
{
|
{
|
||||||
if ((alien != anEnemy) && (anEnemy->flags & FL_WEAPCO) &&
|
if ((alien != &aliens[i]) && (aliens[i].flags & FL_WEAPCO) &&
|
||||||
(anEnemy->shield > 0))
|
(aliens[i].shield > 0))
|
||||||
{
|
{
|
||||||
if ((alien->y > anEnemy->y - 15) &&
|
if ((alien->y > aliens[i].y - 15) &&
|
||||||
(alien->y < anEnemy->y + anEnemy->image[0]->h + 15))
|
(alien->y < aliens[i].y + aliens[i].image[0]->h + 15))
|
||||||
{
|
{
|
||||||
if ((alien->face == 1) && (anEnemy->x < alien->x))
|
if ((alien->face == 1) && (aliens[i].x < alien->x))
|
||||||
return 1;
|
return 1;
|
||||||
if ((alien->face == 0) && (anEnemy->x > alien->x))
|
if ((alien->face == 0) && (aliens[i].x > alien->x))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
anEnemy++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1303,8 +1299,6 @@ void alien_move(object *alien)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object *anEnemy = aliens;
|
|
||||||
|
|
||||||
if (checkCollisions)
|
if (checkCollisions)
|
||||||
{
|
{
|
||||||
for (int i = 0 ; i < ALIEN_MAX ; i++)
|
for (int i = 0 ; i < ALIEN_MAX ; i++)
|
||||||
|
@ -1312,18 +1306,17 @@ void alien_move(object *alien)
|
||||||
if ((alien->flags & FL_LEAVESECTOR) ||
|
if ((alien->flags & FL_LEAVESECTOR) ||
|
||||||
(alien->classDef == CD_DRONE) ||
|
(alien->classDef == CD_DRONE) ||
|
||||||
(alien->classDef == CD_ASTEROID2) ||
|
(alien->classDef == CD_ASTEROID2) ||
|
||||||
(alien->owner == anEnemy->owner) ||
|
(alien->owner == aliens[i].owner) ||
|
||||||
(alien->owner->owner == anEnemy->owner) ||
|
(alien->owner->owner == aliens[i].owner) ||
|
||||||
(anEnemy->shield < 1))
|
(aliens[i].shield < 1))
|
||||||
{
|
{
|
||||||
anEnemy++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collision(alien, anEnemy))
|
if (collision(alien, &aliens[i]))
|
||||||
{
|
{
|
||||||
if ((anEnemy->classDef == CD_BARRIER) &&
|
if ((aliens[i].classDef == CD_BARRIER) &&
|
||||||
(anEnemy->owner != alien))
|
(aliens[i].owner != alien))
|
||||||
{
|
{
|
||||||
alien->shield--;
|
alien->shield--;
|
||||||
alien->hit = 3;
|
alien->hit = 3;
|
||||||
|
@ -1332,8 +1325,6 @@ void alien_move(object *alien)
|
||||||
audio_playSound(SFX_HIT, alien->x);
|
audio_playSound(SFX_HIT, alien->x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
anEnemy++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,82 +209,6 @@ char checkPlayerShockDamage(float x, float y)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Fill in later...
|
|
||||||
*/
|
|
||||||
void fireRay(object *attacker)
|
|
||||||
{
|
|
||||||
SDL_Rect ray;
|
|
||||||
|
|
||||||
if (attacker->face == 0)
|
|
||||||
{
|
|
||||||
ray.x = (int)(attacker->x + attacker->image[0]->w);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ray.x = (int)(attacker->x - 800);
|
|
||||||
}
|
|
||||||
ray.y = (int)(attacker->y + attacker->engineY - 1);
|
|
||||||
ray.h = 3;
|
|
||||||
ray.w = 800;
|
|
||||||
|
|
||||||
int red = SDL_MapRGB(screen->format, rand() % 256, 0x00, 0x00);
|
|
||||||
SDL_FillRect(screen, &ray, red);
|
|
||||||
addBuffer(ray.x, ray.y, ray.w, ray.h);
|
|
||||||
|
|
||||||
if (attacker != &player)
|
|
||||||
{
|
|
||||||
if (player.shield > 0)
|
|
||||||
{
|
|
||||||
if (collision(player.x, player.y, player.image[0]->w,
|
|
||||||
player.image[0]->h, ray.x, ray.y, ray.w, ray.h) &&
|
|
||||||
(!engine.cheatShield))
|
|
||||||
{
|
|
||||||
if (player.shield > engine.lowShield)
|
|
||||||
{
|
|
||||||
if (player.shield - 1 <= engine.lowShield)
|
|
||||||
{
|
|
||||||
setInfoLine("!!! WARNING: SHIELD LOW !!!", FONT_RED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
player.shield--;
|
|
||||||
|
|
||||||
addExplosion(player.x, player.y, E_SMALL_EXPLOSION);
|
|
||||||
audio_playSound(SFX_HIT, player.x);
|
|
||||||
if (player.shield < 1)
|
|
||||||
{
|
|
||||||
audio_playSound(SFX_DEATH, player.x);
|
|
||||||
audio_playSound(SFX_EXPLOSION, player.x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object *anEnemy = aliens;
|
|
||||||
|
|
||||||
for (int i = 0 ; i < ALIEN_MAX ; i++)
|
|
||||||
{
|
|
||||||
if (anEnemy->flags & FL_IMMORTAL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ((anEnemy->shield > 0) && (attacker != anEnemy) &&
|
|
||||||
(attacker->classDef != anEnemy->classDef))
|
|
||||||
{
|
|
||||||
if (collision(anEnemy->x, anEnemy->y, anEnemy->image[0]->w,
|
|
||||||
anEnemy->image[0]->h, ray.x, ray.y, ray.w, ray.h))
|
|
||||||
{
|
|
||||||
alien_hurt(anEnemy, attacker->owner, 1, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
anEnemy++;
|
|
||||||
}
|
|
||||||
|
|
||||||
attacker->ammo[0]--;
|
|
||||||
if (attacker->ammo[0] < 1)
|
|
||||||
attacker->flags &= ~FL_FIRERAY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This handles active bullets in a linked list. The current bullet and
|
This handles active bullets in a linked list. The current bullet and
|
||||||
previous bullet pointers are first assigned to the main header bullet
|
previous bullet pointers are first assigned to the main header bullet
|
||||||
|
|
|
@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
void bullet_add(object *theWeapon, object *attacker, int y, int dy);
|
void bullet_add(object *theWeapon, object *attacker, int y, int dy);
|
||||||
extern char checkPlayerShockDamage(float x, float y);
|
extern char checkPlayerShockDamage(float x, float y);
|
||||||
extern void fireRay(object *attacker);
|
|
||||||
extern void doBullets();
|
extern void doBullets();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -784,7 +784,7 @@ int mainGameLoop()
|
||||||
|
|
||||||
if (alien->flags & FL_FIRERAY)
|
if (alien->flags & FL_FIRERAY)
|
||||||
{
|
{
|
||||||
fireRay(alien);
|
ship_fireRay(alien);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
72
src/ship.cpp
72
src/ship.cpp
|
@ -110,3 +110,75 @@ void ship_fireBullet(object *ship, int weaponType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Fill in later...
|
||||||
|
*/
|
||||||
|
void ship_fireRay(object *ship)
|
||||||
|
{
|
||||||
|
SDL_Rect ray;
|
||||||
|
|
||||||
|
if (ship->face == 0)
|
||||||
|
{
|
||||||
|
ray.x = (int)(ship->x + ship->image[0]->w);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ray.x = (int)(ship->x - 800);
|
||||||
|
}
|
||||||
|
ray.y = (int)(ship->y + ship->engineY - 1);
|
||||||
|
ray.h = 3;
|
||||||
|
ray.w = 800;
|
||||||
|
|
||||||
|
int red = SDL_MapRGB(screen->format, rand() % 256, 0x00, 0x00);
|
||||||
|
SDL_FillRect(screen, &ray, red);
|
||||||
|
addBuffer(ray.x, ray.y, ray.w, ray.h);
|
||||||
|
|
||||||
|
if (ship != &player)
|
||||||
|
{
|
||||||
|
if (player.shield > 0)
|
||||||
|
{
|
||||||
|
if (collision(player.x, player.y, player.image[0]->w,
|
||||||
|
player.image[0]->h, ray.x, ray.y, ray.w, ray.h) &&
|
||||||
|
(!engine.cheatShield))
|
||||||
|
{
|
||||||
|
if (player.shield > engine.lowShield)
|
||||||
|
{
|
||||||
|
if (player.shield - 1 <= engine.lowShield)
|
||||||
|
{
|
||||||
|
setInfoLine("!!! WARNING: SHIELD LOW !!!", FONT_RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.shield--;
|
||||||
|
|
||||||
|
addExplosion(player.x, player.y, E_SMALL_EXPLOSION);
|
||||||
|
audio_playSound(SFX_HIT, player.x);
|
||||||
|
if (player.shield < 1)
|
||||||
|
{
|
||||||
|
audio_playSound(SFX_DEATH, player.x);
|
||||||
|
audio_playSound(SFX_EXPLOSION, player.x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0 ; i < ALIEN_MAX ; i++)
|
||||||
|
{
|
||||||
|
if (aliens[i].flags & FL_IMMORTAL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((aliens[i].shield > 0) && (ship != &aliens[i]) &&
|
||||||
|
(ship->classDef != aliens[i].classDef))
|
||||||
|
{
|
||||||
|
if (collision(aliens[i].x, aliens[i].y, aliens[i].image[0]->w,
|
||||||
|
aliens[i].image[0]->h, ray.x, ray.y, ray.w, ray.h))
|
||||||
|
{
|
||||||
|
alien_hurt(&aliens[i], ship->owner, 1, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ship->ammo[0]--;
|
||||||
|
if (ship->ammo[0] < 1)
|
||||||
|
ship->flags &= ~FL_FIRERAY;
|
||||||
|
}
|
||||||
|
|
|
@ -19,5 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define SHIP_H
|
#define SHIP_H
|
||||||
|
|
||||||
void ship_fireBullet(object *ship, int weaponType);
|
void ship_fireBullet(object *ship, int weaponType);
|
||||||
|
void ship_fireRay(object *ship);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue