aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2015-12-08 15:56:24 -0500
committerdrumsetmonkey <abelleisle@roadrunner.com>2015-12-08 15:56:24 -0500
commit07432bdce4ec75eb0f41e81eed1a2cdf1b606eb2 (patch)
treea37e1d8e3e6ab24efa8d258642f2cd9e26692237
parent443b77e47a7ef3a137e39c64abb277229a665d03 (diff)
parent887a2da911805fe93b2bd33b39226f433641dee7 (diff)
Merge branch 'master' of http://github.com/tcsullivan/gamedev
-rw-r--r--.gitignore4
-rw-r--r--Changelog17
-rw-r--r--include/Quest.h85
-rw-r--r--include/Texture.h69
-rw-r--r--include/common.h139
-rw-r--r--include/world.h74
-rw-r--r--src/Texture.cpp4
-rw-r--r--src/ui.cpp24
-rw-r--r--src/world.cpp5
9 files changed, 327 insertions, 94 deletions
diff --git a/.gitignore b/.gitignore
index 4304556..c00a3b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,3 @@
main.exe
main
-
-.kdev4
-gamedev.kdev4
+doc/**
diff --git a/Changelog b/Changelog
index 903e91e..fbe14bc 100644
--- a/Changelog
+++ b/Changelog
@@ -371,3 +371,20 @@
- improved inventory draw
- fixed most segfaults, including those when exiting
- added -Wall,-Wextra, and -Werror to enforce better/safer coding
+
+12/4/2015,
+12/7/2015:
+==========
+
+ - re-did fullscreen text (importantText)
+ - began doxygening headers
+ - fixed entity name reading
+ - fixed entity sprites
+
+12/8/2015:
+==========
+
+ - continued to document header files through doxygen
+ - added border to dialogBox
+ - fix entity movement handling; npcs stop when you talk to them
+ - added sword animation?
diff --git a/include/Quest.h b/include/Quest.h
index 75de64c..8f5446c 100644
--- a/include/Quest.h
+++ b/include/Quest.h
@@ -1,3 +1,10 @@
+/** @file Quest.h
+ * @brief The quest handling system.
+ *
+ * This file contains Quest and QuestHandler, used to manage quests inside the
+ * game.
+ */
+
#ifndef QUEST_H
#define QUEST_H
@@ -6,24 +13,100 @@
#include <common.h>
#include <inventory.h>
+/**
+ * When defined, DEBUG allows extra messages to be printed to the terminal for
+ * debugging purposes.
+ */
+
#define DEBUG
+/**
+ * Contains the total number of quests in the game at compile time, see Quest.cpp
+ * for the actual definition of these quests.
+ */
+
#define TOTAL_QUESTS 1
+/**
+ * The Quest class.
+ *
+ * This contains information for a single quest, and should only really be interacted
+ * with through QuestHandler.
+ */
+
class Quest {
public:
- char *title,*desc;
+
+ /**
+ * Contains the title of the quest.
+ */
+
+ char *title;
+
+ /**
+ * Contains the description of the quest.
+ */
+
+ char *desc;
+
+ /**
+ * Contains the single item that's given as a reward upon quest completion.
+ */
+
struct item_t reward;
+
+ /**
+ * Populates the values contained in this class.
+ */
+
Quest(const char *t,const char *d,struct item_t r);
+
+ /**
+ * Frees memory allocated for the title and description text.
+ */
+
~Quest();
};
+/**
+ * The Quest Handler class.
+ *
+ * This class handles quests, including the assigning, dropping, and completing
+ * of the quests.
+ */
+
class QuestHandler {
public:
+
+ /**
+ * A vector containing all quests currently being taken by the handler.
+ */
+
std::vector<const Quest *>current;
+
+ /**
+ * Adds a quest to the current quest vector by its title.
+ */
+
int assign(const char *t);
+
+ /**
+ * Drops a quest through its title.
+ */
+
int drop(const char *t);
+
+ /**
+ * Finishes a quest through it's title, also giving a pointer to the Entity
+ * that gave the quest originally.
+ */
+
int finish(const char *t,void *completer);
+
+ /**
+ * Returns true if this handler is currently taking the quest.
+ */
+
bool hasQuest(const char *t);
};
diff --git a/include/Texture.h b/include/Texture.h
index 5f5758b..bcd95af 100644
--- a/include/Texture.h
+++ b/include/Texture.h
@@ -1,28 +1,95 @@
+/** @file Texture.h
+ * @brief Defines a method for loading textures.
+ *
+ * This file gives facilities for easily loading and binding textures.
+ */
+
#ifndef TEXTURE_H
#define TEXTURE_H
#include <common.h>
+/**
+ * When defined, DEBUG allows extra messages to be printed to the terminal for
+ * debugging purposes.
+ */
+
#define DEBUG
+/**
+ * Texture functions are given a namespace for better organization.
+ */
+
namespace Texture{
+
+ /**
+ * Loads a texture from the given file name, returning the GLuint used for
+ * later referencing of the texture.
+ */
+
GLuint loadTexture(const char *fileName);
}
+/**
+ * The Texturec class.
+ *
+ * This class can handle an array of textures and allows easy binding of those
+ * textures.
+ */
+
class Texturec{
private:
+
+ /**
+ * Contains the index in the image array of the currently loaded texture.
+ */
+
unsigned int texState;
+
public:
+
+ /**
+ * Contains an array of the GLuints returned from Texture::loadTexture().
+ */
+
GLuint *image;
+ /**
+ * Populates the image array from a list of strings, with each string as a
+ * separate argument.
+ */
+
Texturec(uint amt, ...);
+
+ /**
+ * Populates the image array from an array of strings.
+ */
+
Texturec(uint amt,const char **paths);
+
+ /**
+ * Frees memory taken by the image array.
+ */
+
~Texturec();
+ /**
+ * Binds the next texture in the array, incrementing texState.
+ */
+
void bindNext();
+
+ /**
+ * Binds the previous texture in the array, decrementing texState.
+ */
+
void bindPrev();
+
+ /**
+ * Binds the texture with the provided index.
+ */
+
void bind(unsigned int);
- void walk();
};
#endif //TEXTURE_H
diff --git a/include/common.h b/include/common.h
index 52daf4b..f8bd935 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1,19 +1,19 @@
+/** @file common.h
+ * @brief Common items needed by most other files.
+ *
+ * This file contains headers, variables and functions that are needed in
+ * most other files included in this project.
+ */
+
#ifndef COMMON_H
#define COMMON_H
-/*
- * Include basic C/C++ facilities
-*/
-
#include <iostream>
#include <cstdlib>
#include <vector>
#include <math.h>
-#include <thread>
-
-/*
- * Include GLEW and the SDL 2 headers
-*/
+#include <string>
+#include <fstream>
#define GLEW_STATIC
#include <GL/glew.h>
@@ -22,9 +22,6 @@
#include <SDL2/SDL_opengl.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
-#include <string>
-#include <fstream>
-
#ifdef __WIN32__
typedef unsigned int uint;
@@ -33,100 +30,128 @@ typedef unsigned int uint;
#include <Texture.h>
-/*
- * This flag lets the compiler know that we are using shaders
-*/
+/**
+ * This flag lets the compiler know that we want to use shaders.
+ */
#define SHADERSs
-/*
- * Create a basic 2-point structure for coordinate saving
-*/
+/**
+ * This structure contains a set of coordinates for ease of coding.
+ */
typedef struct {
float x;
float y;
} vec2;
+/**
+ * This structure contains two sets of coordinates for ray drawing.
+ */
+
typedef struct {
vec2 start;
vec2 end;
} Ray;
-/*
- * Define the game's name (displayed in the window title),
- * the desired window dimensions,
- * and whether or not we want the window to be fullscreen.
-*/
+/**
+ * Define the game's name (displayed in the window title).
+ */
#define GAME_NAME "Independent Study v.0.4 alpha"
+/**
+ * The desired width of the game window.
+ */
+
#define SCREEN_WIDTH 1280
+
+/**
+ * The desired height of the game window.
+ */
+
#define SCREEN_HEIGHT 720
//#define FULLSCREEN
-/*
- * Define the length of a single HLINE.
+/**
+ * Define the length of a single HLINE.
+ * The game has a great amount of elements that need to be drawn or detected, and having each
+ * of them use specific hard-coded numbers would be painful to debug. As a solution, this
+ * definition was made. Every item being drawn to the screen and most object detection/physic
+ * handling is done based off of this number. Increasing it will give the game a zoomed-in
+ * feel, while decreasing it will do the opposite.
*
- * The game has a great amount of elements that need to be drawn or detected, and having each
- * of them use specific hard-coded numbers would be painful to debug. As a solution, this
- * definition was made. Every item being drawn to the screen and most object detection/physic
- * handling is done based off of this number. Increasing it will give the game a zoomed-in
- * feel, while decreasing it will do the opposite.
- *
-*/
+ */
-#define HLINE 3 // 3 as in 3 pixels
+#define HLINE 3
-/*
- * Define 'our' random number generation library. Eventually these macros will be replaced
- * with actual functions.
- *
-*/
+/**
+ * A 'wrapper' for libc's srand(), as we hope to eventually have our own random number
+ * generator.
+ */
#define initRand(s) srand(s)
-#define getRand() rand()
-/*
- * At the bottom of this header is the prototype for DEBUG_prints, which writes a formatted
- * string to the console containing the callee's file and line number. This macro simplifies
- * it to a simple printf call.
- *
- * DEBUG must be defined for this macro to function.
+/**
+ * A 'wrapper' for libc's rand(), as we hope to eventually have our own random number
+ * generator.
+ */
+
+#define getRand() rand()
+
+/**
+ * Included in common.h is a prototype for DEBUG_prints, which writes a formatted
+ * string to the console containing the callee's file and line number. This macro simplifies
+ * it to a simple printf call.
*
-*/
+ * DEBUG must be defined for this macro to function.
+ */
#define DEBUG_printf( message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__ )
+/**
+ * Defines pi for calculations that need it.
+ */
#define PI 3.1415926535
-/*
- * References the variable in main.cpp, used for smoother drawing.
-*/
+/**
+ * References the variable in main.cpp, used for smoother drawing.
+ */
extern unsigned int deltaTime;
-/*
- * References the variable in main.cpp, used for drawing with the player
-*/
+/**
+ * References the variable in main.cpp, used for drawing with the player.
+ */
+
extern vec2 offset;
-extern float handAngle;
-
+/**
+ * Counts the number of times logic() (see main.cpp) has been called, for animating
+ * sprites.
+ */
extern unsigned int loops;
-/*
+/**
* Prints a formatted debug message to the console, along with the callee's file and line
* number.
- *
-*/
+ */
void DEBUG_prints(const char* file, int line, const char *s,...);
+/**
+ * Sets color using glColor3ub(), but handles potential overflow.
+ */
+
void safeSetColor(int r,int g,int b);
+
+/**
+ * Sets color using glColor4ub(), but handles potential overflow.
+ */
+
void safeSetColorA(int r,int g,int b,int a);
#endif // COMMON_H
diff --git a/include/world.h b/include/world.h
index 8aaba0c..ccf93a8 100644
--- a/include/world.h
+++ b/include/world.h
@@ -8,13 +8,18 @@
#ifndef WORLD_H
#define WORLD_H
-#include <common.h> // For HLINE, vec2, OpenGL utilities, etc.
+#include <common.h>
#include <entities.h>
-#define GEN_INC 10 // Defines at what interval y values should be calculated for the array 'line'.
- // As explained in World(), the last few lines in the array 'line' are incorrectly calculated
- // or not calculated at all, so GEN_INC is also used to decrease 'lineCount' in functions like draw()
- // and detect().
+/**
+ * Defines at what interval y values should be calculated for the array 'line'.
+ */
+
+#define GEN_INC 10
+
+/**
+ * Defines how many game ticks it takes for a day to elapse.
+ */
#define DAY_CYCLE 3000
@@ -78,40 +83,65 @@ protected:
int x_start;
/**
- *
+ * Handle physics for a single entity.
+ * This function handles gravity and death for an entity. The public version
+ * of this, World::detect(), handles all entities in the world as well as
+ * the player. World::singleDetect() should never be used outside of
+ * World::detect(), which is why it is declared private.
*/
void singleDetect(Entity *e);
- /*
- * Deletes all entities in the world.
- */
+ /**
+ * Empties all entity vectors.
+ * Each entity vector is iterated through, calling delete for each entry.
+ * Once all specific vectors are cleared, the general entity vector is
+ * emptied of the pointers to those other vectors. This function should only
+ * be called in World's destructor, as there shouldn't be another reason to
+ * call this function.
+ */
void deleteEntities(void);
- /*
- * The size of the line array. This is set once by World->generate().
- */
+ /**
+ * Number of lines in the world.
+ * While this number is helpful for knowing the world's width, it is kept
+ * private for security reasons. To compensate for this,
+ * World::getTheWidth() is provided (see below).
+ */
unsigned int lineCount;
- /*
- * Contains the background image layers (including the background image).
- */
+ /**
+ * An array of star coordinates.
+ */
vec2 *star;
+ /**
+ * The Texturec object that holds the background sprites for this world.
+ */
+
Texturec *bgTex;
+ /**
+ * The Mix_Music object that holds the background soundtrack for the world.
+ */
+
Mix_Music *bgmObj;
+
+ /**
+ * The file path of the song wished to be loaded by bgmObj.
+ */
+
char *bgm;
public:
- /*
- * These pointers keep track of worlds that are adjacent to this one. Used in ui.cpp
- * for world jumping.
- */
+ /**
+ * These pointers keep track of worlds that are adjacent to this one. Used in
+ * ui.cpp for world jumping.
+ */
World *toLeft,
*toRight,
@@ -119,8 +149,10 @@ public:
*infront;
/*
- * Entity arrays.
- */
+ * These vectors contain the NPCs, Mobs, Structures and Objects that are
+ * loaded inside the world, with the Entity vector containing pointers to
+ * the contents of all the others.
+ */
std::vector<NPC *> npc;
std::vector<Structures *> build;
diff --git a/src/Texture.cpp b/src/Texture.cpp
index 5e5651d..5e367a9 100644
--- a/src/Texture.cpp
+++ b/src/Texture.cpp
@@ -100,7 +100,3 @@ void Texturec::bindNext(){
void Texturec::bindPrev(){
bind(--texState);
}
-
-void Texturec::walk(){
- // hey
-}
diff --git a/src/ui.cpp b/src/ui.cpp
index e6dadc2..6fa2770 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -480,11 +480,20 @@ namespace ui {
}
}else{
- glColor3ub(0,0,0);
-
x=offset.x-SCREEN_WIDTH/2+HLINE*8;
y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
+
+ glColor3ub(255,255,255);
+ glBegin(GL_LINE_STRIP);
+ glVertex2f(x-1 ,y+1);
+ glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y+1);
+ glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4);
+ glVertex2f(x-1 ,y-1-SCREEN_HEIGHT/4);
+ glVertex2f(x-1 ,y+2);
+ glEnd();
+
+ glColor3ub(0,0,0);
glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4);
rtext=typeOut(dialogBoxText);
@@ -543,6 +552,7 @@ namespace ui {
}
}
void handleEvents(void){
+ static bool left=true,right=false;
static vec2 premouse={0,0};
static int heyOhLetsGo = 0;
unsigned char i;
@@ -603,12 +613,16 @@ DONE:
player->vel.x=-.15;
player->left = true;
player->right = false;
+ left = true;
+ right = false;
currentWorld=currentWorld->goWorldLeft(player);
break;
case SDLK_d:
player->vel.x=.15;
player->right = true;
player->left = false;
+ left = false;
+ right = true;
currentWorld=currentWorld->goWorldRight(player);
break;
case SDLK_s:
@@ -682,10 +696,10 @@ DONE:
case SDL_KEYUP:
switch(SDL_KEY){
case SDLK_a:
- player->left = false;
+ left = false;
break;
case SDLK_d:
- player->right = false;
+ right = false;
break;
case SDLK_LSHIFT:
player->speed = 1;
@@ -714,7 +728,7 @@ DONE:
break;
}
- if(!player->left&&!player->right)
+ if(!left&&!right)
player->vel.x=0;
break;
diff --git a/src/world.cpp b/src/world.cpp
index 1e37a78..2bceba5 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -277,11 +277,12 @@ void World::update(Player *p,unsigned int delta){
*/
for(auto &e : entity){
- if(e->type != STRUCTURET)
+ e->loc.y += e->vel.y * delta;
+ if(e->type != STRUCTURET && e->canMove){
e->loc.x += e->vel.x * delta;
- e->loc.y += e->vel.y * delta;
if(e->vel.x < 0)e->left = true;
else if(e->vel.x > 0)e->left = false;
+ }
}
}