aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog7
-rw-r--r--assets/house1.pngbin788 -> 749 bytes
-rw-r--r--assets/items/SWORD_WOOD.pngbin256 -> 217 bytes
-rw-r--r--assets/player.pngbin577 -> 543 bytes
-rw-r--r--assets/player1.pngbin586 -> 552 bytes
-rw-r--r--assets/player2.pngbin586 -> 557 bytes
-rw-r--r--include/world.h78
-rw-r--r--main.cpp1
-rw-r--r--src/entities.cpp2
-rw-r--r--src/gameplay.cpp12
-rw-r--r--src/inventory.cpp26
-rw-r--r--src/ui.cpp243
-rw-r--r--src/world.cpp19
13 files changed, 233 insertions, 155 deletions
diff --git a/Changelog b/Changelog
index a272795..903e91e 100644
--- a/Changelog
+++ b/Changelog
@@ -364,3 +364,10 @@
- improved world background drawing; added that to IndoorWorld's
- improved inventory functionality
- fixed issues with cutscenes
+
+12/3/2015:
+==========
+
+ - improved inventory draw
+ - fixed most segfaults, including those when exiting
+ - added -Wall,-Wextra, and -Werror to enforce better/safer coding
diff --git a/assets/house1.png b/assets/house1.png
index 2022992..ce97a81 100644
--- a/assets/house1.png
+++ b/assets/house1.png
Binary files differ
diff --git a/assets/items/SWORD_WOOD.png b/assets/items/SWORD_WOOD.png
index a6d3af3..479eba9 100644
--- a/assets/items/SWORD_WOOD.png
+++ b/assets/items/SWORD_WOOD.png
Binary files differ
diff --git a/assets/player.png b/assets/player.png
index cfc327c..3977092 100644
--- a/assets/player.png
+++ b/assets/player.png
Binary files differ
diff --git a/assets/player1.png b/assets/player1.png
index 8204252..edf8bf8 100644
--- a/assets/player1.png
+++ b/assets/player1.png
Binary files differ
diff --git a/assets/player2.png b/assets/player2.png
index 63f4c08..cfd955f 100644
--- a/assets/player2.png
+++ b/assets/player2.png
Binary files differ
diff --git a/include/world.h b/include/world.h
index 11918c8..8aaba0c 100644
--- a/include/world.h
+++ b/include/world.h
@@ -1,3 +1,10 @@
+/** @file world.h
+ * @brief The world system.
+ *
+ * This file contains the classes and variables necessary to create an in-game
+ * world.
+ */
+
#ifndef WORLD_H
#define WORLD_H
@@ -11,55 +18,68 @@
#define DAY_CYCLE 3000
+/**
+ * The background type enum.
+ * This enum contains all different possibilities for world backgrounds; used
+ * in World::setBackground() to select the appropriate images.
+ */
+
typedef enum {
- BG_FOREST,
- BG_WOODHOUSE
+ BG_FOREST, /**< A forest theme. */
+ BG_WOODHOUSE /**< An indoor wooden house theme. */
} WORLD_BG_TYPE;
+/**
+ * The weather type enum.
+ * This enum contains every type of weather currently implemented in the game.
+ * Weather is set by the world somewhere.
+ */
+
typedef enum {
- SUNNY = 0,
- DARK,
- RAIN
+ SUNNY = 0, /**< Sunny/daytime */
+ DARK, /**< Nighttime */
+ RAIN /**< Rain (not implemented :) )*/
} WEATHER;
+/**
+ * The line structure.
+ * This structure is used to store the world's ground, stored in vertical
+ * lines. Dirt color and grass properties are also kept track of here.
+ */
+
struct line_t {
- bool gs;
- float y,gh[2];
- unsigned char color;
+ float y; /**< Height of this vertical line */
+ bool gs; /**< Show grass */
+ float gh[2]; /**< Height of glass (2 blades per line) */
+ unsigned char color; /**< Lightness of dirt (brown) */
} __attribute__ ((packed));
-/*
- * World - creates and handles an area of land
-*/
+/**
+ * The world class. This class does everything a world should do.
+ */
class World {
protected:
- /*
- * struct line_t
- *
- * The world is stored in an array of lines. Example:
- *
- * ||
- * ||| || |
- * |||||||||
- * line no. 123456789...
- *
+ /**
+ * The line array.
+ * This array is created through 'new' in World::generate(), with an amount
+ * of elements provided by the function.
*/
struct line_t *line;
- /*
- * Contains the starting x-coordinate to draw the world at. This should be equal to
- * - getWidth() (see world.cpp) / 2
- */
+ /**
+ * Starting x coordinate.
+ * This x value is the point at which line[0] should reside, can be used to
+ * calculate the width of the world.
+ */
int x_start;
- /*
- * Runs world detection for a single entity. This function is used in World->detect()
- * to detect the player and all entities in the world.
- */
+ /**
+ *
+ */
void singleDetect(Entity *e);
diff --git a/main.cpp b/main.cpp
index 11fc181..1fb5cb1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -213,6 +213,7 @@ static unsigned int fadeIntensity = 0;
*******************************************************************************/
int main(/*int argc, char *argv[]*/){
+ //*argv = (char *)argc;
gameRunning=false;
/*!
* (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
diff --git a/src/entities.cpp b/src/entities.cpp
index b1a0c09..f812919 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -205,7 +205,7 @@ void Entity::draw(void){ //draws the entities
if(type == PLAYERT){
static int texState = 0;
static bool up = true;
- if(loops % (int)((float)5 / (float)speed) == 0){
+ if(loops % (int)((float)2 / (float)speed) == 0){
if(up){
texState+=1;
if(texState==2)up=false;
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index b4c4b16..eb5ce79 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -29,15 +29,21 @@ int giveTestQuest(NPC *speaker){
return 0;
}
+//static World *a;
+
void CUTSCENEEE(Mob *callee){
player->vel.x = 0;
- ui::dialogBox(player->name,":K.","No way I\'m gettin\' up this hill.");
+ ui::dialogBox(player->name,":K then","No way I\'m gettin\' up this hill.");
ui::waitForDialog();
- player->right = true;
+ //a = new World();//Arena(currentWorld,player);
+ //a->generate(300);
+ currentWorld = currentWorld->toRight;
+
+ /*player->right = true;
player->left = false;
- player->loc.x += HLINE * 5;
+ player->loc.x += HLINE * 5;*/
callee->alive = false;
}
diff --git a/src/inventory.cpp b/src/inventory.cpp
index e6433bb..7d3bc6d 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -148,7 +148,7 @@ void Inventory::draw(void){
curCoord[a].y += float((dfp[a]) * sin(angle*PI/180));
r.end = curCoord[a];
- glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)range)*0.4f);
+ glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)range)*0.4f);
glBegin(GL_QUADS);
glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2));
glVertex2i(r.end.x-(itemWide/2)+itemWide, r.end.y-(itemWide/2));
@@ -161,16 +161,30 @@ void Inventory::draw(void){
glBindTexture(GL_TEXTURE_2D, itemtex[inv[a].id]);
glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)range)*0.8f);
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2));
- glTexCoord2i(1,1);glVertex2i(r.end.x-(itemWide/2)+itemWide, r.end.y-(itemWide/2));
- glTexCoord2i(1,0);glVertex2i(r.end.x-(itemWide/2)+itemWide, r.end.y-(itemWide/2)+itemWide);
- glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)+itemWide);
- glEnd();
+ if(item[inv[a].id].height > item[inv[a].id].width){
+ glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y-(itemWide/2));
+ glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y-(itemWide/2));
+ glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y+(itemWide/2));
+ glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y+(itemWide/2));
+ }else{
+ glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
+ glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2), r.end.y-(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
+ glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2), r.end.y+(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
+ glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2), r.end.y+(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
+ } glEnd();
glDisable(GL_TEXTURE_2D);
ui::putText(r.end.x-(itemWide/2),r.end.y-(itemWide*.9),"%s",item[inv[a].id].name);
ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",inv[a].count);
}
a++;
+ if(sel==a){
+ glBegin(GL_LINES);
+ glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
+ glVertex2i(r.start.x,r.start.y);
+ glColor4f(1.0f, 0.0f, 0.0f, 0.8f);
+ glVertex2i(r.end.x+20, r.end.y-20);
+ glEnd();
+ }
}
}else if(invHover){
static unsigned int highlight = 0;
diff --git a/src/ui.cpp b/src/ui.cpp
index 6f5bdbe..c0b5004 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -480,16 +480,18 @@ namespace ui {
putString(x+HLINE,y-fontSize-HLINE,rtext);
for(i=0;i<dialogOptCount;i++){
- if(mouse.x > dialogOptLoc[i][0] &&
- mouse.x < dialogOptLoc[i][2] &&
- mouse.y > dialogOptLoc[i][1] &&
- mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
- setFontColor(255,255,0);
- }else setFontColor(255,255,255);
+ setFontColor(255,255,255);
dialogOptLoc[i][1]=y-SCREEN_HEIGHT/4+(fontSize+HLINE)*(i+1);
dialogOptLoc[i][2]=
putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
dialogOptLoc[i][0]=offset.x-dialogOptLoc[i][2]/2;
+ if(mouse.x > dialogOptLoc[i][0] &&
+ mouse.x < dialogOptLoc[i][0] + dialogOptLoc[i][2] &&
+ mouse.y > dialogOptLoc[i][1] &&
+ mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
+ setFontColor(255,255,0);
+ putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
+ }
}
setFontColor(255,255,255);
}
@@ -511,23 +513,28 @@ namespace ui {
}
/*
- * Lists all of the quests the player has
+ * Lists all of the quests the player is currently taking.
*/
- hub.y-=fontSize*1.15;
-
- putString(hub.x,hub.y,"Current Quests:");
-
- for(auto &c : player->qh.current){
- hub.y-=fontSize*1.15;
- putString(hub.x,hub.y,c->title);
+ if(player->inv->invOpen){
+ hub.y = player->loc.y + fontSize * 8;
+ hub.x = player->loc.x;
+
+ putStringCentered(hub.x,hub.y,"Current Quests:");
+
+ for(auto &c : player->qh.current){
+ hub.y -= fontSize * 1.15;
+ putString(hub.x,hub.y,c->title);
+ }
}
+
+
}
void handleEvents(void){
- static bool left=false,right=false;
static vec2 premouse={0,0};
static int heyOhLetsGo = 0;
unsigned char i;
+ World *tmp;
SDL_Event e;
mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
@@ -568,108 +575,130 @@ DONE:
KEYDOWN
*/
case SDL_KEYDOWN:
- if(SDL_KEY==SDLK_ESCAPE)gameRunning=false; // Exit the game with ESC
- if(!dialogBoxExists&&!fadeEnable){
- if(SDL_KEY==SDLK_a){ // Move left
- left=true;
- player->vel.x=-.15;
- player->left = true;
- player->right = false;
- currentWorld=currentWorld->goWorldLeft(player);
- }
- if(SDL_KEY==SDLK_d){ // Move right
- right=true;
- player->vel.x=.15;
- player->right = true;
- player->left = false;
- currentWorld=currentWorld->goWorldRight(player);
- }
- if(SDL_KEY==SDLK_s && player->ground==2){
- player->ground=false;
- player->loc.y-=HLINE*1.5;
- }
- if(SDL_KEY==SDLK_w){
- if(inBattle){
- currentWorld=((Arena *)currentWorld)->exitArena(player);
- }else currentWorld=currentWorld->goInsideStructure(player);
- }
- if(SDL_KEY==SDLK_SPACE){ // Jump
- if(player->ground){
- player->vel.y=.4;
- player->loc.y+=HLINE*2;
- player->ground=false;
- }
- }
- World *tmp;
- if(SDL_KEY==SDLK_i){
- tmp=currentWorld;
- currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible
- if(tmp!=currentWorld){
- currentWorld->detect(player);
- player->vel.y=.2;
- player->loc.y+=HLINE*5;
- player->ground=false;
- }
- }
- if(SDL_KEY==SDLK_k){
- tmp=currentWorld;
- currentWorld=currentWorld->goWorldFront(player); // Go forward a layer if possible
- if(tmp!=currentWorld){
- player->loc.y=0;
- currentWorld->behind->detect(player);
- player->vel.y=.2;
- player->ground=false;
- }
- }
-
- if(SDL_KEY==SDLK_LSHIFT)player->speed = debug?4:3; // Sprint
- if(SDL_KEY==SDLK_LCTRL)player->speed = .5;
- }
- if(SDL_KEY==SDLK_p)toggleBlack();
- if(SDL_KEY==SDLK_F3)debug^=true;
- if(((SDL_KEY==SDLK_b) & (SDL_KEY==SDLK_F3)))posFlag^=true;
- if(SDL_KEY==SDLK_e){
- edown=true;
- if(heyOhLetsGo == 0){
- heyOhLetsGo = loops;
- player->inv->mouseSel = false;
- }
- if(loops - heyOhLetsGo >= 2 && !(player->inv->invOpen) && !(player->inv->selected)){
- player->inv->invHover=true;
- //heyOhLetsGo = 0;
+ if(!dialogBoxExists&&!fadeEnable){
+ switch(SDL_KEY){
+ case SDLK_ESCAPE:
+ gameRunning=false;
+ break;
+ case SDLK_a:
+ player->vel.x=-.15;
+ player->left = true;
+ player->right = false;
+ currentWorld=currentWorld->goWorldLeft(player);
+ break;
+ case SDLK_d:
+ player->vel.x=.15;
+ player->right = true;
+ player->left = false;
+ currentWorld=currentWorld->goWorldRight(player);
+ break;
+ case SDLK_s:
+ if(player->ground == 2){
+ player->ground=false;
+ player->loc.y-=HLINE*1.5;
+ }
+ break;
+ case SDLK_w:
+ if(inBattle)
+ currentWorld=((Arena *)currentWorld)->exitArena(player);
+ else currentWorld=currentWorld->goInsideStructure(player);
+ break;
+ case SDLK_SPACE:
+ if(player->ground){
+ player->vel.y=.4;
+ player->loc.y+=HLINE*2;
+ player->ground=false;
+ }
+ break;
+ case SDLK_i:
+ tmp=currentWorld;
+ currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible
+ if(tmp!=currentWorld){
+ currentWorld->detect(player);
+ player->vel.y=.2;
+ player->loc.y+=HLINE*5;
+ player->ground=false;
+ }
+ break;
+ case SDLK_k:
+ tmp=currentWorld;
+ currentWorld=currentWorld->goWorldFront(player); // Go forward a layer if possible
+ if(tmp!=currentWorld){
+ player->loc.y=0;
+ currentWorld->behind->detect(player);
+ player->vel.y=.2;
+ player->ground=false;
+ }
+ break;
+ case SDLK_LSHIFT:
+ player->speed = debug ? 4 : 3;
+ break;
+ case SDLK_LCTRL:
+ player->speed = .5;
+ break;
+ case SDLK_p:
+ toggleBlack();
+ break;
+ case SDLK_F3:
+ debug ^= true;
+ break;
+ case SDLK_b:
+ if(debug)posFlag ^= true;
+ break;
+ case SDLK_e:
+ edown=true;
+ if(!heyOhLetsGo){
+ heyOhLetsGo = loops;
+ player->inv->mouseSel = false;
+ }
+ if(loops - heyOhLetsGo >= 2 && !(player->inv->invOpen) && !(player->inv->selected))
+ player->inv->invHover=true;
+ break;
+ default:
+ break;
}
}
break;
/*
- KEYUP
- */
+ * KEYUP
+ */
+
case SDL_KEYUP:
- if(SDL_KEY==SDLK_a){left=false;}// Stop the player if movement keys are released
- if(SDL_KEY==SDLK_d){right=false;}
- if(!left&&!right)player->vel.x=0;
- if(SDL_KEY==SDLK_LSHIFT)player->speed = 1;
- if(SDL_KEY==SDLK_LCTRL)player->speed = 1;
- if(SDL_KEY==SDLK_h)player->health-=5;
- if(SDL_KEY==SDLK_f)player->light ^= true;
- if(SDL_KEY==SDLK_e){
+ switch(SDL_KEY){
+ case SDLK_a:
+ player->left = false;
+ break;
+ case SDLK_d:
+ player->right = false;
+ break;
+ case SDLK_LSHIFT:
+ case SDLK_LCTRL:
+ player->speed = 1;
+ break;
+ case SDLK_e:
edown=false;
if(player->inv->invHover){
player->inv->invHover = false;
- heyOhLetsGo = 0;
}else{
- if(player->inv->selected == false){
- player->inv->invOpening ^= true;
- player->inv->mouseSel = false;
- heyOhLetsGo = 0;
- }else{
- player->inv->selected = false;
- player->inv->mouseSel = false;
- heyOhLetsGo = 0;
- }
+ if(!player->inv->selected)player->inv->invOpening ^= true;
+ else player->inv->selected = false;
+ player->inv->mouseSel = false;
}
+ heyOhLetsGo = 0;
+ break;
+ case SDLK_LEFT:
+ if(player->inv->sel)player->inv->sel--;
+ break;
+ case SDLK_RIGHT:
+ player->inv->sel++;
+ break;
+ default:
+ break;
}
- if(SDL_KEY==SDLK_RIGHT){player->inv->sel+=1;}
- if(SDL_KEY==SDLK_LEFT){if(player->inv->sel!=0)player->inv->sel-=1;}
+
+ if(!player->left&&!player->right)
+ player->vel.x=0;
+
break;
default:
break;
@@ -677,7 +706,7 @@ DONE:
}
if(!dialogBoxExists&&AIpreaddr.size()){ // Flush preloaded AI functions if necessary
- for(i=0;i<AIpreaddr.size();i++){
+ while(!AIpreaddr.empty()){
AIpreaddr.front()->addAIFunc(AIpreload.front(),false);
AIpreaddr.erase(AIpreaddr.begin());
AIpreload.erase(AIpreload.begin());
diff --git a/src/world.cpp b/src/world.cpp
index 5f8d44c..1b90a4b 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -321,8 +321,8 @@ void World::draw(Player *p){
static float yoff=DRAW_Y_OFFSET; // Initialize stuff
static int shade,bgshade;
static World *current;
- unsigned int i,ie;
- int is,v_offset,cx_start,width;
+ unsigned int i;
+ int is,ie,v_offset,cx_start,width;
struct line_t *cline;
bgshade = worldShade << 1; // *2
@@ -467,7 +467,8 @@ LOOP2:
// ie -> i end
ie=v_offset + (SCREEN_WIDTH / 2 / HLINE) + GEN_INC + HLINE;
- if(ie>current->lineCount)ie=current->lineCount; // Maximum bound
+ if(ie>(int)current->lineCount)ie=current->lineCount; // Maximum bound
+ else if(ie < GEN_INC)ie = GEN_INC;
/*
* Make more direct variables for quicker referencing.
@@ -499,7 +500,7 @@ LOOP2:
bool hey=false;
glBegin(GL_QUADS);
- for(i=is;i<ie-GEN_INC;i++){
+ for(i=is;i<(unsigned)ie-GEN_INC;i++){
cline[i].y+=(yoff-DRAW_Y_OFFSET); // Add the y offset
if(!cline[i].y){
cline[i].y+=50;
@@ -526,7 +527,7 @@ LOOP2:
float cgh[2];
glBegin(GL_QUADS);
- for(i=is;i<ie-GEN_INC;i++){
+ for(i=is;i<(unsigned)ie-GEN_INC;i++){
/*
* Load the current line's grass values
@@ -1043,15 +1044,15 @@ extern bool inBattle;
Arena::Arena(World *leave,Player *p){
generate(300);
- door.y = line[299].y;
- door.x = 100;
+ //door.y = line[299].y;
+ //door.x = 100;
exit = leave;
- npc.push_back(new NPC());
+ /*npc.push_back(new NPC());
entity.push_back(npc.back());
entity.back()->spawn(door.x,door.y);
entity.back()->width = HLINE * 12;
- entity.back()->height = HLINE * 16;
+ entity.back()->height = HLINE * 16;*/
inBattle = true;
pxy = p->loc;