#include "playership.h" #include "spaceship.h" #include "input.h" #include "camera.h" #include "world.h" #include "game.h" #include "sound.h" #include //! initialize singleton static variable PlayerShip *PlayerShip::s_pPlayer = NULL; PlayerShip::PlayerShip() : Spaceship(PLAYER) { _scope.LoadTIFF("scope.tif"); _scope.InitTextureParams(false); _cockpit.LoadTIFF("cockpit.tif"); _cockpit.InitTextureParams(false); _flashcount = 0; _flash = false; } typedef struct materialStruct { GLfloat ambient[4]; GLfloat diffuse[4]; GLfloat specular[4]; GLfloat shininess; } materialStruct; materialStruct brassMaterials = { {0.33, 0.22, 0.03, 1.0}, {0.78, 0.57, 0.11, 1.0}, {0.99, 0.91, 0.81, 1.0}, 27.8 }; materialStruct redPlasticMaterials = { {0.3, 0.0, 0.0, 1.0}, {0.6, 0.0, 0.0, 1.0}, {1.0, 1.0, 1.0, 1.0}, 32.0 }; void PlayerShip::Render() { glPushMatrix(); // update ships position //Math3d::M3d loc = Math3d::M3d(0.0,0.0,0.0); //loc += position; // loc -= direction * 5.0; // loc += hover; //glLoadIdentity(); //cout << axis << endl; //cout << loc << endl; Math3d::M3d direction = GetDirection(); //cout << direction << endl; glDisable(GL_TEXTURE_2D); glTranslatef(position[0]-5*direction[0], position[1]-5*direction[1], position[2]-5*direction[2]); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, brassMaterials.ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, brassMaterials.diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, brassMaterials.specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, brassMaterials.shininess); //glutSolidTeapot(1.0); glEnable(GL_TEXTURE_2D); glPopMatrix(); theWorld.OrthoMode(0,0, theGame.GetWidth(), theGame.GetHeight()); glDisable(GL_LIGHTING); // Render the scope float minX = (theGame.GetWidth()/2) - 32.0; float maxX = (theGame.GetWidth()/2) + 32.0; float minY = (theGame.GetHeight()/2) - 32.0; float maxY = (theGame.GetHeight()/2) + 32.0; glBlendFunc(GL_ONE, GL_ONE); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, _scope.GetName()); // cout << "printin scope" << endl; glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2f(minX,minY); glTexCoord2i(0,1); glVertex2f(minX,maxY); glTexCoord2i(1,1); glVertex2f(maxX,maxY); glTexCoord2i(1,0); glVertex2f(maxX,minY); glEnd(); glDisable(GL_BLEND); // draw the cockpit glBindTexture(GL_TEXTURE_2D, _cockpit.GetName()); minX = 0.0; maxX = theGame.GetWidth(); minY = theGame.GetHeight() * 0.65; maxY = theGame.GetHeight(); glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2f(minX,maxY); glTexCoord2i(1,0); glVertex2f(maxX,maxY); glTexCoord2i(1,1); glVertex2f(maxX,minY); glTexCoord2i(0,1); glVertex2f(minX,minY); glEnd(); glDisable(GL_TEXTURE_2D); if ((_flash && _flashcount > 0.0 && theWorld.GetState() == World::PLAYING) || (theWorld.GetState() == World::GAMEOVER)) { glEnable(GL_BLEND); glDepthMask(GL_FALSE); glColor4f(1.0,0.0,0.0,0.1); glBegin(GL_QUADS); glVertex2f(0.0, 0.0); glVertex2f(0.0, theGame.GetHeight()); glVertex2f(theGame.GetWidth(), theGame.GetHeight()); glVertex2f(theGame.GetWidth(), 0.0); glEnd(); glDisable(GL_BLEND); glDepthMask(GL_TRUE); } _flash = !_flash; glEnable(GL_LIGHTING); theWorld.PerspectiveMode(); } void PlayerShip::Hit(float damage) { Spaceship::Hit(damage); _flashcount = 0.2; theSound.PlaySound(Sound::HIT); } void PlayerShip::UpdateState(float timeElapsed, bool roll) { Spaceship::UpdateState(timeElapsed, roll); if (_flashcount > 0.0) _flashcount -= timeElapsed; else _flash = false; } void PlayerShip::ResetOrientation() { _flash = false; _flashcount = 0.0; velocity = 0.0; position = Math3d::M3d(0.0, 0.0, 0.0); orientation = Math3d::MQuat(0.0, 0.0, 1.0, 0.0); }