From bec35897c7e1789c9c15e566a705002f8d64ffce Mon Sep 17 00:00:00 2001 From: Jerry Aldrich Date: Mon, 6 Apr 2015 18:24:04 -0500 Subject: [PATCH] Change Zombie collision detection Now only moves if char at next position !='@' or =' ' --- structs.h | 11 +++++++++-- zombies.c | 11 +++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/structs.h b/structs.h index f81f70d..fdba6c9 100644 --- a/structs.h +++ b/structs.h @@ -2,7 +2,7 @@ #define _STRUCTS struct Weapon{ - char name[10]; + char *name; int range; int maxCapacity; int curCapacity; @@ -24,12 +24,19 @@ struct Entity { }; +struct Item{ + char *name; + char symbol; + int isAlive; + int curYpos; + int curXpos; +}; struct Projectile{ int isAlive; char symbol; - int curXpos; int curYpos; + int curXpos; int prevYpos; int prevXpos; int nextYpos; diff --git a/zombies.c b/zombies.c index 67e5a86..c6789c9 100644 --- a/zombies.c +++ b/zombies.c @@ -53,14 +53,13 @@ void moveZombies(){ getNextPos(allEntities[i].curYpos,allEntities[i].curXpos,allEntities[0].curYpos,allEntities[0].curXpos); allEntities[i].nextYpos = nextPos.y; allEntities[i].nextXpos = nextPos.x; - - struct Entity * hitEntity = (struct Entity *)collisionDetect(allEntities[i].nextYpos, allEntities[i].nextXpos); - if(hitEntity){ - if(!strcmp(hitEntity->type,"zombie")){ + + char charAtNextPos=mvwinch(viewportWin,allEntities[i].nextYpos,allEntities[i].nextXpos); + if(charAtNextPos!='@' && charAtNextPos!=' '){ allEntities[i].nextYpos = allEntities[i].curYpos; allEntities[i].nextXpos = allEntities[i].curXpos; - } - } + } + if(allEntities[i].nextYpos < 1 || allEntities[i].nextYpos>viewportWinRows-2){ allEntities[i].nextYpos = allEntities[i].curYpos; }