author | terom |
Mon, 08 Dec 2008 17:24:40 +0000 | |
changeset 296 | 4d3ebaa29430 |
parent 295 | 4d3adfbec077 |
child 305 | 56799ec8d7be |
permissions | -rw-r--r-- |
197 | 1 |
#include "Projectile.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:
226
diff
changeset
|
2 |
#include "Graphics.hh" |
208 | 3 |
#include "Timer.hh" |
197 | 4 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
272
diff
changeset
|
5 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
272
diff
changeset
|
6 |
Projectile::Projectile (Player *player, Vector position, Vector velocity, Weapon *weapon, bool visible) : |
279
e36f5e1a1c8d
let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents:
276
diff
changeset
|
7 |
PhysicsObject(player->state.world, PROJECTILE_MASS, position, velocity, PROJECTILE, weapon->getBounce()), |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
8 |
player(player), |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
9 |
visible(visible), |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
10 |
radius(weapon->getRadius()), |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
11 |
explosionRadius(weapon->getExplosionRadius()), |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
272
diff
changeset
|
12 |
expire(weapon->getExpire()) |
265 | 13 |
{ |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
14 |
// set birth tick |
208 | 15 |
birth_tick = world.tick_timer.get_ticks(); |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
16 |
|
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
17 |
// XXX: projectiles should be particles? |
197 | 18 |
std::vector<Vector> shape(4); |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
19 |
|
263
8c999cf4c182
weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
terom
parents:
257
diff
changeset
|
20 |
shape[0] = Vector(0, -radius ); |
8c999cf4c182
weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
terom
parents:
257
diff
changeset
|
21 |
shape[1] = Vector(+radius, 0 ); |
8c999cf4c182
weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
terom
parents:
257
diff
changeset
|
22 |
shape[2] = Vector(0, +radius ); |
8c999cf4c182
weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
terom
parents:
257
diff
changeset
|
23 |
shape[3] = Vector(-radius, 0 ); |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
24 |
|
197 | 25 |
setShape(shape); |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
26 |
|
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
27 |
// add to state |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
272
diff
changeset
|
28 |
player->state.addProjectile(this); |
197 | 29 |
} |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
30 |
|
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:
211
diff
changeset
|
31 |
Projectile::~Projectile (void) { |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
272
diff
changeset
|
32 |
player->state.projectiles.remove(this); |
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:
211
diff
changeset
|
33 |
} |
197 | 34 |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
35 |
void Projectile::onDestroy (Vector position, bool removeGround) { |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
36 |
if (removeGround) |
263
8c999cf4c182
weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
terom
parents:
257
diff
changeset
|
37 |
world.removeGround(position, explosionRadius); |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
38 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
39 |
destroy(); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
40 |
} |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
41 |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
42 |
void Projectile::onHitPlayer (Player *player, Health damage) { |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
43 |
player->takeDamage(damage); |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
44 |
} |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
45 |
|
272 | 46 |
void Projectile::onCollision (Vector collisionPoint, PhysicsObject *other) { |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
47 |
// did we hit a player? |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
48 |
if (other != NULL && other->getType() == PLAYER) { |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
49 |
Player* player = dynamic_cast<Player*>(other); |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
50 |
|
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
51 |
// XXX: check that player really is !NULL |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
52 |
onHitPlayer(player, 10); |
291 | 53 |
} |
54 |
||
279
e36f5e1a1c8d
let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents:
276
diff
changeset
|
55 |
if (collision_elasticity == 0) |
e36f5e1a1c8d
let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents:
276
diff
changeset
|
56 |
onDestroy(collisionPoint, true); |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
57 |
} |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
58 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
59 |
void Projectile::tick (TimeMS dt) { |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
60 |
// expire projectiles |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
61 |
if (world.tick_timer.get_ticks() > birth_tick + expire) |
226
381487d07d17
projectiles remove ground when expiring -> fixed digging
terom
parents:
224
diff
changeset
|
62 |
onDestroy(position, true); |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
63 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
64 |
// super |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
65 |
PhysicsObject::tick(dt); |
199 | 66 |
} |
67 |
||
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
68 |
void Projectile::draw(Graphics *g, PixelCoordinate camera) const { |
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:
226
diff
changeset
|
69 |
CL_GraphicContext *gc = 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:
226
diff
changeset
|
70 |
|
208 | 71 |
if (visible) { |
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
|
72 |
PixelCoordinate pos = getCoordinate() - camera; |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
73 |
PixelDimension radius = (unsigned int) this->radius; |
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
74 |
|
208 | 75 |
CL_Quad projectile( |
263
8c999cf4c182
weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
terom
parents:
257
diff
changeset
|
76 |
pos.x, pos.y - radius, |
8c999cf4c182
weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
terom
parents:
257
diff
changeset
|
77 |
pos.x + radius, pos.y, |
8c999cf4c182
weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
terom
parents:
257
diff
changeset
|
78 |
pos.x, pos.y + radius, |
8c999cf4c182
weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
terom
parents:
257
diff
changeset
|
79 |
pos.x - radius, pos.y |
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
80 |
); |
208 | 81 |
|
82 |
gc->fill_quad(projectile, CL_Color::green); |
|
199 | 83 |
} |
84 |
} |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
85 |