diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Quest.cpp | 11 | ||||
-rw-r--r-- | src/entities.cpp | 69 | ||||
-rw-r--r-- | src/gameplay.cpp | 11 | ||||
-rw-r--r-- | src/inventory.cpp | 7 | ||||
-rw-r--r-- | src/world.cpp | 38 |
5 files changed, 83 insertions, 53 deletions
diff --git a/src/Quest.cpp b/src/Quest.cpp index bfa8966..4e8522d 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -7,25 +7,22 @@ #define END }),
const Quest QuestList[TOTAL_QUESTS]={
-// Quest("Test","A test quest",(struct item_t){1,TEST_ITEM}),
-
// Get quest list
#include "../config/quest_list.txt"
-
};
Quest::Quest(const char *t,const char *d,struct item_t r){
- title = new char[strlen(t)+1]; //(char *)calloc(safe_strlen(t),sizeof(char));
- desc = new char[strlen(d)+1]; //(char *)calloc(safe_strlen(d),sizeof(char));
+ title = new char[strlen(t)+1];
+ desc = new char[strlen(d)+1];
strcpy(title,t);
strcpy(desc,d);
memcpy(&reward,&r,sizeof(struct item_t));
}
Quest::~Quest(){
- delete[] title; //free(title);
- delete[] desc; //free(desc);
+ delete[] title;
+ delete[] desc;
memset(&reward,0,sizeof(struct item_t));
}
diff --git a/src/entities.cpp b/src/entities.cpp index 1681efd..0764284 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -10,6 +10,39 @@ extern Player *player; extern const char *itemName; +void getRandomName(Entity *e){ + int tempNum,max=0; + char buf,*bufs; + + rewind(names); + + bufs = new char[16]; //(char *)malloc(16); + + for(;!feof(names);max++){ + fgets(bufs,16,(FILE*)names); + } + + tempNum = rand() % max; + rewind(names); + + for(int i=0;i<tempNum;i++){ + fgets(bufs,16,(FILE*)names); + } + + switch(fgetc(names)){ + case 'm': e->gender = MALE; break; + case 'f': e->gender = FEMALE;break; + default : break; + } + + if((fgets(bufs,16,(FILE*)names)) != NULL){ + bufs[strlen(bufs)-1] = '\0'; + strcpy(e->name,bufs); + } + + delete[] bufs; +} + void Entity::spawn(float x, float y){ //spawns the entity you pass to it based off of coords and global entity settings loc.x = x; loc.y = y; @@ -33,8 +66,8 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o } } - name = new char[16]; //(char*)malloc(16); - getName(); + name = new char[16]; + getRandomName(this); } Player::Player(){ //sets all of the player specific traits on object creation @@ -210,38 +243,6 @@ NOPE: } } -void Entity::getName(){ - rewind(names); - char buf,*bufs = new char[16]; //(char *)malloc(16); - int tempNum,max = 0; - for(;!feof(names);max++){ - fgets(bufs,16,(FILE*)names); - } - tempNum = rand()%max; - rewind(names); - for(int i=0;i<tempNum;i++){ - fgets(bufs,16,(FILE*)names); - } - switch(fgetc(names)){ - case 'm': - gender = MALE; - //std::puts("Male"); - break; - case 'f': - gender = FEMALE; - //std::puts("Female"); - break; - default: - break; - } - if((fgets(bufs,16,(FILE*)names)) != NULL){ - //std::puts(bufs); - bufs[strlen(bufs)-1] = '\0'; - strcpy(name,bufs); - } - delete[] bufs; //free(bufs); -} - void Player::interact(){ //the function that will cause the player to search for things to interact with } diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 2fd7424..eadd668 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -91,6 +91,9 @@ void CUTSCENEEE(void){ float playerSpawnHillFunc(float x){ return (float)(pow(2,(-x+200)/5) + 80); } + +void destroyEverything(void); + void initEverything(void){ unsigned int i; @@ -153,9 +156,11 @@ void initEverything(void){ currentWorld->addObject(SWORD_WOOD, 650,200); currentWorld->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",700,200); */ - /* - * Link all the entities that were just created to the initial world, and setup a test AI function. - */ currentWorld->npc[0]->addAIFunc(giveTestQuest,false); + atexit(destroyEverything); +} + +void destroyEverything(void){ + //delete currentWorld; } diff --git a/src/inventory.cpp b/src/inventory.cpp index 3b2663b..ff180b0 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -21,8 +21,8 @@ Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const maxStackSize = m; count = 0; - name = new char[strlen(n)+1]; //(char*)calloc(strlen(n ),sizeof(char)); - textureLoc = new char[strlen(tl)+1]; //(char*)calloc(strlen(tl),sizeof(char)); + name = new char[strlen(n)+1]; + textureLoc = new char[strlen(tl)+1]; strcpy(name,n); strcpy(textureLoc,tl); @@ -33,14 +33,13 @@ Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const Inventory::Inventory(unsigned int s){ sel=0; size=s; - inv = new struct item_t[size]; //(struct item_t *)calloc(size,sizeof(struct item_t)); + inv = new struct item_t[size]; memset(inv,0,size*sizeof(struct item_t)); tossd=false; } Inventory::~Inventory(void){ delete[] inv; - //free(item); } void Inventory::setSelection(unsigned int s){ diff --git a/src/world.cpp b/src/world.cpp index c977c7f..36f0f69 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -71,6 +71,18 @@ World::World(void){ memset(star,0,100*sizeof(vec2)); } +World::~World(void){ + delete bgTex; + delete[] star; + delete[] line; + + delete &mob; + delete &npc; + delete &build; + delete &object; + delete &entity; +} + void World::generate(unsigned int width){ // Generates the world and sets all variables contained in the World class. unsigned int i; float inc; @@ -196,10 +208,6 @@ void World::generateFunc(unsigned int width,float(*func)(float)){ } } -World::~World(void){ - delete[] line; -} - void World::update(Player *p,unsigned int delta){ p->loc.y+= p->vel.y *delta; p->loc.x+=(p->vel.x*p->speed)*delta; @@ -836,7 +844,15 @@ IndoorWorld::IndoorWorld(void){ } IndoorWorld::~IndoorWorld(void){ - delete[] line; //free(line); + delete bgTex; + delete[] star; + delete[] line; + + delete &mob; + delete &npc; + delete &build; + delete &object; + delete &entity; } void IndoorWorld::generate(unsigned int width){ // Generates a flat area of width 'width' @@ -897,6 +913,18 @@ Arena::Arena(World *leave,Player *p){ pxy = p->loc; } +Arena::~Arena(void){ + delete bgTex; + delete[] star; + delete[] line; + + delete &mob; + delete &npc; + delete &build; + delete &object; + delete &entity; +} + World *Arena::exitArena(Player *p){ npc[0]->loc.x = door.x; npc[0]->loc.y = door.y; |