225
|
1 |
#include "Player.hh"
|
|
2 |
#include "Rope.hh"
|
|
3 |
#include "Engine.hh"
|
|
4 |
#include <math.h>
|
|
5 |
|
|
6 |
Rope::Rope(Player &climber) : PhysicsObject(climber.state.world, PLAYER_MASS, Vector(0,0), Vector(0,0), false), pl(climber), rs(FOLDED) {
|
|
7 |
std::vector<Vector> shape(4);
|
|
8 |
shape[0] = Vector(-1, -1);
|
|
9 |
shape[1] = Vector(-1, 1);
|
|
10 |
shape[2] = Vector(1, 1);
|
|
11 |
shape[3] = Vector(1, -1);
|
|
12 |
setShape(shape);
|
|
13 |
}
|
|
14 |
|
|
15 |
void Rope::shoot(void) {
|
|
16 |
|
|
17 |
this->rs = FLYING;
|
|
18 |
|
|
19 |
this->length = 100;
|
|
20 |
this->position = pl.getPosition();
|
|
21 |
Vector direction = pl.getFacing() ? Vector( cos(pl.getAim()), -sin(pl.getAim()) )
|
|
22 |
: Vector( -cos(pl.getAim()), -sin(pl.getAim()) );
|
|
23 |
this->velocity = pl.getVelocity() + direction*500;
|
|
24 |
this->inAir = true;
|
|
25 |
|
|
26 |
enable();
|
|
27 |
pl.state.addRope(this);
|
|
28 |
}
|
|
29 |
|
|
30 |
void Rope::onCollision() {
|
|
31 |
this->rs = FIXED;
|
228
|
32 |
|
|
33 |
// stop movement
|
225
|
34 |
disable();
|
228
|
35 |
|
|
36 |
// set player's pivot
|
|
37 |
pl.setPivot(this);
|
225
|
38 |
}
|
|
39 |
|
|
40 |
void Rope::release (void) {
|
229
|
41 |
|
|
42 |
if (this->rs == FLYING)
|
|
43 |
disable();
|
|
44 |
|
225
|
45 |
// TODO make it fly first and fold only
|
|
46 |
// after it's close to the player
|
|
47 |
this->rs = FOLDED;
|
228
|
48 |
|
|
49 |
// player doesn't have a pivot anymore
|
|
50 |
pl.setPivot(NULL);
|
225
|
51 |
}
|
|
52 |
|
|
53 |
RopeState Rope::getState (void) {
|
|
54 |
return this->rs;
|
|
55 |
}
|
|
56 |
|
228
|
57 |
float Rope::getPivotForce (PhysicsObject *bob) {
|
|
58 |
if ( (this->position - pl.getPosition()).length() >= this->length)
|
229
|
59 |
return 3500;
|
228
|
60 |
else
|
|
61 |
return 0;
|
|
62 |
}
|
|
63 |
|
225
|
64 |
void Rope::draw (CL_GraphicContext *gc) const {
|
|
65 |
gc->draw_line((int)(this->pl.getPosition().x), (int)(this->pl.getPosition().y)
|
|
66 |
, (int)(this->position.x), (int)(this->position.y), CL_Color::black);
|
|
67 |
}
|
|
68 |
|