From e336a93c8dec4fcf20250307fa5dda5447f87a9e Mon Sep 17 00:00:00 2001 From: Jerry Aldrich Date: Tue, 7 Apr 2015 23:51:10 -0500 Subject: [PATCH] Make getOpenPos return struct OpenPos --- events.c | 5 +++-- gameLoop.c | 8 ++++---- getPos.c | 9 ++++++--- getPos.h | 5 +++-- world.h | 2 +- zombies.c | 29 +++++++++++++++++++++-------- zombies.h | 2 +- 7 files changed, 39 insertions(+), 21 deletions(-) diff --git a/events.c b/events.c index 66ece93..e95d503 100644 --- a/events.c +++ b/events.c @@ -24,11 +24,12 @@ void addItem(char *type, int yPos, int xPos){ void randomEvents(){ int eventTrigger = rand()%1000+1; if (eventTrigger < 2+itemModifier){ - getOpenPos(); + struct OpenPos openPos = getOpenPos(); addItem("Pistol Magazine", openPos.y, openPos.x); } if (eventTrigger < 10+zombieModifier){ - addZombie(); + struct OpenPos openPos = getOpenPos(); + addZombie(openPos.x, openPos.y); zombieModifier++; } if (eventTrigger==zombieModifier){ diff --git a/gameLoop.c b/gameLoop.c index 5d936d5..00c64a9 100644 --- a/gameLoop.c +++ b/gameLoop.c @@ -10,8 +10,7 @@ void gameLoop(){ drawScore(); drawViewport(); moveProjectiles(); -// moveZombies(); - addZombie(); + moveZombies(); randomEvents(); doupdate(); int ch; @@ -59,11 +58,12 @@ void gameLoop(){ } case 'z': case 'Z':{ - addZombie(); + struct OpenPos openPos = getOpenPos(); + addZombie(openPos.y,openPos.x); break; } case '=':{ - getOpenPos(); + struct OpenPos openPos = getOpenPos(); addItem("Pistol Magazine",openPos.y,openPos.x); break; } diff --git a/getPos.c b/getPos.c index 5ca7bce..d46dcd8 100644 --- a/getPos.c +++ b/getPos.c @@ -1,8 +1,9 @@ #include #include #include -int getOpenPos(){ +struct OpenPos getOpenPos(){ int chooseAnother=1; + struct OpenPos openPos; while(chooseAnother){ spaceExists: openPos.y=(rand()%(viewportWinRows-2)+1); @@ -15,7 +16,7 @@ int getOpenPos(){ } else{ chooseAnother=0; - return 1; + return openPos; } } } @@ -29,7 +30,9 @@ int getOpenPos(){ } } } - return 0; + openPos.y=0; + openPos.x=0; + return openPos; } } } diff --git a/getPos.h b/getPos.h index c9e3a4b..8d1b831 100644 --- a/getPos.h +++ b/getPos.h @@ -1,14 +1,15 @@ #ifndef _GET_POS #define _GET_POS -struct possiblePos{ +struct OpenPos{ int x; int y; -}openPos; +}; struct NextPos{ int x; int y; }nextPos; +struct OpenPos getOpenPos(); #endif diff --git a/world.h b/world.h index 70a4b5b..31f6e5c 100644 --- a/world.h +++ b/world.h @@ -13,7 +13,7 @@ struct Item allItems[MAX_ITEMS]; #define MAX_PROJECTILES 2 struct Projectile projectiles[MAX_PROJECTILES]; -#define INITIAL_SPAWN_NUM 10 +#define INITIAL_SPAWN_NUM 0 int zombieModifier; diff --git a/zombies.c b/zombies.c index 70990a1..7b661cc 100644 --- a/zombies.c +++ b/zombies.c @@ -2,16 +2,16 @@ #include #include #include -void addZombie(){ - if(getOpenPos()){ +void addZombie(int y, int x){ + if (y && x){ int i; for(i=0;i