author | saiam |
Mon, 08 Dec 2008 20:33:40 +0000 | |
changeset 307 | 5b4806c61342 |
parent 302 | e734d8e9bbb5 |
child 308 | 60f4b55d5713 |
permissions | -rw-r--r-- |
218
86d22fe82b30
add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents:
217
diff
changeset
|
1 |
|
236 | 2 |
#include "Player.hh" |
3 |
#include "Weapons.hh" |
|
199 | 4 |
#include "Engine.hh" |
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:
231
diff
changeset
|
5 |
#include "Graphics.hh" |
198 | 6 |
|
209
68cc4248a508
sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents:
208
diff
changeset
|
7 |
#include <cstdlib> |
215
69de8d9fcc0a
image is working.. well.. run it from build/src folder.
nireco
parents:
213
diff
changeset
|
8 |
#include <ClanLib/display.h> |
216 | 9 |
#include <string> |
218
86d22fe82b30
add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents:
217
diff
changeset
|
10 |
#include <cassert> |
215
69de8d9fcc0a
image is working.. well.. run it from build/src folder.
nireco
parents:
213
diff
changeset
|
11 |
|
220
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
12 |
// player static state |
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
13 |
bool Player::skin_loaded = false; |
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
14 |
CL_Surface Player::skin_surface; |
215
69de8d9fcc0a
image is working.. well.. run it from build/src folder.
nireco
parents:
213
diff
changeset
|
15 |
|
220
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
16 |
// XXX: give these better names and move elsewhere |
248 | 17 |
const int img_num_aim = 2; |
219 | 18 |
const int img_num_step = 4; |
248 | 19 |
const int img_height = 20; |
20 |
const int img_width = 17; |
|
216 | 21 |
|
198 | 22 |
Player::Player(GameState &state, Vector position, bool visible) : |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
23 |
PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0), PLAYER, PLAYER_COLLISION_ELASTICITY), |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
24 |
state(state), |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
25 |
visible(visible), |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
26 |
weapons(buildWeaponsList()), |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
27 |
selectedWeapon(0), |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
28 |
rope(*this), |
300 | 29 |
health(PLAYER_HEALTH), |
30 |
respawn_timer(PLAYER_RESPAWN_DELAY), |
|
307
5b4806c61342
Deaths should be counted to Player::deaths parameter. Kills not counted yet.
saiam
parents:
302
diff
changeset
|
31 |
animation_step(0), |
5b4806c61342
Deaths should be counted to Player::deaths parameter. Kills not counted yet.
saiam
parents:
302
diff
changeset
|
32 |
kills(0), |
5b4806c61342
Deaths should be counted to Player::deaths parameter. Kills not counted yet.
saiam
parents:
302
diff
changeset
|
33 |
deaths(0) |
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
221
diff
changeset
|
34 |
{ |
236 | 35 |
// XXX: populate weapons from somewhere else |
36 |
||
220
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
37 |
// build the player's shape |
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
38 |
// XXX: these dimensions are incorrect... |
198 | 39 |
std::vector<Vector> shape(4); |
40 |
shape[0] = Vector(0,-9); |
|
41 |
shape[1] = Vector(6,0); |
|
42 |
shape[2] = Vector(0,9); |
|
43 |
shape[3] = Vector(-6,0); |
|
220
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
44 |
|
198 | 45 |
// Initialize the shape of the player (salmiakki shape) |
46 |
setShape(shape); |
|
220
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
47 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
272
diff
changeset
|
48 |
// add to GameState players list |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
272
diff
changeset
|
49 |
state.addPlayer(this); |
300 | 50 |
|
51 |
// connect respawn timer |
|
52 |
respawn_slot = respawn_timer.sig_tick().connect(this, &Player::respawn); |
|
53 |
||
54 |
// spawn |
|
55 |
spawn(position); |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
272
diff
changeset
|
56 |
} |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
272
diff
changeset
|
57 |
|
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
272
diff
changeset
|
58 |
Player::~Player (void) { |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
272
diff
changeset
|
59 |
state.removePlayer(this); |
198 | 60 |
} |
300 | 61 |
|
62 |
void Player::spawn (Vector position) { |
|
63 |
// dig hole |
|
64 |
world.removeGround(position, PLAYER_DIG_RADIUS); |
|
65 |
||
66 |
// update position |
|
67 |
setPosition(position); |
|
68 |
||
69 |
// enable |
|
70 |
enable(); |
|
71 |
} |
|
72 |
||
302 | 73 |
void Player::die (bool start_timer) { |
307
5b4806c61342
Deaths should be counted to Player::deaths parameter. Kills not counted yet.
saiam
parents:
302
diff
changeset
|
74 |
|
5b4806c61342
Deaths should be counted to Player::deaths parameter. Kills not counted yet.
saiam
parents:
302
diff
changeset
|
75 |
deaths++; // Increment death counter |
5b4806c61342
Deaths should be counted to Player::deaths parameter. Kills not counted yet.
saiam
parents:
302
diff
changeset
|
76 |
|
302 | 77 |
// we don't have a rope anymore |
78 |
rope.release(); |
|
79 |
||
300 | 80 |
// disable our PhysicsObject |
81 |
disable(); |
|
302 | 82 |
|
83 |
// XXX: PhysicsObject::reset |
|
84 |
this->velocity = Vector(0, 0); |
|
300 | 85 |
|
302 | 86 |
if (start_timer) { |
87 |
// start respawn timer |
|
88 |
respawn_timer.fire_once(); |
|
89 |
} |
|
300 | 90 |
} |
91 |
||
92 |
void Player::respawn (TimeMS dt) { |
|
93 |
(void) dt; |
|
94 |
||
95 |
// reset health |
|
96 |
health = PLAYER_HEALTH; |
|
97 |
||
302 | 98 |
// XXX: reload weapons |
99 |
||
300 | 100 |
// XXX: ... |
101 |
spawn(Vector(PLAYER_INITIAL_X, PLAYER_INITIAL_Y)); |
|
102 |
} |
|
236 | 103 |
|
272 | 104 |
void Player::handleDig (Vector pos, float radius) { |
250
84c553d61291
fixed digging, now bugs differently. Changed image_drawing to draw image 1:1
nireco
parents:
248
diff
changeset
|
105 |
// calculate new position and velocity |
272 | 106 |
Vector digPosition = pos + getDirection() * PROJECTILE_START_DISTANCE; |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
270
diff
changeset
|
107 |
|
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
270
diff
changeset
|
108 |
// remove directly |
270
d17126e20de7
Changed dig to use removeGround again. The problem with the digging is the fact that input isn't handled properly.
saiam
parents:
265
diff
changeset
|
109 |
world.removeGround(digPosition, radius); |
209
68cc4248a508
sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents:
208
diff
changeset
|
110 |
} |
68cc4248a508
sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents:
208
diff
changeset
|
111 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
112 |
void Player::handleFireWeapon (Weapon *weapon, Vector position, Vector velocity) { |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
113 |
weaponFired(weapon); |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
114 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
115 |
new Projectile(this, position, velocity, weapon); |
199 | 116 |
} |
237 | 117 |
|
118 |
void Player::handleChangeWeapon (unsigned int weaponIndex) { |
|
119 |
assert(weaponIndex < weapons.size()); |
|
120 |
||
121 |
selectedWeapon = weaponIndex; |
|
122 |
} |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
123 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
124 |
void Player::weaponFired (Weapon *weapon) { |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
125 |
// apply recoil |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
126 |
applyForce(-getDirection() * weapon->getRecoil()); |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
127 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
128 |
// reload weapon |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
129 |
weapon->reload(); |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
130 |
} |
199 | 131 |
|
221 | 132 |
void Player::printDebugInfo (void) { |
133 |
Engine::log(DEBUG, "layer.debug") << "In air: " << this->inAir; |
|
134 |
} |
|
135 |
||
136 |
void Player::tick (TimeMS dt) { |
|
137 |
// let PhysicsObject execute |
|
138 |
PhysicsObject::tick(dt); |
|
300 | 139 |
|
221 | 140 |
// tick current weapon reload |
236 | 141 |
if (getCurrentWeapon()) |
142 |
getCurrentWeapon()->tickReload(dt); |
|
221 | 143 |
} |
241 | 144 |
|
145 |
void Player::handleRopeState (RopeState state) { |
|
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
146 |
(void) state; |
241 | 147 |
} |
148 |
||
149 |
void Player::handleRopeLength (float length) { |
|
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
150 |
(void) length; |
241 | 151 |
} |
199 | 152 |
|
300 | 153 |
/* |
154 |
* LocalPlayer |
|
155 |
*/ |
|
236 | 156 |
void LocalPlayer::fireWeapon (Weapon *weapon) { |
235 | 157 |
// calculate new position and velocity |
158 |
Vector shotPosition = position + getDirection() * PROJECTILE_START_DISTANCE; |
|
236 | 159 |
Vector shotVelocity = velocity + getDirection() * weapon->getSpeed(); |
258
833ad8d7db8b
The first weapon now has a recoil so that you can fly. There is a bug with facing when you are flying with recoil.
saiam
parents:
257
diff
changeset
|
160 |
|
223 | 161 |
// execute |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
162 |
handleFireWeapon(weapon, shotPosition, shotVelocity); |
223 | 163 |
} |
237 | 164 |
|
165 |
void LocalPlayer::changeWeapon (int delta) { |
|
166 |
// need to handle negative deltas |
|
167 |
handleChangeWeapon((weapons.size() + selectedWeapon + delta) % weapons.size()); |
|
168 |
} |
|
223 | 169 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
170 |
void LocalPlayer::handleInput (PlayerInput input, TimeMS dt) { |
299 | 171 |
// if we are dead, we can't do anything |
172 |
if (!isAlive()) |
|
173 |
return; |
|
174 |
||
221 | 175 |
// Movement force, vertical is always zero |
176 |
Vector move_force = Vector(0, 0); |
|
199 | 177 |
|
221 | 178 |
// Crosshair angle change |
179 |
float aim_delta = 0; |
|
199 | 180 |
|
221 | 181 |
// handle movement left/right by applying a horizontal force, but limit the player's speed |
235 | 182 |
// also update facing if needed |
262 | 183 |
if (!((input & INPUT_MOVE_LEFT) && (input & INPUT_MOVE_RIGHT))) { |
184 |
if (input & INPUT_MOVE_LEFT) { |
|
185 |
if (velocity.x > -PLAYER_MAX_SPEED) |
|
186 |
move_force.x -= PLAYER_MOVE_FORCE; |
|
187 |
||
264 | 188 |
setFacing(FACING_LEFT); |
262 | 189 |
} |
221 | 190 |
|
262 | 191 |
if (input & INPUT_MOVE_RIGHT) { |
192 |
if (velocity.x < PLAYER_MAX_SPEED) |
|
193 |
move_force.x += PLAYER_MOVE_FORCE; |
|
194 |
||
264 | 195 |
setFacing(FACING_RIGHT); |
262 | 196 |
} |
221 | 197 |
} |
198 |
||
199 |
// handle aim by creating a aim angle delta |
|
200 |
if (input & INPUT_AIM_UP) |
|
293 | 201 |
aim_delta += CROSSHAIR_ANGLE_SPEED*dt; |
221 | 202 |
|
203 |
if (input & INPUT_AIM_DOWN) |
|
293 | 204 |
aim_delta -= CROSSHAIR_ANGLE_SPEED*dt; |
221 | 205 |
|
206 |
// handle jumping by invoking the jump method |
|
207 |
// XXX: the direction should ideally be given using some other method |
|
208 |
if (input & INPUT_JUMP) { |
|
209 |
if (input & INPUT_MOVE_LEFT) |
|
199 | 210 |
jump(-1); |
221 | 211 |
|
212 |
else if (input & INPUT_MOVE_RIGHT) |
|
199 | 213 |
jump(1); |
221 | 214 |
|
199 | 215 |
else |
216 |
jump(0); |
|
217 |
} |
|
221 | 218 |
|
219 |
// outsource digging to Player::handleDig, since this modifies the Terrain and Network needs to know |
|
235 | 220 |
if (input & INPUT_DIG) |
300 | 221 |
handleDig(position, PLAYER_DIG_RADIUS); |
221 | 222 |
|
237 | 223 |
// change weapon back/forth |
224 |
if (input & INPUT_CHANGE_PREV) |
|
225 |
changeWeapon(-1); |
|
226 |
||
227 |
if (input & INPUT_CHANGE_NEXT) |
|
228 |
changeWeapon(+1); |
|
213 | 229 |
|
221 | 230 |
// validate shoot events, and then outsource to handleShoot so Network can intercept it |
236 | 231 |
if ((input & INPUT_SHOOT) && getCurrentWeapon()->canShoot()) |
232 |
fireWeapon(getCurrentWeapon()); |
|
221 | 233 |
|
241 | 234 |
// rope throw+release+changeLength, but supress spurious events |
225 | 235 |
if (input & INPUT_ROPE) |
235 | 236 |
rope.throwRope(); |
225 | 237 |
|
241 | 238 |
if (input & INPUT_UNROPE && rope.getState() != ROPE_FOLDED) |
229 | 239 |
rope.release(); |
240 |
||
241 | 241 |
if (input & INPUT_ROPE_UP && rope.getState() == ROPE_FIXED) |
235 | 242 |
rope.changeLength(-ROPE_GROWTH_RATE); |
231 | 243 |
|
241 | 244 |
if (input & INPUT_ROPE_DOWN && rope.getState() == ROPE_FIXED) |
235 | 245 |
rope.changeLength(ROPE_GROWTH_RATE); |
231 | 246 |
|
235 | 247 |
// XXX: how should this be written? What does this do? Probably broken under network play |
221 | 248 |
if (move_force.x != 0) |
249 |
animation_step = (animation_step + 1) % img_num_step; |
|
199 | 250 |
|
221 | 251 |
// apply aim delta |
252 |
if (aim_delta) |
|
253 |
changeAim(aim_delta); |
|
219 | 254 |
|
221 | 255 |
// apply force |
256 |
if (!move_force.zero()) |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
257 |
applyForce(move_force, dt); |
300 | 258 |
|
259 |
// suicide? |
|
260 |
if (input & INPUT_SUICIDE) |
|
261 |
die(); |
|
199 | 262 |
} |
263 |
||
236 | 264 |
Weapon* Player::getCurrentWeapon() { |
235 | 265 |
return weapons[selectedWeapon % weapons.size()]; |
212 | 266 |
} |
215
69de8d9fcc0a
image is working.. well.. run it from build/src folder.
nireco
parents:
213
diff
changeset
|
267 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
268 |
Weapon* Player::getWeapon (WeaponID id) { |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
269 |
if (id < weapons.size()) |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
270 |
return weapons[id]; |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
271 |
else |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
272 |
return NULL; |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
273 |
} |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
274 |
|
295 | 275 |
void Player::onCollision (Vector collisionPoint, PhysicsObject *other) { |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
276 |
(void) collisionPoint; |
295 | 277 |
|
278 |
if (other == NULL) |
|
279 |
return; |
|
280 |
||
281 |
// Currently we handle only player-player collision here. |
|
282 |
// Player-projectile collision is handled in projectile's onCollision. |
|
298 | 283 |
// XXX: not completely network-safe |
295 | 284 |
if (other->getType() == PLAYER) { |
285 |
Vector normal = this->getPosition() - other->getPosition(); |
|
286 |
this->bounce(normal); |
|
298 | 287 |
|
295 | 288 |
// Move the player back to its previous position so that players won't |
289 |
// stuff inside each others when having a collision walk, e.g. |
|
290 |
this->setPosition(this->getPreviousPosition()); |
|
291 |
} |
|
292 |
} |
|
293 |
||
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
294 |
void Player::takeDamage (Health damage) { |
299 | 295 |
health -= damage; |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
296 |
|
299 | 297 |
if (health <= 0) |
300 | 298 |
die(); |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
299 |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
300 |
Engine::log(DEBUG, "player.take_damage") << this << ": damage=" << damage << ", health=" << health; |
289 | 301 |
} |
302 |
||
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
303 |
void Player::draw (Graphics *g, PixelCoordinate camera) { |
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:
231
diff
changeset
|
304 |
CL_GraphicContext *gc = g->get_gc(); |
299 | 305 |
|
306 |
if (!isAlive()) |
|
307 |
return; |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
308 |
|
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
309 |
// animation indexes |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
310 |
int aim_img_idx = (int)((1 - (getAim() + KG_PI / 2) / KG_PI) * img_num_aim); |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
311 |
int step_img_idx = animation_step % img_num_step; |
217 | 312 |
|
220
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
313 |
// load skin image if not yet loaded |
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
314 |
if (!skin_loaded) { |
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
315 |
skin_surface = CL_Surface(PLAYER_SKIN_PATH); |
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
316 |
skin_loaded = true; |
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
317 |
} |
221 | 318 |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
319 |
// calulate where to draw the worm |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
320 |
CL_Rectf destination( |
264 | 321 |
position.x + (facing == FACING_RIGHT ? -1 : 1) * img_width / 2 - camera.x, |
322 |
position.y - img_height / 2 - camera.y, |
|
323 |
position.x + (facing == FACING_RIGHT ? 1 : -1) * img_width / 2 - camera.x, |
|
324 |
position.y + img_height / 2 - camera.y |
|
221 | 325 |
); |
217 | 326 |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
327 |
// draw the correct animation frame from the skin |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
328 |
skin_surface.draw_subpixel( |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
329 |
CL_Rectf( |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
330 |
step_img_idx * img_width, |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
331 |
aim_img_idx * img_height, |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
332 |
(1 + step_img_idx) * img_width, |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
333 |
(aim_img_idx + 1) * img_height |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
334 |
), destination, gc |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
335 |
); |
218
86d22fe82b30
add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents:
217
diff
changeset
|
336 |
|
261 | 337 |
// draw a proper crosshair-box |
338 |
PixelCoordinate crosshair = getCoordinate() + world.getPixelCoordinate(getDirection() * PLAYER_CROSSHAIR_DISTANCE) - camera; |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
339 |
|
261 | 340 |
gc->draw_rect( |
341 |
CL_Rectf( |
|
342 |
crosshair.x - PLAYER_CROSSHAIR_WIDTH / 2, |
|
343 |
crosshair.y - PLAYER_CROSSHAIR_WIDTH / 2, |
|
344 |
crosshair.x + PLAYER_CROSSHAIR_WIDTH / 2, |
|
345 |
crosshair.y + PLAYER_CROSSHAIR_WIDTH / 2 |
|
346 |
), CL_Color::red |
|
347 |
); |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
348 |
|
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
349 |
// draw rope |
248 | 350 |
rope.draw(g, camera); |
215
69de8d9fcc0a
image is working.. well.. run it from build/src folder.
nireco
parents:
213
diff
changeset
|
351 |
} |
69de8d9fcc0a
image is working.. well.. run it from build/src folder.
nireco
parents:
213
diff
changeset
|
352 |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
353 |
void LocalPlayer::draw (Graphics *g, bool displayWeapon, PixelCoordinate camera) { |
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:
231
diff
changeset
|
354 |
// superclass draw |
248 | 355 |
Player::draw(g, camera); |
219 | 356 |
|
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:
231
diff
changeset
|
357 |
// display weapon name? |
299 | 358 |
if (isAlive() && displayWeapon && getCurrentWeapon()) { |
236 | 359 |
const std::string weaponName = getCurrentWeapon()->getName(); |
360 |
||
257
549783d71e51
add a handful of consts to PhysicsObject and modify draw to use getCoordinate, and replace old skin.png with new skin.png
terom
parents:
255
diff
changeset
|
361 |
PixelCoordinate pc = getCoordinate() - camera; |
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
362 |
|
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
363 |
// XXX: fix magic constants once we know how big the worm is |
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:
231
diff
changeset
|
364 |
g->getSimpleFont().draw( |
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
365 |
pc.x - g->getSimpleFont().get_width(weaponName) / 2, |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
250
diff
changeset
|
366 |
pc.y - 20, |
236 | 367 |
weaponName, |
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:
231
diff
changeset
|
368 |
g->get_gc() |
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
231
diff
changeset
|
369 |
); |
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
231
diff
changeset
|
370 |
} |
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
231
diff
changeset
|
371 |
} |
235 | 372 |