aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-10-29 09:17:32 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-10-29 09:17:32 -0400
commitdf20af833773ee67d78b3f2e8ab3a0a1753e523a (patch)
treedb47d85bc89f1a2ba5d2ac79ece25cd8684201d8
parentcb2ebd8ec104afb617485c8caa07c1b572d27aea (diff)
world improvements, quest preloads
-rw-r--r--Changelog11
-rw-r--r--Goals.txt6
-rw-r--r--include/common.h2
-rw-r--r--include/world.h134
-rw-r--r--main.cpp2
-rw-r--r--src/ui.cpp45
-rw-r--r--src/world.cpp40
7 files changed, 176 insertions, 64 deletions
diff --git a/Changelog b/Changelog
index 4af9d0c..a5b5df9 100644
--- a/Changelog
+++ b/Changelog
@@ -191,4 +191,13 @@
- found bug with npc quest preloading
- documented more of world.cpp
- improved background textures/parallax stuff
- -
+
+10/29/2015:
+===========
+
+ - re-added NPC quests
+ - fixed issue with player standing on grass
+ - made game exit when player falls in hole
+ - documented world.h
+ - fixed camera ortho
+ - began working on layer-switching animation
diff --git a/Goals.txt b/Goals.txt
index 9b25918..46a35b7 100644
--- a/Goals.txt
+++ b/Goals.txt
@@ -3,9 +3,9 @@ Goals:
End of October:
===============
- - have textures for the world and entities (png's and stuff)
- - have basic quest handling/player can interact with NPCs to take quests
- - have basic mobs/animals
+ - have textures for the world and entities (png's and stuff) check!
+ - have basic quest handling/player can interact with NPCs to take quests check!
+ - have basic mobs/animals check?
End of November:
================
diff --git a/include/common.h b/include/common.h
index f278020..c3b1aed 100644
--- a/include/common.h
+++ b/include/common.h
@@ -47,7 +47,7 @@ typedef struct {
* and whether or not we want the window to be fullscreen.
*/
-#define GAME_NAME "Independent Study v.0.2 alpha"
+#define GAME_NAME "Independent Study v.0.3 alpha"
#define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 720
diff --git a/include/world.h b/include/world.h
index ab161c0..5ec01ae 100644
--- a/include/world.h
+++ b/include/world.h
@@ -13,6 +13,7 @@ typedef struct {
*/
class World {
protected:
+
/*
* struct line_t
*
@@ -24,61 +25,126 @@ protected:
* line no. 123456789...
*
*/
+
struct line_t {
bool gs;
float y,gh[2];
unsigned char color;
} __attribute__ ((packed)) *line;
- std::vector<Platform> platform; // An array (vector thing) of platforms
- int x_start; // Worlds are centered on the x axis (0,n), this contains
- // where to start drawing the world to have it centered properly.
- World *behind; // Pointers to other areas of land that are behind or in front of this one, respectively.
- void singleDetect(Entity *e); // Handles an individual entity (gravity n' stuff)
+
+ /*
+ * Keeps a dynamically allocated array of platforms in the world.
+ */
+
+ std::vector<Platform> platform;
+
+ /*
+ * Contains the starting x-coordinate to draw the world at. This should be equal to
+ * - getWidth() (see world.cpp) / 2
+ */
+
+ 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);
+
+ /*
+ * The size of the line array. This is set once by World->generate().
+ */
+
+ unsigned int lineCount;
+
public:
- unsigned int lineCount; // Size of the array 'line' (aka the width of the world)
- World *toLeft,*toRight; // Pointers to areas to the left and right of this world. These are made public
- // so that they can easily be set without a function.
- World *infront;
-
+
+ /*
+ * These pointers keep track of worlds that are adjacent to this one. Used in ui.cpp
+ * for world jumping.
+ */
+
+ World *toLeft,
+ *toRight,
+ *behind,
+ *infront;
+
+ /*
+ * Constructor and deconstructor, these do what you would expect.
+ */
+
World(void);
~World(void); // Frees the 'line' array.
- virtual void generate(unsigned int width); // Generate the world
+ /*
+ * Generate a world of width `width`. This function is virtual so that other world
+ * classes that are based on this one can generate themselves their own way.
+ */
- void addLayer(unsigned int width); // Generates a new world and makes 'behind' point to it. If 'behind'
- // already points to a world, the new world will be set to be behind 'behind'.
-
- virtual void draw(Player *p); // Draws the world around the coordinates 'vec'
+ virtual void generate(unsigned int width);
+ /*
+ * Looks for the furthest back layer in this world and adds a new layer of width `width` behind it.
+ */
- void detect(Player *p); // Insures objects/entities stored in an Entity class stay outside of the
- // ground (defined by array 'line'), and handles gravity for the object/entity
- // by modifying it's velocity
+ void addLayer(unsigned int width);
- World *goWorldLeft(Player *p); // Returns the world to the left of this one if it exists and the player at
- // location 'loc' with width 'width' is at the left edge of this world.
- World *goWorldRight(Player *p); // Functions the same as goWorldLeft(), but checks/returns the world to the right
- // of the player.
+ /*
+ * Draw the world and entities based on the player's coordinates. Virtual for the same
+ * reason generate() is.
+ */
- World *goWorldBack(Player *p); // Returns the address of the world behind this one if it exists and the player
- // at location 'loc' with width 'width' is within the area of it (i.e., when this
- // world is drawn the world has to appear directly behind the player)
- World *goWorldFront(Player *p); // Functions the same as goWorldBack(), but checks/returns the world in front of
- // this one.
- World *goInsideStructure(Player *p); // Returns the world contained in a structure if the player is requesting to enter
- // it and is standing in front of it.
- void addPlatform(float x,float y,float w,float h); // Dynamically adds a platform to the platform array. These will be automatically
- // drawn and handled by the world.
- void addHole(unsigned int start,unsigned int end); // Create a hole in the world
-
- int getStart(void);
+ virtual void draw(Player *p);
+
+
+ /*
+ * Detect the player and any entities in the current world.
+ */
+
+ void detect(Player *p);
+
+ /*
+ * These functions return the pointer to the world in the direction that is requested if it
+ * exists and the player is in a condition that it can make the switch, otherwise they
+ * return the current world.
+ */
+
+ World *goWorldLeft(Player *p);
+ World *goWorldRight(Player *p);
+ World *goWorldBack(Player *p);
+ World *goWorldFront(Player *p);
+
+ /*
+ * Called to enter/exit a structure.
+ */
+
+ World *goInsideStructure(Player *p);
+
+ /*
+ * These functions add features to the world.
+ */
+
+ void addPlatform(float x,float y,float w,float h);
+ void addHole(unsigned int start,unsigned int end);
+
+ /*
+ * Get's the world's width.
+ */
+
+ int getTheWidth(void);
};
+/*
+ * Gets a good base y value for background rendering.
+*/
+
float worldGetYBase(World *w);
/*
* IndoorWorld - Indoor settings stored in a World class ;)
*/
+
class IndoorWorld : public World {
public:
IndoorWorld(void);
diff --git a/main.cpp b/main.cpp
index faa2be4..3af8baf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -181,6 +181,7 @@ unsigned int millis(void){
/*******************************************************************************
* MAIN ************************************************************************
*******************************************************************************/
+
int main(int argc, char *argv[]){
gameRunning=false;
@@ -740,6 +741,7 @@ void logic(){
*/
currentWorld->detect(player);
+ if(player->loc.y<.02)gameRunning=false;
/*
* Entity logic: This loop finds every entity that is alive and in the current world. It then
diff --git a/src/ui.cpp b/src/ui.cpp
index e5a2f44..5d6c2ab 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -122,15 +122,18 @@ namespace ui {
}
float putString(const float x,const float y,const char *s){
unsigned int i=0,j;
- float xo=x,yo=y;
+ float xo=x,yo=y,pw=0;
do{
if(s[i]=='\n'){
yo-=fontSize*1.05;
xo=x;
}else if(s[i]==' '){
xo+=fontSize/2;
+ }else if(s[i]=='\b'){
+ xo-=pw;
}else{
- xo+=putChar(xo,yo,s[i])+fontSize*.1;
+ pw=putChar(xo,yo,s[i])+fontSize*.1;
+ xo+=pw;
}
}while(s[i++]);
return xo;
@@ -237,17 +240,29 @@ namespace ui {
player->ground=false;
}
}
+ World *tmp;
if(SDL_KEY==SDLK_i){
- player->vel.y=.2;
- player->loc.y+=HLINE*7;
- player->ground=false;
+ 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){
- player->vel.y=.2;
- player->loc.y+=HLINE*10;
- player->ground=false;
+ 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_c){
+ dialogBox("","You pressed `c`, but nothing happened.");
}
if(SDL_KEY==SDLK_LSHIFT)player->speed = 3; // Sprint
if(SDL_KEY==SDLK_LCTRL)player->speed = .5;
@@ -271,12 +286,12 @@ namespace ui {
}
unsigned int i;
- //if(!dialogBoxExists&&AIpreaddr.size()){ // Flush preloaded AI functions if necessary
- //for(i=0;i<AIpreaddr.size();i++){
- //AIpreaddr.front()->addAIFunc(AIpreload.front(),false);
- //AIpreaddr.erase(AIpreaddr.begin());
- //AIpreload.erase(AIpreload.begin());
- //}
- //}
+ if(!dialogBoxExists&&AIpreaddr.size()){ // Flush preloaded AI functions if necessary
+ for(i=0;i<AIpreaddr.size();i++){
+ 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 97ec5ac..599b1ef 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -240,15 +240,26 @@ LOOP2:
* Draw the layer up until the grass portion, which is done later.
*/
+ bool hey=false;
glBegin(GL_QUADS);
for(i=is;i<ie-GEN_INC;i++){
- cline[i].y+=(yoff-DRAW_Y_OFFSET); // Add the y offset
- safeSetColor(cline[i].color+shade,cline[i].color-50+shade,cline[i].color-100+shade); // Set the shaded dirt color
+ cline[i].y+=(yoff-DRAW_Y_OFFSET); // Add the y offset
+ if(!cline[i].y){
+ cline[i].y+=50;
+ hey=true;
+ safeSetColor(cline[i].color-100+shade,cline[i].color-150+shade,cline[i].color-200+shade);
+ }else{
+ safeSetColor(cline[i].color+shade,cline[i].color-50+shade,cline[i].color-100+shade); // Set the shaded dirt color
+ }
glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT);
glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT);
glVertex2i(cx_start+i*HLINE+HLINE,0);
glVertex2i(cx_start+i*HLINE ,0);
- cline[i].y-=(yoff-DRAW_Y_OFFSET); // Restore the line's y value
+ cline[i].y-=(yoff-DRAW_Y_OFFSET); // Restore the line's y value
+ if(hey){
+ hey=false;
+ cline[i].y=0;
+ }
}
glEnd();
@@ -277,6 +288,10 @@ LOOP2:
cline[i].gs=false;
else cline[i].gs=true;
}
+ }else{
+ for(i=0;i<lineCount-GEN_INC;i++){
+ cline[i].gs=true;
+ }
}
/*
@@ -289,12 +304,17 @@ LOOP2:
* Draw non-structure entities.
*/
- if(current==this){
- for(i=0;i<entity.size();i++){
- if(entity[i]->inWorld==this && entity[i]->type != STRUCTURET)
- entity[i]->draw();
- }
+ for(i=0;i<entity.size();i++){
+ if(entity[i]->inWorld==this && entity[i]->type != STRUCTURET)
+ entity[i]->draw();
}
+
+ }else{
+
+ /*for(i=0;i<lineCount-GEN_INC;i++){
+ cline[i].gs=true;
+ }*/
+
}
/*
@@ -581,8 +601,8 @@ void World::addHole(unsigned int start,unsigned int end){
}
}
-int World::getStart(void){
- return -x_start;
+int World::getTheWidth(void){
+ return x_start*2;
}
IndoorWorld::IndoorWorld(void){