float z;
} vec3;
+typedef vec2 dim2;
+
/**
* This structure contains two sets of coordinates for ray drawing.
*/
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>
#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.
*/
* These flags are used elsewhere.
*/
+ extern bool pMenu;
+ extern bool menu;
extern bool debug;
extern bool posFlag;
extern unsigned int fontSize;
void draw(void);
+
+ /*
+ * Draw various menu items
+ */
+ void quitGame();
+ void quitMenu();
+ void drawMenu(std::vector<menuItem>mi);
+
+
/*
* Handle keyboard/mouse events.
*/
vec2 offset; /* OFFSET!!!!!!!!!!!!!!!!!!!! */
+std::vector<menuItem>pauseMenu;
+
extern WEATHER weather;
extern bool fadeEnable;
prevTime = currentTime;
currentTime = millis();
deltaTime = currentTime - prevTime;
+
+ if(ui::menu)goto MENU;
/*
* Run the logic handler if MSEC_PER_TICK milliseconds have passed.
*/
currentWorld->update(player,deltaTime);
+
+ MENU:
/*
* Update debug variables if necessary
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);
/*
}
+ if(ui::menu){
+ if(ui::pMenu)ui::drawMenu(pauseMenu);
+ }
+
/*
* Draw a white triangle as a replacement for the mouse's cursor.
*/
else fadeIntensity = 0;
}
+ if(ui::pMenu){
+ ui::drawMenu(pauseMenu);
+ }
+
/*
* Increment a loop counter used for animating sprites.
*/
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);
}
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);
tex->bind(texState);
}else{
glActiveTexture(GL_TEXTURE0 + 0);
- tex->bind(1);
+ tex->bind(0);
}
break;
case MOBT:
extern World *currentWorld;
extern Player *player;
+extern std::vector<menuItem>pauseMenu;
+
+extern void mainLoop(void);
+
typedef struct {
NPC *npc;
unsigned int index;
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;
#define SDL_KEY e.key.keysym.sym
+extern SDL_Window *window;
+
/*
* External references for updating player coords / current world.
*/
*/
vec2 mouse;
+ static vec2 premouse={0,0};
/*
* Variety of keydown bools
*/
bool edown;
+ bool pMenu = false;
+ bool menu = false;
/*
* Debugging flags.
}
}
}
+
+ 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){
}
void handleEvents(void){
static bool left=true,right=false;
- static vec2 premouse={0,0};
static int heyOhLetsGo = 0;
World *tmp;
vec2 oldpos,tmppos;
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){
*/
case SDL_KEYUP:
+ if(SDL_KEY == SDLK_ESCAPE){
+ //gameRunning = false;
+ pMenu = true;
+ menu = true;
+ return;
+ }
switch(SDL_KEY){
case SDLK_a:
left = false;