|
1 #include <ClanLib/core.h> |
|
2 #include <ClanLib/gl.h> //do I need this in linux? |
|
3 #include <ClanLib/display.h> |
|
4 #include <ClanLib/application.h> |
|
5 #include "GameState.hh" |
|
6 #include "Dimension.hh" |
|
7 |
|
8 class CL_Game : public CL_ClanApplication { |
|
9 private: |
|
10 bool keep_going; |
|
11 void check_input() { |
|
12 if(CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) |
|
13 keep_going = false; |
|
14 |
|
15 LocalPlayer& lp = gs.getLocalPlayer(); |
|
16 |
|
17 if(CL_Keyboard::get_keycode(CL_KEY_UP)) { |
|
18 lp.doMovement(PositionDelta(0,3)); |
|
19 } |
|
20 if(CL_Keyboard::get_keycode(CL_KEY_DOWN)) { |
|
21 lp.doMovement(PositionDelta(0,-3)); |
|
22 } |
|
23 if(CL_Keyboard::get_keycode(CL_KEY_LEFT)) { |
|
24 lp.doMovement(PositionDelta(-3,0)); |
|
25 } |
|
26 if(CL_Keyboard::get_keycode(CL_KEY_RIGHT)) { |
|
27 lp.doMovement(PositionDelta(3,0)); |
|
28 } |
|
29 } |
|
30 |
|
31 public: |
|
32 GameState gs; |
|
33 |
|
34 CL_Game() : keep_going(true) {} |
|
35 virtual int main(int argc, char **argv) { |
|
36 CL_SetupCore setup_init; |
|
37 CL_SetupDisplay setup_disp; |
|
38 CL_SetupGL setup_gl; |
|
39 |
|
40 //gs.player_list.push(Player(Coordinate())); |
|
41 |
|
42 CL_DisplayWindow win("ikkuna", 640, 480); |
|
43 // CL_Surface bg(CL_PNGProvider("image.png"); |
|
44 |
|
45 unsigned int last_draw = CL_System::get_time(); |
|
46 int r = 100, g = 100, b = 100; |
|
47 unsigned int frame_count = 0; |
|
48 bool R = false, G = false, B = false; |
|
49 |
|
50 while(keep_going) { //not good idea to put infinite loop |
|
51 CL_Display::clear(CL_Color(r, g, b)); |
|
52 |
|
53 int colorIdx = 0; |
|
54 for(std::list<Player>::iterator it = gs.player_list.begin(); it != gs.player_list.end(); ++it) { |
|
55 |
|
56 CL_Display::fill_rect(CL_Rect(it->getPosition().scaledX()-10, it->getPosition().scaledY()-10, |
|
57 it->getPosition().scaledX()+10, it->getPosition().scaledY()+10), CL_Color((colorIdx*30)%255, (colorIdx*30)%255, (colorIdx*30)%255)); |
|
58 |
|
59 colorIdx++; |
|
60 } |
|
61 |
|
62 CL_Display::flip(1); |
|
63 frame_count++; |
|
64 unsigned int cur_draw = CL_System::get_time(); |
|
65 |
|
66 check_input(); |
|
67 |
|
68 last_draw = cur_draw; |
|
69 CL_System::keep_alive(); |
|
70 // sleep(10); //flip already wait a short amount of time |
|
71 } |
|
72 return 0; |
|
73 } |
|
74 }; |
|
75 |
|
76 CL_Game inst; |