|
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 "coor.hh" |
|
6 #include "game_state.hh" |
|
7 #include "Player.hh" |
|
8 |
|
9 class CL_Game : public CL_ClanApplication { |
|
10 private: |
|
11 bool keep_going; |
|
12 void check_input() { |
|
13 if(CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) |
|
14 keep_going = false; |
|
15 if(CL_Keyboard::get_keycode(CL_KEY_UP)) { |
|
16 if(gs.cave[(int)(gs.players[0].xy.x+ |
|
17 ((int)gs.players[0].xy.y+1)*640)] == 0) { |
|
18 gs.players[0].xy2.y += 4; |
|
19 } |
|
20 } |
|
21 if(CL_Keyboard::get_keycode(CL_KEY_LEFT)) { |
|
22 gs.players[0].xy2.x += 0.2; |
|
23 } |
|
24 if(CL_Keyboard::get_keycode(CL_KEY_RIGHT)) { |
|
25 gs.players[0].xy2.x -= 0.2; |
|
26 } |
|
27 } |
|
28 |
|
29 public: |
|
30 game_state gs; |
|
31 |
|
32 CL_Game() : keep_going(true) {} |
|
33 virtual int main(int argc, char **argv) { |
|
34 CL_SetupCore setup_init; |
|
35 CL_SetupDisplay setup_disp; |
|
36 CL_SetupGL setup_gl; |
|
37 gs.addPlayer(Player()); |
|
38 |
|
39 CL_DisplayWindow win("ikkuna", 640, 480); |
|
40 // CL_Surface bg(CL_PNGProvider("image.png"); |
|
41 |
|
42 unsigned int last_draw = CL_System::get_time(); |
|
43 int r = 100, g = 100, b = 100; |
|
44 unsigned int frame_count = 0; |
|
45 bool R = false, G = false, B = false; |
|
46 |
|
47 while(keep_going) { //not good idea to put infinite loop |
|
48 CL_Display::clear(CL_Color(r, g, b)); |
|
49 // bg.draw(0, 0); |
|
50 // CL_Display::fill_rect(CL_Rect((int)(x-10.0), (int)(y-10.0), |
|
51 // (int)(x+10.0), |
|
52 // (int)(y+10.0)), CL_Color(255-r, 255-g, 255-b)); |
|
53 for(int i = 0; i < 640*480; i++) { |
|
54 int x = i%640; |
|
55 int y = i/640; |
|
56 CL_Color col = CL_Color(200, 100, 60); |
|
57 if(gs.cave[i] == 1) { |
|
58 col = CL_Color(50, 50, 200); |
|
59 } |
|
60 CL_Display::draw_pixel(x, y, col); |
|
61 } |
|
62 Player& pl1 = gs.players[0]; |
|
63 int pl1xi = (int)(pl1.xy.x); |
|
64 int pl1yi = (int)(pl1.xy.y); |
|
65 CL_Display::fill_rect(CL_Rect(pl1xi-10, pl1yi-10, |
|
66 pl1xi+10, pl1yi+10), CL_Color(255-r, 255-g, 255-b)); |
|
67 |
|
68 for(int i = 0; i < gs.players.size(); i++) { |
|
69 Player& pl2 = gs.players[i]; |
|
70 pl2.xy2.y -= 0.2; |
|
71 double tmpx = pl2.xy.x, tmpy = pl2.xy.y; |
|
72 pl2.xy.x = 2*pl2.xy.x-pl2.xy2.x; |
|
73 pl2.xy.y = 2*pl2.xy.y-pl2.xy2.y; |
|
74 pl2.xy2.x = tmpx; |
|
75 pl2.xy2.y = tmpy; |
|
76 if(gs.cave[((int)(pl2.xy.x + |
|
77 ((int)pl2.xy.y)*640))%(640*480)] == 0) { |
|
78 pl2.xy = pl2.xy2; |
|
79 } |
|
80 } |
|
81 |
|
82 CL_Display::flip(1); |
|
83 frame_count++; |
|
84 unsigned int cur_draw = CL_System::get_time(); |
|
85 |
|
86 check_input(); |
|
87 |
|
88 if(R) { r++; |
|
89 } else { r--; } |
|
90 if(G) { g++; |
|
91 } else { g--; } |
|
92 if(B) { b++; |
|
93 } else { b--; } |
|
94 if(r < 0) r = 0; |
|
95 if(g < 0) g = 0; |
|
96 if(b < 0) b = 0; |
|
97 if(r > 255) r = 255; |
|
98 if(g > 255) g = 255; |
|
99 if(b > 255) b = 255; |
|
100 |
|
101 if(frame_count % 100 == 0) { |
|
102 R = rand()%2; |
|
103 G = rand()%2; |
|
104 B = rand()%2; |
|
105 } |
|
106 |
|
107 last_draw = cur_draw; |
|
108 CL_System::keep_alive(); |
|
109 // sleep(10); //flip already wait a short amount of time |
|
110 } |
|
111 return 0; |
|
112 } |
|
113 }; |
|
114 |
|
115 CL_Game inst; |