| author | ekku |
| Thu, 04 Dec 2008 19:53:59 +0000 | |
| changeset 197 | d9ac888de778 |
| parent 196 | e2d32c4601ce |
| child 199 | f5c86420facd |
| permissions | -rw-r--r-- |
| 25 | 1 |
|
2 |
#include "Graphics.hh" |
|
| 86 | 3 |
#include "GameState.hh" |
| 108 | 4 |
#include <cmath> |
| 25 | 5 |
|
6 |
Graphics::Graphics (Engine &engine, GameState &state) : |
|
7 |
engine(engine), |
|
8 |
state(state), |
|
9 |
update_timer(GRAPHICS_UPDATE_INTERVAL_MS), |
|
| 60 | 10 |
win(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT), |
| 25 | 11 |
keyboard(win.get_ic()->get_keyboard()) {
|
| 86 | 12 |
|
| 25 | 13 |
// connect timer signal |
14 |
slots.connect(update_timer.sig_timer(), this, &Graphics::on_update); |
|
15 |
||
16 |
// enable |
|
17 |
update_timer.enable(); |
|
18 |
} |
|
19 |
||
20 |
void Graphics::check_input (void) {
|
|
21 |
LocalPlayer *player; |
|
| 58 | 22 |
PlayerInput_Move input_move = 0; |
| 25 | 23 |
|
24 |
// stop on escape |
|
25 |
if (keyboard.get_keycode(CL_KEY_ESCAPE)) {
|
|
| 108 | 26 |
engine.stop(); |
| 25 | 27 |
|
| 108 | 28 |
return; |
| 25 | 29 |
} |
30 |
||
31 |
// ignore if we don't have a local player |
|
32 |
if ((player = state.getLocalPlayer()) == NULL) |
|
33 |
return; |
|
34 |
||
|
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
35 |
// handle movement |
| 25 | 36 |
if (keyboard.get_keycode(CL_KEY_LEFT)) |
| 108 | 37 |
input_move |= INPUT_MOVE_LEFT; |
| 25 | 38 |
|
39 |
if (keyboard.get_keycode(CL_KEY_RIGHT)) |
|
| 108 | 40 |
input_move |= INPUT_MOVE_RIGHT; |
41 |
||
42 |
if (keyboard.get_keycode(CL_KEY_UP)) |
|
43 |
input_move |= INPUT_MOVE_UP; |
|
44 |
||
45 |
if (keyboard.get_keycode(CL_KEY_DOWN)) |
|
46 |
input_move |= INPUT_MOVE_DOWN; |
|
| 94 | 47 |
|
|
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
48 |
if (keyboard.get_keycode(CL_KEY_RSHIFT)) |
| 108 | 49 |
input_move |= INPUT_MOVE_JUMP; |
|
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
50 |
|
| 108 | 51 |
if (keyboard.get_keycode(CL_KEY_I)) |
52 |
player->debugInfo(); |
|
| 180 | 53 |
|
54 |
if (keyboard.get_keycode(CL_KEY_F)) {
|
|
55 |
Engine::log(DEBUG, "Graphics.check_input") << "Fire!"; |
|
|
182
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
56 |
input_move |= INPUT_SHOOT; |
| 180 | 57 |
} |
| 116 | 58 |
|
59 |
if (keyboard.get_keycode(CL_KEY_M)) |
|
60 |
input_move |= INPUT_MOVE_DIG; |
|
61 |
||
| 25 | 62 |
// apply movement if applicable |
|
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
25
diff
changeset
|
63 |
if (input_move) |
|
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
25
diff
changeset
|
64 |
player->handleMove(input_move); |
| 25 | 65 |
} |
66 |
||
67 |
void Graphics::do_redraw (void) {
|
|
68 |
CL_GraphicContext *gc = win.get_gc(); |
|
69 |
||
|
162
f760591b7481
Removed unnecessary variables (factoFoo) from do_redraw. Renamed
saiam
parents:
161
diff
changeset
|
70 |
// White background |
| 25 | 71 |
gc->clear(CL_Color::white); |
72 |
||
|
162
f760591b7481
Removed unnecessary variables (factoFoo) from do_redraw. Renamed
saiam
parents:
161
diff
changeset
|
73 |
// Draw terrain |
|
182
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
74 |
state.draw(gc); |
| 180 | 75 |
|
| 184 | 76 |
// Flip window buffer, sync |
77 |
win.flip(1); |
|
| 25 | 78 |
} |
79 |
||
80 |
void Graphics::on_update (void) {
|
|
81 |
// check keyboard input |
|
82 |
check_input(); |
|
83 |
||
84 |
// redraw display |
|
85 |
do_redraw(); |
|
86 |
} |