aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog10
-rw-r--r--assets/mountain.pngbin2125 -> 2197 bytes
-rw-r--r--include/entities.h6
-rw-r--r--main.cpp10
-rw-r--r--src/entities.cpp14
-rw-r--r--src/gameplay.cpp6
-rw-r--r--src/world.cpp155
-rw-r--r--xcf/mountain.xcfbin209841 -> 12475 bytes
8 files changed, 153 insertions, 48 deletions
diff --git a/Changelog b/Changelog
index 4c4d823..4af9d0c 100644
--- a/Changelog
+++ b/Changelog
@@ -182,3 +182,13 @@
- gained knowledge on sprite creation
- created tree and mountain sprites
- created a decent bird AI
+
+10/28/2015:
+===========
+
+ - fixed world drawing bug
+ - fixed segfault with entering buildings
+ - found bug with npc quest preloading
+ - documented more of world.cpp
+ - improved background textures/parallax stuff
+ -
diff --git a/assets/mountain.png b/assets/mountain.png
index 12c0f64..7039174 100644
--- a/assets/mountain.png
+++ b/assets/mountain.png
Binary files differ
diff --git a/include/entities.h b/include/entities.h
index 94febcf..a9375c3 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -69,7 +69,7 @@ public:
void spawn(float, float);
void draw(void);
- virtual void wander(int, vec2*){}
+ virtual void wander(int){}
void getName();
virtual void interact(){}
int ticksToUse; //The variable for deciding how long an entity should do a certain task
@@ -89,14 +89,16 @@ public:
NPC();
void addAIFunc(int (*func)(NPC *),bool preload);
void interact();
- void wander(int, vec2*);
+ void wander(int);
};
+
class Structures : public Entity{
public:
void *inside;
Structures();
unsigned int spawn(_TYPE, float, float);
};
+
class Mob : public Entity{
public:
float init_y;
diff --git a/main.cpp b/main.cpp
index 002fc83..4fb5a00 100644
--- a/main.cpp
+++ b/main.cpp
@@ -62,7 +62,7 @@ static GLuint bgImage, bgTreesFirst;
*
*/
-bool gameRunning = true;
+bool gameRunning;
/*
* currentWorld - This is a pointer to the current world that the player
@@ -173,6 +173,7 @@ unsigned int millis(void){
* MAIN ************************************************************************
*******************************************************************************/
int main(int argc, char *argv[]){
+ gameRunning=false;
/*
* (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
@@ -383,6 +384,7 @@ int main(int argc, char *argv[]){
**** GAMELOOP ****
**************************/
+ gameRunning=true;
while(gameRunning){
mainLoop();
}
@@ -558,7 +560,7 @@ void render(){
glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2,SCREEN_HEIGHT);
glEnd();
- int base = 50 - (int)worldGetYBase(currentWorld);
+ int base = 40 - (int)worldGetYBase(currentWorld);
glBindTexture(GL_TEXTURE_2D, bgTreesFirst);
@@ -729,9 +731,9 @@ void logic(){
* that the NPC doesn't move when it talks to the player.
*
*/
-
+
if(entity[i]->canMove)
- NPCp(entity[i])->wander((rand() % 120 + 30), &entity[i]->vel);
+ NPCp(entity[i])->wander((rand() % 120 + 30));
/*
* Don't bother handling the NPC if another has already been handled.
diff --git a/src/entities.cpp b/src/entities.cpp
index 0479d5e..acc45bd 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -227,28 +227,32 @@ void Player::interact(){ //the function that will cause the player to search for
* the memory address passed to it is directly modified.
*/
-void NPC::wander(int timeRun, vec2 *v){ //this makes the entites wander about
+void NPC::wander(int timeRun){
+
/*
* Direction is the variable that decides what direction the entity will travel in
* the value is either -1, 0, or 1. -1 being left, 0 means that the npc will stay still
* and a value of 1 makes the entity move to the right
*/
- static int direction; //variable to decide what direction the entity moves
+
+ static int direction;
+
/*
* Ticks to use is a variable in the entity class that counts the total ticks that need to be used
*
* This loop only runs when ticksToUse is 0, this means that the speed, direction, etc... Will be
* calculated only after the npc has finished his current walking state
*/
+
if(ticksToUse == 0){
ticksToUse = timeRun;
- v->x = .008*HLINE; //sets the inital velocity of the entity
+ vel.x = .008*HLINE; //sets the inital velocity of the entity
direction = (getRand() % 3 - 1); //sets the direction to either -1, 0, 1
//this lets the entity move left, right, or stay still
if(direction==0)ticksToUse*=2;
- v->x *= direction; //changes the velocity based off of the direction
+ vel.x *= direction; //changes the velocity based off of the direction
}
- ticksToUse--; //removes one off of the entities timer
+ ticksToUse--; //removes one off of the entities timer
}
std::vector<int (*)(NPC *)> AIpreload; // A dynamic array of AI functions that are being preloaded
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index d3cc4f4..9e0cc99 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -20,9 +20,10 @@ int compTestQuest(NPC *speaker){
}
int giveTestQuest(NPC *speaker){
+ unsigned int i;
ui::dialogBox(speaker->name,"Here, have a quest!");
player->qh.assign("Test");
- NPCp(entity[2])->addAIFunc(compTestQuest,true);
+ npc[1]->addAIFunc(compTestQuest,true);
return 0;
}
@@ -41,7 +42,6 @@ void initEverything(void){
*/
test->addLayer(400);
- //test->addLayer(100);
test->addPlatform(150,100,100,10);
@@ -91,7 +91,7 @@ void initEverything(void){
/*
* Link all the entities that were just created to the initial world, and setup a test AI function.
*/
- NPCp(entity[1])->addAIFunc(giveTestQuest,false);
+ npc[0]->addAIFunc(giveTestQuest,false);
for(i=0;i<entity.size();i++){
entity[i]->inWorld=currentWorld;
diff --git a/src/world.cpp b/src/world.cpp
index e1d05ab..168ac4c 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -15,7 +15,8 @@
#define INDOOR_FLOOR_HEIGHT 100 // Defines how high the base floor of an IndoorWorld should be
-extern std::vector<Entity *>entity;
+extern std::vector<Entity *> entity;
+extern std::vector<Structures *> build;
void safeSetColor(int r,int g,int b){ // safeSetColor() is an alternative to directly using glColor3ub() to set
if(r>255)r=255; // the color for OpenGL drawing. safeSetColor() checks for values that are
@@ -79,8 +80,8 @@ void World::generate(unsigned int width){ // Generates the world and sets all va
*/
line[i].y=rand() % 8 - 4 + line[i-GEN_INC].y; // Add +/- 4 to the previous line
- if(line[i].y < 60)line[i].y = 60; // Minimum bound
- else if(line[i].y > 90)line[i].y = 90; // Maximum bound
+ if(line[i].y < 40)line[i].y = 40; // Minimum bound
+ else if(line[i].y > 70)line[i].y = 70; // Maximum bound
}
@@ -198,14 +199,16 @@ LOOP2:
* the 'for' loop below that draws the layer.
*/
- v_offset=(p->loc.x - current->x_start) / HLINE;
+ v_offset=(p->loc.x + p->width / 2 - current->x_start) / HLINE;
// is -> i start
- is=v_offset - SCREEN_WIDTH / (yoff / (DRAW_Y_OFFSET / 2));
+ is=v_offset - (SCREEN_WIDTH / 2 / HLINE) - GEN_INC;
if(is<0)is=0; // Minimum bound
-
- ie=v_offset + SCREEN_WIDTH / (yoff / (DRAW_Y_OFFSET / 2));
+
+ // ie -> i end
+
+ ie=v_offset + (SCREEN_WIDTH / 2 / HLINE) + GEN_INC;
if(ie>current->lineCount)ie=current->lineCount; // Maximum bound
/*
@@ -222,12 +225,13 @@ LOOP2:
//shade*=-1;
/*
- * Draw entities in the current layer if we're on the one we started at.
+ * Draw structures in the current layer if we're on the one we started at. We draw
+ * structures behind the dirt/grass so that the buildings corners don't stick out.
*/
if(current==this){
for(i=0;i<entity.size();i++){
- if(entity[i]->inWorld==this)
+ if(entity[i]->inWorld==this && entity[i]->type == STRUCTURET)
entity[i]->draw();
}
}
@@ -248,48 +252,133 @@ LOOP2:
}
glEnd();
+ /*
+ * If we're drawing the closest/last world, handle and draw the player and entities in
+ * the world.
+ */
+
if(current==this){
- int ph;
- ph=(p->loc.x+p->width/2-x_start)/HLINE; // Calculate what line the player is currently on
- for(i=0;i<lineCount-GEN_INC;i++){
- if(p->ground==1&&i<ph+6&&i>ph-6)cline[i].gs=false;
- else cline[i].gs=true;
+
+ /*
+ * Calculate the line that the player is on
+ */
+
+ int ph = (p->loc.x + p->width / 2 - x_start) / HLINE;
+
+ /*
+ * If the player is on the ground, flatten the grass where the player is standing
+ * by setting line.gs to false.
+ */
+
+ if(p->ground){
+ for(i=0;i<lineCount-GEN_INC;i++){
+ if(i < ph + 6 &&
+ i > ph - 6 )
+ cline[i].gs=false;
+ else cline[i].gs=true;
+ }
}
+
+ /*
+ * Draw the player.
+ */
+
p->draw();
+
+ /*
+ * 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();
+ }
+ }
}
+
+ /*
+ * Draw grass on every line.
+ */
+
float cgh[2];
glBegin(GL_QUADS);
for(i=is;i<ie-GEN_INC;i++){
- memcpy(cgh,cline[i].gh,2*sizeof(float));
+
+ /*
+ * Load the current line's grass values
+ */
+
+ if(cline[i].y)memcpy(cgh,cline[i].gh,2*sizeof(float));
+ else memset(cgh,0 ,2*sizeof(float));
+
+
+
+ /*
+ * Flatten the grass if the player is standing on it.
+ */
+
if(!cline[i].gs){
cgh[0]/=4;
cgh[1]/=4;
}
+
+ /*
+ * Actually draw the grass.
+ */
+
cline[i].y+=(yoff-DRAW_Y_OFFSET);
+
safeSetColor(shade,150+shade,shade);
+
glVertex2i(cx_start+i*HLINE ,cline[i].y+cgh[0]);
glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[0]);
glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT);
glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT);
+
glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[1]);
glVertex2i(cx_start+i*HLINE+HLINE ,cline[i].y+cgh[1]);
glVertex2i(cx_start+i*HLINE+HLINE ,cline[i].y-GRASS_HEIGHT);
glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT);
+
cline[i].y-=(yoff-DRAW_Y_OFFSET);
}
glEnd();
+
+ /*
+ * Restore the inverted shading if it was inverted above.
+ */
+
//shade*=-1;
+
+ /*
+ * Draw platforms...
+ */
+
safeSetColor(255+shade*2,0+shade,0+shade);
+
for(i=0;i<current->platform.size();i++){
- glRectf(current->platform[i].p1.x,current->platform[i].p1.y+yoff-DRAW_Y_OFFSET,
- current->platform[i].p2.x,current->platform[i].p2.y+yoff-DRAW_Y_OFFSET);
+ glRectf(current->platform[i].p1.x, current->platform[i].p1.y + yoff - DRAW_Y_OFFSET,
+ current->platform[i].p2.x, current->platform[i].p2.y + yoff - DRAW_Y_OFFSET);
}
- if(current->infront){ // If there's a world in front of the one that was just drawn
- yoff-=DRAW_Y_OFFSET; // draw it as well.
- shade-=DRAW_SHADE;
+
+ /*
+ * Draw the next closest world if it exists.
+ */
+
+ if(current->infront){
+ yoff -= DRAW_Y_OFFSET;
+ shade -= DRAW_SHADE;
+
current=current->infront;
goto LOOP2;
- }else{ // Otherwise reset static values and return
+
+ }else{
+
+ /*
+ * If finished, reset the yoff and shade variables for the next call.
+ */
+
yoff=DRAW_Y_OFFSET;
shade=0;
}
@@ -470,17 +559,16 @@ void World::addPlatform(float x,float y,float w,float h){
World *World::goInsideStructure(Player *p){
unsigned int i;
- for(i=0;i<entity.size();i++){
- if(entity[i]->type==-1){
- if(entity[i]->inWorld==this){
- if(p->loc.x>entity[i]->loc.x&&p->loc.x+p->width<entity[i]->loc.x+entity[i]->width){
- return (World *)((Structures *)entity[i])->inside;
- }
- }else if(((Structures *)entity[i])->inside==this){
- p->loc.x=entity[i]->loc.x+entity[i]->width/2-p->width/2;
- p->loc.y=entity[i]->loc.y+HLINE;
- return (World *)entity[i]->inWorld;
+ for(i=0;i<build.size();i++){
+ if(build[i]->inWorld==this){
+ if(p->loc.x > build[i]->loc.x &&
+ p->loc.x + p->width < build[i]->loc.x + build[i]->width){
+ return (World *)build[i]->inside;
}
+ }else if(build[i]->inside==this){
+ p->loc.x=build[i]->loc.x + build[i]->width / 2 - p->width / 2;
+ p->loc.y=build[i]->loc.y + HLINE;
+ return (World *)build[i]->inWorld;
}
}
return this;
@@ -493,8 +581,6 @@ void World::addHole(unsigned int start,unsigned int end){
}
}
-
-
IndoorWorld::IndoorWorld(void){
}
@@ -519,6 +605,7 @@ void IndoorWorld::generate(unsigned int width){ // Generates a flat area of wid
void IndoorWorld::draw(Player *p){
int i,ie,v_offset;
+
v_offset=(p->loc.x-x_start)/HLINE; // Calculate the player's offset in the array 'line' using the player's location 'vec'
i=v_offset-SCREEN_WIDTH/2; // um
if(i<0)i=0; // If the player is past the start of that world 'i' should start at the beginning
@@ -535,7 +622,7 @@ void IndoorWorld::draw(Player *p){
glVertex2i(x_start+i*HLINE ,line[i].y-50);
}
glEnd();
- for(i=0;i<entity.size()+1;i++){
+ for(i=0;i<entity.size();i++){
if(entity[i]->inWorld==this)
entity[i]->draw();
}
diff --git a/xcf/mountain.xcf b/xcf/mountain.xcf
index 5ef311e..32fd5b1 100644
--- a/xcf/mountain.xcf
+++ b/xcf/mountain.xcf
Binary files differ