From bd48516d32e8f1487288116c7be6f87cb59c2a66 Mon Sep 17 00:00:00 2001 From: Jerry Aldrich Date: Tue, 7 Apr 2015 23:06:35 -0500 Subject: [PATCH] Move safe zone logic into getOpenPos --- gameLoop.c | 4 +++- getPos.c | 6 +++--- weaponsSystem.c | 4 ---- zombies.c | 49 +++++++++++++++---------------------------------- 4 files changed, 21 insertions(+), 42 deletions(-) diff --git a/gameLoop.c b/gameLoop.c index c68b1ff..5d936d5 100644 --- a/gameLoop.c +++ b/gameLoop.c @@ -10,7 +10,8 @@ void gameLoop(){ drawScore(); drawViewport(); moveProjectiles(); - moveZombies(); +// moveZombies(); + addZombie(); randomEvents(); doupdate(); int ch; @@ -101,5 +102,6 @@ void gameLoop(){ break; } checkPlayerCollision(); + usleep(30000); } } diff --git a/getPos.c b/getPos.c index d714488..5ca7bce 100644 --- a/getPos.c +++ b/getPos.c @@ -7,7 +7,7 @@ int getOpenPos(){ spaceExists: openPos.y=(rand()%(viewportWinRows-2)+1); openPos.x=(rand()%(viewportWinCols-2)+1); - if(mvwinch(viewportWin,openPos.y,openPos.x)==' '){ + if(mvwinch(viewportWin,openPos.y,openPos.x)==' ' && ((openPos.y > allEntities[0].curYpos+5 || openPos.y < allEntities[0].curYpos-5) || (openPos.x > allEntities[0].curXpos+5 || openPos.x < allEntities[0].curXpos-5))){ int i; for(i=1;i allEntities[0].curYpos+5 || y < allEntities[0].curYpos-5) || (x > allEntities[0].curXpos+5 || x < allEntities[0].curXpos-5))){ chooseAnother=1; goto spaceExists; } @@ -31,7 +32,6 @@ int getOpenPos(){ return 0; } } - return 1; } void getNextPos(int y, int x, int y2, int x2){ diff --git a/weaponsSystem.c b/weaponsSystem.c index 0960def..23ea14c 100644 --- a/weaponsSystem.c +++ b/weaponsSystem.c @@ -42,11 +42,7 @@ void moveProjectiles(){ mvwaddch(viewportWin, projectiles[i].curYpos, projectiles[i].curXpos, ' '); } } - else{ - mvwaddch(viewportWin, projectiles[i].curYpos, projectiles[i].curXpos, ' '); - } } - usleep(30000); } void fireWeapon(struct Weapon *weaponRef, char *direction){ diff --git a/zombies.c b/zombies.c index b24501a..70990a1 100644 --- a/zombies.c +++ b/zombies.c @@ -4,43 +4,24 @@ #include void addZombie(){ if(getOpenPos()){ - int attempts=0; - while (attempts<=10){ - if(getOpenPos()){ - if((openPos.y > allEntities[0].curYpos+5 || openPos.y < allEntities[0].curYpos-5) || (openPos.x > allEntities[0].curXpos+5 || openPos.x < allEntities[0].curXpos-5)) { - attempts=0; - break; - } - else{ - getOpenPos(); - attempts++; - } - } - else{ - attempts=0; + int i; + for(i=0;i