Nyt kaivaminen visualisoidaan oikein, mutta fysiikkakoodi on kyll? edelleen ihan kauheata, pit?isi tuo Terrain v??nt??
authorsaiam
Sun, 30 Nov 2008 00:23:44 +0000
changeset 138 cc326b64ae20
parent 137 8736fdd12197
child 139 77220921ae7d
Nyt kaivaminen visualisoidaan oikein, mutta fysiikkakoodi on kyll? edelleen ihan kauheata, pit?isi tuo Terrain v??nt??
kuntoon nyt.
src/proto2/Graphics.cc
src/proto2/Graphics.hh
src/proto2/Physics.cc
src/proto2/Physics.hh
--- a/src/proto2/Graphics.cc	Sat Nov 29 23:43:47 2008 +0000
+++ b/src/proto2/Graphics.cc	Sun Nov 30 00:23:44 2008 +0000
@@ -11,27 +11,6 @@
     win(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT),
     keyboard(win.get_ic()->get_keyboard()) {
 
-    Vector tmp;
-    CL_Color color;
-    CL_PixelBuffer terr(MAP_WIDTH, MAP_HEIGHT, 4*MAP_WIDTH, CL_PixelFormat::rgba8888);
-    
-    
-    for (tmp.x = 0; tmp.x < MAP_WIDTH; tmp.x++) {
-        for (tmp.y = 0; tmp.y < MAP_HEIGHT; tmp.y++) {
-            if (state.getType(tmp) == EMPTY) {
-                color = CL_Color(86, 41, 0);
-            } else if (state.getType(tmp) == DIRT) {
-                color = CL_Color(144, 82, 23);
-            } else if (state.getType(tmp) == ROCK) {
-                color = CL_Color(132, 136, 135);
-            } else {
-                // Fale
-            }
-            terr.draw_pixel(tmp.x, tmp.y, color);
-     	}
-    }
-    terrain = CL_Surface(terr);
- 
     // connect timer signal
     slots.connect(update_timer.sig_timer(), this, &Graphics::on_update);
 
@@ -91,15 +70,16 @@
     const float factorY = GRAPHICS_RESOLUTION_HEIGHT / MAP_HEIGHT;
 
     // draw terrain
-    terrain.draw(0,0, gc);
-
+    state.drawTerrain(gc);
+    //terrain.draw(gc);
+    /*
     // Demonstrates digging, but is very slow
-/*    Vector tmp(0, 0);
+    Vector tmp(0, 0);
     CL_Color color;
     CL_PixelBuffer pix(1, 1, 4, CL_PixelFormat::rgba8888);
     CL_Surface surf(pix);
-    for (tmp.x = 380; tmp.x < 430; tmp.x++) {
-        for (tmp.y = 560; tmp.y < 600; tmp.y++) {
+    for (tmp.x = 0; tmp.x < MAP_WIDTH; tmp.x++) {
+        for (tmp.y = 0; tmp.y < MAP_HEIGHT; tmp.y++) {
             if (state.getType(tmp) == EMPTY) {
                 color = CL_Color(86, 41, 0);
             } else if (state.getType(tmp) == DIRT) {
@@ -112,7 +92,7 @@
             surf.set_color(color);
             surf.draw(tmp.x, tmp.y, gc);
         }
-    }*/
+        }*/
   
     // draw players
     for (std::list<Player*>::iterator it = state.player_list.begin(); it != state.player_list.end(); it++) {
--- a/src/proto2/Graphics.hh	Sat Nov 29 23:43:47 2008 +0000
+++ b/src/proto2/Graphics.hh	Sun Nov 30 00:23:44 2008 +0000
@@ -28,8 +28,6 @@
     CL_DisplayWindow win;
     CL_InputDevice &keyboard;
     
-    CL_Surface terrain;
-    
 public:
     Graphics (Engine &engine, GameState &state);
     
--- a/src/proto2/Physics.cc	Sat Nov 29 23:43:47 2008 +0000
+++ b/src/proto2/Physics.cc	Sun Nov 30 00:23:44 2008 +0000
@@ -14,8 +14,12 @@
       terrain(dimensions.x, 
               std::vector<TerrainType>(dimensions.y, DIRT)) {
 
+
+    terr = CL_PixelBuffer(MAP_WIDTH, MAP_HEIGHT, 4*MAP_WIDTH, CL_PixelFormat::rgba8888);
+
     generateTerrain(1337);
 
+
     slots.connect(tick_timer.sig_timer(), this, &PhysicsWorld::tick);
     tick_timer.enable();
 }
@@ -423,7 +427,7 @@
     const int max_range = 80;
     const int num = 50;
     const int rock_rarity = 4; // 1 / rock_rarity will be rock circle
-
+    
     // loops for amount of circles
     for(int i = 0; i < num; i++) {
         // information of new circle
@@ -450,10 +454,32 @@
                 //if((x-midx) * (x-midx) + (y-midy) * (y-midy) < range*range) {
                 // and sets it to type
                 terrain[x][y] = type;
+                
                 //}
             }
         }
     }
+
+    for (int i = 0; i < MAP_WIDTH; i++) {
+        for (int j = 0; j < MAP_HEIGHT; j++) {
+            CL_Color color;
+            switch(getType(i,j)) {
+            case EMPTY:
+                color = CL_Color(86, 41, 0);
+                break;
+            case DIRT:
+                color = CL_Color(144, 82, 23);
+                break;
+            case ROCK:
+                color = CL_Color(132, 136, 135);
+                break;
+            default:
+                break;
+            }
+            terr.draw_pixel(i, j, color);
+        }
+    }
+    
 }
 
 /**
@@ -484,6 +510,7 @@
                 if((i-x)*(i-x)+(j-y)*(j-y) < r*r) {
                     // Safe because getType returns ROCK if tile is out of bounds
                     terrain[i][j] = EMPTY;
+                    terr.draw_pixel(i, j, CL_Color(86, 41, 0));
                 }
             }
         }
@@ -492,3 +519,8 @@
 void PhysicsWorld::removeGround(Vector pos, float r) {
     removeGround((int)pos.x, (int)pos.y, r);
 }
+
+void PhysicsWorld::drawTerrain(CL_GraphicContext *gc) {
+    CL_Surface surf(terr);
+    surf.draw(0, 0, gc);
+}
--- a/src/proto2/Physics.hh	Sat Nov 29 23:43:47 2008 +0000
+++ b/src/proto2/Physics.hh	Sun Nov 30 00:23:44 2008 +0000
@@ -4,6 +4,7 @@
 #include <vector>
 #include <queue>
 #include <ClanLib/core.h>
+#include <ClanLib/display.h>
 
 #include "Vector.hh"
 #include "Config.hh"
@@ -57,6 +58,8 @@
 
     // TODO: Should this be it's own class?
     std::vector<std::vector<TerrainType> > terrain;
+    CL_PixelBuffer terr;
+    //    CL_Surface surf;
 
 public:
     // TODO: Replace addObject with these?
@@ -126,6 +129,7 @@
      */
     TerrainType getType(Vector pos) const;
 
+    void drawTerrain(CL_GraphicContext *gc);
 };
 
 /**