diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Quest.h | 85 | ||||
-rw-r--r-- | include/Texture.h | 69 | ||||
-rw-r--r-- | include/common.h | 139 | ||||
-rw-r--r-- | include/world.h | 42 |
4 files changed, 265 insertions, 70 deletions
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 083474a..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 @@ -113,17 +118,30 @@ protected: 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, @@ -131,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; |