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