Modularized enemy shooting process.
authorlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Wed, 22 Jul 2009 15:00:56 +0000 (15:00 +0000)
committerlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Wed, 22 Jul 2009 15:00:56 +0000 (15:00 +0000)
git-svn-id: svn+ssh://svn/var/repos/curfender@855 bc5cbbab-a4ec-0310-bb52-ff3d296db539

Makefile
enemy_shoot.cpp [new file with mode: 0644]
enemy_shoot.h [new file with mode: 0644]
main.cpp
powerup.h

index 038f894..71a4dae 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@ CXX = g++
 INST = /usr/local/bin
 
 
-main: main.o check_collision.o age_bullet.o gravitize.o radar_plot.o object_out.o motion.o init.o draw.o powerup.o play_sound_effect.o mishaps.o
-       $(CXX) -o curfender main.o check_collision.o age_bullet.o gravitize.o radar_plot.o object_out.o motion.o init.o draw.o powerup.o play_sound_effect.o mishaps.o -lncurses -lSDL_mixer
+main: main.o check_collision.o age_bullet.o gravitize.o radar_plot.o object_out.o motion.o init.o draw.o powerup.o play_sound_effect.o mishaps.o enemy_shoot.o
+       $(CXX) -o curfender main.o check_collision.o age_bullet.o gravitize.o radar_plot.o object_out.o motion.o init.o draw.o powerup.o play_sound_effect.o mishaps.o enemy_shoot.o -lncurses -lSDL_mixer
 main.o: main.cpp
        $(CXX) -g -c main.cpp
 check_collision.o: check_collision.cpp check_collision.h
@@ -28,6 +28,8 @@ play_sound_effect.o: play_sound_effect.cpp play_sound_effect.h
        $(CXX) -g -c play_sound_effect.cpp                                              
 mishaps.o: mishaps.cpp mishaps.h
        $(CXX) -g -c mishaps.cpp                                                
+enemy_shoot.o: enemy_shoot.cpp enemy_shoot.h
+       $(CXX) -g -c enemy_shoot.cpp                                            
 install:
        cp curfender $(INST)
 remove:
diff --git a/enemy_shoot.cpp b/enemy_shoot.cpp
new file mode 100644 (file)
index 0000000..d958d23
--- /dev/null
@@ -0,0 +1,30 @@
+#include "SDL/SDL.h"
+#include "SDL/SDL_mixer.h"
+
+#include "game_object.h"
+#include "play_sound_effect.h"
+
+game_object enemy_shoot(game_object enemy, game_object player, game_object shot, int enshotchannel, Mix_Chunk *enshotsound){
+
+  int multiplier = 1;
+  enshotchannel = play_sound_effect(enshotsound);
+  shot.active=1;
+  //set direction
+  if(player.y<enemy.y){ 
+    if(player.x<enemy.x){ shot.direction = 7; };
+    if(player.x==enemy.x){ shot.direction = 4; };
+    if(player.x>enemy.x){ shot.direction = 1; };
+    //set multipler based on direction
+    multiplier = -1; 
+  };
+  if(player.y>=enemy.y){
+    if(player.x<enemy.x){ shot.direction = 9; };
+    if(player.x==enemy.x){ shot.direction = 6; };
+    if(player.x>enemy.x){ shot.direction = 3; };
+  };
+  shot.speed = enemy.speed;
+  shot.x = enemy.x;
+  shot.y = enemy.y + (enemy.speed * multiplier);
+
+  return shot;
+};
\ No newline at end of file
diff --git a/enemy_shoot.h b/enemy_shoot.h
new file mode 100644 (file)
index 0000000..6fcf5e8
--- /dev/null
@@ -0,0 +1 @@
+game_object enemy_shoot(game_object, game_object, game_object, int, Mix_Chunk*);
index 8a57208..2f0307c 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -40,7 +40,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "powerup.h"
 #include "play_sound_effect.h"
 #include "mishaps.h"
-
+#include "enemy_shoot.h"
 
 const int podmax = 8;
 const int bulletmax = 10;
@@ -1444,26 +1444,8 @@ int main(int argc, char *argv[]){
        if(rand()%1000>500){
          // lander shoot
          for(int landershotloop = 0; landershotloop<landershotmax; landershotloop++){ 
-           if(landershot[landershotloop].active==0){ 
-             int multiplier = 1;
-             enshotchannel = play_sound_effect(enshotsound);
-             landershot[landershotloop].active=1;
-             //set direction
-             if(player.y<landers[landerloop].y){ 
-               if(player.x<landers[landerloop].x){ landershot[landershotloop].direction = 7; };
-               if(player.x==landers[landerloop].x){ landershot[landershotloop].direction = 4; };
-               if(player.x>landers[landerloop].x){ landershot[landershotloop].direction = 1; };
-               //set multipler based on direction
-               multiplier = -1; 
-             };
-             if(player.y>=landers[landerloop].y){
-               if(player.x<landers[landerloop].x){ landershot[landershotloop].direction = 9; };
-               if(player.x==landers[landerloop].x){ landershot[landershotloop].direction = 6; };
-               if(player.x>landers[landerloop].x){ landershot[landershotloop].direction = 3; };
-             };
-             landershot[landershotloop].speed = landers[landerloop].speed;
-             landershot[landershotloop].x = landers[landerloop].x;
-             landershot[landershotloop].y = landers[landerloop].y + (landers[landerloop].speed * multiplier);
+           if(landershot[landershotloop].active==0){
+             landershot[landershotloop] = enemy_shoot(landers[landerloop], player, landershot[landershotloop], enshotchannel, enshotsound);
              break;
            };
          };
@@ -1478,25 +1460,7 @@ int main(int argc, char *argv[]){
          // crazy shoot
          for(int crazyshotloop = 0; crazyshotloop<landershotmax; crazyshotloop++){ 
            if(landershot[crazyshotloop].active==0){ 
-             int multiplier = 1;
-              enshotchannel = play_sound_effect(enshotsound);
-             landershot[crazyshotloop].active=1;
-             //set direction
-             if(player.y<crazies[crazyloop].y){ 
-               if(player.x<crazies[crazyloop].x){ landershot[crazyshotloop].direction = 7; };
-               if(player.x==crazies[crazyloop].x){ landershot[crazyshotloop].direction = 4; };
-               if(player.x>crazies[crazyloop].x){ landershot[crazyshotloop].direction = 1; };
-               //set multipler based on direction
-               multiplier = -1; 
-             };
-             if(player.y>=crazies[crazyloop].y){
-               if(player.x<crazies[crazyloop].x){ landershot[crazyshotloop].direction = 9; };
-               if(player.x==crazies[crazyloop].x){ landershot[crazyshotloop].direction = 6; };
-               if(player.x>crazies[crazyloop].x){ landershot[crazyshotloop].direction = 3; };
-             };
-             landershot[crazyshotloop].speed = crazies[crazyloop].speed;
-             landershot[crazyshotloop].x = crazies[crazyloop].x;
-             landershot[crazyshotloop].y = crazies[crazyloop].y + (crazies[crazyloop].speed * multiplier);
+             landershot[crazyshotloop] = enemy_shoot(crazies[crazyloop], player, landershot[crazyshotloop], enshotchannel, enshotsound);
              break;
            };
          };
@@ -1511,25 +1475,7 @@ int main(int argc, char *argv[]){
          // crawler shoot
          for(int crawlershotloop = 0; crawlershotloop<landershotmax; crawlershotloop++){ 
            if(landershot[crawlershotloop].active==0){ 
-             int multiplier = 1;
-             enshotchannel = play_sound_effect(enshotsound);
-             landershot[crawlershotloop].active=1;
-             //set direction
-             if(player.y<crawlers[crawlerloop].y){ 
-               if(player.x<crawlers[crawlerloop].x){ landershot[crawlershotloop].direction = 7; };
-               if(player.x==crawlers[crawlerloop].x){ landershot[crawlershotloop].direction = 4; };
-               if(player.x>crawlers[crawlerloop].x){ landershot[crawlershotloop].direction = 1; };
-               //set multipler based on direction
-               multiplier = -1; 
-             };
-             if(player.y>=crawlers[crawlerloop].y){
-               if(player.x<crawlers[crawlerloop].x){ landershot[crawlershotloop].direction = 9; };
-               if(player.x==crawlers[crawlerloop].x){ landershot[crawlershotloop].direction = 6; };
-               if(player.x>crawlers[crawlerloop].x){ landershot[crawlershotloop].direction = 3; };
-             };
-             landershot[crawlershotloop].speed = crawlers[crawlerloop].speed;
-             landershot[crawlershotloop].x = crawlers[crawlerloop].x;
-             landershot[crawlershotloop].y = crawlers[crawlerloop].y + (crawlers[crawlerloop].speed * multiplier);
+             landershot[crawlershotloop] = enemy_shoot(crawlers[crawlerloop], player, landershot[crawlershotloop], enshotchannel, enshotsound);
              break;
            };
          };
@@ -1540,29 +1486,11 @@ int main(int argc, char *argv[]){
     // boss shots
     for(int bossloop = 0; bossloop<6; bossloop++){
       if(bosses[bossloop].active==1){
-        if(rand()%1000>600){
+        if(rand()%1000>100){
          // boss shoot
          for(int bossshotloop = 0; bossshotloop<landershotmax; bossshotloop++){ 
            if(landershot[bossshotloop].active==0){ 
-             int multiplier = 1;
-             enshotchannel = play_sound_effect(enshotsound);
-             landershot[bossshotloop].active=1;
-             //set direction
-             if(player.y<bosses[bossloop].y){ 
-               if(player.x<bosses[bossloop].x){ landershot[bossshotloop].direction = 7; };
-               if(player.x==bosses[bossloop].x){ landershot[bossshotloop].direction = 4; };
-               if(player.x>bosses[bossloop].x){ landershot[bossshotloop].direction = 1; };
-               //set multipler based on direction
-               multiplier = -1; 
-             };
-             if(player.y>=bosses[bossloop].y){
-               if(player.x<bosses[bossloop].x){ landershot[bossshotloop].direction = 9; };
-               if(player.x==bosses[bossloop].x){ landershot[bossshotloop].direction = 6; };
-               if(player.x>bosses[bossloop].x){ landershot[bossshotloop].direction = 3; };
-             };
-             landershot[bossshotloop].speed = bosses[bossloop].speed;
-             landershot[bossshotloop].x = bosses[bossloop].x;
-             landershot[bossshotloop].y = bosses[bossloop].y + (bosses[bossloop].speed * multiplier);
+             landershot[bossshotloop] = enemy_shoot(bosses[bossloop], player, landershot[bossshotloop], enshotchannel, enshotsound);
              break;
            };
          };
index 9fc7f80..7f569df 100644 (file)
--- a/powerup.h
+++ b/powerup.h
@@ -1,2 +1,2 @@
 game_object powerup_init(game_object, game_object);
-void determine_powerup(game_object[], game_object, int, Mix_Chunk *sound, int channel);
+void determine_powerup(game_object[], game_object, int, Mix_Chunk*, int);