author | ekku |
Sat, 06 Dec 2008 19:38:01 +0000 | |
changeset 225 | 22ecb9cb9245 |
parent 224 | e6faefba2ec1 |
child 226 | 381487d07d17 |
permissions | -rw-r--r-- |
197 | 1 |
#include "Projectile.hh" |
208 | 2 |
#include "Timer.hh" |
197 | 3 |
|
208 | 4 |
Projectile::Projectile(GameState &state, Vector position, Vector velocity, bool visible, float radius, TickCount age) : |
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
|
5 |
PhysicsObject(state.world, PLAYER_MASS, position, velocity), state(state), visible(visible), radius(radius), age(age) { |
208 | 6 |
birth_tick = world.tick_timer.get_ticks(); |
211
d5d52fb191e4
some minor fixes, shots now explode in collisionpoint
nireco
parents:
208
diff
changeset
|
7 |
// Don't think these are needed anymore |
197 | 8 |
std::vector<Vector> shape(4); |
9 |
shape[0] = Vector(-1, -1); |
|
10 |
shape[1] = Vector(-1, 1); |
|
11 |
shape[2] = Vector(1, 1); |
|
12 |
shape[3] = Vector(1, -1); |
|
13 |
setShape(shape); |
|
211
d5d52fb191e4
some minor fixes, shots now explode in collisionpoint
nireco
parents:
208
diff
changeset
|
14 |
|
197 | 15 |
target_visible = false; |
16 |
collision_elasticity = 0.9; // = shotType.elasticity |
|
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
|
17 |
state.addProjectile(this); |
197 | 18 |
} |
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
|
19 |
|
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
|
20 |
Projectile::~Projectile (void) { |
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
|
21 |
state.projectiles.remove(this); |
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
|
22 |
} |
197 | 23 |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
24 |
void Projectile::onDestroy (Vector position, bool removeGround) { |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
25 |
if (removeGround) |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
26 |
world.removeGround(position, radius); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
27 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
28 |
destroy(); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
29 |
} |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
30 |
|
201 | 31 |
void Projectile::onCollision() { |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
32 |
onDestroy(position, true); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
33 |
} |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
34 |
|
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 |
void Projectile::tick (TimeMS dt) { |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
37 |
// expire projectiles |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
38 |
if (world.tick_timer.get_ticks() > birth_tick + age) |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
39 |
onDestroy(position, false); |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
40 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
41 |
// super |
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
42 |
PhysicsObject::tick(dt); |
199 | 43 |
} |
44 |
||
211
d5d52fb191e4
some minor fixes, shots now explode in collisionpoint
nireco
parents:
208
diff
changeset
|
45 |
void Projectile::draw(CL_GraphicContext *gc) const { |
208 | 46 |
if (visible) { |
204 | 47 |
|
208 | 48 |
CL_Quad projectile( |
49 |
(int)((position).x+1), (int)((position).y+1), |
|
50 |
(int)((position).x-1), (int)((position).y+1), |
|
51 |
(int)((position).x+1), (int)((position).y-1), |
|
52 |
(int)((position).x-1), (int)((position).y-1) |
|
53 |
); |
|
54 |
||
55 |
gc->fill_quad(projectile, CL_Color::green); |
|
56 |
||
57 |
const uint16_t chlen = 10; |
|
58 |
uint16_t x = projectile.center().x; |
|
59 |
uint16_t y = projectile.center().y; |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
60 |
if (target_visible) { |
208 | 61 |
if (facingRight) { |
62 |
gc->draw_line(x, y, |
|
63 |
x + std::cos(aim)*chlen, |
|
64 |
y - std::sin(aim)*chlen, |
|
65 |
CL_Color::black); |
|
66 |
} else { |
|
67 |
gc->draw_line(x, y, |
|
68 |
x - std::cos(aim)*chlen, |
|
69 |
y - std::sin(aim)*chlen, |
|
70 |
CL_Color::black); |
|
71 |
} |
|
199 | 72 |
} |
73 |
} |
|
74 |
} |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
222
diff
changeset
|
75 |