--- a/src/proto2/Graphics.cc Thu Nov 20 21:50:55 2008 +0000
+++ b/src/proto2/Graphics.cc Thu Nov 20 22:45:10 2008 +0000
@@ -1,5 +1,7 @@
#include "Graphics.hh"
+#include "Physics.hh"
+#include "GameState.hh"
Graphics::Graphics (Engine &engine, GameState &state) :
engine(engine),
@@ -7,7 +9,26 @@
update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
win(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT),
keyboard(win.get_ic()->get_keyboard()) {
-
+
+ Vector tmp;
+ CL_Color color;
+ CL_PixelBuffer terr;
+ 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::white;
+ } else if (state.getType(tmp) == DIRT) {
+ color = CL_Color::brown;
+ } else if (state.getType(tmp) == ROCK) {
+ color = CL_Color::grey;
+ } else {
+ // Fale
+ }
+ terr.draw_pixel(tmp.x, tmp.y, color);
+ }
+ }
+ terrain.set_pixeldata(terr);
+
// connect timer signal
slots.connect(update_timer.sig_timer(), this, &Graphics::on_update);
@@ -57,6 +78,9 @@
const float factorX = GRAPHICS_RESOLUTION_WIDTH / MAP_WIDTH;
const float factorY = GRAPHICS_RESOLUTION_HEIGHT / MAP_HEIGHT;
+ // draw terrain
+ terrain.draw(0,0, gc);
+
// draw players
for (std::list<Player*>::iterator it = state.player_list.begin(); it != state.player_list.end(); it++) {
Player *p = *it;
--- a/src/proto2/Graphics.hh Thu Nov 20 21:50:55 2008 +0000
+++ b/src/proto2/Graphics.hh Thu Nov 20 22:45:10 2008 +0000
@@ -17,26 +17,28 @@
const uint16_t GRAPHICS_UPDATE_INTERVAL_MS = 20;
class Graphics {
- private:
- Engine &engine;
- GameState &state;
+private:
+ Engine &engine;
+ GameState &state;
- CL_SlotContainer slots;
-
- CL_Timer update_timer;
-
- CL_DisplayWindow win;
- CL_InputDevice &keyboard;
+ CL_SlotContainer slots;
- public:
- Graphics (Engine &engine, GameState &state);
-
- private:
- void check_input (void);
- void do_redraw (void);
-
- void on_update (void);
-
+ CL_Timer update_timer;
+
+ CL_DisplayWindow win;
+ CL_InputDevice &keyboard;
+
+ CL_Surface terrain;
+
+public:
+ Graphics (Engine &engine, GameState &state);
+
+private:
+ void check_input (void);
+ void do_redraw (void);
+
+ void on_update (void);
+
};
#endif /* GRAPHICS_HH */
--- a/src/proto2/Physics.cc Thu Nov 20 21:50:55 2008 +0000
+++ b/src/proto2/Physics.cc Thu Nov 20 22:45:10 2008 +0000
@@ -7,7 +7,7 @@
#include <cmath>
PhysicsWorld::PhysicsWorld (Vector gravity, Vector dimensions)
- : tick_timer(PHYSICS_TICK_MS), gravity(gravity), dimensions(dimensions), terrain(dimensions.x, std::vector<TerrainType>(dimensions.y, EMPTY)) {
+ : tick_timer(PHYSICS_TICK_MS), gravity(gravity), dimensions(dimensions), terrain(dimensions.x, std::vector<TerrainType>(dimensions.y, DIRT)) {
slots.connect(tick_timer.sig_timer(), this, &PhysicsWorld::tick);
tick_timer.enable();
@@ -194,7 +194,7 @@
// some constants to control random generation
const int min_range = 10;
const int max_range = 40;
- const int num = 0;
+ const int num = 30;
const int rock_rarity = 4; // 1 / rock_rarity will be rock circle
// loops for amount of circles
--- a/src/proto2/Physics.hh Thu Nov 20 21:50:55 2008 +0000
+++ b/src/proto2/Physics.hh Thu Nov 20 22:45:10 2008 +0000
@@ -27,15 +27,18 @@
protected:
std::vector<PhysicsObject*> objects;
Vector gravity;
- Vector dimensions; //const requested
-
+ Vector dimensions;
+
+
std::vector<std::vector<TerrainType> > terrain;
CL_SlotContainer slots;
PhysicsWorld (Vector gravity, Vector dimensions);
+
+
+public:
-public:
void addObject (PhysicsObject *object);
void tick (void);