Make getOpenPos return struct OpenPos

main
Jerry Aldrich 11 years ago
parent bd48516d32
commit e336a93c8d
  1. 5
      events.c
  2. 8
      gameLoop.c
  3. 9
      getPos.c
  4. 5
      getPos.h
  5. 2
      world.h
  6. 29
      zombies.c
  7. 2
      zombies.h

@ -24,11 +24,12 @@ void addItem(char *type, int yPos, int xPos){
void randomEvents(){ void randomEvents(){
int eventTrigger = rand()%1000+1; int eventTrigger = rand()%1000+1;
if (eventTrigger < 2+itemModifier){ if (eventTrigger < 2+itemModifier){
getOpenPos(); struct OpenPos openPos = getOpenPos();
addItem("Pistol Magazine", openPos.y, openPos.x); addItem("Pistol Magazine", openPos.y, openPos.x);
} }
if (eventTrigger < 10+zombieModifier){ if (eventTrigger < 10+zombieModifier){
addZombie(); struct OpenPos openPos = getOpenPos();
addZombie(openPos.x, openPos.y);
zombieModifier++; zombieModifier++;
} }
if (eventTrigger==zombieModifier){ if (eventTrigger==zombieModifier){

@ -10,8 +10,7 @@ void gameLoop(){
drawScore(); drawScore();
drawViewport(); drawViewport();
moveProjectiles(); moveProjectiles();
// moveZombies(); moveZombies();
addZombie();
randomEvents(); randomEvents();
doupdate(); doupdate();
int ch; int ch;
@ -59,11 +58,12 @@ void gameLoop(){
} }
case 'z': case 'z':
case 'Z':{ case 'Z':{
addZombie(); struct OpenPos openPos = getOpenPos();
addZombie(openPos.y,openPos.x);
break; break;
} }
case '=':{ case '=':{
getOpenPos(); struct OpenPos openPos = getOpenPos();
addItem("Pistol Magazine",openPos.y,openPos.x); addItem("Pistol Magazine",openPos.y,openPos.x);
break; break;
} }

@ -1,8 +1,9 @@
#include <screen.h> #include <screen.h>
#include <world.h> #include <world.h>
#include <getPos.h> #include <getPos.h>
int getOpenPos(){ struct OpenPos getOpenPos(){
int chooseAnother=1; int chooseAnother=1;
struct OpenPos openPos;
while(chooseAnother){ while(chooseAnother){
spaceExists: spaceExists:
openPos.y=(rand()%(viewportWinRows-2)+1); openPos.y=(rand()%(viewportWinRows-2)+1);
@ -15,7 +16,7 @@ int getOpenPos(){
} }
else{ else{
chooseAnother=0; chooseAnother=0;
return 1; return openPos;
} }
} }
} }
@ -29,7 +30,9 @@ int getOpenPos(){
} }
} }
} }
return 0; openPos.y=0;
openPos.x=0;
return openPos;
} }
} }
} }

@ -1,14 +1,15 @@
#ifndef _GET_POS #ifndef _GET_POS
#define _GET_POS #define _GET_POS
struct possiblePos{ struct OpenPos{
int x; int x;
int y; int y;
}openPos; };
struct NextPos{ struct NextPos{
int x; int x;
int y; int y;
}nextPos; }nextPos;
struct OpenPos getOpenPos();
#endif #endif

@ -13,7 +13,7 @@ struct Item allItems[MAX_ITEMS];
#define MAX_PROJECTILES 2 #define MAX_PROJECTILES 2
struct Projectile projectiles[MAX_PROJECTILES]; struct Projectile projectiles[MAX_PROJECTILES];
#define INITIAL_SPAWN_NUM 10 #define INITIAL_SPAWN_NUM 0
int zombieModifier; int zombieModifier;

@ -2,16 +2,16 @@
#include <getPos.h> #include <getPos.h>
#include <screen.h> #include <screen.h>
#include <collisionDetection.h> #include <collisionDetection.h>
void addZombie(){ void addZombie(int y, int x){
if(getOpenPos()){ if (y && x){
int i; int i;
for(i=0;i<MAX_ENTITIES-1;i++){ for(i=0;i<MAX_ENTITIES-1;i++){
if(!allEntities[i].isAlive){ if(!allEntities[i].isAlive){
struct Entity zombie; struct Entity zombie;
zombie.curYpos=openPos.y; zombie.curYpos=y;
zombie.curXpos=openPos.x; zombie.curXpos=x;
zombie.nextYpos=openPos.y; zombie.nextYpos=y;
zombie.nextXpos=openPos.x; zombie.nextXpos=x;
zombie.type="zombie"; zombie.type="zombie";
zombie.symbol='Z'; zombie.symbol='Z';
zombie.isAlive=1; zombie.isAlive=1;
@ -26,8 +26,21 @@ void addZombie(){
} }
void addHorde(){ void addHorde(){
getOpenPos(); // if(getOpenPos()){
// int y=openPos.y;
// int x=openPos.x;
// addZombie();
/*
addZombie(y-1,x);
addZombie(y,x-1);
addZombie(y-1,x-1);
addZombie(y+1,x);
addZombie(y,x+1);
addZombie(y+1,x+1);
addZombie(y-1,x+1);
addZombie(y+1,x-1);
*/
// }
} }
void moveZombies(){ void moveZombies(){

@ -1,7 +1,7 @@
#ifndef _ZOMBIES #ifndef _ZOMBIES
#define _ZOMBIES #define _ZOMBIES
void addZombies(); void addZombie(int y, int x);
void addHorde(); void addHorde();
void moveZombies(); void moveZombies();

Loading…
Cancel
Save