aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-12-01 08:38:21 -0500
committerClyne Sullivan <tullivan99@gmail.com>2015-12-01 08:38:21 -0500
commitd8554c12fdea5640df0ba42925f296f1711ba389 (patch)
tree8204651ac0e7dc6189ffabb9df39763b19c61886
parent45bca98b792f8ced1a57ef8c5beed2a90a79d47f (diff)
andy cant code
-rw-r--r--Changelog3
-rw-r--r--assets/door.pngbin0 -> 255 bytes
-rw-r--r--config/items.h10
-rw-r--r--include/Texture.h6
-rw-r--r--include/common.h6
-rw-r--r--include/entities.h85
-rw-r--r--include/inventory.h9
-rw-r--r--include/ui.h4
-rw-r--r--include/world.h7
-rw-r--r--main.cpp27
-rw-r--r--src/Quest.cpp11
-rw-r--r--src/Texture.cpp7
-rw-r--r--src/entities.cpp103
-rw-r--r--src/gameplay.cpp134
-rw-r--r--src/inventory.cpp49
-rw-r--r--src/ui.cpp16
-rw-r--r--src/world.cpp53
-rw-r--r--xcf/door.xcfbin0 -> 1404 bytes
18 files changed, 332 insertions, 198 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/assets/door.png b/assets/door.png
new file mode 100644
index 0000000..2a8b0dd
--- /dev/null
+++ b/assets/door.png
Binary files differ
diff --git a/config/items.h b/config/items.h
index 62db071..fc0ca96 100644
--- a/config/items.h
+++ b/config/items.h
@@ -1,6 +1,6 @@
ID DEBUG_ITEM
- NAME "Debug\0"
+ NAME "Debug"
TYPE TOOL
WIDTH 1
HEIGHT 1
@@ -9,7 +9,7 @@ ID DEBUG_ITEM
ENI
ID TEST_ITEM
- NAME "Dank MayMay\0"
+ NAME "Dank MayMay"
TYPE TOOL
WIDTH HLINE
HEIGHT HLINE
@@ -18,7 +18,7 @@ ID TEST_ITEM
ENI
ID PLAYER_BAG
- NAME "Your Bag\0"
+ NAME "Your Bag"
TYPE EQUIP
WIDTH HLINE*5
HEIGHT HLINE*5
@@ -27,7 +27,7 @@ ID PLAYER_BAG
ENI
ID FLASHLIGHT
- NAME "Flashlight\0"
+ NAME "Flashlight"
TYPE TOOL
WIDTH HLINE*2
HEIGHT HLINE*4
@@ -36,7 +36,7 @@ ID FLASHLIGHT
ENI
ID SWORD_WOOD
- NAME "Wood Sword\0"
+ NAME "Wood Sword"
TYPE SWORD
WIDTH HLINE*4
HEIGHT HLINE*10
diff --git a/include/Texture.h b/include/Texture.h
index c590f6a..1a32aae 100644
--- a/include/Texture.h
+++ b/include/Texture.h
@@ -13,13 +13,15 @@ class Texturec{
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
diff --git a/include/common.h b/include/common.h
index 0ddb5e4..52daf4b 100644
--- a/include/common.h
+++ b/include/common.h
@@ -61,8 +61,8 @@ typedef struct {
#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
@@ -116,6 +116,8 @@ extern vec2 offset;
extern float handAngle;
+extern unsigned int loops;
+
/*
* Prints a formatted debug message to the console, along with the callee's file and line
* number.
diff --git a/include/entities.h b/include/entities.h
index b9881ea..c593710 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -38,56 +38,74 @@ 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();
+ ~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);
@@ -97,7 +115,10 @@ class Structures : public Entity{
public:
void *inWorld;
void *inside;
+
Structures();
+ ~Structures();
+
unsigned int spawn(_TYPE, float, float);
};
@@ -105,22 +126,28 @@ class Mob : public Entity{
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
diff --git a/include/inventory.h b/include/inventory.h
index a9a4bcb..cde8d2a 100644
--- a/include/inventory.h
+++ b/include/inventory.h
@@ -49,13 +49,19 @@ public:
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;
@@ -67,14 +73,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/ui.h b/include/ui.h
index c3c8940..4d30b9b 100644
--- a/include/ui.h
+++ b/include/ui.h
@@ -59,7 +59,8 @@ namespace ui {
* 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.
@@ -76,7 +77,6 @@ namespace ui {
/*
* Handle keyboard/mouse events.
*/
-
void handleEvents(void);
/*
diff --git a/include/world.h b/include/world.h
index a2414e6..6c0395d 100644
--- a/include/world.h
+++ b/include/world.h
@@ -63,6 +63,12 @@ protected:
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().
*/
@@ -205,6 +211,7 @@ private:
World *exit;
public:
Arena(World *leave,Player *p);
+ ~Arena(void);
World *exitArena(Player *p);
};
diff --git a/main.cpp b/main.cpp
index 5ac85ba..422a329 100644
--- a/main.cpp
+++ b/main.cpp
@@ -256,9 +256,11 @@ int main(int argc, char *argv[]){
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);
/*
@@ -439,6 +441,7 @@ int main(int argc, char *argv[]){
/**************************
**** GAMELOOP ****
**************************/
+
gameRunning=true;
while(gameRunning){
mainLoop();
@@ -452,6 +455,11 @@ int main(int argc, char *argv[]){
* Close the window and free resources
*/
+ Mix_HaltMusic();
+ Mix_FreeMusic(music);
+
+ Mix_FreeChunk(horn);
+
fclose(names);
SDL_GL_DeleteContext(mainGLContext);
@@ -483,7 +491,6 @@ void mainLoop(void){
currentTime=millis();
prevPrevTime=currentTime;
}
-
/*
* Update timing values. This is crucial to calling logic and updating the window (basically
* the entire game).
@@ -496,8 +503,8 @@ void mainLoop(void){
/*
* 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;
}
@@ -511,7 +518,6 @@ void mainLoop(void){
/*
* Update debug variables if necessary
*/
-
if(++debugDiv==20){
debugDiv=0;
@@ -522,7 +528,6 @@ void mainLoop(void){
}
render(); // Call the render loop
-
}
extern bool fadeEnable;
@@ -773,7 +778,6 @@ void render(){
/*
* Here we draw a black overlay if it's been requested.
*/
-
if(fadeIntensity){
glColor4ub(0,0,0,fadeIntensity);
glRectf(offset.x-SCREEN_WIDTH /2,
@@ -784,7 +788,6 @@ void render(){
ui::importantText("The screen is black.");
}
}else if(ui::fontSize != 16) ui::setFontSize(16);
-
/**************************
**** END RENDERING ****
**************************/
@@ -805,7 +808,6 @@ void render(){
}
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.
@@ -816,14 +818,12 @@ void logic(){
/*
* 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;
@@ -833,7 +833,6 @@ void logic(){
* 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){
@@ -907,7 +906,6 @@ void logic(){
}else n->near=false;
}
}
-
for(auto &m : currentWorld->mob){
if(m->alive){
@@ -929,7 +927,6 @@ void logic(){
}
}
}
-
unsigned int i = 0;
for(auto &o : currentWorld->object){
if(o->alive){
@@ -960,7 +957,6 @@ void logic(){
/*
* Switch between day and night (SUNNY and DARK) if necessary.
*/
-
if(!(tickCount%DAY_CYCLE)||!tickCount){
if(weather==SUNNY){
weather=DARK;
@@ -978,7 +974,6 @@ void logic(){
/*
* Transition to and from black if necessary.
*/
-
if(fadeEnable){
if(fadeIntensity < 160)fadeIntensity+=5;
else if(fadeIntensity < 255)fadeIntensity+=1;
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/Texture.cpp b/src/Texture.cpp
index 8b40513..a3a8afe 100644
--- a/src/Texture.cpp
+++ b/src/Texture.cpp
@@ -13,7 +13,6 @@ namespace Texture{
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)){
@@ -74,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, image[texState]);
+ glBindTexture(GL_TEXTURE_2D,image[(int)texState]);
}
void Texturec::bindNext(){
diff --git a/src/entities.cpp b/src/entities.cpp
index 4e582c9..100eefb 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
@@ -48,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;
@@ -63,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;
@@ -74,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;
@@ -99,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;
@@ -107,6 +164,7 @@ Object::Object(ITEM_ID id, bool qo, const char *pd){
pickupDialog = new char[strlen(pd)+1];
strcpy(pickupDialog,pd);
+
type = OBJECTT;
alive = true;
near = false;
@@ -115,8 +173,15 @@ 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();
@@ -208,38 +273,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..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;
@@ -91,6 +50,13 @@ void CUTSCENEEE(void){
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;
@@ -98,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);
/*
@@ -116,6 +83,7 @@ void initEverything(void){
*/
currentWorld=playerSpawnHill;
+
playerSpawnHill->toRight=test;
test->toLeft=playerSpawnHill;
@@ -130,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);
@@ -153,9 +120,52 @@ 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);
+ 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);
+ }
+}*/
diff --git a/src/inventory.cpp b/src/inventory.cpp
index cd01c11..28612ae 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -7,10 +7,6 @@
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){
@@ -25,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);
@@ -37,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){
@@ -86,6 +81,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
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);
@@ -106,9 +102,9 @@ void Inventory::draw(void){
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;
@@ -118,15 +114,9 @@ void Inventory::draw(void){
}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){
@@ -136,14 +126,24 @@ void Inventory::draw(void){
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++;
}
}
@@ -181,6 +181,7 @@ void Inventory::draw(void){
}*/
if(inv[sel].count)itemDraw(player,inv[sel].id);
+ lop++;
}
static vec2 item_coord = {0,0};
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 c977c7f..5cc3f2a 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -71,6 +71,39 @@ 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;
+
+ deleteEntities();
+}
+
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 +229,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;
@@ -654,7 +683,7 @@ void World::singleDetect(Entity *e){
}else{
- if(e->vel.y > -2)e->vel.y-=.001 * deltaTime;
+ if(e->vel.y > -2)e->vel.y-=.003 * deltaTime;
}
@@ -836,7 +865,11 @@ IndoorWorld::IndoorWorld(void){
}
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'
@@ -897,6 +930,14 @@ Arena::Arena(World *leave,Player *p){
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;
diff --git a/xcf/door.xcf b/xcf/door.xcf
new file mode 100644
index 0000000..7965018
--- /dev/null
+++ b/xcf/door.xcf
Binary files differ