]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
ortho binds to y
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 4 Nov 2015 13:50:18 +0000 (08:50 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 4 Nov 2015 13:50:18 +0000 (08:50 -0500)
Changelog
include/common.h
main.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp
src/world.cpp

index e2da060afd80c78b575135e4b1f02f98cc3efcbe..d11bfe510a537715cfefcad6318c9bcd4b857360 100644 (file)
--- a/Changelog
+++ b/Changelog
        - added typewriter-esque text drawing
        - documented ui.h
        - continued work on GLSL shaders
+       
+11/4/2015:
+==========
+
+       - fixed typewriter output free() error
+       - added y-binding to ortho (if player is high in the sky ortho and UI will match it)
+       - added maximum to gravity's pull
+       - worked on storyline
index 41cc7b91e3376f1955c4d4e02d5e91b30543a67b..39812c4b627a4a535657cea7095edc25b2a5ca00 100644 (file)
@@ -101,6 +101,10 @@ typedef struct {
 
 #define DEBUG_printf( message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__ )
 
+
+#define PI 3.1415926535
+
+
 /*
  *     References the variable in main.cpp, used for smoother drawing.
 */
index a49873c76beacd7108cbb71088485fa1e57432ac..9d7f08547b3f5f287ce57689cf24430538314b86 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -186,7 +186,8 @@ std::string readFile(const char *filePath) {
  *     This offset is used as the player offset in the world drawing so
  *     everything can be moved according to the player
 */
-vec2 offset;
+
+vec2 offset;                                                                                                                                                   /**     OFFSET!!!!!!!!!!!!!!!!!!!! **/
 
 /*
  *     millis
@@ -568,8 +569,8 @@ void render(){
          *     objects on the screen so they always appear to be in the same relative area
         */
        
-       offset = player->loc;
-       offset.x += player->width/2;
+       offset.x = player->loc.x + player->width/2;
+       offset.y = SCREEN_HEIGHT/2;
 
        /*
         *      If the camera will go off of the left  or right of the screen we want to lock it so we can't
@@ -581,6 +582,9 @@ void render(){
        if(player->loc.x + SCREEN_WIDTH/2 > currentWorld->getTheWidth() *  0.5f)
                offset.x = ((currentWorld->getTheWidth() *  0.5f) - SCREEN_WIDTH / 2) + player->width / 2;
 
+       if(player->loc.y > 300 )
+               offset.y = player->loc.y + player->height;
+
        /*
         *      These functions run everyloop to update the current stacks presets
         *
@@ -621,7 +625,7 @@ void render(){
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
-       glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),0,SCREEN_HEIGHT,-1,1);
+       glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1);
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();
@@ -656,16 +660,16 @@ void render(){
        glBegin(GL_QUADS);
                glTexCoord2i(0,1);glVertex2i(-SCREEN_WIDTH*2+offset.x,0);
                glTexCoord2i(1,1);glVertex2i( SCREEN_WIDTH*2+offset.x,0);
-               glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT);
-               glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT);
+               glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2);
+               glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2);
        glEnd();
        glBindTexture(GL_TEXTURE_2D,bgNight);
        safeSetColorA(255,255,255,worldShade*4);
        glBegin(GL_QUADS);
                glTexCoord2i(0,1);glVertex2i(-SCREEN_WIDTH*2+offset.x,0);
                glTexCoord2i(1,1);glVertex2i( SCREEN_WIDTH*2+offset.x,0);
-               glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT);
-               glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT);
+               glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2);
+               glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2);
        glEnd();
 
        glDisable(GL_TEXTURE_2D);
@@ -774,7 +778,6 @@ void render(){
                glUseProgramObjectARB(0);
        #endif //SHADERS
 
-       #define pi 3.1415926535
        #define raysNOPE
 
        #ifdef rays
@@ -809,20 +812,20 @@ void render(){
                                break;
                        default:
                                if(angle > 0 && angle < 90){
-                                       curCoord.x = r.start.x + float(HLINE / cos(angle*pi/180));
-                                       curCoord.y = r.start.y + float(HLINE / sin(angle*pi/180));
+                                       curCoord.x = r.start.x + float(HLINE / cos(angle*PI/180));
+                                       curCoord.y = r.start.y + float(HLINE / sin(angle*PI/180));
                                }
                                if(angle > 90 && angle < 180){
-                                       curCoord.x = r.start.x - float(HLINE / cos((90-angle)*pi/180));
-                                       curCoord.y = r.start.y + float(HLINE / sin((90-angle)*pi/180));
+                                       curCoord.x = r.start.x - float(HLINE / cos((90-angle)*PI/180));
+                                       curCoord.y = r.start.y + float(HLINE / sin((90-angle)*PI/180));
                                }
                                if(angle > 180 && angle < 270){
-                                       curCoord.x = r.start.x - float(HLINE / cos((270-angle)*pi/180));
-                                       curCoord.y = r.start.y - float(HLINE / sin((270-angle)*pi/180));
+                                       curCoord.x = r.start.x - float(HLINE / cos((270-angle)*PI/180));
+                                       curCoord.y = r.start.y - float(HLINE / sin((270-angle)*PI/180));
                                }
                                if(angle > 270 && angle < 360){
-                                       curCoord.x = r.start.x + float(HLINE / cos((360-angle)*pi/180));
-                                       curCoord.y = r.start.y - float(HLINE / sin((360-angle)*pi/180));
+                                       curCoord.x = r.start.x + float(HLINE / cos((360-angle)*PI/180));
+                                       curCoord.y = r.start.y - float(HLINE / sin((360-angle)*PI/180));
                                }
                        }//end swtich
                        /*for(auto &en : entity){
@@ -844,8 +847,6 @@ void render(){
        }
        #endif //rays
 
-
-       //LIGHT
        player->inv->draw();
 
        /*
@@ -863,7 +864,7 @@ void render(){
                ui::setFontSize(16);
                
                ui::putText(offset.x-SCREEN_WIDTH/2,
-                                       SCREEN_HEIGHT-ui::fontSize,
+                                       (offset.y+SCREEN_HEIGHT/2)-ui::fontSize,
                                        "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n     (y)%+.2f\nTc: %u\nQc: %u",
                                        fps,
                                        player->ground,
@@ -910,10 +911,10 @@ void render(){
 
        if(fadeIntensity){
                glColor4ub(0,0,0,fadeIntensity);
-               glRectf(player->loc.x-SCREEN_WIDTH,
-                               SCREEN_HEIGHT,
-                               player->loc.x+SCREEN_WIDTH,
-                               0);
+               glRectf(offset.x-SCREEN_WIDTH /2,
+                               offset.y-SCREEN_HEIGHT/2,
+                               offset.x+SCREEN_WIDTH /2,
+                               offset.y+SCREEN_HEIGHT/2);
                if(fadeIntensity == 255){
                        ui::importantText("The screen is black.");
                }
@@ -969,8 +970,7 @@ void logic(){
        */
 
        for(int i = 0 ; i < entity.size(); i++){
-               if(!entity[i]->alive)std::cout<<"Entity "<<i<<" is not alive!"<<std::endl;
-
+               
                /*
                 *      Check if the entity is in this world and is alive.
                */
@@ -1092,7 +1092,6 @@ void logic(){
         *      Calculate an in-game shading value (as opposed to GLSL shading).
        */
 
-       #define PI 3.1415926535
        worldShade=50*sin((tickCount+(DAY_CYCLE/2))/(DAY_CYCLE/PI));
 
        /*
index f986ce3abf4e681ea13543bbb3b8cfd9643ca201..baa91e80886a61e4d80a7363250af22c75bd09e5 100644 (file)
@@ -51,7 +51,7 @@ void initEverything(void){
        */
        
        player=new Player();
-       player->spawn(0,100);
+       player->spawn(0,5000);
        
        /*
         *      Create a structure (this will create villagers when spawned).
index cb33deb6d2e549537072713870ff5bdca2c1fd6f..c79a29bd7d46e31af81aeee8dfff377b7fa038bc 100644 (file)
@@ -91,7 +91,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
 
 void Inventory::draw(void){
        unsigned int i=0;
-       float y=SCREEN_HEIGHT/2,xoff;
+       float y=offset.y,xoff;
        ui::setFontSize(14);
        ui::putText(offset.x-SCREEN_WIDTH/2,y,"Inventory:");
        while(item[i].count){
index a089c5fb956c45c47bb0706b1a2bd5b4f2f8c2e4..d6556e332b4e86f94274f1ef7818f516385779cb 100644 (file)
@@ -142,12 +142,13 @@ namespace ui {
                return xo;
        }
        char *typeOut(char *str){
-               static unsigned int sinc,linc,size;
+               static unsigned int sinc,linc,size=0;
                static char *ret = NULL;
                unsigned int i;
-               if(!ret || size != strlen(str)){
+               if(!ret)ret=(char *)calloc(512,sizeof(char));
+               if(size != strlen(str)){
+                       memset(ret,0,512);
                        size=strlen(str);
-                       ret=(char *)calloc(size,sizeof(char));
                        linc=0;
                        sinc=2;
                }
@@ -189,6 +190,7 @@ namespace ui {
        void importantText(const char *text,...){
                va_list textArgs;
                char *ttext;
+               if(!player->ground)return;
                va_start(textArgs,text);
                ttext=(char *)calloc(512,sizeof(char));
                vsnprintf(ttext,512,text,textArgs);
@@ -196,8 +198,8 @@ namespace ui {
                setFontSize(24);
                char *rtext;
                rtext=typeOut(ttext);
-               putString(player->loc.x+player->width/2-SCREEN_WIDTH/2,
-                                 SCREEN_HEIGHT/2+fontSize,
+               putString(offset.x-SCREEN_WIDTH/2,
+                                 offset.y+fontSize,
                                  rtext);
                free(ttext);
        }
@@ -206,7 +208,7 @@ namespace ui {
                if(dialogBoxExists){
                        glColor3ub(0,0,0);
                        x=player->loc.x-SCREEN_WIDTH/2+HLINE*8;
-                       y=SCREEN_HEIGHT-HLINE*8;
+                       y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
                        glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4);
                        char *rtext;
                        rtext=typeOut(dialogBoxText);
@@ -214,14 +216,14 @@ namespace ui {
                        putString(x+HLINE,y-fontSize-HLINE,rtext);
                }
                setFontSize(14);
-               putText(((SCREEN_WIDTH/2)+offset.x)-125,SCREEN_HEIGHT-fontSize,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
+               putText(((SCREEN_WIDTH/2)+offset.x)-125,(offset.y+SCREEN_HEIGHT/2)-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+offset.x)-125,
-                                       SCREEN_HEIGHT-32,
+                                       (offset.y+SCREEN_HEIGHT/2)-32,
                                        ((SCREEN_WIDTH/2+offset.x)-125)+((player->health/player->maxHealth)*100),
-                                       SCREEN_HEIGHT-32+12);
+                                       (offset.y+SCREEN_HEIGHT/2)-32+12);
                }
        }
        void handleEvents(void){
@@ -229,7 +231,7 @@ namespace ui {
                static vec2 premouse={0,0};
                SDL_Event e;
                mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
-               mouse.y=SCREEN_HEIGHT-premouse.y;
+               mouse.y=(offset.y+SCREEN_HEIGHT/2)-premouse.y;
                while(SDL_PollEvent(&e)){
                        switch(e.type){
                        case SDL_QUIT:
@@ -250,7 +252,7 @@ namespace ui {
                        */
                        case SDL_KEYDOWN:
                                if(SDL_KEY==SDLK_ESCAPE)gameRunning=false;                                                      // Exit the game with ESC
-                       if(!dialogBoxExists){
+                       if(!dialogBoxExists&&!fadeEnable){
                                if(SDL_KEY==SDLK_a){                                                                                            // Move left
                                        left=true;
                                        player->vel.x=-.15;
@@ -272,7 +274,7 @@ namespace ui {
                                if(SDL_KEY==SDLK_w)currentWorld=currentWorld->goInsideStructure(player);
                                if(SDL_KEY==SDLK_SPACE){                                                                                        // Jump
                                        if(player->ground){
-                                               player->vel.y=.5;
+                                               player->vel.y=.4;
                                                player->loc.y+=HLINE*2;
                                                player->ground=false;
                                        }
@@ -307,10 +309,10 @@ namespace ui {
                                if(SDL_KEY==SDLK_c){
                                        dialogBox("","You pressed `c`, but nothing happened?");
                                }
-                               if(SDL_KEY==SDLK_p)toggleBlack();
                                if(SDL_KEY==SDLK_LSHIFT)player->speed = debug?4:3;                                                      // Sprint
                                if(SDL_KEY==SDLK_LCTRL)player->speed = .5;
                        }
+                               if(SDL_KEY==SDLK_p)toggleBlack();
                                if(SDL_KEY==SDLK_F3)debug^=true;
                                if(SDL_KEY==SDLK_b & SDL_KEY==SDLK_F3)posFlag^=true;
                                break;
index 0ec0f35ef9bec05fbb08adaec4f5d106efa57fe7..5e7fb41faf143012fee718d6444c4f6e834261ff 100644 (file)
@@ -446,7 +446,7 @@ void World::singleDetect(Entity *e){
                         *      Handle gravity.
                        */
                        
-                       e->vel.y-=.001 * deltaTime;
+                       if(e->vel.y > -2)e->vel.y-=.001 * deltaTime;
                        
                }