--- /dev/null
+#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
#include "powerup.h"
#include "play_sound_effect.h"
#include "mishaps.h"
-
+#include "enemy_shoot.h"
const int podmax = 8;
const int bulletmax = 10;
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;
};
};
// 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;
};
};
// 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;
};
};
// 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;
};
};