aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2015-12-01 07:29:47 -0500
committerdrumsetmonkey <abelleisle@roadrunner.com>2015-12-01 07:29:47 -0500
commit813f30f8d7e4db971fbb9aab429b489e884ad2e9 (patch)
tree706a0dc14485acfb7cb711f20c98f821465f8fe3
parentaf22d85f9a417a94ea75db1878219f8baeba8b73 (diff)
parent80bc1b24bcf6862a7fbd3223a3d6988ce4e389e0 (diff)
Merge branch 'master' of http://github.com/tcsullivan/gamedev
-rw-r--r--Changelog3
-rw-r--r--include/entities.h78
-rw-r--r--include/inventory.h3
-rw-r--r--include/world.h1
-rw-r--r--src/Quest.cpp11
-rw-r--r--src/entities.cpp69
-rw-r--r--src/gameplay.cpp11
-rw-r--r--src/inventory.cpp7
-rw-r--r--src/world.cpp38
9 files changed, 137 insertions, 84 deletions
diff --git a/Changelog b/Changelog
index c9c94d8..c09d63a 100644
--- a/Changelog
+++ b/Changelog
@@ -345,3 +345,6 @@
- Converted all m/calloc/free calls to new/delete
- fixed hardcoded string issues
- improved inventory animation
+ - began writing songs for game soundtrack
+
+ ~ About 4280 lines of code + documentation written ( +7ish pages of story on gdoc)
diff --git a/include/entities.h b/include/entities.h
index b9881ea..0bdadb7 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -38,56 +38,72 @@ class Entity{
public:
Inventory *inv;
- float width; //width and height of the player
+ /*
+ * Movement variables
+ */
+
+ vec2 loc;
+ vec2 vel;
+
+ float width;
float height;
- float speed; //speed of the play
+
+ float speed; // A speed factor for X movement
+
+ /*
+ * Movement flags
+ */
+
+ bool near; // Causes name to display
+ bool canMove; // Enables movement
+ bool right,left; // Direction faced by Entity
+ bool alive;
+ unsigned char ground; // Shows how the Entity is grounded (if it is)
+
+ /*
+ * Health variables
+ */
float health;
float maxHealth;
- int subtype;
- _TYPE type;
- //example:
- //type 1(NPC)
- // |(subtype)
- // |-> 0 Base NPC
- // |-> 1 Merchant
+ /*
+ * Identification variables
+ */
- vec2 loc; //location and velocity of the entity
- vec2 vel;
-
- bool near;
- bool right,left, canMove; //movement variables
- bool alive; //the flag for whether or not the entity is alive
- unsigned char ground; //variable for testing what ground the entity is on to apply certain traits
+ _TYPE type;
+ int subtype;
- char* name;
- GENDER gender;
- //GLuint texture[3]; //TODO: ADD TEXTURES
- Texturec* tex;
+ char *name;
+ GENDER gender;
+
+ Texturec *tex;
- void spawn(float, float);
void draw(void);
+ void spawn(float, float);
+
+ int ticksToUse; // Used by wander()
+
virtual void wander(int){}
- void getName();
virtual void interact(){}
- int ticksToUse; //The variable for deciding how long an entity should do a certain task
-private:
};
class Player : public Entity {
public:
QuestHandler qh;
+ bool light = false;
+
Player();
void interact();
- bool light = false;
};
class NPC : public Entity{
public:
std::vector<int (*)(NPC *)>aiFunc;
+
NPC();
+
void addAIFunc(int (*func)(NPC *),bool preload);
void interact();
void wander(int);
@@ -97,6 +113,7 @@ class Structures : public Entity{
public:
void *inWorld;
void *inside;
+
Structures();
unsigned int spawn(_TYPE, float, float);
};
@@ -105,22 +122,25 @@ class Mob : public Entity{
public:
double init_y;
void (*hey)();
+
Mob(int);
Mob(int,unsigned int);
void wander(int);
};
class Object : public Entity{
+private:
+ int identifier;
public:
+ char *pickupDialog;
+ bool questObject = false;
+
Object(ITEM_ID id, bool qo, const char *pd);
+
void interact(void);
- bool questObject = false;
- char *pickupDialog;
std::thread runInteract() {
return std::thread([=] { interact(); });
}
-private:
- int identifier;
};
#endif // ENTITIES_H
diff --git a/include/inventory.h b/include/inventory.h
index 2b402fc..8567b8b 100644
--- a/include/inventory.h
+++ b/include/inventory.h
@@ -74,14 +74,13 @@ private:
unsigned int size; // Size of 'item' array
item_t *inv;
int os = 0;
- //struct item_t *item; // An array of the items contained in this inventory.
public:
unsigned int sel;
bool invOpen = false;
bool invOpening = false;
Inventory(unsigned int s); // Creates an inventory of size 's'
- ~Inventory(void); // Free's 'item'
+ ~Inventory(void); // Free's allocated memory
int addItem(ITEM_ID id,unsigned char count); // Add 'count' items with an id of 'id' to the inventory
int takeItem(ITEM_ID id,unsigned char count); // Take 'count' items with an id of 'id' from the inventory
diff --git a/include/world.h b/include/world.h
index a2414e6..4e4c28d 100644
--- a/include/world.h
+++ b/include/world.h
@@ -205,6 +205,7 @@ private:
World *exit;
public:
Arena(World *leave,Player *p);
+ ~Arena(void);
World *exitArena(Player *p);
};
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;