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