author | Tero Marttila <terom@fixme.fi> |
Tue, 13 Jan 2009 23:15:47 +0200 | |
changeset 393 | 5dd4d782cf3a |
parent 392 | 6c4dc68360eb |
child 394 | 82def222fe7d |
permissions | -rw-r--r-- |
25 | 1 |
|
2 |
#include "Graphics.hh" |
|
86 | 3 |
#include "GameState.hh" |
108 | 4 |
#include <cmath> |
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
5 |
#include <sstream> |
25 | 6 |
|
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
7 |
/* |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
8 |
* XXX: until we figure out a better way to layout stuff |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
9 |
*/ |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
10 |
static PixelArea getMessageViewArea (PixelCoordinate resolution) { |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
11 |
return PixelArea( |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
12 |
400, |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
13 |
resolution.y - 100, |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
14 |
resolution.x, |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
15 |
resolution.y |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
16 |
); |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
17 |
} |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
18 |
|
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
19 |
Graphics::Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen) : |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
20 |
CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, resolution.x, resolution.y, fullscreen), |
25 | 21 |
engine(engine), |
22 |
state(state), |
|
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
23 |
resolution(resolution), |
25 | 24 |
update_timer(GRAPHICS_UPDATE_INTERVAL_MS), |
235 | 25 |
input(get_ic()->get_keyboard()), |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
26 |
simple_font("Font2", engine.getResourceManager()), |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
27 |
message_view(getMessageViewArea(resolution)) |
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
28 |
{ |
86 | 29 |
|
25 | 30 |
// connect timer signal |
205 | 31 |
slots.connect(update_timer.sig_tick(), this, &Graphics::on_update); |
25 | 32 |
|
33 |
// enable |
|
205 | 34 |
update_timer.start(); |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
35 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
36 |
// push something to message_view |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
37 |
message_view.add_message(CL_Color::white, "Hello World"); |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
38 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
39 |
// GameState events.... |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
40 |
state.setEventHandler(this); |
25 | 41 |
} |
42 |
||
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
43 |
const std::vector<CL_DisplayMode> & Graphics::getDisplayModes (void) { |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
44 |
return CL_DisplayMode::get_display_modes(); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
45 |
} |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
46 |
|
392
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
47 |
const CL_DisplayMode Graphics::getBestMode (void) { |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
48 |
const std::vector<CL_DisplayMode> &modes = Graphics::getDisplayModes(); |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
49 |
|
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
50 |
const CL_DisplayMode *best_mode = NULL; |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
51 |
|
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
52 |
for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++) |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
53 |
if (best_mode == NULL || ( |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
54 |
it->get_resolution().width * it->get_resolution().height > |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
55 |
best_mode->get_resolution().width * best_mode->get_resolution().height |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
56 |
)) |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
57 |
best_mode = &*it; |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
58 |
|
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
59 |
if (best_mode == NULL) |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
60 |
throw Error("No available video modes!"); |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
61 |
|
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
62 |
return *best_mode; |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
63 |
} |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
64 |
|
311
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
282
diff
changeset
|
65 |
void Graphics::check_input (void) { |
25 | 66 |
LocalPlayer *player; |
311
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
282
diff
changeset
|
67 |
PlayerInput input_mask; |
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
282
diff
changeset
|
68 |
TimeMS input_dt; |
25 | 69 |
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
70 |
// update gui flags |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
71 |
handle_input(input.readGuiInput()); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
72 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
73 |
// stop here if we don't have a local player |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
74 |
if ((player = state.getLocalPlayer()) == NULL) |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
75 |
return; |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
76 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
77 |
// build input_mask |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
78 |
input.readPlayerInput(input_mask, input_dt); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
79 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
80 |
// apply input if there was any |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
81 |
if (input_mask) |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
82 |
player->handleInput(input_mask, input_dt); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
83 |
} |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
84 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
85 |
void Graphics::handle_input (GuiInput flags) { |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
86 |
// update flags |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
87 |
this->flags = flags; |
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
88 |
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
89 |
// quit? |
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
90 |
if (flags & GUI_INPUT_QUIT) { |
108 | 91 |
engine.stop(); |
25 | 92 |
|
108 | 93 |
return; |
25 | 94 |
} |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
95 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
96 |
// dump player debug info on stderr |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
97 |
if ((flags & GUI_INPUT_DEBUG_PLAYER) && state.getLocalPlayer()) { |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
98 |
state.getLocalPlayer()->printDebugInfo(); |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
99 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
100 |
message_view.add_message(CL_Color::green, "..."); |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
101 |
} |
25 | 102 |
|
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
103 |
// toggle fullscreen? |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
104 |
if (flags & GUI_INPUT_TOGGLE_FULLSCREEN) { |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
105 |
if (is_fullscreen()) |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
106 |
set_windowed(); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
107 |
else |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
108 |
set_fullscreen(); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
109 |
} |
25 | 110 |
} |
111 |
||
266
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
112 |
static PixelDimension value_between (PixelDimension low, PixelDimension value, PixelDimension high) { |
316
d909a7e36f8d
value_between now puts small map in the center, or at least should
nireco
parents:
315
diff
changeset
|
113 |
if (high < low) |
d909a7e36f8d
value_between now puts small map in the center, or at least should
nireco
parents:
315
diff
changeset
|
114 |
return (high + low) / 2; |
d909a7e36f8d
value_between now puts small map in the center, or at least should
nireco
parents:
315
diff
changeset
|
115 |
|
d909a7e36f8d
value_between now puts small map in the center, or at least should
nireco
parents:
315
diff
changeset
|
116 |
else if (value < low) |
266
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
117 |
return low; |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
118 |
|
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
119 |
else if (value > high) |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
120 |
return high; |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
121 |
|
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
122 |
else |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
123 |
return value; |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
124 |
} |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
125 |
|
25 | 126 |
void Graphics::do_redraw (void) { |
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
127 |
CL_GraphicContext *gc = get_gc(); |
266
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
128 |
LocalPlayer *player; |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
129 |
|
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
130 |
// calculate camera |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
131 |
PixelCoordinate camera(0, 0); |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
132 |
|
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
133 |
// ...to track our local player |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
134 |
if ((player = state.getLocalPlayer()) != NULL) { |
377
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
135 |
// try and center the screen on the player |
318 | 136 |
PixelCoordinate target = player->getCoordinate() - PixelCoordinate(resolution.x / 2, (resolution.y - 100) / 2); |
377
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
137 |
|
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
138 |
// ...but keep the world in view |
318 | 139 |
PixelCoordinate max = state.world.getDimensions() - resolution + PixelCoordinate(0, 100); |
266
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
140 |
|
377
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
141 |
// ...by limiting the value to 0...max |
266
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
142 |
camera = PixelCoordinate( |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
143 |
value_between(0, target.x, max.x), |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
144 |
value_between(0, target.y, max.y) |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
145 |
); |
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
146 |
} |
25 | 147 |
|
312 | 148 |
// Black background |
248 | 149 |
gc->clear(CL_Color::black); |
25 | 150 |
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
151 |
// Draw the game |
266
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
248
diff
changeset
|
152 |
state.draw(this, camera, flags & GUI_INPUT_DISPLAY_WEAPON); |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
153 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
154 |
// draw player info box |
312 | 155 |
if (player != NULL) { |
377
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
156 |
draw_player_info(gc, player); |
312 | 157 |
} |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
158 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
159 |
// draw messages |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
160 |
message_view.draw(this); |
312 | 161 |
|
184 | 162 |
// Flip window buffer, sync |
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
163 |
flip(1); |
25 | 164 |
} |
165 |
||
205 | 166 |
void Graphics::on_update (TimeMS tick_length) { |
311
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
282
diff
changeset
|
167 |
(void) tick_length; |
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
282
diff
changeset
|
168 |
|
25 | 169 |
// check keyboard input |
311
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
282
diff
changeset
|
170 |
check_input(); |
25 | 171 |
|
172 |
// redraw display |
|
173 |
do_redraw(); |
|
174 |
} |
|
315 | 175 |
|
176 |
void Graphics::draw_player_info(CL_GraphicContext *gc, Player *p) { |
|
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
177 |
int box_top = resolution.y - 100; |
315 | 178 |
int box_left = 0; |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
179 |
int box_right = resolution.x; |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
377
diff
changeset
|
180 |
int box_bottom = resolution.y; |
318 | 181 |
int bar_length = 3; // *100 |
315 | 182 |
|
183 |
// draw status info at bottom of display |
|
184 |
gc->fill_rect( |
|
185 |
CL_Rect( |
|
186 |
box_left, |
|
187 |
box_top, |
|
188 |
box_right, |
|
189 |
box_bottom |
|
190 |
), |
|
191 |
CL_Gradient( |
|
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
192 |
CL_Color(0, 0, 0), |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
193 |
CL_Color(50, 50, 50), |
315 | 194 |
CL_Color(50, 50, 50, 150), |
195 |
CL_Color(100, 100, 100, 200) |
|
196 |
) |
|
197 |
); |
|
318 | 198 |
|
377
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
199 |
// Health |
315 | 200 |
gc->draw_rect( |
201 |
CL_Rect( |
|
202 |
box_left + 9, |
|
203 |
box_top + 9, |
|
318 | 204 |
box_left + 11 + 100 * bar_length, |
315 | 205 |
box_top + 31 |
206 |
), |
|
207 |
CL_Color(150, 150, 150) |
|
208 |
); |
|
209 |
||
210 |
gc->fill_rect( |
|
211 |
CL_Rect( |
|
212 |
box_left + 10, |
|
213 |
box_top + 10, |
|
318 | 214 |
box_left + 10 + (int) (p->getHealthPercent() * bar_length), |
315 | 215 |
box_top + 30 |
216 |
), |
|
217 |
CL_Gradient( |
|
218 |
CL_Color(200, 0, 0), |
|
219 |
CL_Color(200 - (int)(p->getHealthPercent() * 2), (int)(p->getHealthPercent() * 2), 0), |
|
220 |
CL_Color(200, 0, 0), |
|
221 |
CL_Color(200 - (int)(p->getHealthPercent() * 2), (int)(p->getHealthPercent() * 2), 0) |
|
222 |
) |
|
223 |
); |
|
377
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
224 |
|
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
225 |
// stats - kills |
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
226 |
std::stringstream sskills; |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
227 |
sskills << "Kills: " << p->getKills(); |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
228 |
getSimpleFont().draw( |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
229 |
box_left + 20 + 100 * bar_length, |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
230 |
box_top + 10, |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
231 |
sskills.str(), |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
232 |
get_gc() |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
233 |
); |
377
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
234 |
|
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
235 |
// stats - deaths |
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
236 |
std::stringstream ssdeaths; |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
237 |
ssdeaths << "Deaths: " << p->getDeaths(); |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
238 |
getSimpleFont().draw( |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
239 |
box_left + 20 + 100 * bar_length, |
326 | 240 |
box_top + 30, |
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
241 |
ssdeaths.str(), |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
242 |
get_gc() |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
243 |
); |
377
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
244 |
|
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
245 |
// stats - ratio |
326 | 246 |
std::stringstream ssratio; |
247 |
ssratio << "Ratio: " << (p->getKills()+1) / (p->getDeaths()+1); |
|
248 |
getSimpleFont().draw( |
|
249 |
box_left + 20 + 100 * bar_length, |
|
250 |
box_top + 50, |
|
251 |
ssratio.str(), |
|
252 |
get_gc() |
|
253 |
); |
|
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
254 |
|
318 | 255 |
|
377
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
256 |
// Weapon clip / reloading |
318 | 257 |
gc->draw_rect( |
258 |
CL_Rect( |
|
259 |
box_left + 9, |
|
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
260 |
box_top + 69, |
318 | 261 |
box_left + 11 + 100 * bar_length, |
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
262 |
box_top + 91 |
318 | 263 |
), |
264 |
CL_Color(150, 150, 150) |
|
265 |
); |
|
266 |
||
267 |
gc->fill_rect( |
|
268 |
CL_Rect( |
|
269 |
box_left + 10, |
|
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
270 |
box_top + 70, |
354 | 271 |
box_left + 10 + (100 - (int) (p->getCurrentWeapon()->getReloadTimer() * 100 / p->getCurrentWeapon()->getReloadTime())) * bar_length, |
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
272 |
box_top + 90 |
318 | 273 |
), |
274 |
CL_Gradient( |
|
275 |
CL_Color(100, 100, 0), |
|
276 |
CL_Color(100, 100, 0), |
|
277 |
CL_Color(100, 100, 0), |
|
278 |
CL_Color(100, 100, 100) |
|
279 |
) |
|
280 |
); |
|
377
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
281 |
|
01d3c340b372
direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents:
354
diff
changeset
|
282 |
// current weapon name |
325
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
283 |
getSimpleFont().draw( |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
284 |
box_left + 20 + 100 * bar_length, |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
285 |
box_top + 70, |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
286 |
p->getCurrentWeapon()->getName(), |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
287 |
get_gc() |
a19c78786d7f
kills, deaths and weapon name is displayed in right place
nireco
parents:
318
diff
changeset
|
288 |
); |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
289 |
|
315 | 290 |
} |
291 |
||
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
292 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
293 |
void Graphics::on_player_joined (Player *p) { |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
294 |
message_view.add_message(CL_Color::white, " *** Player joined"); |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
295 |
} |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
296 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
297 |
void Graphics::on_player_left (Player *p) { |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
298 |
message_view.add_message(CL_Color::white, " *** Player left"); |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
299 |
} |