aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/World.h22
-rw-r--r--res/dirt.jpgbin0 -> 1033 bytes
-rw-r--r--res/dirt.pngbin0 -> 3212 bytes
-rw-r--r--res/dirt.xcfbin0 -> 1067 bytes
-rw-r--r--src/World.cpp38
5 files changed, 60 insertions, 0 deletions
diff --git a/include/World.h b/include/World.h
new file mode 100644
index 0000000..4a097a6
--- /dev/null
+++ b/include/World.h
@@ -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
index 0000000..ebe4ea0
--- /dev/null
+++ b/res/dirt.jpg
Binary files differ
diff --git a/res/dirt.png b/res/dirt.png
new file mode 100644
index 0000000..f9a0809
--- /dev/null
+++ b/res/dirt.png
Binary files differ
diff --git a/res/dirt.xcf b/res/dirt.xcf
new file mode 100644
index 0000000..ad72197
--- /dev/null
+++ b/res/dirt.xcf
Binary files differ
diff --git a/src/World.cpp b/src/World.cpp
new file mode 100644
index 0000000..feeeb1f
--- /dev/null
+++ b/src/World.cpp
@@ -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);
+}