From 717d56755c973d046cb9307bd449b28790af89c7 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Tue, 17 Mar 2015 10:34:29 -0400 Subject: [PATCH] Moved fireRay to the ship module. Also removed a really bad convention where a variable called "anEnemy" was used, rather than just "aliens[i]". --- src/alien.cpp | 33 ++++++++-------------- src/bullet.cpp | 76 -------------------------------------------------- src/bullet.h | 1 - src/game.cpp | 2 +- src/ship.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++++ src/ship.h | 1 + 6 files changed, 86 insertions(+), 99 deletions(-) diff --git a/src/alien.cpp b/src/alien.cpp index 5cde1f2..284dd98 100644 --- a/src/alien.cpp +++ b/src/alien.cpp @@ -1246,24 +1246,20 @@ any enemy craft that enter their line of sight. */ int alien_enemiesInFront(object *alien) { - object *anEnemy = aliens; - for (int i = 0 ; i < ALIEN_MAX ; i++) { - if ((alien != anEnemy) && (anEnemy->flags & FL_WEAPCO) && - (anEnemy->shield > 0)) + if ((alien != &aliens[i]) && (aliens[i].flags & FL_WEAPCO) && + (aliens[i].shield > 0)) { - if ((alien->y > anEnemy->y - 15) && - (alien->y < anEnemy->y + anEnemy->image[0]->h + 15)) + if ((alien->y > aliens[i].y - 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; - if ((alien->face == 0) && (anEnemy->x > alien->x)) + if ((alien->face == 0) && (aliens[i].x > alien->x)) return 1; } } - - anEnemy++; } return 0; @@ -1303,8 +1299,6 @@ void alien_move(object *alien) } } - object *anEnemy = aliens; - if (checkCollisions) { for (int i = 0 ; i < ALIEN_MAX ; i++) @@ -1312,18 +1306,17 @@ void alien_move(object *alien) if ((alien->flags & FL_LEAVESECTOR) || (alien->classDef == CD_DRONE) || (alien->classDef == CD_ASTEROID2) || - (alien->owner == anEnemy->owner) || - (alien->owner->owner == anEnemy->owner) || - (anEnemy->shield < 1)) + (alien->owner == aliens[i].owner) || + (alien->owner->owner == aliens[i].owner) || + (aliens[i].shield < 1)) { - anEnemy++; continue; } - if (collision(alien, anEnemy)) + if (collision(alien, &aliens[i])) { - if ((anEnemy->classDef == CD_BARRIER) && - (anEnemy->owner != alien)) + if ((aliens[i].classDef == CD_BARRIER) && + (aliens[i].owner != alien)) { alien->shield--; alien->hit = 3; @@ -1332,8 +1325,6 @@ void alien_move(object *alien) audio_playSound(SFX_HIT, alien->x); } } - - anEnemy++; } } diff --git a/src/bullet.cpp b/src/bullet.cpp index a9154a7..e1a2350 100644 --- a/src/bullet.cpp +++ b/src/bullet.cpp @@ -209,82 +209,6 @@ char checkPlayerShockDamage(float x, float y) 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 previous bullet pointers are first assigned to the main header bullet diff --git a/src/bullet.h b/src/bullet.h index 22be9a8..7bb4579 100644 --- a/src/bullet.h +++ b/src/bullet.h @@ -22,7 +22,6 @@ along with this program. If not, see . void bullet_add(object *theWeapon, object *attacker, int y, int dy); extern char checkPlayerShockDamage(float x, float y); -extern void fireRay(object *attacker); extern void doBullets(); #endif diff --git a/src/game.cpp b/src/game.cpp index 5dc0bca..d1c07be 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -784,7 +784,7 @@ int mainGameLoop() if (alien->flags & FL_FIRERAY) { - fireRay(alien); + ship_fireRay(alien); } else { diff --git a/src/ship.cpp b/src/ship.cpp index 027c603..964bbcb 100644 --- a/src/ship.cpp +++ b/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; +} diff --git a/src/ship.h b/src/ship.h index a310724..63b1025 100644 --- a/src/ship.h +++ b/src/ship.h @@ -19,5 +19,6 @@ along with this program. If not, see . #define SHIP_H void ship_fireBullet(object *ship, int weaponType); +void ship_fireRay(object *ship); #endif