diff --git a/src/Player.js b/src/Player.js index 9f830c7..6521b11 100644 --- a/src/Player.js +++ b/src/Player.js @@ -171,9 +171,8 @@ export class Player { } } cutRope = (index) => { - if (index >= this.rope.length - 1) index = this.rope.length - 2; // Make sure we can cut the rope if we pass the wrong index this.isRopeCut = true; - this.rope[index].removeLink(); + this.rope.cutRope(index); }; listenForGameEvents() { diff --git a/src/Rope.js b/src/Rope.js index bc99044..10e414a 100644 --- a/src/Rope.js +++ b/src/Rope.js @@ -113,17 +113,21 @@ export class Rope { const max = Math.max(left, right, top, bot); if (max === right) { - node.pos.x = b.x - 5; + node.pos.x = b.x - 3; } else if (max === left) { - node.pos.x = b.x + b.width + 5; + node.pos.x = b.x + b.width + 3; } else if (max === bot) { - node.pos.y = b.y - 5; + node.pos.y = b.y - 3; } else if (max === top) { - node.pos.y = b.y + b.height + 5; + node.pos.y = b.y + b.height + 3; } } }); } + cutRope(index) { + if (index >= this.nodes.length - 1) index = this.nodes.length - 2; // Make sure we can cut the rope if we pass the wrong index + this.links.splice(index, 1); + } get length() { return this.nodes.length; diff --git a/src/VerletNode.js b/src/VerletNode.js index f59934b..127a4e1 100644 --- a/src/VerletNode.js +++ b/src/VerletNode.js @@ -3,8 +3,8 @@ import { Vector } from 'kontra'; export class VerletNode { pos; oldPos; - width = 5; - height = 5; + width = 2; + height = 2; constructor({ x, y }) { this.pos = Vector(x, y); console.log(this.pos); diff --git a/src/level/level2.json b/src/level/level2.json new file mode 100644 index 0000000..3fc44c8 --- /dev/null +++ b/src/level/level2.json @@ -0,0 +1,19 @@ +{ + "p": { "x": 400, "y": 240 }, + "r": 30, + "s": [], + "b": [ + { "x": 272, "y": 220 }, + { "x": 304, "y": 220 }, + { "x": 336, "y": 220 }, + { "x": 368, "y": 220 }, + { "x": 400, "y": 220 }, + { "x": 432, "y": 220 }, + { "x": 464, "y": 220 }, + { "x": 496, "y": 220 }, + { "x": 464, "y": 300 }, + { "x": 304, "y": 300 } + ], + "g": [{ "x": 368, "y": 700 }], + "h": [{ "x": 550, "y": 290 }] +}