author | nireco |
Tue, 02 Dec 2008 00:23:16 +0000 | |
changeset 174 | 073f25a84f60 |
parent 162 | f760591b7481 |
child 180 | bfe1077edab3 |
permissions | -rw-r--r-- |
25 | 1 |
|
2 |
#include "Graphics.hh" |
|
86 | 3 |
#include "Physics.hh" |
4 |
#include "GameState.hh" |
|
108 | 5 |
#include <cmath> |
25 | 6 |
|
7 |
Graphics::Graphics (Engine &engine, GameState &state) : |
|
8 |
engine(engine), |
|
9 |
state(state), |
|
10 |
update_timer(GRAPHICS_UPDATE_INTERVAL_MS), |
|
60 | 11 |
win(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT), |
25 | 12 |
keyboard(win.get_ic()->get_keyboard()) { |
86 | 13 |
|
25 | 14 |
// connect timer signal |
15 |
slots.connect(update_timer.sig_timer(), this, &Graphics::on_update); |
|
16 |
||
17 |
// enable |
|
18 |
update_timer.enable(); |
|
19 |
} |
|
20 |
||
21 |
void Graphics::check_input (void) { |
|
22 |
LocalPlayer *player; |
|
58 | 23 |
PlayerInput_Move input_move = 0; |
25 | 24 |
|
25 |
// stop on escape |
|
26 |
if (keyboard.get_keycode(CL_KEY_ESCAPE)) { |
|
108 | 27 |
engine.stop(); |
25 | 28 |
|
108 | 29 |
return; |
25 | 30 |
} |
31 |
||
32 |
// ignore if we don't have a local player |
|
33 |
if ((player = state.getLocalPlayer()) == NULL) |
|
34 |
return; |
|
35 |
||
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
36 |
// handle movement |
25 | 37 |
if (keyboard.get_keycode(CL_KEY_LEFT)) |
108 | 38 |
input_move |= INPUT_MOVE_LEFT; |
25 | 39 |
|
40 |
if (keyboard.get_keycode(CL_KEY_RIGHT)) |
|
108 | 41 |
input_move |= INPUT_MOVE_RIGHT; |
42 |
||
43 |
if (keyboard.get_keycode(CL_KEY_UP)) |
|
44 |
input_move |= INPUT_MOVE_UP; |
|
45 |
||
46 |
if (keyboard.get_keycode(CL_KEY_DOWN)) |
|
47 |
input_move |= INPUT_MOVE_DOWN; |
|
94 | 48 |
|
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
49 |
if (keyboard.get_keycode(CL_KEY_RSHIFT)) |
108 | 50 |
input_move |= INPUT_MOVE_JUMP; |
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
51 |
|
108 | 52 |
if (keyboard.get_keycode(CL_KEY_I)) |
53 |
player->debugInfo(); |
|
116 | 54 |
|
55 |
if (keyboard.get_keycode(CL_KEY_M)) |
|
56 |
input_move |= INPUT_MOVE_DIG; |
|
57 |
||
25 | 58 |
// apply movement if applicable |
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
25
diff
changeset
|
59 |
if (input_move) |
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
25
diff
changeset
|
60 |
player->handleMove(input_move); |
25 | 61 |
} |
62 |
||
63 |
void Graphics::do_redraw (void) { |
|
64 |
CL_GraphicContext *gc = win.get_gc(); |
|
65 |
||
162
f760591b7481
Removed unnecessary variables (factoFoo) from do_redraw. Renamed
saiam
parents:
161
diff
changeset
|
66 |
// White background |
25 | 67 |
gc->clear(CL_Color::white); |
68 |
||
162
f760591b7481
Removed unnecessary variables (factoFoo) from do_redraw. Renamed
saiam
parents:
161
diff
changeset
|
69 |
// Draw terrain |
f760591b7481
Removed unnecessary variables (factoFoo) from do_redraw. Renamed
saiam
parents:
161
diff
changeset
|
70 |
state.drawTerrain(gc); |
60 | 71 |
|
162
f760591b7481
Removed unnecessary variables (factoFoo) from do_redraw. Renamed
saiam
parents:
161
diff
changeset
|
72 |
// Draw players |
25 | 73 |
for (std::list<Player*>::iterator it = state.player_list.begin(); it != state.player_list.end(); it++) { |
74 |
Player *p = *it; |
|
153
73402d5b778e
Lots of small fixe. Moved drawing PhysicsObjects away from Graphics.cc.
saiam
parents:
138
diff
changeset
|
75 |
p->draw(gc); |
73402d5b778e
Lots of small fixe. Moved drawing PhysicsObjects away from Graphics.cc.
saiam
parents:
138
diff
changeset
|
76 |
} |
25 | 77 |
|
162
f760591b7481
Removed unnecessary variables (factoFoo) from do_redraw. Renamed
saiam
parents:
161
diff
changeset
|
78 |
// Flip window buffer, LIEK NAO |
25 | 79 |
win.flip(0); |
80 |
} |
|
81 |
||
82 |
void Graphics::on_update (void) { |
|
83 |
// check keyboard input |
|
84 |
check_input(); |
|
85 |
||
86 |
// redraw display |
|
87 |
do_redraw(); |
|
88 |
} |