Skip to content

Commit

Permalink
reorder levels
Browse files Browse the repository at this point in the history
  • Loading branch information
edloper committed Dec 7, 2024
1 parent ca6eb0b commit 0bda524
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
36 changes: 27 additions & 9 deletions javascript/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,37 @@ class Game {
const startDot = this.activeEdge.start;
const edge = this.addEdge(startDot, endDot);
this.history.push(new GameHistoryEvent("add", startDot, endDot));
this.graph.removeEdge(this.activeEdge);
} else {
this.graph.removeEdge(this.activeEdge, /*animate=*/ true);
}
this.graph.removeEdge(this.activeEdge);
this.activeEdge = null;
}

okToConnectActiveEdgeTo(targetDot, x, y) {
return (
(targetDot !== null) &&
(targetDot !== this.activeEdge.start) &&
(!this.dotsAreConnectedByEdge(this.activeEdge.start, targetDot)) &&
(targetDot.numEdgesLeft() > 0) &&
(Math.hypot(targetDot.x-x, targetDot.y-y) < 40)
);
okToConnectActiveEdgeTo(endDot, x, y) {
const startDot = this.activeEdge.start;
if (endDot === null) {
return false;
}
if (endDot === startDot) {
return false;
}
if (this.dotsAreConnectedByEdge(startDot, endDot)) {
return false;
}
if (endDot.numEdgesLeft() <= 0) {
return false;
}
if (Math.hypot(endDot.x-x, endDot.y-y) > 40) {
return false;
}
for (const edge of this.graph.edges) {
if (edge.end && linesIntersect(edge.start, edge.end, startDot, endDot)) {
console.log("Can't connect -- overlap edge!")
return false;
}
}
return true;
}

dotsAreConnectedByEdge(dot1, dot2) {
Expand Down
2 changes: 1 addition & 1 deletion javascript/level_urls.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

const LEVEL_URLS = [
"levels/butter.json",
"levels/tri.json",
"levels/dog.json",
"levels/fox.json",
"levels/penguin.json",
"levels/butter.json",
];
1 change: 1 addition & 0 deletions javascript/shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function trianglesOverlap(corners1, corners2) {

// returns true if the line from p1->p2 intersects with p3->p4.
function linesIntersect(p1, p2, p3, p4) {
console.log(p1, p2, p3, p4);
const x1 = p1.x;
const x2 = p2.x;
const x3 = p3.x;
Expand Down

0 comments on commit 0bda524

Please sign in to comment.