| author | terom |
| Tue, 09 Dec 2008 03:28:25 +0000 | |
| changeset 358 | 37b18b779ffb |
| parent 338 | fe2b3c6fff54 |
| child 408 | e6cfc44266af |
| 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) : |
| 338 | 7 |
PhysicsObject(player->state.world, weapon->getMass(), 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), |
| 305 | 10 |
weapon(weapon) |
| 265 | 11 |
{
|
|
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
12 |
// set birth tick |
| 208 | 13 |
birth_tick = world.tick_timer.get_ticks(); |
|
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
14 |
|
|
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
15 |
// XXX: projectiles should be particles? |
| 197 | 16 |
std::vector<Vector> shape(4); |
|
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
17 |
|
| 305 | 18 |
shape[0] = Vector(0 , -weapon->getRadius() ); |
19 |
shape[1] = Vector(weapon->getRadius() , 0 ); |
|
20 |
shape[2] = Vector(0 , weapon->getRadius() ); |
|
21 |
shape[3] = Vector(-weapon->getRadius(), 0 ); |
|
|
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
22 |
|
| 197 | 23 |
setShape(shape); |
|
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
24 |
|
|
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
25 |
// 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
|
26 |
player->state.addProjectile(this); |
| 197 | 27 |
} |
|
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
28 |
|
|
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
|
29 |
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
|
30 |
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
|
31 |
} |
| 197 | 32 |
|
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
33 |
void Projectile::onDestroy (Vector position, bool removeGround) {
|
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
34 |
if (removeGround) |
| 305 | 35 |
world.removeGround(position, weapon->getExplosionRadius()); |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
36 |
|
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
37 |
destroy(); |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
38 |
} |
|
308
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
39 |
|
|
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
40 |
Health Projectile::getDamage () {
|
|
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
41 |
return weapon->getDamage(); |
|
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
42 |
} |
|
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
43 |
|
|
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
44 |
void Projectile::addKillToOwner () {
|
|
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
45 |
player->addKill(); |
|
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
46 |
} |
| 309 | 47 |
|
48 |
const Player* Projectile::getOwner () {
|
|
49 |
return player; |
|
50 |
} |
|
|
308
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
51 |
|
|
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
52 |
void Projectile::onHitPlayer (Player *player) {
|
|
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
53 |
player->takeDamage(this); |
|
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
54 |
} |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
55 |
|
| 272 | 56 |
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
|
57 |
// did we hit a player? |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
58 |
if (other != NULL && other->getType() == PLAYER) {
|
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
59 |
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
|
60 |
|
|
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
61 |
// XXX: check that player really is !NULL |
|
308
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
62 |
onHitPlayer(player); |
| 291 | 63 |
} |
64 |
||
|
279
e36f5e1a1c8d
let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents:
276
diff
changeset
|
65 |
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
|
66 |
onDestroy(collisionPoint, true); |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
67 |
} |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
68 |
|
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
69 |
void Projectile::tick (TimeMS dt) {
|
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
70 |
// expire projectiles |
| 305 | 71 |
if (world.tick_timer.get_ticks() > birth_tick + weapon->getExpire()) |
|
226
381487d07d17
projectiles remove ground when expiring -> fixed digging
terom
parents:
224
diff
changeset
|
72 |
onDestroy(position, true); |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
73 |
|
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
74 |
// super |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
75 |
PhysicsObject::tick(dt); |
| 199 | 76 |
} |
77 |
||
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
78 |
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
|
79 |
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
|
80 |
|
| 208 | 81 |
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
|
82 |
PixelCoordinate pos = getCoordinate() - camera; |
|
311
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
309
diff
changeset
|
83 |
// XXX: scale |
| 305 | 84 |
PixelDimension radius = (unsigned int) weapon->getRadius(); |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
252
diff
changeset
|
85 |
|
| 208 | 86 |
CL_Quad projectile( |
|
311
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
309
diff
changeset
|
87 |
pos.x, pos.y - radius, |
|
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
309
diff
changeset
|
88 |
pos.x + radius, pos.y, |
|
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
309
diff
changeset
|
89 |
pos.x, pos.y + radius, |
|
440763821484
make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents:
309
diff
changeset
|
90 |
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
|
91 |
); |
| 208 | 92 |
|
93 |
gc->fill_quad(projectile, CL_Color::green); |
|
| 199 | 94 |
} |
95 |
} |
|
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
96 |