]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
World stuff
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 9 Sep 2015 23:54:58 +0000 (19:54 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 9 Sep 2015 23:54:58 +0000 (19:54 -0400)
include/World.h [new file with mode: 0644]
res/dirt.jpg [new file with mode: 0644]
res/dirt.png [new file with mode: 0644]
res/dirt.xcf [new file with mode: 0644]
src/World.cpp [new file with mode: 0644]

diff --git a/include/World.h b/include/World.h
new file mode 100644 (file)
index 0000000..4a097a6
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef WORLD_H
+#define WORLD_H
+
+#include <common.h>
+#include <cstring>
+
+#define LAYER0_Y (-0.8f)
+#define TEX_SIZE ( 0.2f)
+
+class World {
+private:
+       struct layer_t {
+               unsigned int tex;
+               float offset; 
+       } layer[4];
+public:
+       World(const char *l1,const char *l2,const char *l3,const char *bg);
+       void draw(void);
+       void update(int player_accel);
+};
+
+#endif // WORLD_H
diff --git a/res/dirt.jpg b/res/dirt.jpg
new file mode 100644 (file)
index 0000000..ebe4ea0
Binary files /dev/null and b/res/dirt.jpg differ
diff --git a/res/dirt.png b/res/dirt.png
new file mode 100644 (file)
index 0000000..f9a0809
Binary files /dev/null and b/res/dirt.png differ
diff --git a/res/dirt.xcf b/res/dirt.xcf
new file mode 100644 (file)
index 0000000..ad72197
Binary files /dev/null and b/res/dirt.xcf differ
diff --git a/src/World.cpp b/src/World.cpp
new file mode 100644 (file)
index 0000000..feeeb1f
--- /dev/null
@@ -0,0 +1,38 @@
+#include <World.h>
+
+World::World(const char *l1,const char *l2,const char *l3,const char *bg){
+       unsigned char i=0;
+       SDL_Surface *l;
+       const char *f[4]={l1,l2,l3,bg};
+       memset(layer,0,sizeof(struct layer_t)*4);
+       for(;i<4;i++){
+               l=IMG_Load(f[i]);
+               if(l!=NULL){
+                       glGenTextures(1,&layer[i].tex);
+                       glBindTexture(GL_TEXTURE_2D,layer[i].tex);
+                       glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+                       glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+                       glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
+                       glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
+                       glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,l->w,l->h,0,GL_RGB,GL_UNSIGNED_BYTE,l->pixels);
+                       SDL_FreeSurface(l);
+               }
+       }
+}
+void World::draw(void){
+       int i;
+       float x;
+       glEnable(GL_TEXTURE_2D);
+       for(i=2;i>=0;i--){
+               glBindTexture(GL_TEXTURE_2D,layer[i].tex);
+               glBegin(GL_QUADS);
+                       for(x=-1;x<=1;x+=(TEX_SIZE/(float)(i+1))){
+                               glTexCoord2d(1,1);glVertex2f(x             ,LAYER0_Y-TEX_SIZE+(i*.2));
+                               glTexCoord2d(0,1);glVertex2f(x+TEX_SIZE,LAYER0_Y-TEX_SIZE+(i*.2));
+                               glTexCoord2d(0,0);glVertex2f(x+TEX_SIZE,LAYER0_Y                        +(i*.2));
+                               glTexCoord2d(1,0);glVertex2f(x             ,LAYER0_Y                    +(i*.2));
+                       }
+               glEnd();
+       }
+       glDisable(GL_TEXTURE_2D);
+}