Make getOpenPos return struct OpenPos

main
Jerry Aldrich 11 years ago
parent bd48516d32
commit e336a93c8d
  1. 5
      events.c
  2. 8
      gameLoop.c
  3. 9
      getPos.c
  4. 5
      getPos.h
  5. 2
      world.h
  6. 29
      zombies.c
  7. 2
      zombies.h

@ -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){

@ -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;
}

@ -1,8 +1,9 @@
#include <screen.h>
#include <world.h>
#include <getPos.h>
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;
}
}
}

@ -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

@ -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;

@ -2,16 +2,16 @@
#include <getPos.h>
#include <screen.h>
#include <collisionDetection.h>
void addZombie(){
if(getOpenPos()){
void addZombie(int y, int x){
if (y && x){
int i;
for(i=0;i<MAX_ENTITIES-1;i++){
if(!allEntities[i].isAlive){
struct Entity zombie;
zombie.curYpos=openPos.y;
zombie.curXpos=openPos.x;
zombie.nextYpos=openPos.y;
zombie.nextXpos=openPos.x;
zombie.curYpos=y;
zombie.curXpos=x;
zombie.nextYpos=y;
zombie.nextXpos=x;
zombie.type="zombie";
zombie.symbol='Z';
zombie.isAlive=1;
@ -26,8 +26,21 @@ void addZombie(){
}
void addHorde(){
getOpenPos();
// if(getOpenPos()){
// int y=openPos.y;
// int x=openPos.x;
// addZombie();
/*
addZombie(y-1,x);
addZombie(y,x-1);
addZombie(y-1,x-1);
addZombie(y+1,x);
addZombie(y,x+1);
addZombie(y+1,x+1);
addZombie(y-1,x+1);
addZombie(y+1,x-1);
*/
// }
}
void moveZombies(){

@ -1,7 +1,7 @@
#ifndef _ZOMBIES
#define _ZOMBIES
void addZombies();
void addZombie(int y, int x);
void addHorde();
void moveZombies();

Loading…
Cancel
Save