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