]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Fixed the hand angle and made the flashlight, kinda okay
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 5 Nov 2015 14:24:36 +0000 (09:24 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 5 Nov 2015 14:24:36 +0000 (09:24 -0500)
README.md
include/entities.h
main.cpp
src/ui.cpp

index dda1214e9c5b7a84ca12cc5490523904e12c4d3c..858068f1b8fae52e473ca5173418369036ae03a6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
 # gamedev
 
 gamedev is a high school project between drumsetmonkey and tcsullivan written in C++ and using SDL2/OpenGL. The goal of this project is to have a completed commercial-grade video game available to Linux and Windows users. We plan on profiting off of the game once we finish it, so once the game reaches its final stages it may become closed source (however, what was uploaded will stay for others to use as a resource).
+
+Link to story outline: https://docs.google.com/document/d/18cavXmE0MTp2GCAvIABPs61qKblVLSbfOb5zmBXoZJw/edit
\ No newline at end of file
index a9375c31d92bcf5014aaa06585dcf12e032e2fde..422d5d80566deefb32d55fd8c654e7e22573c2d1 100644 (file)
@@ -81,6 +81,7 @@ public:
        QuestHandler qh;
        Player();
        void interact();
+       bool light = false;
 };
 
 class NPC : public Entity{
index cc42acf24079a880e0855f2a963f09ded9bcca4a..30869bff2d727288e616c4a96b65b71a6b56e5ea 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -590,7 +590,7 @@ void render(){
                        offset.x = ((currentWorld->getTheWidth() *  0.5f) - SCREEN_WIDTH / 2) + player->width / 2;
        }
 
-       if(player->loc.y > 300 )
+       if(player->loc.y > SCREEN_HEIGHT/2)
                offset.y = player->loc.y + player->height;
 
        /*
@@ -666,18 +666,18 @@ void render(){
        glBindTexture(GL_TEXTURE_2D,bgDay);
        safeSetColorA(255,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*2);
-               glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2);
+               glTexCoord2i(0,1);glVertex2i(-SCREEN_WIDTH*2+offset.x,0+offset.y-SCREEN_HEIGHT/2);
+               glTexCoord2i(1,1);glVertex2i( SCREEN_WIDTH*2+offset.x,0+offset.y-SCREEN_HEIGHT/2);
+               glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2+offset.y-SCREEN_HEIGHT/2);
+               glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2+offset.y-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*2);
-               glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2);
+               glTexCoord2i(0,1);glVertex2i(-SCREEN_WIDTH*2+offset.x,0+offset.y-SCREEN_HEIGHT/2);
+               glTexCoord2i(1,1);glVertex2i( SCREEN_WIDTH*2+offset.x,0+offset.y-SCREEN_HEIGHT/2);
+               glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2+offset.y-SCREEN_HEIGHT/2);
+               glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2+offset.y-SCREEN_HEIGHT/2);
        glEnd();
 
        glDisable(GL_TEXTURE_2D);
@@ -786,89 +786,97 @@ void render(){
                glUseProgramObjectARB(0);
        #endif //SHADERS
 
-       #define raysSHITUPMYASS
-
-       #ifdef rays
-       //LIGHT
-       vec2 light;
-       int lightStr = 150;
-       vec2 curCoord;
-
-       light.x = 0;
-       light.y = 300;
-
-       std::vector<Ray>ray(180);
-       unsigned int a = 0;
-       float angle = 0;
-
-       glColor3f(0.0f, 0.0f, 0.0f);
-       for(auto &r : ray){
-               r.start = light;
-               curCoord = r.start;
-               angle = 2*a;
-               //for length
-               for(int l = 0;l<=lightStr;l++){
-                       //std::cout << a << ": " << curCoord.x << "," << curCoord.y << "\n";
-                       if(angle == 0){
-                               curCoord.x += HLINE;
-                               curCoord.y += 0;
+       float handAngle;
+       if(player->light){
+               handAngle = atan((ui::mouse.y - (player->loc.y + player->height/2)) / (ui::mouse.x - player->loc.x + player->width/2))*180/PI;
+               if(ui::mouse.x < player->loc.x){
+                       if(handAngle <= 0)
+                               handAngle+=180;
+                       if(ui::mouse.y < player->loc.y + player->height/2){
+                               handAngle+=180;
                        }
-                       if(angle == 90){
-                               curCoord.y += HLINE;
-                               curCoord.x += 0;
-                       }
-                       if(angle == 180){
-                               curCoord.x -= HLINE;
-                               curCoord.y += 0;
-                       }
-                       if(angle == 270){
-                               curCoord.y -= HLINE;
-                               curCoord.x += 0;
-                       }
-                       if(angle == 360){
-                               curCoord.x += HLINE;
-                               curCoord.y += 0;
-                       }else{
-                               curCoord.x += float((HLINE) * cos(angle*PI/180));
-                               curCoord.y += float((HLINE) * sin(angle*PI/180));
-                       }
-                       for(auto &en : entity){
-                               if(curCoord.x > en->loc.x && curCoord.x < en->loc.x + en->width){
-                                       if(curCoord.y > en->loc.y && curCoord .y < en->loc.y + en->height){
-                                               r.end = curCoord;
-                                               l=lightStr;
-                                       }
+               }
+               if(ui::mouse.x > player->loc.x && ui::mouse.y < player->loc.y+player->height/2 && handAngle <= 0) handAngle = 360+handAngle;
+               vec2 light;
+               int lightStr = 150;
+               vec2 curCoord;
+
+               light.x = player->loc.x + player->width;
+               light.y = player->loc.y + player->height/2;
+
+               std::vector<Ray>fray(60);
+               unsigned int a = 0;
+               float angle = 0;
+
+               glColor3f(0.0f, 0.0f, 0.0f);
+
+               for(auto &r : fray){
+                       r.start = light;
+                       curCoord = r.start;
+                       angle = .5*a + handAngle;
+                       //for length
+                       for(int l = 0;l<=lightStr;l++){
+                               //std::cout << a << ": " << curCoord.x << "," << curCoord.y << "\n";
+                               if(angle == 0){
+                                       curCoord.x += HLINE;
+                                       curCoord.y += 0;
                                }
-                       }
-                       if(curCoord.x > player->loc.x && curCoord.x < player->loc.x + player->width){
-                                       if(curCoord.y > player->loc.y && curCoord .y < player->loc.y + player->height){
-                                               r.end = curCoord;
-                                               l=lightStr;
+                               if(angle == 90){
+                                       curCoord.y += HLINE;
+                                       curCoord.x += 0;
+                               }
+                               if(angle == 180){
+                                       curCoord.x -= HLINE;
+                                       curCoord.y += 0;
+                               }
+                               if(angle == 270){
+                                       curCoord.y -= HLINE;
+                                       curCoord.x += 0;
+                               }
+                               if(angle == 360){
+                                       curCoord.x += HLINE;
+                                       curCoord.y += 0;
+                               }else{
+                                       curCoord.x += float((HLINE) * cos(angle*PI/180));
+                                       curCoord.y += float((HLINE) * sin(angle*PI/180));
+                               }
+                               for(auto &en : entity){
+                                       if(curCoord.x > en->loc.x && curCoord.x < en->loc.x + en->width){
+                                               if(curCoord.y > en->loc.y && curCoord .y < en->loc.y + en->height){
+                                                       r.end = curCoord;
+                                                       l=lightStr;
+                                               }
                                        }
-                       }if(l==lightStr)r.end = curCoord;
-               }//end length
-               /*glBegin(GL_LINES);
-                       glVertex2f(r.start.x,r.start.y);
-                       glVertex2f(r.end.x, r.end.y);
-               glEnd();*/
-               //std::cout << angle << "\n";
-               a++;
-       }
-       glUseProgramObjectARB(shaderProgram);
-       glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 640,300);
-       glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1,1,1);
-       glUniform1f(glGetUniformLocation(shaderProgram, "lightStrength"), 5);
-       glColor4f(1.0f, 1.0f, 1.0f, .5f);
-       for(auto r = 0; r < ray.size(); r++){
-               glBegin(GL_TRIANGLES);
-                       glVertex2f(ray[r].start.x, ray[r].start.y);
-                       glVertex2f(ray[r].end.x, ray[r].end.y);
-                       r==ray.size()-1 ? glVertex2f(ray[0].end.x, ray[0].end.y) : glVertex2f(ray[r+1].end.x, ray[r+1].end.y);
-               glEnd();
-       }
-       glUseProgramObjectARB(0);
-       #endif //ray
+                               }
+                               /*if(curCoord.x > player->loc.x && curCoord.x < player->loc.x + player->width){
+                                               if(curCoord.y > player->loc.y && curCoord .y < player->loc.y + player->height){
+                                                       r.end = curCoord;
+                                                       l=lightStr;
+                                               }
+                               }*/if(l==lightStr)r.end = curCoord;
+                       }//end length
+                       glBegin(GL_LINES);
+                               glVertex2f(r.start.x,r.start.y);
+                               glVertex2f(r.end.x, r.end.y);
+                       glEnd();
+                       //std::cout << angle << "\n";
+                       a++;
+               }
 
+               glUseProgramObjectARB(shaderProgram);
+               glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 640,300);
+               glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1,1,1);
+               glUniform1f(glGetUniformLocation(shaderProgram, "lightStrength"), 5);
+               glColor4f(1.0f, 1.0f, 1.0f, .5f);
+               for(auto r = 0; r < fray.size(); r++){
+                       glBegin(GL_TRIANGLES);
+                               glVertex2f(fray[r].start.x, fray[r].start.y);
+                               glVertex2f(fray[r].end.x, fray[r].end.y);
+                               r==fray.size()-1 ? glVertex2f(fray[r].end.x, fray[r].end.y) : glVertex2f(fray[r+1].end.x, fray[r+1].end.y);
+                       glEnd();
+               }
+               glUseProgramObjectARB(0);
+       }
        player->inv->draw();
 
        /*
@@ -887,7 +895,7 @@ void render(){
                
                ui::putText(offset.x-SCREEN_WIDTH/2,
                                        (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: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n     (y)%+.2f\nTc: %u\nQc: %u\n HA: %+.2f",
                                        fps,
                                        player->ground,
                                        SCREEN_WIDTH,                           // Window dimensions
@@ -896,7 +904,8 @@ void render(){
                                        player->loc.x,                          // The player's x coordinate
                                        debugY,                                         // The player's y coordinate
                                        tickCount,
-                                       player->qh.current.size()       // Active quest count
+                                       player->qh.current.size(),      // Active quest count
+                                       handAngle
                                        );
                if(ui::posFlag){
                        glBegin(GL_LINES);
index d6556e332b4e86f94274f1ef7818f516385779cb..7329f6afcafab434addcdb6c6dc4b06ef6fcb7e3 100644 (file)
@@ -326,6 +326,7 @@ namespace ui {
                                if(SDL_KEY==SDLK_LSHIFT)player->speed = 1;
                                if(SDL_KEY==SDLK_LCTRL)player->speed = 1;
                                if(SDL_KEY==SDLK_h)player->health-=5;
+                               if(SDL_KEY==SDLK_f)player->light ^= true;
                                break;
                        default:
                                break;