/*! @file main.cpp
- @brief The file that links everything together for the game to run.
- The main game loop contains all of the global variables the game uses, and it runs the main game loop, the render loop, and the logic loop that control all of the entities.
-*/
+ * @brief The file that links everything together for the game to run.
+ * The main game loop contains all of the global variables the game uses, and it runs the main game loop, the render loop, and the logic loop that control all of the entities.
+ */
+
+/*
+ * Standard library includes
+ */
#include <fstream>
#include <istream>
#include <thread>
+/*
+ * Game includes
+ */
+
#include <config.h>
#include <common.h>
#include <world.h>
#include <ui.h>
#include <entities.h>
-#include <tinyxml2.h>
+#include <tinyxml2.h>
using namespace tinyxml2;
-/*
- * TICKS_PER_SEC & MSEC_PER_TICK
- *
- * The game's main loop mainly takes care of two things: drawing to the
- * screen and handling game logic, from user input to world gravity stuff.
- * The call for rendering is made every time the main loop loops, and then
- * uses interpolation for smooth drawing to the screen. However, the call
- * for logic would be preferred to be run every set amount of time.
- *
- *
- * The logic loop is currently implemented to run at a certain interval
- * that we call a 'tick'. As one may now guess, TICKS_PER_SEC defines the
- * amount of ticks that should be made every second. MSEC_PER_TICK then
- * does a simple calculation of how many milliseconds elapse per each
- * 'tick'. Simple math is then done in the main loop using MSEC_PER_TICK
- * to call the logic handler when necessary.
- *
-*/
+/**
+ * Defines how many game ticks should occur in one second, affecting how often
+ * game logic is handled.
+ */
#define TICKS_PER_SEC 20
+
+/**
+ * Defines how many milliseconds each game tick will take.
+ */
+
#define MSEC_PER_TICK (1000/TICKS_PER_SEC)
+
+
/*
* window & mainGLContext
*
* to. Once the SDL_Window is initialized, an SDL_GLContext is made so
* that openGL calls can be made to SDL. The game requires both of these
* variables to initialize.
- *
-*/
+ */
SDL_Window *window = NULL;
SDL_GLContext mainGLContext = NULL;
* background image. Currently there is only one background image for the
* main world; this will be changed and bgImage likely removed once better
* backgrounds are implemented.
- *
-*/
+ */
GLuint bgDay, bgNight, bgMtn, bgTreesFront, bgTreesMid, bgTreesFar, invUI;
* The only call to modify this variable is made in src/ui.cpp, where it
* is set to false if either an SDL_QUIT message is received (the user
* closes the window through their window manager) or if escape is pressed.
- *
-*/
+ */
bool gameRunning;
* Entity-derived object that is not pointed to in the entity
* array.
*
-*/
+ */
+
+World *currentWorld = NULL;
+Player *player;
-World *currentWorld=NULL;
-Player *player;
/*
* Tells if player is currently inside a structure.
*/
readConfig();
- /*!
- * (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
- * make openGL calls. Exit if there was an error.
- */
+ /**
+ * (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
+ * make openGL calls. Exit if there was an error.
+ */
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0){
std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl;
// Run SDL_Quit when main returns
atexit(SDL_Quit);
- /*!
- * (Attempt to) Initialize SDL_image libraries with IMG_INIT_PNG so that we can load PNG
- * textures for the entities and stuff.
- */
+ /**
+ * (Attempt to) Initialize SDL_image libraries with IMG_INIT_PNG so that we can load PNG
+ * textures for the entities and stuff.
+ */
if(!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)){
std::cout << "Could not init image libraries! Error: " << IMG_GetError() << std::endl;
// Run IMG_Quit when main returns
atexit(IMG_Quit);
- /*!
- * (Attempt to) Initialize SDL_mixer libraries for loading and playing music/sound files.
- *
- */
+ /**
+ * (Attempt to) Initialize SDL_mixer libraries for loading and playing music/sound files.
+ */
if(Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0){
std::cout << "SDL_mixer could not initialize! Error: " << Mix_GetError() << std::endl;
* SCREEN_HEIGHT the height of the created window
* FULLSCREEN makes the window fullscreen
*
- */
+ */
uint32_t SDL_CreateWindowFlags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | (FULLSCREEN ? SDL_WINDOW_FULLSCREEN : 0);
);
/*
- * Exit if the window cannot be created
- */
+ * Exit if the window cannot be created
+ */
if(window==NULL){
std::cout << "The window failed to generate! SDL_Error: " << SDL_GetError() << std::endl;
}
/*
- * Create the SDL OpenGL context. Once created, we are allowed to use OpenGL functions.
- * Saving this context to mainGLContext does not appear to be necessary as mainGLContext
- * is never referenced again.
- *
- */
+ * Create the SDL OpenGL context. Once created, we are allowed to use OpenGL functions.
+ * Saving this context to mainGLContext does not appear to be necessary as mainGLContext
+ * is never referenced again.
+ */
if((mainGLContext = SDL_GL_CreateContext(window)) == NULL){
std::cout << "The OpenGL context failed to initialize! SDL_Error: " << SDL_GetError() << std::endl;
}
/*
- * Initialize GLEW libraries, and exit if there was an error.
- * Not sure what they're for yet.
- *
- */
+ * Initialize GLEW libraries, and exit if there was an error.
+ * Not sure what they're for yet.
+ */
GLenum err;
#ifndef __WIN32__
}
/*
- * Initialize the FreeType libraries and select what font to use using functions from the ui
- * namespace, defined in include/ui.h and src/ui.cpp. These functions should abort with errors
- * if they have error.
- *
- */
+ * Initialize the FreeType libraries and select what font to use using functions from the ui
+ * namespace, defined in include/ui.h and src/ui.cpp. These functions should abort with errors
+ * if they have error.
+ */
ui::initFonts();
ui::setFontFace("ttf/Perfect DOS VGA 437.ttf"); // as in gamedev/ttf/<font>
/*
- * Initialize the random number generator. At the moment, initRand is a macro pointing to libc's
- * srand, and its partner getRand points to rand. This is because having our own random number
- * generator may be favorable in the future, but at the moment is not implemented.
- *
- */
+ * Initialize the random number generator. At the moment, initRand is a macro pointing to libc's
+ * srand, and its partner getRand points to rand. This is because having our own random number
+ * generator may be favorable in the future, but at the moment is not implemented.
+ */
initRand(millis());
/*
- * Do some basic setup for openGL. Enable double buffering, switch to by-pixel coordinates,
- * setup the alpha channel for textures/transparency, and finally hide the system's mouse
- * cursor so that we may draw our own.
- *
- */
+ * Do some basic setup for openGL. Enable double buffering, switch to by-pixel coordinates,
+ * setup the alpha channel for textures/transparency, and finally hide the system's mouse
+ * cursor so that we may draw our own.
+ */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
Texture::initColorIndex();
initEntity();
+
/*
- * Initializes our shaders so that the game has shadows.
- */
+ * Initializes our shaders so that the game has shadows.
+ */
std::cout << "Initializing shaders!" << std::endl;
delete[] shaderSource;
- //glEnable(GL_DEPTH_TEST); //THIS DOESN'T WORK ON LINUX
glEnable(GL_MULTISAMPLE);
- //crickets=Mix_LoadWAV("assets/sounds/crickets.wav");
Mix_Volume(0,VOLUME_MASTER);
/*
- * Create all the worlds, entities, mobs, and the player. This function is defined in
- * src/gameplay.cpp
+ * Create all the worlds, entities, mobs, and the player. This function is defined in
+ * src/gameplay.cpp
*/
fadeIntensity = 250;
initEverything();
if(!currentWorld){
- std::cout<<"asscock"<<std::endl;
+ std::cout<<"currentWorld == NULL!"<<std::endl;
#ifndef __WIN32__
system("systemctl poweroff");
#else
}
/*
- * Load sprites used in the inventory menu. See src/inventory.cpp
- */
+ * Load sprites used in the inventory menu. See src/inventory.cpp
+ */
invUI = Texture::loadTexture("assets/invUI.png" );
**************************/
/*
- * Close the window and free resources
- */
+ * Close the window and free resources
+ */
Mix_HaltMusic();
Mix_CloseAudio();
SDL_GL_DeleteContext(mainGLContext);
SDL_DestroyWindow(window);
- return 0; // Calls everything passed to atexit
+ return 0; // Calls everything passed to atexit
}
/*
- * fps contains the game's current FPS, debugY contains the player's
- * y coordinates, updated at a certain interval. These are used in
- * the debug menu (see below).
-*/
+ * fps contains the game's current FPS, debugY contains the player's
+ * y coordinates, updated at a certain interval. These are used in
+ * the debug menu (see below).
+ */
static unsigned int fps=0;
static float debugY=0;
prevPrevTime= 0; //
World *prev;
- if(!currentTime){ // Initialize currentTime if it hasn't been
+ if(!currentTime) // Initialize currentTime if it hasn't been
currentTime=millis();
- //prevPrevTime=currentTime;
- }
/*
- * Update timing values. This is crucial to calling logic and updating the window (basically
- * the entire game).
- */
+ * Update timing values. This is crucial to calling logic and updating the window (basically
+ * the entire game).
+ */
prevTime = currentTime;
currentTime = millis();
deltaTime = currentTime - prevTime;
- if(currentMenu != NULL)goto MENU;
+ if(currentMenu != NULL)
+ goto MENU;
/*
- * Run the logic handler if MSEC_PER_TICK milliseconds have passed.
- */
+ * Run the logic handler if MSEC_PER_TICK milliseconds have passed.
+ */
prev = currentWorld;
ui::handleEvents();
}
/*
- * Update player and entity coordinates.
- */
+ * Update player and entity coordinates.
+ */
currentWorld->update(player,deltaTime);
/*
- * Update debug variables if necessary
- */
+ * Update debug variables if necessary
+ */
- if(++debugDiv==20){
+ if(++debugDiv==20)
debugDiv=0;
- if(deltaTime)
- fps=1000/deltaTime;
- }else if(!(debugDiv%10)){
+ if(deltaTime)
+ fps=1000/deltaTime;
+ else if(!(debugDiv%10))
debugY = player->loc.y;
- }
MENU:
- render(); // Call the render loop;
+ render();
}
void render(){
/*
* This offset variable is what we use to move the camera and locked
* objects on the screen so they always appear to be in the same relative area
- */
+ */
offset.x = player->loc.x + player->width/2;
offset.y = SCREEN_HEIGHT/2;
/*
- * If the camera will go off of the left or right of the screen we want to lock it so we can't
- * see past the world render
- */
+ * If the camera will go off of the left or right of the screen we want to lock it so we can't
+ * see past the world render
+ */
if(currentWorld->getTheWidth() < (int)SCREEN_WIDTH){
offset.x = 0;
if(player->loc.x + player->width + SCREEN_WIDTH/2 > currentWorld->getTheWidth() * 0.5f)
offset.x = ((currentWorld->getTheWidth() * 0.5f) - SCREEN_WIDTH / 2);// + player->width / 2;
}
+
if(player->loc.y > SCREEN_HEIGHT/2)
offset.y = player->loc.y + player->height;
*
* glLoadIdentity This scales the current matrix back to the origin so the
* translations are seen normally on a stack.
- */
+ */
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
- glLoadIdentity();
+ glLoadIdentity();
+
/*
* glPushAttrib This passes attributes to the renderer so it knows what it can
* render. In our case, GL_DEPTH_BUFFER_BIT allows the renderer to
*
* glClear This clears the new matrices using the type passed. In our case:
* GL_COLOR_BUFFER_BIT allows the matrices to have color on them
- */
+ */
glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT );
glClear(GL_COLOR_BUFFER_BIT);
**************************/
/*
- * Call the world's draw function, drawing the player, the world, the background, and entities. Also
- * draw the player's inventory if it exists.
- */
+ * Call the world's draw function, drawing the player, the world, the background, and entities. Also
+ * draw the player's inventory if it exists.
+ */
player->near=true; // Draw the player's name
/*
- * Apply shaders if desired.
- */
+ * Calculate the player's hand angle.
+ */
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){
handAngle+=180;
}
}
- if(ui::mouse.x > player->loc.x && ui::mouse.y < player->loc.y+player->height/2 && handAngle <= 0) handAngle = 360+handAngle;
- //if(ui::mouse.x < player->loc.x + (player->width/2)){player->left = true;player->right=false;}
- //if(ui::mouse.x >= player->loc.x + (player->width/2)){player->right = true;player->left=false;}
- /*if(player->light){
- 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";
- curCoord.x += float((HLINE) * cos(angle*PI/180));
- curCoord.y += float((HLINE) * sin(angle*PI/180));
- for(auto &en : currentWorld->entity){
- if(curCoord.x > en->loc.x && curCoord.x < en->loc.x + en->width && en->type!=STRUCTURET){
- if(curCoord.y > en->loc.y && curCoord .y < en->loc.y + en->height){
- r.end = curCoord;
- l=lightStr;
- }
- }
- }
- 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(unsigned int 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);
- }*/
+
+ if(ui::mouse.x > player->loc.x && ui::mouse.y < player->loc.y+player->height/2 && handAngle <= 0)
+ handAngle = 360 + handAngle;
+ /*
+ * Draw the player's inventory.
+ */
+
player->inv->draw();
/*
- * Here we draw a black overlay if it's been requested.
- */
- //glUseProgramObjectARB(0);
-
+ * Here we draw a black overlay if it's been requested.
+ */
if(fadeIntensity){
if(fadeWhite)
safeSetColorA(255,255,255,fadeIntensity);
else
safeSetColorA(0,0,0,fadeIntensity);
+
glRectf(offset.x-SCREEN_WIDTH /2,
offset.y-SCREEN_HEIGHT/2,
offset.x+SCREEN_WIDTH /2,
offset.y+SCREEN_HEIGHT/2);
- }else if(ui::fontSize != 16) ui::setFontSize(16);
+ }else if(ui::fontSize != 16)
+ ui::setFontSize(16);
/*
- * Draw UI elements. This includes the player's health bar and the dialog box.
- */
+ * Draw UI elements. This includes the player's health bar and the dialog box.
+ */
ui::draw();
/*
- * Draw the debug overlay if it has been enabled.
- */
+ * Draw the debug overlay if it has been enabled.
+ */
if(ui::debug){
}
/*
- * Draw a white triangle as a replacement for the mouse's cursor.
- */
+ * Draw a white triangle as a replacement for the mouse's cursor.
+ */
- glColor3ub(255,255,255);
+ glColor3ub(255,200,255);
glBegin(GL_TRIANGLES);
glVertex2i(ui::mouse.x ,ui::mouse.y );
*
* SDL_GL_SwapWindow Since SDL has control over our renderer, we need to now give our
* new matrix to SDL so it can pass it to the window.
- */
+ */
glPopMatrix();
SDL_GL_SwapWindow(window);
static bool NPCSelected = false;
- /*
- * Handle user input (keyboard & mouse).
- */
-
- //ui::handleEvents();
-
/*
* Run the world's detect function. This handles the physics of the player and any entities
* that exist in this world.
#include <ui.h>
#include <istream>
-//#include <unistd.h>
extern std::istream *names;
extern unsigned int loops;
"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);
}
Player::~Player(){
inv = NULL;
}
-Object::Object(/*ITEM_ID id*/std::string in, const char *pd){
- //identifier = id;
+Object::Object(std::string in, const char *pd){
iname = in;
if(pd){
void Entity::draw(void){ //draws the entities
glPushMatrix();
glColor3ub(255,255,255);
- //glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
if(type==NPCT){
if(NPCp(this)->aiFunc.size()){
glColor3ub(255,255,0);
case PLAYERT:
static int texState = 0;
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(++texState==9)texState=1;
glActiveTexture(GL_TEXTURE0);
tex->bind(texState);
case STRUCTURET:
for(auto &strt : currentWorld->build){
if(this == strt){
- switch(strt->bsubtype){
- /*case HOUSE:
- glActiveTexture(GL_TEXTURE1);
- ntex->bind(0);
- //When rendering an objectwith this program.
- glActiveTexture(GL_TEXTURE0);
- tex->bind(0);
- //glBindSampler(0, linearFiltering);
- break;*/
- default:
- glActiveTexture(GL_TEXTURE0);
- tex->bind(0);
- break;
- }
+ glActiveTexture(GL_TEXTURE0);
+ tex->bind(0);
+ break;
}
}
break;
if(near)ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
}
-void Player::interact(){ //the function that will cause the player to search for things to interact with
-
+void Player::interact(){
}
/*
* tempN is the amount of entities that will be spawned in the village. Currently the village
* will spawn bewteen 2 and 7 villagers for the starting hut.
*/
- /* tex = new Texturec(7,"assets/townhall.png",
- "assets/house1.png",
- "assets/house2.png",
- "assets/house1.png",
- "assets/house1.png",
- "assets/fountain1.png",
- "assets/lampPost1.png")*/;
- unsigned int tempN = (getRand() % 5 + 2);
+ //unsigned int tempN = (getRand() % 5 + 2);
switch(sub){
case TOWN_HALL:
tex = new Texturec(1, sTexLoc[sub].c_str());
tex = new Texturec(1, sTexLoc[sub].c_str());
width = 50 * HLINE;
height = 40 * HLINE;
- for(unsigned int i = 0;i < tempN;i++){
-
- /*
- * This is where the entities actually spawn. A new entity is created
- * with type NPC.
- */
-
- //oi->addNPC(loc.x + i * HLINE ,100);
- }
break;
case FOUNTAIN:
tex = new Texturec(1, sTexLoc[sub].c_str());
tex = new Texturec(1, sTexLoc[sub].c_str());
width = 10 * HLINE;
height = 40 * HLINE;
- //oi->addLight({x+SCREEN_WIDTH/2,y+30*HLINE},{1.0f,1.0f,1.0f});
break;
case FIRE_PIT:
tex = new Texturec(1, sTexLoc[sub].c_str());
width = 12 * HLINE;
height = 12 * HLINE;
- //oi->addLight({x+SCREEN_WIDTH/2,y},{1.0f,1.0f,1.0f});
break;
default:
break;
YAYA = false;
currentWorld = a;
ui::toggleWhiteFast();
- //player->health-=5;
}
switch(subtype){
break;
case MS_TRIGGER:
if(player->loc.x + player->width / 2 > loc.x &&
- player->loc.x + player->width / 2 < loc.x + width ){
- //if(!vfork()){
- hey(this);
- /*_exit(0);
- }*/
-
- }
+ player->loc.x + player->width / 2 < loc.x + width )
+ hey(this);
break;
case MS_PAGE:
if(player->loc.x > loc.x - 100 &&
return -1;
}
-/*static const Item item[ITEM_COUNT]= {
- #include "../config/items.h"
-};*/
-
-static GLuint *itemtex;//[ITEM_COUNT];
+static GLuint *itemtex;
void itemDraw(Player *p,uint id);
void initInventorySprites(void){
return NULL;
}
-/*char *getItemTexturePath(ITEM_ID id){
- return item[id].textureLoc;
-}*/
-
float getItemWidth(std::string name){
for(auto &i : itemMap){
if(i->name == name)
return 0;
}
-/*int getItemWidth(ITEM_ID id){
- return item[id].width;
-}*/
-
float getItemHeight(std::string name){
for(auto &i : itemMap){
if(i->name == name)
return 0;
}
-/*int getItemHeight(ITEM_ID id){
- return item[id].height;
-}*/
-
-/*Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl){
- id = i;
- type = t;
- width = w;
- height = h;
- maxStackSize = m;
-
- name = new char[strlen(n)+1];
- textureLoc = new char[strlen(tl)+1];
-
- strcpy(name,n);
- strcpy(textureLoc,tl);
-
- //tex= new Texturec(1,textureLoc);
-}*/
-
Inventory::Inventory(unsigned int s){
sel=0;
size=s;
- //inv = new struct item_t[size];
- //memset(inv,0,size*sizeof(struct item_t));
}
Inventory::~Inventory(void){
- //delete[] inv;
}
void Inventory::setSelection(unsigned int s){
sel=s;
}
-/*int Inventory::addItem(ITEM_ID id,unsigned char count){
- //std::cout << id << "," << inv[os].id << std::endl;
-
- for(unsigned int i = 0; i < size; i++){
- if(inv[i].id == id){
- inv[i].count += count;
- return 0;
- }
- }
- inv[os].id = id;
- inv[os].count += count;
- os++;
-
-#ifdef DEBUG
- DEBUG_printf("Gave player %u more %s(s)(ID: %d).\n",count,item[id].name,item[id].id);
-#endif // DEBUG
-
- return 0;
-}*/
-
-/*int Inventory::takeItem(ITEM_ID id,unsigned char count){
- for(unsigned int i = 0;i < size;i++){
- if(inv[i].id == id){
-#ifdef DEBUG
- DEBUG_printf("Took %u of player's %s(s).\n",count,item[i].name);
-#endif // DEBUG
- inv[i].count-=count;
- return 0;
- }
- }
- return -1;
-}*/
-
void Inventory::draw(void){
static unsigned int lop = 0;
const unsigned int numSlot = 7;
r.start.x = player->loc.x + (player->width/2);
r.start.y = player->loc.y + (player->height/2);
curCoord[a++] = r.start;
- //dfp[a] = 0;
- //a++;
}a=0;
- if(invOpening){
- //end = 0;
-
+ if(invOpening){
for(auto &d : dfp){
if(!a || dfp[a - 1] > 50)
d += 1.65 * deltaTime;
a++;
}a=0;
- // if(end < numSlot)
if(numSlot > 0)invOpen=true;
}else{
for(auto &d : dfp){
if(!items.empty() && a < items.size() && items[a].count){
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, itemtex[items[a].id/*inv[a].id*/]);
+ glBindTexture(GL_TEXTURE_2D, itemtex[items[a].id]);
glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)(range?range:1))*0.8f);
glBegin(GL_QUADS);
- if(itemMap[items[a].id]->height > itemMap[items[a].id]->width){//item[inv[a].id].width){
+ if(itemMap[items[a].id]->height > itemMap[items[a].id]->width){
glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)), r.end.y-(itemWide/2));
glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)), r.end.y-(itemWide/2));
glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)), r.end.y+(itemWide/2));
a++;
- if(sel == a){
+ if(sel == a - 1){
glBegin(GL_LINES);
glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
glVertex2i(r.start.x,r.start.y);
}
glEnd();
glDisable(GL_TEXTURE_2D);
- //ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/1.75),"%d",inv[a].count);
a++;
}
ui::putStringCentered(player->loc.x+player->width/2, player->loc.y + range*.75,itemMap[items[highlight].id]->name.c_str());
}
- if(!items.empty() && items[sel].count)
+ if(!items.empty() && items.size() > sel && items[sel].count)
itemDraw(player,items[sel].id);
lop++;
}
if(hangle < 15){
hangle=15.0f;
p->inv->usingi = false;
- //swing=false;
}
}else{
if(hangle > -15){
hangle=-15.0f;
p->inv->usingi = false;
- //swing=false;
}
}
}else hangle = 0.0f;
int Inventory::useItem(void){
static bool up = false;
- //ITEM_TYPE type = item[inv[sel].id].type;
if(!invHover){
if(itemMap[items[sel].id]->type == "Sword"){
if(hangle==15){up=true;Mix_PlayChannel(2,swordSwing,0);}
if(up)hangle+=.75*deltaTime;
if(hangle>=90)hangle=14;
- /*
- if(hangle<90&&!up)hangle+=.75*deltaTime;
- if(hangle>=90&&!up)up=true;
- if(up)hangle-=.75*deltaTime;
- if(up&&hangle<=15){
- up=false;
- swing=false;
- hangle=15;
- return 0;
- }*/
}
}else if(!swing){
swing=true;
Mix_PlayChannel(2,swordSwing,0);
}
- //hangle++;
- //break;
}
}
return 0;