Skip to content

Commit

Permalink
fix: Fix cut rope and adjust box collision
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedvard committed Aug 25, 2022
1 parent 7072874 commit d5d24c7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 8 additions & 4 deletions src/Rope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/VerletNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions src/level/level2.json
Original file line number Diff line number Diff line change
@@ -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 }]
}

0 comments on commit d5d24c7

Please sign in to comment.