Commits

Dino Drokan committed 951133a

Added LevelBackground subclass of Layer and Level background layer is drawing

  • Participants
  • Parent commits ccde681

Comments (0)

Files changed (5)

File Pucaljka.cbp

 		<Unit filename="gm_mainmenu.h" />
 		<Unit filename="layer.cpp" />
 		<Unit filename="layer.h" />
+		<Unit filename="levelbackground.cpp" />
+		<Unit filename="levelbackground.h" />
 		<Unit filename="playership.cpp" />
 		<Unit filename="playership.h" />
 		<Unit filename="pucaljka.cpp" />

File gm_level.cpp

 #include "blueenemyship.h"
 #include "bullet.h"
 #include "asteroid.h"
+#include "levelbackground.h"
 
 
 extern bool gRunning;
     this->layers.push_back(layer);
      */
 
+    LevelBackground *layer(new LevelBackground(0,0));
+    this->layers.push_back(layer);
+
     EnemyShip *enemyShip(new EnemyShip("enemyship01.png", 600, 400));
     this->addGameObject(enemyShip);
 
 #include "gameobject.h"
 #include "enemyship.h"
 #include "bullet.h"
+#include "levelbackground.h"
 
 class PlayerShip;
 class Layer;
 class RedEnemyShip;
 class BlueEnemyShip;
 class Asteroid;
+class LevelBackground;
 
 class GM_Level : public GameMode
 {
     std::vector<Layer*> layers;
     std::vector<Asteroid*> asteroids;
     PlayerShip * playership;
+    LevelBackground * levelbackground;
 };
 
 #endif

File levelbackground.cpp

+#include<math.h>
+#include "levelbackground.h"
+#include "texture.h"
+#include "gm_level.h"
+
+
+LevelBackground::LevelBackground(const int argX,
+                                 const int argY) : Layer ("lvlbackground1.png", 0,0)
+                       {
+                       }
+LevelBackground::~LevelBackground()
+{
+    delete this->texture;
+}
+
+void
+LevelBackground::paintSelf()
+{
+    this->texture->bind();
+    glEnable(GL_TEXTURE_2D);
+
+    glPushMatrix();
+    glTranslatef(this->x, this->y, 0);
+    glScalef(this->texture->getW(), this->texture->getH(), 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();
+
+}
+
+void
+LevelBackground::updateSelf(const double timeDelta)
+{
+
+}

File levelbackground.h

+#ifndef PUCALJKA_LEVELBACKGROUND_H
+#define PUCALJKA_LEVELBACKGROUND_H
+
+#include <string>
+#include "texture.h"
+#include "layer.h"
+
+
+class LevelBackground : public Layer
+{
+    public:
+    LevelBackground(const int x,
+                    const int y);
+    virtual ~LevelBackground();
+    void paintSelf();
+    void updateSelf(const double timeDelta);
+
+    private:
+    Texture * texture;
+    float x, y;
+
+};
+
+
+#endif