From e017c5cbc9f1cf357ca82593e5d2829dd7f729ce Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 26 Oct 2015 08:49:10 -0400 Subject: bug fixes --- main.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 25 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index e43029a..8e67d8e 100644 --- a/main.cpp +++ b/main.cpp @@ -173,16 +173,6 @@ unsigned int millis(void){ * MAIN ************************************************************************ *******************************************************************************/ int main(int argc, char *argv[]){ - /* - * Initialize GLEW libraries, and exit if there was an error. - * Not sure what they're for yet. - * - */ - - if(glewInit() < 0){ - std::cout << "GLEW was not able to initialize! Error: " << std::endl; - return -1; - } /* * (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually @@ -267,6 +257,19 @@ int main(int argc, char *argv[]){ return -1; } + /* + * Initialize GLEW libraries, and exit if there was an error. + * Not sure what they're for yet. + * + */ + + GLenum err; + glewExperimental = GL_TRUE; + if((err=glewInit()) != GLEW_OK){ + std::cout << "GLEW was not able to initialize! Error: " << glewGetErrorString(err) << std::endl; + return -1; + } + /* * 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 @@ -303,22 +306,21 @@ int main(int argc, char *argv[]){ SDL_ShowCursor(SDL_DISABLE); /* - * TODO - Initialize shaders n' stuff + * Initializes our shaders so that the game has shadows. */ - /* - - GLuint fragShader; + /*GLuint fragShader; GLuint shaderProgram; const GLchar *shaderSource = "shader.frag"; - GLint bufferln = GL_FALSE; + GLint bufferln = GL_FALSE; - shaderProgram = glCreateProgram(); fragShader = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(fragShader, 1, &shaderSource, NULL); glCompileShader(fragShader); + + shaderProgram = glCreateProgram(); + glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bufferln); if(bufferln == GL_TRUE){ @@ -329,10 +331,8 @@ int main(int argc, char *argv[]){ glLinkProgram(shaderProgram); glValidateProgram(shaderProgram); - //glEnable(GL_DEPTH_TEST); - //glEnable(GL_MULTISAMPLE); - - */ + glEnable(GL_DEPTH_TEST); + glEnable(GL_MULTISAMPLE);*/ /* * Open the names file containing potential names for NPCs and store it in the names file @@ -628,6 +628,14 @@ void render(){ } void logic(){ + + /* + * NPCSelected is used to insure that only one NPC is made interactable with the mouse + * if, for example, multiple entities are occupying one space. + */ + + static bool NPCSelected = false; + /* * Handle user input (keyboard & mouse). */ @@ -647,10 +655,11 @@ void logic(){ * click detection is done as well for NPC/player interaction. * */ - //std::cout << "Game Loop: "<< loops << std::endl; for(unsigned int i=0;ialive)std::cout<<"Entity "<canMove) NPCp(entity[i])->wander((rand() % 120 + 30), &entity[i]->vel); + /* + * Don't bother handling the NPC if another has already been handled. + */ + + if(NPCSelected){ + entity[i]->near=false; + break; + } + /* * Check if the NPC is under the mouse. */ @@ -698,10 +716,12 @@ void logic(){ if(pow((entity[i]->loc.x - player->loc.x),2) + pow((entity[i]->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){ /* - * Set Entity->near so that this NPC's name is drawn under them. + * Set Entity->near so that this NPC's name is drawn under them, and toggle NPCSelected + * so this NPC is the only one that's clickable. */ entity[i]->near=true; + NPCSelected=true; /* * Check for a right click, and allow the NPC to interact with the @@ -729,8 +749,13 @@ void logic(){ /* * Run the Mob's AI function. */ - - Mobp(entity[i])->wander((rand()%240 + 15),&entity[i]->vel); // Make the mob wander + + switch(entity[i]->subtype){ + case MS_RABBIT: + case MS_BIRD: + Mobp(entity[i])->wander((rand()%240 + 15)); // Make the mob wander + break; + } break; // End case MOBT @@ -745,4 +770,5 @@ void logic(){ */ loops++; + NPCSelected=false; } -- cgit v1.2.3