Commits

Filip Mravunac committed c6c67d3

Fixing background layers scrolling.

  • Participants
  • Parent commits dc3761b

Comments (0)

Files changed (3)

File gm_level.cpp

     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
 
+    playership->paintSelf();
+    for(std::vector<GameObject*>::iterator it = gameObjects.begin(); it != gameObjects.end(); it++)
+    {
+        (*it)->paintSelf();
+    }
     for(std::vector<Layer*>::iterator it = layers.begin(); it != layers.end(); it++)
     {
         (*it)->paintSelf();
     }
+
     for(std::vector<Asteroid*>::iterator it = asteroids.begin(); it != asteroids.end(); it++)
     {
         (*it)->paintSelf();
     }
 
 
-    playership->paintSelf();
-    for(std::vector<GameObject*>::iterator it = gameObjects.begin(); it != gameObjects.end(); it++)
-    {
-        (*it)->paintSelf();
-    }
+
 
     SDL_GL_SwapBuffers();
 }
         double randomNumberY = 240 - ((rand() % 10000) / 10000.) * 480;
         spawnAsteroid(randomNumberX, randomNumberY);
     }
+    this->playership->updateSelf(timeDelta);
+    for(std::vector<Layer*>::iterator it = this->layers.begin(); it != this->layers.end(); it++)
+    {
+        (*it)->updateSelf(timeDelta);
+    }
     for(std::vector<Asteroid*>::iterator it = this->asteroids.begin(); it != this->asteroids.end(); it++)
     {
         (*it)->updateSelf(timeDelta);
     }
-    this->playership->updateSelf(timeDelta);
     for(std::vector<GameObject*>::iterator it = this->gameObjects.begin(); it != this->gameObjects.end(); it++)
     {
         (*it)->updateSelf(timeDelta);

File levelbackground.cpp

 
 
 LevelBackground::LevelBackground(const int argX,
-                                 const int argY) : Layer ("background.png", 0,0)
+                                 const int argY) : Layer ("lvlbackground1.png", 0,0), xOffset(0), yOffset(0)
 {
 }
 LevelBackground::~LevelBackground()
 void
 LevelBackground::paintSelf()
 {
-    this->texture->bind();
-    glEnable(GL_TEXTURE_2D);
+    glMatrixMode(GL_TEXTURE);
+    glPushMatrix();
+    glTranslatef(xOffset, yOffset, 0);
 
-    glPushMatrix();
-    glTranslatef(this->x, this->y, 0);
-    glScalef(this->texture->getW(), this->texture->getH(), 0);
+    glMatrixMode(GL_MODELVIEW);
 
-    glBegin(GL_TRIANGLES);
+    Layer::paintSelf();
 
-    glTexCoord2f(0, 0);
-    glVertex2f(-0.5, -0.5);
-    glTexCoord2f(0, 1);
-    glVertex2f(-0.5, 0.5);
-    glTexCoord2f(1, 1);
-    glVertex2f(0.5, 0.5);
+    glMatrixMode(GL_TEXTURE);
+    glPopMatrix();
 
-    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();
+    glMatrixMode(GL_MODELVIEW);
 
 }
 
 LevelBackground::updateSelf(const double timeDelta)
 {
     Layer::updateSelf(timeDelta);
+    xOffset += timeDelta / 25;
 }

File levelbackground.h

     void paintSelf();
     void updateSelf(const double timeDelta);
 
+    private:
+    double xOffset;
+    double yOffset;
 };