Skip to content

Commit d5d24c7

Browse files
committed
fix: Fix cut rope and adjust box collision
1 parent 7072874 commit d5d24c7

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

src/Player.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ export class Player {
171171
}
172172
}
173173
cutRope = (index) => {
174-
if (index >= this.rope.length - 1) index = this.rope.length - 2; // Make sure we can cut the rope if we pass the wrong index
175174
this.isRopeCut = true;
176-
this.rope[index].removeLink();
175+
this.rope.cutRope(index);
177176
};
178177

179178
listenForGameEvents() {

src/Rope.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,21 @@ export class Rope {
113113
const max = Math.max(left, right, top, bot);
114114

115115
if (max === right) {
116-
node.pos.x = b.x - 5;
116+
node.pos.x = b.x - 3;
117117
} else if (max === left) {
118-
node.pos.x = b.x + b.width + 5;
118+
node.pos.x = b.x + b.width + 3;
119119
} else if (max === bot) {
120-
node.pos.y = b.y - 5;
120+
node.pos.y = b.y - 3;
121121
} else if (max === top) {
122-
node.pos.y = b.y + b.height + 5;
122+
node.pos.y = b.y + b.height + 3;
123123
}
124124
}
125125
});
126126
}
127+
cutRope(index) {
128+
if (index >= this.nodes.length - 1) index = this.nodes.length - 2; // Make sure we can cut the rope if we pass the wrong index
129+
this.links.splice(index, 1);
130+
}
127131

128132
get length() {
129133
return this.nodes.length;

src/VerletNode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Vector } from 'kontra';
33
export class VerletNode {
44
pos;
55
oldPos;
6-
width = 5;
7-
height = 5;
6+
width = 2;
7+
height = 2;
88
constructor({ x, y }) {
99
this.pos = Vector(x, y);
1010
console.log(this.pos);

src/level/level2.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"p": { "x": 400, "y": 240 },
3+
"r": 30,
4+
"s": [],
5+
"b": [
6+
{ "x": 272, "y": 220 },
7+
{ "x": 304, "y": 220 },
8+
{ "x": 336, "y": 220 },
9+
{ "x": 368, "y": 220 },
10+
{ "x": 400, "y": 220 },
11+
{ "x": 432, "y": 220 },
12+
{ "x": 464, "y": 220 },
13+
{ "x": 496, "y": 220 },
14+
{ "x": 464, "y": 300 },
15+
{ "x": 304, "y": 300 }
16+
],
17+
"g": [{ "x": 368, "y": 700 }],
18+
"h": [{ "x": 550, "y": 290 }]
19+
}

0 commit comments

Comments
 (0)