From 70eaac72ef917784cba10184a1df7c25d179d541 Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Mon, 25 Jan 2016 08:46:49 -0500 Subject: [PATCH] Menus! --- assets/playerk.png | Bin 485 -> 473 bytes assets/playerk1.png | Bin 0 -> 482 bytes assets/playerk2.png | Bin 0 -> 478 bytes assets/playerk3.png | Bin 0 -> 490 bytes assets/playerk4.png | Bin 0 -> 478 bytes assets/playerk5.png | Bin 0 -> 472 bytes assets/playerk6.png | Bin 0 -> 475 bytes assets/playerk7.png | Bin 0 -> 485 bytes assets/playerk8.png | Bin 0 -> 489 bytes include/common.h | 20 ++++++++- include/ui.h | 41 +++++++++++++++++ main.cpp | 16 ++++++- src/entities.cpp | 27 ++++++------ src/gameplay.cpp | 7 +++ src/ui.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++-- 15 files changed, 194 insertions(+), 21 deletions(-) create mode 100644 assets/playerk1.png create mode 100644 assets/playerk2.png create mode 100644 assets/playerk3.png create mode 100644 assets/playerk4.png create mode 100644 assets/playerk5.png create mode 100644 assets/playerk6.png create mode 100644 assets/playerk7.png create mode 100644 assets/playerk8.png diff --git a/assets/playerk.png b/assets/playerk.png index b51415126af0da3b9140df39a46db6b2801f5210..7abf012dc74b06b722c296d4b4722becf05340ed 100644 GIT binary patch delta 426 zcmV;b0agCx1K9(RIe&{uL_t(&-tCw%PQx%1hJQzFZ~;UoxB(LgsT&9m5G1a^1fmk* z1SG1eGBNc8?G3tj?G0c+;RanBGc*>ll?2C0A$h#FId-1^e0k5$wt%}y%WGww~ZlU2+*RTQL#@OUbR~kAGI<_bwvA1j}sqJlv#c z%4szZQgUHBBH|cyiaqjKT)C1ct4i?yW%04+$tEV~Uk-EqEt5phj6w5DpL)GUCwz`$ zR3X{j7;Ksx*>#Ww{#q?o+2CkFpYL+c5C0T#Q5 UsPgE+6aWAK07*qoM6N<$g2OPzbpQYW delta 438 zcmV;n0ZIPZ1LXsdIe(W)L_t(&-tC#aPQx$|$N!GlU}Hjbf;V6SA+dqr0fNLUFoCE< z`vfGaDwvpf0{RBsyY>xWK;aFt5;HUww$-GzW2(fxlQP)3oG-uJ<@~|mF5FO$H5daC zS}x3$-0kVUk@D;8yAjEt2wIWzMY8n-x0;fZ$oz{0L9muwK7V~Q(%-pA84;|L?ek=j zq9vz%Iw;8{rAA6I=oEXwXR&o95n@Yl^RoCTinxyf&Mrqw?ahmVg&BkTn+|(DuLC}1 z8Ei;)HwJx^3-&)q4z8^hi|liaP5pU2o9PpigXADNNDhWpNv_^*)V4N5cC9GFu4Iqb z%?s%h(`-gxoqrvl>;VAc*%yGneM7P1P}N4Z++OF`B+PVOJTD66{z3c<0Qj8T8?`07 zfv<~egv(^AL?@{CBeY$9a*!PCOeI+*RoP1fP5*zZ$RgD9VsdaDwU`3{=ZneB;q{Ah z^W*&v05D)<06>a9WPQCKn|R``NIdxg03`fDAtc&@4=*c^Jq1b8pQ6ugNVcA!={(Tq gwcGX>%x#o^0rd}?fCffJlmGw#07*qoM6N<$g1AZ3h5!Hn diff --git a/assets/playerk1.png b/assets/playerk1.png new file mode 100644 index 0000000000000000000000000000000000000000..1c4fb490c5338d40ba8f33ec797ec4efe55096c3 GIT binary patch literal 482 zcmV<80UiE{P)v(m3pZ?Y&$%qqbMOY9lBsZTtdG$ZIjFk{9lKqQl8KN1d z`DBohi?SZE_+Ta9V;{w(Gl`b61a~irkAr}k7~uTsb)~*pnkt??X#eSRx7+A|FG+$j zB-`tQO_O804vK*r%f&kSs`{q=y&cUm#bTfsCO)clHh++xPoc#gb4K%|v97i|EnF#4-BhlbiYZU^reFL|lZFGQq^E&ohdBYBSov80{ta Y2l=v#I7*TE>;M1&07*qoM6N<$g0pPmjsO4v literal 0 HcmV?d00001 diff --git a/assets/playerk2.png b/assets/playerk2.png new file mode 100644 index 0000000000000000000000000000000000000000..97f769bbaa7955a3f356cef4cf89e3175eb45cac GIT binary patch literal 478 zcmV<40U`d0P){QzSQ@;8tC7IWnyn34%s)tNFcE{LWb{n4rnFPov)!%{Z;* z-RG-K{eHch`4w}4Tp$<71yY+yE?%#SzP3X4ol#WYTs~=97xF9S z)r`J7J3QJ20ECNA0DtF(>cpYSM^c`z^Lr9uyDwg*Y2o+1@Cg9$F}t<$b9ssHiw!38 zWU5Rjs9y)QQ+_UR9p6DK?fqxDu9hxZ?9VBGRrmH?P-2edgFP}@V zkHr*#{r^tgC+JHgoP7fTB6(McQ@&DOjFC}`bTnv7M2I4YSd5H5>Ghy&F*hB8KiN5y Up((_KxBvhE07*qoM6N<$f*#z?mjD0& literal 0 HcmV?d00001 diff --git a/assets/playerk3.png b/assets/playerk3.png new file mode 100644 index 0000000000000000000000000000000000000000..19b97c44466733cebed624abd9d4a1b5e5245991 GIT binary patch literal 490 zcmV{gpI?4{pZ~Q2_C|(&qDCJG&~g*D zSM&BlEr|DCf~FhQMdpGI?uW}If@ zK}IghJYudvtJ?Ek#g$hQX;leso{A5GfSTyw}4&-pWnFg+Jf)3ors8x8>gpQBr&b}p{x=VFaf zo=lmk1l7;s+busQxQcnusP;CNpjftg%lu5$>~syTwf1=G*UjP6A literal 0 HcmV?d00001 diff --git a/assets/playerk4.png b/assets/playerk4.png new file mode 100644 index 0000000000000000000000000000000000000000..c32a9b387a353a133bd3428480706bc5b611441d GIT binary patch literal 478 zcmV<40U`d0P){ zo9WfTc)TE$sGFSJW2vokQ6P)+-MjV%FraXQuEY$DMPfCP|FueA-?uq&o?m`>&(C%Q+$9bB36C)lq2&^; zeoT-l%E~k*gR;ex@;y((D`qtX*PR~#YsZnLFX8ha#^a6uiq*+KgV|ffT4H+ z0Hheuj=_#CIbHGO7XXmRhYC5>R@_nyB*|JVd((Tvk- zKF-KRS&x`=&?)!GSFyE{D6=KlzbZZm0_kIblk>+?f6Fu#G;>gY(}&^E>wuFafep#- z=AdtKWamK+ur)1K)#sX<`ty1<^C#v2IY17O1Ei)T7q3^vwzficRTSkn=TFwH3;7fC zYDV9k9Ukoh0K&y5fZuaNb>dLfMpEvt^Lr9ux-VX)Y2p4}_yhp>nB5w+bAE~Mi)&2g z$yAw6P`{2op7L8+RW6d92c7@bnUZnMJ(fDw;=gjwSC#TS`2KbS0NB5LF1Fi5kZ{{M$tM%1*hd~ zEXYM-Mod2F4WN@-VcYhF8Ginupzm* zK3F$7Z}T7-_-D0PMxU#1s^6>8Oj}F_l7VC(8R%OjIeWdxx0MsJYekWIGy1shTu56? zry2Ejc5t{200`%w0Dj*M<%>gE8%eRgjlYvH(|hqEO>^VB;S&JhV|s1W&gk|0UaS$G zB~vCULA4)UeC4;2GGC-T=qj$h=VcUIMRR8e_H4<~X{KrvSIl#L0IN0=Ts1+E0|4i1 z7u-94&JDi5U1|Hr>>B_OgvN+s&?)wU&tmINBE^uo8lCVdO<_ZF zb7Qb+a>3R?a&T?ESZ1GVZ0gVJ*-W3993%(HL2@v(PIB>arH-`~vTH|?c60W4)w+;A zF|B6w-Pz&M4gesY{s35=8_E-hvN6(PdmFzeVW#`yS(YjH_u^Lo!1wspXq>Yf_`bM8 zc%Dp|=mhoa=;A5Am6XLI)j?NrjlFQQSdX>N6C?-Mk;NPUIA4a~{^eVpI@bfR@R{JE z4T6fq<39kaU*5hxZxpi7t`C{izvsfizRv`Etr2958Ieu+ognw3jAa!RB#rB0kpG)0 f>@01~?LEPN^{bDH*@BcV00000NkvXXu0mjf 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 #include +#include #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::vectormi); + + /* * Handle keyboard/mouse events. */ diff --git a/main.cpp b/main.cpp index dcfc722..9a71729 100644 --- a/main.cpp +++ b/main.cpp @@ -167,6 +167,8 @@ void mainLoop(void); vec2 offset; /* OFFSET!!!!!!!!!!!!!!!!!!!! */ +std::vectorpauseMenu; + 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::vectorpauseMenu; + +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 AIpreload; diff --git a/src/ui.cpp b/src/ui.cpp index e2cc39f..37c646b 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -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::vectormi){ + 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; -- 2.39.5