Compare commits

...

5 Commits

  1. 2
      .gitignore
  2. 4
      collisionDetection.c
  3. 43
      drawWindows.c
  4. 9
      drawWindows.h
  5. 1
      events.c
  6. 1
      events.h
  7. 2
      gameLoop.c
  8. 6
      gameLoop.h
  9. 2
      getPos.c
  10. 3
      getPos.h
  11. 11
      initializeWorld.c
  12. 7
      initializeWorld.h
  13. 3
      nZombies.c
  14. 6
      nZombies.h
  15. 2
      weaponsSystem.c
  16. 1
      weaponsSystem.h
  17. 1
      world.h
  18. 3
      zombies.c

2
.gitignore vendored

@ -0,0 +1,2 @@
# Ignore nZombies binary
nZombies

@ -1,5 +1,9 @@
#include <world.h> #include <world.h>
#include <string.h> #include <string.h>
#include <drawWindows.h>
#include <weaponsSystem.h>
#include <unistd.h>
struct CollisionEvent collisionDetect(int objYpos, int objXpos){ struct CollisionEvent collisionDetect(int objYpos, int objXpos){
int i; int i;
for(i=1; i<MAX_ENTITIES; i++){ for(i=1; i<MAX_ENTITIES; i++){

@ -1,8 +1,9 @@
#include <world.h> #include <world.h>
#include <initializeWorld.h>
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <weaponsSystem.h> #include <weaponsSystem.h>
void updateViewportWin(){ void updateViewportWin(){
int i; int i;
for(i=0; i<MAX_ITEMS; i++){ for(i=0; i<MAX_ITEMS; i++){
@ -70,7 +71,6 @@ void updateInfoWin(){
mvwprintw(infoWin, 1, 7, "Weapon: %s",allEntities[0].weapons[allEntities[0].curWeapon].type); mvwprintw(infoWin, 1, 7, "Weapon: %s",allEntities[0].weapons[allEntities[0].curWeapon].type);
mvwprintw(infoWin, 2, 9, "Ammo: %d/%d:%d",allEntities[0].weapons[allEntities[0].curWeapon].curCapacity,allEntities[0].weapons[allEntities[0].curWeapon].maxCapacity,allEntities[0].weapons[allEntities[0].curWeapon].curMags); mvwprintw(infoWin, 2, 9, "Ammo: %d/%d:%d",allEntities[0].weapons[allEntities[0].curWeapon].curCapacity,allEntities[0].weapons[allEntities[0].curWeapon].maxCapacity,allEntities[0].weapons[allEntities[0].curWeapon].curMags);
mvwprintw(infoWin, 3, 8, "Bombs: 0");
mvwaddch(infoWin, 1, 26, ACS_ULCORNER); mvwaddch(infoWin, 1, 26, ACS_ULCORNER);
mvwaddch(infoWin, 2, 26, ACS_VLINE); mvwaddch(infoWin, 2, 26, ACS_VLINE);
@ -161,6 +161,36 @@ void updateInfoWin(){
wnoutrefresh(infoWin); wnoutrefresh(infoWin);
} }
void drawGameStartWin(){
gameStartWin=newwin(11,39,viewportWinRows/4,viewportWinCols/4);
int gameStartWinRows, gameStartWinCols;
getmaxyx(gameStartWin,gameStartWinRows,gameStartWinCols);
mvwprintw(gameStartWin,1,(gameStartWinCols-strlen("HOW TO PLAY"))/2,"%s","HOW TO PLAY");
mvwprintw(gameStartWin,3,13,"WASD | MOVE");
mvwprintw(gameStartWin,4,11,"ARROWS | ATTACK");
mvwprintw(gameStartWin,5,13,"1234 | SELECT WEAPON");
mvwprintw(gameStartWin,6,16,"R | RELOAD");
mvwprintw(gameStartWin,7,15,"QE | USE ITEM");
mvwprintw(gameStartWin,(gameStartWinRows)-2,(gameStartWinCols-strlen("Press any key to start or 'q' to quit"))/2,"%s","Press any key to start or 'q' to quit");
box(gameStartWin,0,0);
wnoutrefresh(gameStartWin);
doupdate();
char input = wgetch(gameStartWin);
switch(input){
case 'q':
case 'Q':
endwin();
exit(0);
default:
nodelay(stdscr, TRUE);
return;
}
}
void drawGameOverWin(){ void drawGameOverWin(){
gameOverWin=newwin(11,39,viewportWinRows/4,viewportWinCols/4); gameOverWin=newwin(11,39,viewportWinRows/4,viewportWinCols/4);
@ -169,16 +199,9 @@ void drawGameOverWin(){
mvwprintw(gameOverWin,1,(gameOverWinCols-strlen("GAME OVER"))/2,"%s","GAME OVER"); mvwprintw(gameOverWin,1,(gameOverWinCols-strlen("GAME OVER"))/2,"%s","GAME OVER");
mvwprintw(gameOverWin,3,5,"Zombies Killed: %i",allEntities[0].killCount); mvwprintw(gameOverWin,3,5,"Zombies Killed: %i",allEntities[0].killCount);
mvwprintw(gameOverWin,4,8,"Shots Fired: %i",allEntities[0].projectilesFired); mvwprintw(gameOverWin,4,8,"Shots Fired: %i",allEntities[0].projectilesFired);
if (allEntities[0].projectilesFired!=0){
float hitPercent = (((float)allEntities[0].hitCount/(float)allEntities[0].projectilesFired)*100);
mvwprintw(gameOverWin,5,11,"Accuracy: %.0f%%",hitPercent);
}
else {
mvwprintw(gameOverWin,5,11,"Accuracy: N/A");
}
int mins=secsElapsed/60; int mins=secsElapsed/60;
int secs=(int)secsElapsed%60; int secs=(int)secsElapsed%60;
mvwprintw(gameOverWin,6,15,"Time: %02d:%02d",mins,secs); mvwprintw(gameOverWin,5,15,"Time: %02d:%02d",mins,secs);
mvwprintw(gameOverWin,(gameOverWinRows)-2,(gameOverWinCols-strlen("Press 'q' to quit or 'r' to restart"))/2,"%s","Press 'q' to quit or 'r' to restart"); mvwprintw(gameOverWin,(gameOverWinRows)-2,(gameOverWinCols-strlen("Press 'q' to quit or 'r' to restart"))/2,"%s","Press 'q' to quit or 'r' to restart");
nodelay(stdscr, FALSE); nodelay(stdscr, FALSE);
box(gameOverWin,0,0); box(gameOverWin,0,0);

@ -0,0 +1,9 @@
#ifndef _DRAW_WINDOWS
#define _DRAW_WINDOWS
void updateViewportWin();
void updateInfoWin();
void drawGameStartWin();
void drawGameOverWin();
#endif

@ -4,6 +4,7 @@
#include <getPos.h> #include <getPos.h>
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <zombies.h> #include <zombies.h>
void addItem(char *type, int yPos, int xPos){ void addItem(char *type, int yPos, int xPos){

@ -3,4 +3,5 @@
void addItem(char *type, int yPos, int xPos); void addItem(char *type, int yPos, int xPos);
void randomEvent(); void randomEvent();
void tryRandomEvent();
#endif #endif

@ -3,6 +3,8 @@
#include <events.h> #include <events.h>
#include <getPos.h> #include <getPos.h>
#include <weaponsSystem.h> #include <weaponsSystem.h>
#include <zombies.h>
#include <drawWindows.h>
void gameLoop(){ void gameLoop(){
while(1) { while(1) {

@ -0,0 +1,6 @@
#ifndef _GAME_LOOP
#define _GAME_LOOP
void gameLoop();
#endif

@ -1,5 +1,7 @@
#include <world.h> #include <world.h>
#include <getPos.h> #include <getPos.h>
#include <stdlib.h>
struct OpenPos getOpenPos(){ struct OpenPos getOpenPos(){
int chooseAnother=1; int chooseAnother=1;
struct OpenPos openPos; struct OpenPos openPos;

@ -12,4 +12,7 @@ struct NextPos{
}nextPos; }nextPos;
struct OpenPos getOpenPos(); struct OpenPos getOpenPos();
void getNextPos(int y, int x, int y2, int x2);
#endif #endif

@ -3,12 +3,12 @@
#include <string.h> #include <string.h>
#include <ncurses.h> #include <ncurses.h>
#include <world.h> #include <world.h>
#include <drawWindows.h>
#include <zombies.h>
#include <nZombies.h>
#include <getPos.h> #include <getPos.h>
void initializeWorld() { void initializeWorld() {
startTime=clock();
timerStart=clock();
srand(time(NULL)); srand(time(NULL));
initscr(); initscr();
@ -42,6 +42,8 @@ void initializeWorld() {
exit(0); exit(0);
} }
drawGameStartWin();
viewportWin=newwin(viewportWinRows,viewportWinCols,0,0); viewportWin=newwin(viewportWinRows,viewportWinCols,0,0);
infoWin=newwin(infoWinRows,infoWinCols,viewportWinRows,0); infoWin=newwin(infoWinRows,infoWinCols,viewportWinRows,0);
@ -62,6 +64,9 @@ void initializeWorld() {
struct OpenPos openPos = getOpenPos(); struct OpenPos openPos = getOpenPos();
addZombie(openPos.y,openPos.x); addZombie(openPos.y,openPos.x);
} }
startTime=clock();
timerStart=clock();
} }
void restartGame(){ void restartGame(){

@ -0,0 +1,7 @@
#ifndef _EVENTS
#define _EVENTS
void initializeWorld();
void restartGame();
#endif

@ -1,4 +1,7 @@
#include <time.h> #include <time.h>
#include <initializeWorld.h>
#include <gameLoop.h>
int main() { int main() {
initializeWorld(); initializeWorld();
gameLoop(); gameLoop();

@ -0,0 +1,6 @@
#ifndef _N_Zombies
#define _N_Zombies
void main();
#endif

@ -1,6 +1,8 @@
#include <world.h> #include <world.h>
#include <collisionDetection.h> #include <collisionDetection.h>
#include <weaponsSystem.h> #include <weaponsSystem.h>
#include <string.h>
void moveProjectiles(){ void moveProjectiles(){
int i; int i;
for(i=0; i<MAX_PROJECTILES; i++){ for(i=0; i<MAX_PROJECTILES; i++){

@ -4,5 +4,6 @@
void moveProjectiles(); void moveProjectiles();
void fireWeapon(); void fireWeapon();
void addMagazine(); void addMagazine();
void reload(struct Weapon *weaponRef);
#endif #endif

@ -12,6 +12,7 @@ float secsElapsed;
WINDOW* viewportWin; WINDOW* viewportWin;
WINDOW* infoWin; WINDOW* infoWin;
WINDOW* gameStartWin;
WINDOW* gameOverWin; WINDOW* gameOverWin;
int stdscrRows,stdscrCols; int stdscrRows,stdscrCols;

@ -1,6 +1,9 @@
#include <world.h> #include <world.h>
#include <getPos.h> #include <getPos.h>
#include <collisionDetection.h> #include <collisionDetection.h>
#include <stdlib.h>
#include <getPos.h>
void addZombie(int y, int x){ void addZombie(int y, int x){
if (y && x){ if (y && x){
int i; int i;

Loading…
Cancel
Save