author | Tero Marttila <terom@fixme.fi> |
Sun, 02 Jun 2013 16:15:23 +0300 | |
changeset 448 | 34bdf0783874 |
parent 434 | a8ba81432ddd |
permissions | -rw-r--r-- |
197 | 1 |
#include "Projectile.hh" |
208 | 2 |
#include "Timer.hh" |
197 | 3 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
272
diff
changeset
|
4 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
272
diff
changeset
|
5 |
Projectile::Projectile (Player *player, Vector position, Vector velocity, Weapon *weapon, bool visible) : |
338 | 6 |
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
|
7 |
player(player), |
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
279
diff
changeset
|
8 |
visible(visible), |
305 | 9 |
weapon(weapon) |
265 | 10 |
{ |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
11 |
// set birth tick |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
338
diff
changeset
|
12 |
birth_tick = world.getTicks(); |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
13 |
|
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
14 |
// XXX: projectiles should be particles? |
197 | 15 |
std::vector<Vector> shape(4); |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
16 |
|
305 | 17 |
shape[0] = Vector(0 , -weapon->getRadius() ); |
18 |
shape[1] = Vector(weapon->getRadius() , 0 ); |
|
19 |
shape[2] = Vector(0 , weapon->getRadius() ); |
|
20 |
shape[3] = Vector(-weapon->getRadius(), 0 ); |
|
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
21 |
|
197 | 22 |
setShape(shape); |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
23 |
|
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
24 |
// 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
|
25 |
player->state.addProjectile(this); |
197 | 26 |
} |
271
bf6784a95b08
touch up weapon/projectile with comments and slight tweaking
terom
parents:
265
diff
changeset
|
27 |
|
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
|
28 |
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
|
29 |
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
|
30 |
} |
197 | 31 |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
32 |
void Projectile::onDestroy (Vector position, bool removeGround) { |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
33 |
if (removeGround) |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
338
diff
changeset
|
34 |
world.terrain.removeGround(position, weapon->getExplosionRadius()); |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
35 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
36 |
destroy(); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
37 |
} |
308
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
38 |
|
434
a8ba81432ddd
move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents:
428
diff
changeset
|
39 |
Health Projectile::getDamage (void) { |
308
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
40 |
return weapon->getDamage(); |
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
41 |
} |
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
42 |
|
434
a8ba81432ddd
move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents:
428
diff
changeset
|
43 |
void Projectile::addKillToOwner (void) { |
308
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
44 |
player->addKill(); |
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
45 |
} |
309 | 46 |
|
308
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
47 |
void Projectile::onHitPlayer (Player *player) { |
60f4b55d5713
Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents:
305
diff
changeset
|
48 |
player->takeDamage(this); |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
49 |
} |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
50 |
|
272 | 51 |
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
|
52 |
// did we hit a player? |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
53 |
if (other != NULL && other->getType() == PLAYER) { |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
54 |
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
|
55 |
|
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
295
diff
changeset
|
56 |
// 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
|
57 |
onHitPlayer(player); |
291 | 58 |
} |
59 |
||
279
e36f5e1a1c8d
let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents:
276
diff
changeset
|
60 |
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
|
61 |
onDestroy(collisionPoint, true); |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
62 |
} |
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 |
void Projectile::tick (TimeMS dt) { |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
65 |
// expire projectiles |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
338
diff
changeset
|
66 |
if (world.getTicks() > birth_tick + weapon->getExpire()) |
428
712b943195a6
clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents:
417
diff
changeset
|
67 |
onDestroy(getPosition(), true); |
224
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 |
// super |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
70 |
PhysicsObject::tick(dt); |
199 | 71 |
} |
72 |
||
417
c503e0c6a740
support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents:
412
diff
changeset
|
73 |
#if GRAPHICS_ENABLED |
412
721c60072091
new graphics code compiles... no, it doesn't work yet
Tero Marttila <terom@fixme.fi>
parents:
408
diff
changeset
|
74 |
void Projectile::draw(graphics::Display &display, PixelCoordinate camera) const { |
721c60072091
new graphics code compiles... no, it doesn't work yet
Tero Marttila <terom@fixme.fi>
parents:
408
diff
changeset
|
75 |
CL_GraphicContext *gc = display.get_gc(); |
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
|
76 |
|
208 | 77 |
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
|
78 |
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
|
79 |
// XXX: scale |
305 | 80 |
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
|
81 |
|
208 | 82 |
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
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
); |
208 | 88 |
|
89 |
gc->fill_quad(projectile, CL_Color::green); |
|
199 | 90 |
} |
91 |
} |
|
417
c503e0c6a740
support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents:
412
diff
changeset
|
92 |
#endif |
c503e0c6a740
support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents:
412
diff
changeset
|
93 |