- 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)
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);
public:
void *inWorld;
void *inside;
+
Structures();
unsigned int spawn(_TYPE, float, float);
};
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
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
World *exit;
public:
Arena(World *leave,Player *p);
+ ~Arena(void);
World *exitArena(Player *p);
};
#define END }),\r
\r
const Quest QuestList[TOTAL_QUESTS]={\r
-// Quest("Test","A test quest",(struct item_t){1,TEST_ITEM}),\r
-\r
// Get quest list\r
#include "../config/quest_list.txt"\r
-\r
};\r
\r
\r
Quest::Quest(const char *t,const char *d,struct item_t r){\r
- title = new char[strlen(t)+1]; //(char *)calloc(safe_strlen(t),sizeof(char));\r
- desc = new char[strlen(d)+1]; //(char *)calloc(safe_strlen(d),sizeof(char));\r
+ title = new char[strlen(t)+1];\r
+ desc = new char[strlen(d)+1];\r
strcpy(title,t);\r
strcpy(desc,d);\r
memcpy(&reward,&r,sizeof(struct item_t));\r
}\r
\r
Quest::~Quest(){\r
- delete[] title; //free(title);\r
- delete[] desc; //free(desc);\r
+ delete[] title;\r
+ delete[] desc;\r
memset(&reward,0,sizeof(struct item_t));\r
}\r
\r
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;
}
}
- 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
}
}
-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
}
float playerSpawnHillFunc(float x){
return (float)(pow(2,(-x+200)/5) + 80);
}
+
+void destroyEverything(void);
+
void initEverything(void){
unsigned int i;
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;
}
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);
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){
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;
}
}
-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;
}
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'
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;