aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/common.h10
-rw-r--r--include/world.h1
-rw-r--r--main.cpp101
-rw-r--r--src/inventory.cpp6
-rw-r--r--src/ui.cpp8
-rw-r--r--src/world.cpp5
6 files changed, 90 insertions, 41 deletions
diff --git a/include/common.h b/include/common.h
index 1da279c..6d11c57 100644
--- a/include/common.h
+++ b/include/common.h
@@ -49,8 +49,9 @@ typedef struct {
#define GAME_NAME "Independent Study v.0.2 alpha"
-#define SCREEN_WIDTH 1280
-#define SCREEN_HEIGHT 720
+#define SCREEN_WIDTH 1920
+#define SCREEN_HEIGHT 1080
+#define FULLSCREEN
//#define FULLSCREEN
@@ -94,6 +95,11 @@ typedef struct {
extern unsigned int deltaTime;
/*
+ * References the variable in main.cpp, used for drawing with the player
+*/
+extern vec2 offset;
+
+/*
* Loads an image from the given file path and attempts to make a texture out of it. The
* resulting GLuint is returned (used to recall the texture in glBindTexture).
*
diff --git a/include/world.h b/include/world.h
index 18e1878..03b0d96 100644
--- a/include/world.h
+++ b/include/world.h
@@ -36,6 +36,7 @@ protected:
void singleDetect(Entity *e); // Handles an individual entity (gravity n' stuff)
public:
unsigned int lineCount; // Size of the array 'line' (aka the width of the world)
+ unsigned int worldWidth;
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;
diff --git a/main.cpp b/main.cpp
index 4fb5a00..faa2be4 100644
--- a/main.cpp
+++ b/main.cpp
@@ -49,7 +49,7 @@ SDL_GLContext mainGLContext = NULL;
*
*/
-static GLuint bgImage, bgTreesFirst;
+static GLuint bgImage, bgMtn, bgTreesFirst;
/*
* gameRunning
@@ -142,6 +142,9 @@ extern void initEverything(void);
/*
* mainLoop is in fact the main loop, which runs 'infinitely' (as long as gameRunning
+
+
+
* is set). Each loop updates timing values (tickCount and deltaTime), runs logic()
* if MSEC_PER_TICK milliseconds have passed, and then runs render().
*
@@ -155,6 +158,12 @@ void logic(void);
void render(void);
void mainLoop(void);
+/*
+ * This offset is used as the player offset in the world drawing so
+ * everything can be moved according to the player
+*/
+vec2 offset;
+
/*
* millis
*
@@ -371,7 +380,8 @@ int main(int argc, char *argv[]){
* Load a temporary background image.
*/
- bgImage=Texture::loadTexture("assets/bg.png");
+ bgImage= Texture::loadTexture("assets/bg.png");
+ bgMtn= Texture::loadTexture("assets/bgFarMountain.png");
bgTreesFirst = Texture::loadTexture("assets/antree.png");
/*
@@ -519,10 +529,24 @@ void render(){
* glLoadIdentity This scales the current matrix back to the origin so the
* translations are seen normally on a stack.
*/
+
+ /*
+ * This offset variable is what we use to move the camera and locked
+ * objects on the screen so they always appear to be in the same relative area
+ */
+ offset = player->loc;
+ offset.x += player->width/2;
+
+ /*
+ * If the camera will go off of the left or right of the screen we want to lock it so we can't
+ * see past the world render
+ */
+ if(player->loc.x - SCREEN_WIDTH/2 < SCREEN_WIDTH*-1.5)offset.x = ((SCREEN_WIDTH*-1.5) + SCREEN_WIDTH/2) + player->width/2;
+ if(player->loc.x + SCREEN_WIDTH/2 > SCREEN_WIDTH*1.5)offset.x = ((SCREEN_WIDTH*1.5) - SCREEN_WIDTH/2) + player->width/2;
glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on
glPushMatrix(); //push the matrix to the top of the matrix stack
glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode
- glOrtho(player->loc.x-SCREEN_WIDTH/2,player->loc.x+SCREEN_WIDTH/2,0,SCREEN_HEIGHT,-1,1);
+ glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),0,SCREEN_HEIGHT,-1,1);
glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects
glPushMatrix(); //push the matrix to the top of the matrix stack
glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode
@@ -562,48 +586,65 @@ void render(){
int base = 40 - (int)worldGetYBase(currentWorld);
+ glBindTexture(GL_TEXTURE_2D, bgMtn);
+
+ glColor4ub(150,150,150,220);
+ glBegin(GL_QUADS);
+ glTexCoord2i(0,1);glVertex2i(-1920+offset.x*.85,base);
+ glTexCoord2i(1,1);glVertex2i( offset.x*.85,base);
+ glTexCoord2i(1,0);glVertex2i( offset.x*.85,base+1080);
+ glTexCoord2i(0,0);glVertex2i(-1920+offset.x*.85,base+1080);
+ glEnd();
+ glColor4ub(150,150,150,220);
+ glBegin(GL_QUADS);
+ glTexCoord2i(0,1);glVertex2i( offset.x*.85,base);
+ glTexCoord2i(1,1);glVertex2i(1920+offset.x*.85,base);
+ glTexCoord2i(1,0);glVertex2i(1920+offset.x*.85,base+1080);
+ glTexCoord2i(0,0);glVertex2i( offset.x*.85,base+1080);
+ glEnd();
+
glBindTexture(GL_TEXTURE_2D, bgTreesFirst);
glPushMatrix();
- glColor4ub(100,100,100,220);
+ glColor4ub(100,100,100,240);
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2i(-1920+player->loc.x*.6,base);
- glTexCoord2i(1,1);glVertex2i( player->loc.x*.6,base);
- glTexCoord2i(1,0);glVertex2i( player->loc.x*.6,base+1080);
- glTexCoord2i(0,0);glVertex2i(-1920+player->loc.x*.6,base+1080);
+ glTexCoord2i(0,1);glVertex2i(-1920+offset.x*.6,base);
+ glTexCoord2i(1,1);glVertex2i( offset.x*.6,base);
+ glTexCoord2i(1,0);glVertex2i( offset.x*.6,base+1080);
+ glTexCoord2i(0,0);glVertex2i(-1920+offset.x*.6,base+1080);
glEnd();
- glColor4ub(100,100,100,220);
+ glColor4ub(100,100,100,240);
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2i( player->loc.x*.6,base);
- glTexCoord2i(1,1);glVertex2i(1920+player->loc.x*.6,base);
- glTexCoord2i(1,0);glVertex2i(1920+player->loc.x*.6,base+1080);
- glTexCoord2i(0,0);glVertex2i( player->loc.x*.6,base+1080);
+ glTexCoord2i(0,1);glVertex2i( offset.x*.6,base);
+ glTexCoord2i(1,1);glVertex2i(1920+offset.x*.6,base);
+ glTexCoord2i(1,0);glVertex2i(1920+offset.x*.6,base+1080);
+ glTexCoord2i(0,0);glVertex2i( offset.x*.6,base+1080);
glEnd();
glPopMatrix();
- glColor4ub(150,150,150,240);
+ glColor4ub(150,150,150,250);
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2i(-1920+player->loc.x*.4,base);
- glTexCoord2i(1,1);glVertex2i( player->loc.x*.4,base);
- glTexCoord2i(1,0);glVertex2i( player->loc.x*.4,base+1080);
- glTexCoord2i(0,0);glVertex2i(-1920+player->loc.x*.4,base+1080);
+ glTexCoord2i(0,1);glVertex2i(-1920+offset.x*.4,base);
+ glTexCoord2i(1,1);glVertex2i( offset.x*.4,base);
+ glTexCoord2i(1,0);glVertex2i( offset.x*.4,base+1080);
+ glTexCoord2i(0,0);glVertex2i(-1920+offset.x*.4,base+1080);
glEnd();
- glColor4ub(150,150,150,240);
+ glColor4ub(150,150,150,250);
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2i( player->loc.x*.4,base);
- glTexCoord2i(1,1);glVertex2i(1920+player->loc.x*.4,base);
- glTexCoord2i(1,0);glVertex2i(1920+player->loc.x*.4,base+1080);
- glTexCoord2i(0,0);glVertex2i( player->loc.x*.4,base+1080);
+ glTexCoord2i(0,1);glVertex2i( offset.x*.4,base);
+ glTexCoord2i(1,1);glVertex2i(1920+offset.x*.4,base);
+ glTexCoord2i(1,0);glVertex2i(1920+offset.x*.4,base+1080);
+ glTexCoord2i(0,0);glVertex2i( offset.x*.4,base+1080);
glEnd();
glColor4ub(255,255,255,255);
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2i(-960+player->loc.x*.25,base);
- glTexCoord2i(1,1);glVertex2i( 960+player->loc.x*.25,base);
- glTexCoord2i(1,0);glVertex2i( 960+player->loc.x*.25,base+1080);
- glTexCoord2i(0,0);glVertex2i(-960+player->loc.x*.25,base+1080);
+ glTexCoord2i(0,1);glVertex2i(-960+offset.x*.25,base);
+ glTexCoord2i(1,1);glVertex2i( 960+offset.x*.25,base);
+ glTexCoord2i(1,0);glVertex2i( 960+offset.x*.25,base+1080);
+ glTexCoord2i(0,0);glVertex2i(-960+offset.x*.25,base+1080);
glEnd();
glDisable(GL_TEXTURE_2D);
@@ -632,7 +673,7 @@ void render(){
ui::setFontSize(16);
- ui::putText(player->loc.x-SCREEN_WIDTH/2,
+ ui::putText(offset.x-SCREEN_WIDTH/2,
SCREEN_HEIGHT-ui::fontSize,
"FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nQc: %u",
fps,
@@ -654,9 +695,9 @@ void render(){
glColor3ub(255,255,255);
glBegin(GL_TRIANGLES);
- glVertex2i(ui::mouse.x ,ui::mouse.y );
+ glVertex2i(ui::mouse.x ,ui::mouse.y );
glVertex2i(ui::mouse.x+HLINE*3.5,ui::mouse.y );
- glVertex2i(ui::mouse.x ,ui::mouse.y-HLINE*3.5);
+ glVertex2i(ui::mouse.x ,ui::mouse.y-HLINE*3.5);
glEnd();
/**************************
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 1adcbab..2eb0087 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -86,10 +86,10 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
void Inventory::draw(void){
unsigned int i=0;
float y=SCREEN_HEIGHT/2,xoff;
- ui::putText(player->loc.x-SCREEN_WIDTH/2,y,"Inventory:");
+ ui::putText(offset.x-SCREEN_WIDTH/2,y,"Inventory:");
while(item[i].count){
y-=HLINE*12;
- xoff=ui::putText(player->loc.x-SCREEN_WIDTH/2,y,"%d x ",item[i].count);
+ xoff=ui::putText(offset.x-SCREEN_WIDTH/2,y,"%d x ",item[i].count);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,ITEM_TEX[item[i].id-1]);
if(sel==i)glColor3ub(255,0,255);
@@ -101,7 +101,7 @@ void Inventory::draw(void){
glTexCoord2i(0,0);glVertex2i(xoff ,y+HLINE*10);
glEnd();
y-=ui::fontSize*1.15;
- ui::putText(player->loc.x-SCREEN_WIDTH/2,y,"%s",itemName[(unsigned)item[i].id]);
+ ui::putText(offset.x-SCREEN_WIDTH/2,y,"%s",itemName[(unsigned)item[i].id]);
glDisable(GL_TEXTURE_2D);
i++;
}
diff --git a/src/ui.cpp b/src/ui.cpp
index 9d7de8a..8f19e34 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -174,13 +174,13 @@ namespace ui {
putString(x+HLINE,y-fontSize-HLINE,dialogBoxText);
}
setFontSize(16);
- putText(((SCREEN_WIDTH/2)+player->loc.x)-125,SCREEN_HEIGHT-fontSize,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
+ putText(((SCREEN_WIDTH/2)+offset.x)-125,SCREEN_HEIGHT-fontSize,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
(unsigned)player->maxHealth);
if(player->alive){
glColor3ub(255,0,0);
- glRectf((SCREEN_WIDTH/2+player->loc.x)-125,
+ glRectf((SCREEN_WIDTH/2+offset.x)-125,
SCREEN_HEIGHT-32,
- ((SCREEN_WIDTH/2+player->loc.x)-125)+((player->health/player->maxHealth)*100),
+ ((SCREEN_WIDTH/2+offset.x)-125)+((player->health/player->maxHealth)*100),
SCREEN_HEIGHT-32+12);
}
}
@@ -188,7 +188,7 @@ namespace ui {
static bool left=false,right=false;
static vec2 premouse={0,0};
SDL_Event e;
- mouse.x=premouse.x+player->loc.x-(SCREEN_WIDTH/2);
+ mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
mouse.y=SCREEN_HEIGHT-premouse.y;
while(SDL_PollEvent(&e)){
switch(e.type){
diff --git a/src/world.cpp b/src/world.cpp
index 168ac4c..9fe76b0 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -42,6 +42,7 @@ World::World(void){
}
void World::generate(unsigned int width){ // Generates the world and sets all variables contained in the World class.
+ worldWidth = width;
unsigned int i;
float inc;
@@ -199,7 +200,7 @@ LOOP2:
* the 'for' loop below that draws the layer.
*/
- v_offset=(p->loc.x + p->width / 2 - current->x_start) / HLINE;
+ v_offset=(offset.x + p->width / 2 - current->x_start) / HLINE;
// is -> i start
@@ -208,7 +209,7 @@ LOOP2:
// ie -> i end
- ie=v_offset + (SCREEN_WIDTH / 2 / HLINE) + GEN_INC;
+ ie=v_offset + (SCREEN_WIDTH / 2 / HLINE) + GEN_INC + HLINE;
if(ie>current->lineCount)ie=current->lineCount; // Maximum bound
/*