diff options
-rw-r--r-- | assets/playerk.png | bin | 485 -> 473 bytes | |||
-rw-r--r-- | assets/playerk1.png | bin | 0 -> 482 bytes | |||
-rw-r--r-- | assets/playerk2.png | bin | 0 -> 478 bytes | |||
-rw-r--r-- | assets/playerk3.png | bin | 0 -> 490 bytes | |||
-rw-r--r-- | assets/playerk4.png | bin | 0 -> 478 bytes | |||
-rw-r--r-- | assets/playerk5.png | bin | 0 -> 472 bytes | |||
-rw-r--r-- | assets/playerk6.png | bin | 0 -> 475 bytes | |||
-rw-r--r-- | assets/playerk7.png | bin | 0 -> 485 bytes | |||
-rw-r--r-- | assets/playerk8.png | bin | 0 -> 489 bytes | |||
-rw-r--r-- | include/common.h | 20 | ||||
-rw-r--r-- | include/ui.h | 41 | ||||
-rw-r--r-- | main.cpp | 16 | ||||
-rw-r--r-- | src/entities.cpp | 27 | ||||
-rw-r--r-- | src/gameplay.cpp | 7 | ||||
-rw-r--r-- | src/ui.cpp | 104 |
15 files changed, 194 insertions, 21 deletions
diff --git a/assets/playerk.png b/assets/playerk.png Binary files differindex b514151..7abf012 100644 --- a/assets/playerk.png +++ b/assets/playerk.png diff --git a/assets/playerk1.png b/assets/playerk1.png Binary files differnew file mode 100644 index 0000000..1c4fb49 --- /dev/null +++ b/assets/playerk1.png diff --git a/assets/playerk2.png b/assets/playerk2.png Binary files differnew file mode 100644 index 0000000..97f769b --- /dev/null +++ b/assets/playerk2.png diff --git a/assets/playerk3.png b/assets/playerk3.png Binary files differnew file mode 100644 index 0000000..19b97c4 --- /dev/null +++ b/assets/playerk3.png diff --git a/assets/playerk4.png b/assets/playerk4.png Binary files differnew file mode 100644 index 0000000..c32a9b3 --- /dev/null +++ b/assets/playerk4.png diff --git a/assets/playerk5.png b/assets/playerk5.png Binary files differnew file mode 100644 index 0000000..fabfa60 --- /dev/null +++ b/assets/playerk5.png diff --git a/assets/playerk6.png b/assets/playerk6.png Binary files differnew file mode 100644 index 0000000..269fccb --- /dev/null +++ b/assets/playerk6.png diff --git a/assets/playerk7.png b/assets/playerk7.png Binary files differnew file mode 100644 index 0000000..aeac120 --- /dev/null +++ b/assets/playerk7.png diff --git a/assets/playerk8.png b/assets/playerk8.png Binary files differnew file mode 100644 index 0000000..ff03a02 --- /dev/null +++ b/assets/playerk8.png diff --git a/include/common.h b/include/common.h index 8e08d1d..d0f539b 100644 --- a/include/common.h +++ b/include/common.h @@ -61,6 +61,8 @@ typedef struct { float z; } vec3; +typedef vec2 dim2; + /** * This structure contains two sets of coordinates for ray drawing. */ @@ -70,11 +72,25 @@ typedef struct { vec2 end; } Ray; -typedef struct{ +struct col{ float red; float green; float blue; -} Color; + col operator-=(float a){ + red-=a; + green-=a; + blue-=a; + return *this; + } + col operator+=(float a){ + return{red+a,green+a,blue+a}; + } + col operator=(float a){ + return{red=a,green=a,blue=a}; + } +}; + +typedef col Color; #include <Texture.h> diff --git a/include/ui.h b/include/ui.h index c018008..030c73d 100644 --- a/include/ui.h +++ b/include/ui.h @@ -10,12 +10,42 @@ #include <world.h> #include <ft2build.h> +#include <SDL2/SDL_opengl.h> #include FT_FREETYPE_H #define DEBUG +typedef void(*menuFunc)(); + + +struct menuItem{ + int member; + union{ + + struct{ + vec2 loc; + dim2 dim; + Color color; + const char* text; + menuFunc func; + }button; + + struct{ + vec2 loc; + dim2 dim; + Color color; + float minValue; + float maxValue; + const char* text; + void* var; + }slider; + + }; +}; + namespace ui { + menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f); /** * Contains the coordinates of the mouse inside the window. */ @@ -26,6 +56,8 @@ namespace ui { * These flags are used elsewhere. */ + extern bool pMenu; + extern bool menu; extern bool debug; extern bool posFlag; extern unsigned int fontSize; @@ -83,6 +115,15 @@ namespace ui { void draw(void); + + /* + * Draw various menu items + */ + void quitGame(); + void quitMenu(); + void drawMenu(std::vector<menuItem>mi); + + /* * Handle keyboard/mouse events. */ @@ -167,6 +167,8 @@ void mainLoop(void); vec2 offset; /* OFFSET!!!!!!!!!!!!!!!!!!!! */ +std::vector<menuItem>pauseMenu; + extern WEATHER weather; extern bool fadeEnable; @@ -461,6 +463,8 @@ void mainLoop(void){ prevTime = currentTime; currentTime = millis(); deltaTime = currentTime - prevTime; + + if(ui::menu)goto MENU; /* * Run the logic handler if MSEC_PER_TICK milliseconds have passed. @@ -484,6 +488,8 @@ void mainLoop(void){ */ currentWorld->update(player,deltaTime); + + MENU: /* * Update debug variables if necessary @@ -596,9 +602,7 @@ void render(){ player->near=true; // Draw the player's name - //glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 640,100); currentWorld->draw(player); - //glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0,1.0f,0); /* @@ -741,6 +745,10 @@ void render(){ } + if(ui::menu){ + if(ui::pMenu)ui::drawMenu(pauseMenu); + } + /* * Draw a white triangle as a replacement for the mouse's cursor. */ @@ -986,6 +994,10 @@ void logic(){ else fadeIntensity = 0; } + if(ui::pMenu){ + ui::drawMenu(pauseMenu); + } + /* * Increment a loop counter used for animating sprites. */ diff --git a/src/entities.cpp b/src/entities.cpp index 88ef6b9..8608aeb 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -100,7 +100,15 @@ Player::Player(){ //sets all of the player specific traits on object creation subtype = 0; health = maxHealth = 100; speed = 1; - tex = new Texturec(3, "assets/player1.png", "assets/playerk.png", "assets/player2.png"); + tex = new Texturec(9, "assets/playerk.png", + "assets/playerk1.png", + "assets/playerk2.png", + "assets/playerk3.png", + "assets/playerk4.png", + "assets/playerk5.png", + "assets/playerk6.png", + "assets/playerk7.png", + "assets/playerk8.png"); //tex = new Texturec(3, "assets/maybeplayer.png", "assets/maybeplayer.png", "assets/maybeplayer.png"); inv = new Inventory(PLAYER_INV_SIZE); } @@ -268,18 +276,11 @@ void Entity::draw(void){ //draws the entities switch(type){ case PLAYERT: static int texState = 0; - static bool up = true; - if(speed && !(loops % (int)(4.0f/(float)speed))){ + if(speed && !(loops % (int)(2.0f/(float)speed))){ //currentWorld->addParticle(loc.x,loc.y-HLINE,HLINE,HLINE,0,0,{0.0f,.17f,0.0f},1000); - if(up){ - if(++texState==2)up=false; - glActiveTexture(GL_TEXTURE0); - tex->bindNext(); - }else{ - if(!--texState)up=true; - glActiveTexture(GL_TEXTURE0); - tex->bindPrev(); - } + if(++texState==9)texState=1; + glActiveTexture(GL_TEXTURE0); + tex->bind(texState); } if(!ground){ glActiveTexture(GL_TEXTURE0 + 0); @@ -289,7 +290,7 @@ void Entity::draw(void){ //draws the entities tex->bind(texState); }else{ glActiveTexture(GL_TEXTURE0 + 0); - tex->bind(1); + tex->bind(0); } break; case MOBT: diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 7730cf6..562791d 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -10,6 +10,10 @@ using namespace tinyxml2; extern World *currentWorld; extern Player *player; +extern std::vector<menuItem>pauseMenu; + +extern void mainLoop(void); + typedef struct { NPC *npc; unsigned int index; @@ -211,6 +215,9 @@ void initEverything(void){ currentWorld->bgmPlay(NULL); atexit(destroyEverything); + + pauseMenu.push_back(ui::createButton({-256/2,0},{256,75},{0.0f,0.0f,0.0f}, (const char*)("Resume"), ui::quitMenu)); + pauseMenu.push_back(ui::createButton({-256/2,-100},{256,75},{0.0f,0.0f,0.0f}, (const char*)("Save and Quit"), ui::quitGame)); } extern std::vector<int (*)(NPC *)> AIpreload; @@ -6,6 +6,8 @@ #define SDL_KEY e.key.keysym.sym +extern SDL_Window *window; + /* * External references for updating player coords / current world. */ @@ -76,11 +78,14 @@ namespace ui { */ vec2 mouse; + static vec2 premouse={0,0}; /* * Variety of keydown bools */ bool edown; + bool pMenu = false; + bool menu = false; /* * Debugging flags. @@ -604,6 +609,91 @@ namespace ui { } } } + + void quitGame(){ + if(pMenu)pMenu^=pMenu; + if(menu)menu^=menu; + gameRunning = false; + } + + void quitMenu(){ + if(pMenu)pMenu^=pMenu; + if(menu)menu^=menu; + } + + + menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f){ + menuItem temp; + temp.member = 0; + temp.button.loc = l; + temp.button.dim = d; + temp.button.color = c; + temp.button.text = t; + temp.button.func = f; + return temp; + } + + void drawMenu(std::vector<menuItem>mi){ + SDL_Event e; + + mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2); + mouse.y=(offset.y+SCREEN_HEIGHT/2)-premouse.y; + + while(SDL_PollEvent(&e)){ + switch(e.type){ + case SDL_QUIT: + gameRunning=false; + return; + break; + case SDL_MOUSEMOTION: + premouse.x=e.motion.x; + premouse.y=e.motion.y; + break; + case SDL_KEYUP: + if(SDL_KEY == SDLK_ESCAPE){ + quitMenu(); + return; + } + break; + default:break; + } + } + + glColor4f(0.0f, 0.0f, 0.0f, .8f); + glRectf(offset.x-SCREEN_WIDTH/2,0,offset.x+SCREEN_WIDTH/2,SCREEN_HEIGHT); + for(auto &m : mi){ + if(m.member == 0){ + glColor3f(m.button.color.red,m.button.color.green,m.button.color.blue); + glRectf(offset.x+m.button.loc.x, + offset.y+m.button.loc.y, + offset.x+m.button.loc.x + m.button.dim.x, + offset.y+m.button.loc.y + m.button.dim.y); + putStringCentered(offset.x + m.button.loc.x + (m.button.dim.x/2), (offset.y + m.button.loc.y + (m.button.dim.y/2)) - ui::fontSize/2, m.button.text); + if(mouse.x >= offset.x+m.button.loc.x && mouse.x <= offset.x+m.button.loc.x + m.button.dim.x){ + if(mouse.y >= offset.y+m.button.loc.y && mouse.y <= offset.y+m.button.loc.y + m.button.dim.y){ + + glColor3f(1.0f,1.0f,1.0f); + glBegin(GL_LINE_STRIP); + glVertex2f(offset.x+m.button.loc.x, offset.y+m.button.loc.y); + glVertex2f(offset.x+m.button.loc.x+m.button.dim.x, offset.y+m.button.loc.y); + glVertex2f(offset.x+m.button.loc.x+m.button.dim.x, offset.y+m.button.loc.y+m.button.dim.y); + glVertex2f(offset.x+m.button.loc.x, offset.y+m.button.loc.y+m.button.dim.y); + glVertex2f(offset.x+m.button.loc.x, offset.y+m.button.loc.y); + glEnd(); + + if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) m.button.func(); + } + } + } + } + + /*glColor3ub(255,255,255); + glBegin(GL_TRIANGLES); + glVertex2i(mx ,my ); + glVertex2i(mx+HLINE*3.5,my ); + glVertex2i(mx ,my-HLINE*3.5); + glEnd();*/ + } void dialogAdvance(void){ unsigned char i; if(!typeOutDone){ @@ -630,7 +720,6 @@ DONE: } void handleEvents(void){ static bool left=true,right=false; - static vec2 premouse={0,0}; static int heyOhLetsGo = 0; World *tmp; vec2 oldpos,tmppos; @@ -660,10 +749,11 @@ DONE: KEYDOWN */ case SDL_KEYDOWN: - if(SDL_KEY == SDLK_ESCAPE){ - gameRunning = false; + /*if(SDL_KEY == SDLK_ESCAPE){ + //gameRunning = false; + pMenu = true; return; - }else if(SDL_KEY == SDLK_SPACE){ + }else */if(SDL_KEY == SDLK_SPACE){ /*if(dialogBoxExists) dialogAdvance(); else */if(player->ground){ @@ -794,6 +884,12 @@ DONE: */ case SDL_KEYUP: + if(SDL_KEY == SDLK_ESCAPE){ + //gameRunning = false; + pMenu = true; + menu = true; + return; + } switch(SDL_KEY){ case SDLK_a: left = false; |