Drawer lis?tty. Pari metodia gamestateen ja dimensioniin.
--- a/proto/p2/Dimension.hh Mon Nov 03 21:36:17 2008 +0000
+++ b/proto/p2/Dimension.hh Mon Nov 03 22:20:21 2008 +0000
@@ -20,6 +20,16 @@
this->x += d.dx;
this->y += d.dy;
}
+
+ uint32_t scaledX() {
+ // Scale the coordinate so that it
+ // matches the pixel resolution
+ return this->x/1;
+ }
+
+ uint32_t scaledY() {
+ return this->y/1;
+ }
};
class PositionDelta {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/proto/p2/Drawer.cc Mon Nov 03 22:20:21 2008 +0000
@@ -0,0 +1,76 @@
+#include <ClanLib/core.h>
+#include <ClanLib/gl.h> //do I need this in linux?
+#include <ClanLib/display.h>
+#include <ClanLib/application.h>
+#include "GameState.hh"
+#include "Dimension.hh"
+
+class CL_Game : public CL_ClanApplication {
+private:
+ bool keep_going;
+ void check_input() {
+ if(CL_Keyboard::get_keycode(CL_KEY_ESCAPE))
+ keep_going = false;
+
+ LocalPlayer& lp = gs.getLocalPlayer();
+
+ if(CL_Keyboard::get_keycode(CL_KEY_UP)) {
+ lp.doMovement(PositionDelta(0,3));
+ }
+ if(CL_Keyboard::get_keycode(CL_KEY_DOWN)) {
+ lp.doMovement(PositionDelta(0,-3));
+ }
+ if(CL_Keyboard::get_keycode(CL_KEY_LEFT)) {
+ lp.doMovement(PositionDelta(-3,0));
+ }
+ if(CL_Keyboard::get_keycode(CL_KEY_RIGHT)) {
+ lp.doMovement(PositionDelta(3,0));
+ }
+ }
+
+public:
+ GameState gs;
+
+ CL_Game() : keep_going(true) {}
+ virtual int main(int argc, char **argv) {
+ CL_SetupCore setup_init;
+ CL_SetupDisplay setup_disp;
+ CL_SetupGL setup_gl;
+
+ //gs.player_list.push(Player(Coordinate()));
+
+ CL_DisplayWindow win("ikkuna", 640, 480);
+// CL_Surface bg(CL_PNGProvider("image.png");
+
+ unsigned int last_draw = CL_System::get_time();
+ int r = 100, g = 100, b = 100;
+ unsigned int frame_count = 0;
+ bool R = false, G = false, B = false;
+
+ while(keep_going) { //not good idea to put infinite loop
+ CL_Display::clear(CL_Color(r, g, b));
+
+ int colorIdx = 0;
+ for(std::list<Player>::iterator it = gs.player_list.begin(); it != gs.player_list.end(); ++it) {
+
+ CL_Display::fill_rect(CL_Rect(it->getPosition().scaledX()-10, it->getPosition().scaledY()-10,
+ it->getPosition().scaledX()+10, it->getPosition().scaledY()+10), CL_Color((colorIdx*30)%255, (colorIdx*30)%255, (colorIdx*30)%255));
+
+ colorIdx++;
+ }
+
+ CL_Display::flip(1);
+ frame_count++;
+ unsigned int cur_draw = CL_System::get_time();
+
+ check_input();
+
+ last_draw = cur_draw;
+ CL_System::keep_alive();
+// sleep(10); //flip already wait a short amount of time
+ }
+ return 0;
+ }
+};
+
+CL_Game inst;
--- a/proto/p2/GameState.hh Mon Nov 03 21:36:17 2008 +0000
+++ b/proto/p2/GameState.hh Mon Nov 03 22:20:21 2008 +0000
@@ -1,6 +1,8 @@
#ifndef GAMESTATE_HH
#define GAMESTATE_HH
+#include "Dimension.hh"
+
class GameState {
public:
Dimension map_dimensions;
@@ -21,10 +23,13 @@
Coordinate position;
public:
+
+ Player(Coordinate c) : position(c) {}
+
PlayerType type;
Dimensions dimensions;
- Coordinate getPosition (void) {
+ Coordinate getPosition (void) const {
return this->position;
}
};