aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2016-01-25 08:46:49 -0500
committerdrumsetmonkey <abelleisle@roadrunner.com>2016-01-25 08:46:49 -0500
commit70eaac72ef917784cba10184a1df7c25d179d541 (patch)
treeeeaccf047e920f8e127799ce0db9699ce10daa1f /src
parent9c3e9dccdbb5804b47a3ecd5ca50ca3d424dab21 (diff)
Menus!
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp27
-rw-r--r--src/gameplay.cpp7
-rw-r--r--src/ui.cpp104
3 files changed, 121 insertions, 17 deletions
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;
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::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;