- 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)
ID DEBUG_ITEM
- NAME "Debug\0"
+ NAME "Debug"
TYPE TOOL
WIDTH 1
HEIGHT 1
ENI
ID TEST_ITEM
- NAME "Dank MayMay\0"
+ NAME "Dank MayMay"
TYPE TOOL
WIDTH HLINE
HEIGHT HLINE
ENI
ID PLAYER_BAG
- NAME "Your Bag\0"
+ NAME "Your Bag"
TYPE EQUIP
WIDTH HLINE*5
HEIGHT HLINE*5
ENI
ID FLASHLIGHT
- NAME "Flashlight\0"
+ NAME "Flashlight"
TYPE TOOL
WIDTH HLINE*2
HEIGHT HLINE*4
ENI
ID SWORD_WOOD
- NAME "Wood Sword\0"
+ NAME "Wood Sword"
TYPE SWORD
WIDTH HLINE*4
HEIGHT HLINE*10
private:
unsigned int texState;
public:
+ GLuint *image;
+
Texturec(uint amt, ...);
+ ~Texturec();
+
void bindNext();
void bindPrev();
void bind(unsigned int);
void walk();
-
- GLuint *image;
};
#endif //TEXTURE_H
#define GAME_NAME "Independent Study v.0.4 alpha"
-#define SCREEN_WIDTH 800
-#define SCREEN_HEIGHT 600
+#define SCREEN_WIDTH 1280
+#define SCREEN_HEIGHT 720
//#define FULLSCREEN
extern float handAngle;
+extern unsigned int loops;
+
/*
* Prints a formatted debug message to the console, along with the callee's file and line
* number.
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();
+ ~Player();
void interact();
- bool light = false;
};
class NPC : public Entity{
public:
std::vector<int (*)(NPC *)>aiFunc;
+
NPC();
+ ~NPC();
+
void addAIFunc(int (*func)(NPC *),bool preload);
void interact();
void wander(int);
public:
void *inWorld;
void *inside;
+
Structures();
+ ~Structures();
+
unsigned int spawn(_TYPE, float, float);
};
public:
double init_y;
void (*hey)();
+
Mob(int);
Mob(int,unsigned int);
+ ~Mob();
+
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);
+ ~Object();
+
void interact(void);
- bool questObject = false;
- char *pickupDialog;
std::thread runInteract() {
return std::thread([=] { interact(); });
}
-private:
- int identifier;
};
#endif // ENTITIES_H
int maxStackSize;
char* textureLoc;
Texturec *tex;
+ GLuint text;
int count;
+
Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl);
GLuint rtex(){
return tex->image[0];
}
};
+static Item item[5]= {
+ #include "../config/items.h"
+};
+
struct item_t{
int count;
ITEM_ID id;
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
* limited until a right click is given, closing the box.
*/
- void dialogBox(const char *name,char *opt,const char *text,...);
+ void dialogBox(const char *name,const char *opt,const char *text,...);
+ void waitForDialog(void);
/*
* Draws a larger string in the center of the screen. Drawing is done inside this function.
/*
* Handle keyboard/mouse events.
*/
-
void handleEvents(void);
/*
void singleDetect(Entity *e);
+ /*
+ * Deletes all entities in the world.
+ */
+
+ void deleteEntities(void);
+
/*
* The size of the line array. This is set once by World->generate().
*/
World *exit;
public:
Arena(World *leave,Player *p);
+ ~Arena(void);
World *exitArena(Player *p);
};
if(Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0){
std::cout << "SDL_mixer could not initialize! Error: " << Mix_GetError() << std::endl;
+ return -1;
}
// Run Mix_Quit when main returns
+ atexit(Mix_CloseAudio);
atexit(Mix_Quit);
/*
/**************************
**** GAMELOOP ****
**************************/
+
gameRunning=true;
while(gameRunning){
mainLoop();
* Close the window and free resources
*/
+ Mix_HaltMusic();
+ Mix_FreeMusic(music);
+
+ Mix_FreeChunk(horn);
+
fclose(names);
SDL_GL_DeleteContext(mainGLContext);
currentTime=millis();
prevPrevTime=currentTime;
}
-
/*
* Update timing values. This is crucial to calling logic and updating the window (basically
* the entire game).
/*
* Run the logic handler if MSEC_PER_TICK milliseconds have passed.
*/
-
- if(prevPrevTime + MSEC_PER_TICK >= currentTime){
+ ui::handleEvents();
+ if(prevPrevTime + MSEC_PER_TICK <= currentTime){
logic();
prevPrevTime = currentTime;
}
/*
* Update debug variables if necessary
*/
-
if(++debugDiv==20){
debugDiv=0;
}
render(); // Call the render loop
-
}
extern bool fadeEnable;
/*
* Here we draw a black overlay if it's been requested.
*/
-
if(fadeIntensity){
glColor4ub(0,0,0,fadeIntensity);
glRectf(offset.x-SCREEN_WIDTH /2,
ui::importantText("The screen is black.");
}
}else if(ui::fontSize != 16) ui::setFontSize(16);
-
/**************************
**** END RENDERING ****
**************************/
}
void logic(){
-
/*
* NPCSelected is used to insure that only one NPC is made interactable with the mouse
* if, for example, multiple entities are occupying one space.
/*
* Handle user input (keyboard & mouse).
*/
-
- ui::handleEvents();
+ //ui::handleEvents();
/*
* Run the world's detect function. This handles the physics of the player and any entities
* that exist in this world.
*/
-
currentWorld->detect(player);
if(player->loc.y<.02)gameRunning=false;
* click detection is done as well for NPC/player interaction.
*
*/
-
if((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) && !ui::dialogBoxExists)player->inv->useItem();
for(auto &n : currentWorld->npc){
}else n->near=false;
}
}
-
for(auto &m : currentWorld->mob){
if(m->alive){
}
}
}
-
unsigned int i = 0;
for(auto &o : currentWorld->object){
if(o->alive){
/*
* Switch between day and night (SUNNY and DARK) if necessary.
*/
-
if(!(tickCount%DAY_CYCLE)||!tickCount){
if(weather==SUNNY){
weather=DARK;
/*
* Transition to and from black if necessary.
*/
-
if(fadeEnable){
if(fadeIntensity < 160)fadeIntensity+=5;
else if(fadeIntensity < 255)fadeIntensity+=1;
#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
GLuint loadTexture(const char *fileName){
SDL_Surface *image;
GLuint object = 0;
- unsigned int i;
for(unsigned int i=0;i<LoadedTextureCounter;i++){
if(!strcmp(LoadedTexture[i]->name,fileName)){
va_end(fNames);
}
+Texturec::~Texturec(){
+ delete[] image;
+}
+
void Texturec::bind(unsigned int bn){
texState = bn;
- glBindTexture(GL_TEXTURE_2D, image[texState]);
+ glBindTexture(GL_TEXTURE_2D,image[(int)texState]);
}
void Texturec::bindNext(){
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
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;
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;
inWorld = NULL;
}
+Structures::~Structures(){
+ delete inv;
+ delete tex;
+ delete[] name;
+}
Mob::Mob(int sub){
type = MOBT;
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;
pickupDialog = new char[strlen(pd)+1];
strcpy(pickupDialog,pd);
+
type = OBJECTT;
alive = true;
near = false;
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();
}
}
-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
}
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 ;).");
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);
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;
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){
unsigned int i;
* 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);
/*
*/
currentWorld=playerSpawnHill;
+
playerSpawnHill->toRight=test;
test->toLeft=playerSpawnHill;
* 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);
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);
+ playerSpawnHill->npc[0]->addAIFunc(giveTestQuest,false);
+
+ atexit(destroyEverything);
+}
+
+extern std::vector<int (*)(NPC *)> AIpreload;
+extern std::vector<NPC *> AIpreaddr;
+
+void destroyEverything(void){
+ 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);
+ }
+}*/
extern Player *player;
extern GLuint invUI;
-static Item item[5]= {
- #include "../config/items.h"
-};
-
void itemDraw(Player *p,ITEM_ID id);
char *getItemTexturePath(ITEM_ID id){
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){
void Inventory::draw(void){
ui::putText(offset.x-SCREEN_WIDTH/2,480,"%d",sel);
unsigned int i=0;
+ static unsigned int lop = 0;
float y,xoff;
static int numSlot = 7;
static std::vector<int>dfp(numSlot);
end = 0;
for(auto &d : dfp){
if(a != 0){
- if(dfp[a-1]>25)d+=25;
+ if(dfp[a-1]>50)d+=1.65*deltaTime;
}else{
- d += 25;
+ d += 1.65*deltaTime;
}
if(d >= range)
d = range;
}else if(!invOpening){
for(auto &d : dfp){
if(d > 0){
- if(a != 0){
- //d-=25;
- if(dfp[a-1]+25<d || dfp[a-1]<=0)d-=25;
- }else{
- d-=25;
- }
+ d-=1.65*deltaTime;
}else end++;
- a++;
- }a=0;
+ }
if(end >= numSlot)invOpen=false;
}
if(invOpen){
curCoord[a].y += float((dfp[a]) * sin(angle*PI/180));
r.end = curCoord[a];
- item[inv[i].id].tex->bind(0);
- glColor4f(1.0f, 1.0f, 1.0f, (float)dfp[a]/(float)range);
+ glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)range));
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2i(r.end.x, r.end.y);
- glTexCoord2i(1,1);glVertex2i(r.end.x+45, r.end.y);
- glTexCoord2i(1,0);glVertex2i(r.end.x+45, r.end.y+45);
- glTexCoord2i(0,0);glVertex2i(r.end.x, r.end.y+45);
+ glVertex2i(r.end.x, r.end.y);
+ glVertex2i(r.end.x+45, r.end.y);
+ glVertex2i(r.end.x+45, r.end.y+45);
+ glVertex2i(r.end.x, r.end.y+45);
glEnd();
+
+ if(inv[a].count > 0){
+ glBindTexture(GL_TEXTURE_2D, item[inv[a].id].text);
+ glColor4f(1.0f, 1.0f, 1.0f, (float)dfp[a]/(float)range);
+ glBegin(GL_QUADS);
+ glTexCoord2i(0,1);glVertex2i(r.end.x, r.end.y);
+ glTexCoord2i(1,1);glVertex2i(r.end.x+45, r.end.y);
+ glTexCoord2i(1,0);glVertex2i(r.end.x+45, r.end.y+45);
+ glTexCoord2i(0,0);glVertex2i(r.end.x, r.end.y+45);
+ glEnd();
+ }
a++;
}
}
}*/
if(inv[sel].count)itemDraw(player,inv[sel].id);
+ lop++;
}
static vec2 item_coord = {0,0};
static float dialogOptLoc[4][3];
static unsigned char dialogOptCount = 0;
+extern void mainLoop(void);
+
/*
* Toggled by pressing 'q', disables some controls when true.
*/
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.
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);
dialogBoxExists = true;
}
+ void waitForDialog(void){
+ do{
+ mainLoop();
+ }while(ui::dialogBoxExists);
+ }
void importantText(const char *text,...){
va_list textArgs;
char *ttext,*rtext;
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;
+
+ deleteEntities();
+}
+
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;
}else{
- if(e->vel.y > -2)e->vel.y-=.001 * deltaTime;
+ if(e->vel.y > -2)e->vel.y-=.003 * deltaTime;
}
}
IndoorWorld::~IndoorWorld(void){
- delete[] line; //free(line);
+ delete bgTex;
+ delete[] star;
+ delete[] line;
+
+ deleteEntities();
}
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;
+
+ deleteEntities();
+}
+
World *Arena::exitArena(Player *p){
npc[0]->loc.x = door.x;
npc[0]->loc.y = door.y;