-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathninjarope.cpp
119 lines (101 loc) · 2.02 KB
/
ninjarope.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "worm.hpp"
#include "constants.hpp"
#include "game.hpp"
#include "colour.hpp"
#include "math.hpp"
//#include <cmath>
void Ninjarope::process(Worm& owner)
{
if(out)
{
x += velX;
y += velY;
int ix = ftoi(x), iy = ftoi(y);
anchor = 0;
for(std::size_t i = 0; i < game.worms.size(); ++i)
{
Worm& w = *game.worms[i];
if(&w != &owner
&& checkForSpecWormHit(ix, iy, 1, w))
{
anchor = &w;
break;
}
}
fixed forceX, forceY;
fixed diffX = x - owner.x;
fixed diffY = y - owner.y;
forceX = (diffX << C[NRForceShlX]) / C[NRForceDivX];
forceY = (diffY << C[NRForceShlY]) / C[NRForceDivY];
curLen = (vectorLength(ftoi(diffX), ftoi(diffY)) + 1) << C[NRForceLenShl];
if(ix <= 0
|| ix >= game.level.width - 1
|| iy <= 0
|| iy >= game.level.height - 1
|| game.materials[game.level.pixel(ix, iy)].dirtRock())
{
if(!attached)
{
length = C[NRAttachLength];
attached = true;
if(game.level.inside(ix, iy))
{
PalIdx pix = game.level.pixel(ix, iy);
if(game.materials[pix].anyDirt())
{
for(int i = 0; i < 11; ++i) // TODO: Check 11 and read from exe
{
game.nobjectTypes[2].create2(
game.rand(128),
0, 0,
x, y,
pix,
&owner);
}
}
}
}
velX = 0;
velY = 0;
}
else if(anchor)
{
if(!attached)
{
length = C[NRAttachLength]; // TODO: Should this value be separate from the non-worm attaching?
attached = true;
}
if(curLen > length)
{
anchor->velX -= forceX / curLen;
anchor->velY -= forceY / curLen;
}
velX = anchor->velX;
velY = anchor->velY;
x = anchor->x;
y = anchor->y;
}
else
{
attached = false;
}
if(attached)
{
// curLen can't be 0
if(curLen > length)
{
owner.velX += forceX / curLen;
owner.velY += forceY / curLen;
}
}
else
{
velY += C[NinjaropeGravity];
if(curLen > length)
{
velX -= forceX / curLen;
velY -= forceY / curLen;
}
}
}
}