Commits

Nikola Cvetko committed abea2b1

Drawing playerShip lives.

  • Participants
  • Parent commits 8c7eae8

Comments (0)

Files changed (4)

File gm_level.cpp

 #include "asteroid.h"
 #include "levelbackground.h"
 #include "explosion.h"
+#include "texture_manager.h"
 
 
 extern bool gRunning;
 extern SDL_Surface * gScreen;
+extern int playerShipLives;
 
 void
 GM_Level::addGameObject(const GameObject *gameObject, bool toFront)
     Asteroid *asteroid(new Asteroid(x, y, 60 + 200*(rand() % 10000) / 10000. ));
     this->asteroids.push_back(asteroid);
 }
+void
+GM_Level::drawHealth(double x, double y)
+{
+    this->texture->bind();
+    glEnable(GL_TEXTURE_2D);
+
+    glPushMatrix();
+    glTranslatef(x, y, 0);
+    glScalef(16, 32, 0);
+    glBegin(GL_TRIANGLES);
+
+    glTexCoord2f(0, 0);
+    glVertex2f(-0.5, -0.5);
+    glTexCoord2f(0, 1);
+    glVertex2f(-0.5, 0.5);
+    glTexCoord2f(1, 1);
+    glVertex2f(0.5, 0.5);
+
+    glTexCoord2f(1, 1);
+    glVertex2f(0.5, 0.5);
+    glTexCoord2f(1, 0);
+    glVertex2f(0.5, -0.5);
+    glTexCoord2f(0, 0);
+    glVertex2f(-0.5, -0.5);
+
+    glEnd();
+
+    glPopMatrix();
+
+}
 
 GM_Level::~GM_Level()
 {
     delete playership;
 }
 
-GM_Level::GM_Level() : playership(new PlayerShip("playership.png", -250, 200))
+GM_Level::GM_Level() : playership(new PlayerShip("playership.png", -250, 200)),
+                       texture(TextureManager::getInstance()->getTexture("health.png")),
+                                            x(x), y(y)
 {
     /*
     Layer *layer(new Layer("background.png", 0,0));
     {
         (*it)->paintSelf();
     }
-
+    for(int i = playerShipLives; i > 0; i--)
+    {
+        this->drawHealth((-320 + this->texture->getW() / 2 - 17) + i * 17, (-240 + this->texture->getH()/ 2));
+    }
 
 
 
 class BlueEnemyShip;
 class Asteroid;
 class LevelBackground;
+class Texture;
 
 class GM_Level : public GameMode
 {
     void addGameObject(const GameObject *gameObject, bool toFront = false);
 
     void spawnAsteroid(double x, double y);
+    void drawHealth(double x, double y);
 
     std::vector<GameObject*>& getGameObjects()
     {
     std::vector<Asteroid*> asteroids;
     PlayerShip * playership;
     LevelBackground * levelbackground;
+    Texture * texture;
+    double x, y;
 
     std::vector<GameObject*> gameObjectsToInsertToFront;
     std::vector<GameObject*> gameObjectsToInsertToBack;

File health.png

Added
New image

File playership.cpp

 
 static const double playerShipAngleV = 180;
 static const double playerShipYV = 380;
-static int playerShipLives = 3;
+extern int playerShipLives = 3;
 
 extern SDL_Joystick * gJoystick;