//initialize player - more to come, for now just animations void setPlayerSprites() { if (mainPlayer.getCharName().compare("Flu") == 0) { mainPlayer.loadPlayerSprites(6); mainPlayer.getSprites()[0] = SOIL_load_OGL_texture("Textures/Flu.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y); mainPlayer.getSprites()[1] = SOIL_load_OGL_texture("Textures/Fluattack1.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y); mainPlayer.getSprites()[2] = SOIL_load_OGL_texture("Textures/Fluattack2.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y); mainPlayer.getSprites()[3] = SOIL_load_OGL_texture("Textures/Fluattack3.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y); mainPlayer.getSprites()[4] = SOIL_load_OGL_texture("Textures/Fluattack4.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y); mainPlayer.getSprites()[5] = SOIL_load_OGL_texture("Textures/Fluattack5.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y); } }
void drawPlayer() { int x, y, r; //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //get players position x = (int)mainPlayer.getPosition().x; y = (int)mainPlayer.getPosition().y; r = (int)mainPlayer.getRadius(); //start drawing the player glPushMatrix(); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); //for rotation if (wasclicked_RB == true || follow == true) { float PI = (float)3.14159265; float dy, dx; if (follow == true) { dy = (enemy[chase].getPosition().y - y); dx = (enemy[chase].getPosition().x - x); } else { dy = (mouse.y - y); dx = (mouse.x - x); } //find angle of rotation, if dx is 0 then you cant divide by 0 so set angle to 180 if (dx == 0) {} else angle = atan(dy / dx) * 180/PI + 90; //if dx is negative then we have to compensate the angle to go left if (dx < 0) angle += 180; } //draw the player texture glBindTexture(GL_TEXTURE_2D, mainPlayer.getSprites()[player_animation_select]); //translate the player to the origin glTranslatef((GLfloat)x,(GLfloat)y, (GLfloat)0.0f); //rotate player glRotatef(angle,0,0,1); //draw player glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f((GLfloat)(-r), (GLfloat)(r)); glTexCoord2f(1, 0); glVertex2f((GLfloat)(r), (GLfloat)(r)); glTexCoord2f(1, 1); glVertex2f((GLfloat)(r), (GLfloat)(-r)); glTexCoord2f(0, 1); glVertex2f((GLfloat)(-r), (GLfloat)(-r)); glEnd(); glDisable(GL_TEXTURE_2D); //reset the screen so only player rotated glPopMatrix(); //flush the buffer glFlush(); }