From a8a46633c23a5d3fbe1b4f3ebc6fb595170d1e04 Mon Sep 17 00:00:00 2001 From: Jerry Aldrich Date: Sun, 29 Mar 2015 01:42:37 -0500 Subject: [PATCH] Add .h files and remove moveable.c --- collisionDetection.h | 7 + getPos.h | 14 ++ moveable.c | 374 ------------------------------------------- screen.h | 13 ++ structs.h | 38 +++++ weaponsSystem.h | 9 ++ world.h | 10 ++ 7 files changed, 91 insertions(+), 374 deletions(-) create mode 100644 collisionDetection.h create mode 100644 getPos.h delete mode 100644 moveable.c create mode 100644 screen.h create mode 100644 structs.h create mode 100644 weaponsSystem.h create mode 100644 world.h diff --git a/collisionDetection.h b/collisionDetection.h new file mode 100644 index 0000000..d20303d --- /dev/null +++ b/collisionDetection.h @@ -0,0 +1,7 @@ +#ifndef _COLLISION_DETECT +#define _COLLISION_DETECT + +#include + +struct Entity * collisionDetect(); +#endif diff --git a/getPos.h b/getPos.h new file mode 100644 index 0000000..c9e3a4b --- /dev/null +++ b/getPos.h @@ -0,0 +1,14 @@ +#ifndef _GET_POS +#define _GET_POS + +struct possiblePos{ + int x; + int y; +}openPos; + +struct NextPos{ + int x; + int y; +}nextPos; + +#endif diff --git a/moveable.c b/moveable.c deleted file mode 100644 index 71ce142..0000000 --- a/moveable.c +++ /dev/null @@ -1,374 +0,0 @@ -#include -#include - -#define MAX_PROJECTILES 2 -#define MAX_ZOMBIES 1000 -#define MAX_ALIVE 10 - - -int scrRows,scrCols; -int viewportWinRows,viewportWinCols; -int lastPressed; - -WINDOW* viewportWin; - -WINDOW* scoreWin; - -struct Projectile{ - int isAlive; - char symbol; - int curXpos; - int curYpos; - int prevYpos; - int prevXpos; - int nextYpos; - int nextXpos; - int range; - char direction; - int distanceTraveled; -}; -struct Projectile projectiles[MAX_PROJECTILES]; - -struct Weapon{ - char name[10]; - int range; - int maxCapacity; - int curCapacity; - char projectileSymbol; - char symbols[8]; -}; - -struct Entity { - char *type; - char symbol; - int curYpos, curXpos; - int nextYpos, nextXpos; - struct Weapon weapons[8]; - int curWeapon; - int isAlive; -}; - - -struct Entity player = {.type="player",.symbol='@', .curYpos=1, .curXpos=1, .nextYpos=1, .nextXpos=1 ,.isAlive=1}; -struct Entity zombies[MAX_ZOMBIES]; -struct Entity allEntities[MAX_ALIVE]; -struct Entity zombie = {.type="zombie", .symbol='A', .curYpos=5, .curXpos=5, .nextYpos=5, .nextXpos=5 ,.isAlive=1}; - -struct Weapon pistol = {.name="Pistol", .range=3, .maxCapacity=12, .curCapacity=12, .symbols="-\\|/-\\|/"}; - - - -struct Entity * collisionDetect(int objYpos, int objXpos){ - int i; - for(i=1; itype=="zombie"){ - projectiles[i].isAlive=0; - hitEntity->isAlive=0; - mvwaddch(viewportWin, allEntities[i].curYpos, allEntities[i].curXpos, ' '); - } - } - if(mvwinch(viewportWin,projectiles[i].prevYpos, projectiles[i].prevXpos)==projectiles[i].symbol){ - mvwaddch(viewportWin, projectiles[i].prevYpos, projectiles[i].prevXpos, ' '); - } - if(projectiles[i].distanceTraveled>=projectiles[i].range || projectiles[i].curYpos > viewportWinRows || projectiles[i].curYpos < 0 || projectiles[i].curXpos > viewportWinCols || projectiles[i].curXpos < 0){ - projectiles[i].isAlive=0; - mvwaddch(viewportWin, projectiles[i].curYpos, projectiles[i].curXpos, ' '); - } - usleep(30000); - } - else{ - mvwaddch(viewportWin, projectiles[i].curYpos, projectiles[i].curXpos, ' '); - } - } -} - -void fireWeapon(struct Weapon *weaponRef, char *direction){ - struct Projectile projectile; - if (!strcmp(weaponRef->name,"Pistol")){ - projectile.range=20; - } - projectile.isAlive=1; - projectile.distanceTraveled=0; - projectile.curYpos=allEntities[0].curYpos; - projectile.curXpos=allEntities[0].curXpos; - if(direction=="up"){ - projectile.range*=.4; - projectile.direction='w'; - projectile.symbol=weaponRef->symbols[2]; - } - if(direction=="left"){ - projectile.direction='a'; - projectile.symbol=weaponRef->symbols[0]; - } - if(direction=="down"){ - projectile.range*=.4; - projectile.direction='s'; - projectile.symbol=weaponRef->symbols[6]; - } - if(direction=="right"){ - projectile.direction='d'; - projectile.symbol=weaponRef->symbols[4]; - } - int i; - for(i=0;i 1){ - allEntities[0].nextYpos--; - if(allEntities[0].nextYpos < 0){ - allEntities[0].nextYpos = 0; - } - } - break; - } - case 's': - case 'S':{ - if(allEntities[0].curYpos < viewportWinRows - 2){ - allEntities[0].nextYpos++; - if(allEntities[0].nextYpos > viewportWinRows-1){ - allEntities[0].nextYpos = viewportWinRows-1; - } - } - break; - } - case 'a': - case 'A':{ - if(allEntities[0].curXpos > 1){ - allEntities[0].nextXpos--; - if(allEntities[0].nextXpos < 0){ - allEntities[0].nextXpos = 0; - } - } - break; - } - case 'd': - case 'D':{ - if(allEntities[0].curXpos < scrCols-2){ - allEntities[0].nextXpos++; - if(allEntities[0].nextXpos > viewportWinCols-1){ - allEntities[0].nextXpos = viewportWinCols-1; - } - } - break; - } - case 'z': - case 'Z':{ - addZombie(); - break; - } - case KEY_UP:{ - if(allEntities[0].weapons[allEntities[0].curWeapon].curCapacity>0){ - fireWeapon(&pistol, "up"); - } - break; - } - case KEY_LEFT:{ - if(allEntities[0].weapons[allEntities[0].curWeapon].curCapacity>0){ - fireWeapon(&pistol, "left"); - } - break; - } - case KEY_DOWN:{ - if(allEntities[0].weapons[allEntities[0].curWeapon].curCapacity>0){ - fireWeapon(&pistol, "down"); - } - break; - } - case KEY_RIGHT:{ - if(allEntities[0].weapons[allEntities[0].curWeapon].curCapacity>0){ - fireWeapon(&pistol, "right"); - } - break; - } - - default: - if (ch != ERR) {lastPressed=ch;}; - break; - } - struct Entity * hitEntity = collisionDetect(allEntities[0].curYpos, allEntities[0].curXpos); - if(hitEntity){ - if(hitEntity->type=="zombie"){ - mvwprintw(viewportWin,1,10,"TEST"); - allEntities[0].isAlive=0; - mvwaddch(viewportWin, allEntities[0].curYpos, allEntities[0].curXpos, ' '); - } - } - - } - return 0; -} diff --git a/screen.h b/screen.h new file mode 100644 index 0000000..a481465 --- /dev/null +++ b/screen.h @@ -0,0 +1,13 @@ +#ifndef _SCREEN +#define _SCREEN + +#include + +WINDOW* viewportWin; +WINDOW* scoreWin; +WINDOW* gameOverWin; + +int scrRows,scrCols; +int viewportWinRows,viewportWinCols; + +#endif diff --git a/structs.h b/structs.h new file mode 100644 index 0000000..dae30ae --- /dev/null +++ b/structs.h @@ -0,0 +1,38 @@ +#ifndef _STRUCTS +#define _STRUCTS + +struct Weapon{ + char name[10]; + int range; + int maxCapacity; + int curCapacity; + char projectileSymbol; + char symbols[8]; +}; + +struct Entity { + char *type; + char symbol; + int curYpos, curXpos; + int nextYpos, nextXpos; + struct Weapon weapons[8]; + int curWeapon; + int isAlive; +}; + + +struct Projectile{ + int isAlive; + char symbol; + int curXpos; + int curYpos; + int prevYpos; + int prevXpos; + int nextYpos; + int nextXpos; + int range; + char direction; + int distanceTraveled; +}; + +#endif diff --git a/weaponsSystem.h b/weaponsSystem.h new file mode 100644 index 0000000..44ebe44 --- /dev/null +++ b/weaponsSystem.h @@ -0,0 +1,9 @@ +#ifndef _WEAPONS_SYSTEM +#define _WEAPONS_SYSTEM + +#include + +#define MAX_PROJECTILES 2 +struct Projectile projectiles[MAX_PROJECTILES]; + +#endif diff --git a/world.h b/world.h new file mode 100644 index 0000000..c595deb --- /dev/null +++ b/world.h @@ -0,0 +1,10 @@ +#ifndef _INITIALIZE_WORLD +#define _INITIALIZE_WORLD + +#define MAX_ALIVE 1000 +#include +struct Entity allEntities[MAX_ALIVE]; + +void initializeWorld(); + +#endif