aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Texture.cpp6
-rw-r--r--src/entities.cpp33
-rw-r--r--src/gameplay.cpp125
-rw-r--r--src/ui.cpp16
-rw-r--r--src/world.cpp49
5 files changed, 144 insertions, 85 deletions
diff --git a/src/Texture.cpp b/src/Texture.cpp
index de1af14..a3a8afe 100644
--- a/src/Texture.cpp
+++ b/src/Texture.cpp
@@ -73,9 +73,13 @@ Texturec::Texturec(uint amt, ...){
va_end(fNames);
}
+Texturec::~Texturec(){
+ delete[] image;
+}
+
void Texturec::bind(unsigned int bn){
texState = bn;
- glBindTexture(GL_TEXTURE_2D, (unsigned int)image[(int)texState]);
+ glBindTexture(GL_TEXTURE_2D,image[(int)texState]);
}
void Texturec::bindNext(){
diff --git a/src/entities.cpp b/src/entities.cpp
index 0764284..7dc561b 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -81,6 +81,11 @@ Player::Player(){ //sets all of the player specific traits on object creation
tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png");
inv = new Inventory(PLAYER_INV_SIZE);
}
+Player::~Player(){
+ delete inv;
+ delete tex;
+ delete[] name;
+}
NPC::NPC(){ //sets all of the NPC specific traits on object creation
width = HLINE * 10;
@@ -96,6 +101,15 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation
tex = new Texturec(1,"assets/NPC.png");
inv = new Inventory(NPC_INV_SIZE);
}
+NPC::~NPC(){
+ while(!aiFunc.empty()){
+ aiFunc.pop_back();
+ }
+
+ delete inv;
+ delete tex;
+ delete[] name;
+}
Structures::Structures(){ //sets the structure type
health = maxHealth = 1;
@@ -107,6 +121,11 @@ Structures::Structures(){ //sets the structure type
inWorld = NULL;
}
+Structures::~Structures(){
+ delete inv;
+ delete tex;
+ delete[] name;
+}
Mob::Mob(int sub){
type = MOBT;
@@ -132,6 +151,11 @@ Mob::Mob(int sub){
inv = new Inventory(NPC_INV_SIZE);
}
+Mob::~Mob(){
+ delete inv;
+ delete tex;
+ delete[] name;
+}
Object::Object(ITEM_ID id, bool qo, const char *pd){
identifier = id;
@@ -149,9 +173,14 @@ Object::Object(ITEM_ID id, bool qo, const char *pd){
maxHealth = health = 1;
tex = new Texturec(1,getItemTexturePath(id));
-
}
-
+Object::~Object(){
+ delete[] pickupDialog;
+
+ delete inv;
+ delete tex;
+ delete[] name;
+}
void Entity::draw(void){ //draws the entities
glPushMatrix();
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index eadd668..b7eab72 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -5,42 +5,6 @@
extern World *currentWorld;
extern Player *player;
-extern void mainLoop(void);
-extern SDL_Window *window;
-extern bool fadeEnable;
-
-void story(void){
- for(int i=0;i<600;i++){
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- glEnable(GL_STENCIL_TEST);
- glPushMatrix();
-
- glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT );
- glClear(GL_COLOR_BUFFER_BIT);
-
- glColor4f(0.0f,0.0f,0.0f,0.0f);
- glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT);
- glColor4f(1.0f,1.0f,1.0f,1.0f);
- ui::importantText("Oh hello, where are you?");
- //ui::setFontSize(16);
- //ui::putText(54,540,"BITC.");
-
- glPopMatrix();
- SDL_GL_SwapWindow(window);
- }
-}
-
-void waitForDialog(void){
- do{
- mainLoop();
- }while(ui::dialogBoxExists);
-}
int compTestQuest(NPC *speaker){
ui::dialogBox(speaker->name,NULL,"Ooo, that's a nice quest you got there. Lemme finish that for you ;).");
@@ -51,16 +15,13 @@ int compTestQuest(NPC *speaker){
int giveTestQuest(NPC *speaker){
unsigned char i;
- char opt[]=":Yes:No";
- ui::dialogBox(speaker->name,opt,"Here, have a quest!");
-
- waitForDialog();
+ ui::dialogBox(speaker->name,":Yes:No","Here, have a quest!");
+ ui::waitForDialog();
if(ui::dialogOptChosen == 1){
ui::dialogBox(speaker->name,NULL,"Have a good day! :)");
-
- waitForDialog();
+ ui::waitForDialog();
player->qh.assign("Test");
currentWorld->npc[1]->addAIFunc(compTestQuest,true);
@@ -73,14 +34,12 @@ int giveTestQuest(NPC *speaker){
static Arena *a;
void CUTSCENEEE(void){
- char opt[]=":K.";
player->vel.x = 0;
- ui::dialogBox(player->name,opt,"No way I\'m gettin\' up this hill.");
- waitForDialog();
+ ui::dialogBox(player->name,":K.","No way I\'m gettin\' up this hill.");
+ ui::waitForDialog();
a = new Arena(currentWorld,player);
-
currentWorld = a;
/*player->right = true;
@@ -92,6 +51,10 @@ float playerSpawnHillFunc(float x){
return (float)(pow(2,(-x+200)/5) + 80);
}
+static World *test;
+static World *playerSpawnHill;
+static IndoorWorld *iw;
+
void destroyEverything(void);
void initEverything(void){
@@ -101,17 +64,18 @@ void initEverything(void){
* World creation:
*/
- World *test=new World();
- World *playerSpawnHill=new World();
+ test=new World();
test->generate(SCREEN_WIDTH*2);
- test->addHole(100,150);
-
test->setBackground(BG_FOREST);
+
+ test->addHole(100,150);
test->addLayer(400);
- playerSpawnHill->generateFunc(1280,playerSpawnHillFunc);
+ playerSpawnHill=new World();
+
playerSpawnHill->setBackground(BG_FOREST);
+ playerSpawnHill->generateFunc(1280,playerSpawnHillFunc);
//playerSpawnHill->generate(1920);
/*
@@ -119,6 +83,7 @@ void initEverything(void){
*/
currentWorld=playerSpawnHill;
+
playerSpawnHill->toRight=test;
test->toLeft=playerSpawnHill;
@@ -133,22 +98,21 @@ void initEverything(void){
* Create a structure (this will create villagers when spawned).
*/
- IndoorWorld *iw=new IndoorWorld();
+ iw=new IndoorWorld();
iw->generate(200);
- currentWorld->addStructure(STRUCTURET,(rand()%120*HLINE),10,test,iw);
-
/*
- * Spawn some mobs.
+ * Spawn some entities.
*/
+ playerSpawnHill->addStructure(STRUCTURET,(rand()%120*HLINE),10,test,iw);
playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);
+ playerSpawnHill->addObject(SWORD_WOOD, false, "", 500,200);
+ playerSpawnHill->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200);
+
test->addMob(MS_RABBIT,200,100);
test->addMob(MS_BIRD,-500,500);
-
- currentWorld->addObject(SWORD_WOOD, false, "", 500,200);
- currentWorld->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200);
/*currentWorld->addObject(DEBUG_ITEM, 500,200);
currentWorld->addObject(TEST_ITEM, 550,200);
@@ -157,10 +121,51 @@ void initEverything(void){
currentWorld->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",700,200);
*/
- currentWorld->npc[0]->addAIFunc(giveTestQuest,false);
+ playerSpawnHill->npc[0]->addAIFunc(giveTestQuest,false);
+
atexit(destroyEverything);
}
+extern std::vector<int (*)(NPC *)> AIpreload;
+extern std::vector<NPC *> AIpreaddr;
+
void destroyEverything(void){
- //delete currentWorld;
+ delete test;
+ delete playerSpawnHill;
+
+ while(!AIpreload.empty()){
+ AIpreload.pop_back();
+ }
+ while(!AIpreaddr.empty()){
+ AIpreaddr.pop_back();
+ }
+
+ //delete iw; // segfaults
}
+
+/*void story(void){
+ for(int i=0;i<600;i++){
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glEnable(GL_STENCIL_TEST);
+ glPushMatrix();
+
+ glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT );
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glColor4f(0.0f,0.0f,0.0f,0.0f);
+ glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT);
+ glColor4f(1.0f,1.0f,1.0f,1.0f);
+ ui::importantText("Oh hello, where are you?");
+ //ui::setFontSize(16);
+ //ui::putText(54,540,"BITC.");
+
+ glPopMatrix();
+ SDL_GL_SwapWindow(window);
+ }
+}*/
diff --git a/src/ui.cpp b/src/ui.cpp
index 324192d..8d57c36 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -49,6 +49,8 @@ static char *dialogOptText[4];
static float dialogOptLoc[4][3];
static unsigned char dialogOptCount = 0;
+extern void mainLoop(void);
+
/*
* Toggled by pressing 'q', disables some controls when true.
*/
@@ -366,11 +368,10 @@ namespace ui {
return width;
}
-
- void dialogBox(const char *name,char *opt,const char *text,...){
+ void dialogBox(const char *name,const char *opt,const char *text,...){
va_list dialogArgs;
unsigned int len;
- char *sopt;
+ char *sopt,*soptbuf;
/*
* Set up the text buffer.
@@ -404,7 +405,9 @@ namespace ui {
dialogOptChosen=0;
dialogOptCount=0;
- sopt=strtok(opt,":");
+ soptbuf = new char[strlen(opt)+1];
+
+ sopt=strtok(soptbuf,":");
while(sopt != NULL){
dialogOptText[dialogOptCount] = new char[strlen(sopt)+1]; //(char *)malloc(strlen(sopt));
strcpy(dialogOptText[dialogOptCount++],sopt);
@@ -418,6 +421,11 @@ namespace ui {
dialogBoxExists = true;
}
+ void waitForDialog(void){
+ do{
+ mainLoop();
+ }while(ui::dialogBoxExists);
+ }
void importantText(const char *text,...){
va_list textArgs;
char *ttext,*rtext;
diff --git a/src/world.cpp b/src/world.cpp
index 281cbad..8067fe7 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -71,16 +71,37 @@ World::World(void){
memset(star,0,100*sizeof(vec2));
}
+void World::deleteEntities(void){
+ while(!mob.empty()){
+ delete mob.back();
+ mob.pop_back();
+ }
+ while(!npc.empty()){
+ delete npc.back();
+ npc.pop_back();
+ }
+ while(!build.empty()){
+ delete build.back();
+ build.pop_back();
+ }
+ while(!object.empty()){
+ delete object.back();
+ object.pop_back();
+ }
+ while(!entity.empty()) entity.pop_back();
+}
+
World::~World(void){
+
+ if(behind){
+ delete behind;
+ }
+
delete bgTex;
delete[] star;
delete[] line;
-
- delete &mob;
- delete &npc;
- delete &build;
- delete &object;
- delete &entity;
+
+ deleteEntities();
}
void World::generate(unsigned int width){ // Generates the world and sets all variables contained in the World class.
@@ -847,12 +868,8 @@ IndoorWorld::~IndoorWorld(void){
delete bgTex;
delete[] star;
delete[] line;
-
- delete &mob;
- delete &npc;
- delete &build;
- delete &object;
- delete &entity;
+
+ deleteEntities();
}
void IndoorWorld::generate(unsigned int width){ // Generates a flat area of width 'width'
@@ -917,12 +934,8 @@ Arena::~Arena(void){
delete bgTex;
delete[] star;
delete[] line;
-
- delete &mob;
- delete &npc;
- delete &build;
- delete &object;
- delete &entity;
+
+ deleteEntities();
}
World *Arena::exitArena(Player *p){