-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tom Hohler
committed
Apr 19, 2018
1 parent
d64067d
commit 0682623
Showing
8 changed files
with
200 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Position } from "./position"; | ||
import { Vector2 } from "./vector2"; | ||
|
||
export class CheckPoint { | ||
|
||
constructor(readonly pos1: Position, readonly pos2: Position) {} | ||
|
||
passed(previousPos: Position, nextPos: Position) { | ||
const AB = new Vector2(this.pos2.x - this.pos1.x, this.pos2.y - this.pos1.y); | ||
const pAM = new Vector2(previousPos.x - this.pos1.x, previousPos.y - this.pos1.y); | ||
const nAM = new Vector2(nextPos.x - this.pos1.x, nextPos.y - this.pos1.y); | ||
|
||
if (nAM.norm > AB.norm) { | ||
return false; | ||
} | ||
if (AB.dot(nAM) < 0) { | ||
return false; | ||
} | ||
|
||
return AB.determinant(nAM) === 0 || (AB.determinant(nAM) >= 0 && AB.determinant(pAM) <= 0); | ||
} | ||
|
||
distanceTo(pos: Position) { | ||
return new Position((this.pos2.x + this.pos1.x) / 2, (this.pos2.y + this.pos1.y) / 2).distanceTo(pos); | ||
} | ||
|
||
static fromJson(json: any) { | ||
return new CheckPoint(new Position(json.pos1.x, json.pos1.y), new Position(json.pos2.x, json.pos2.y)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
[ | ||
{ | ||
"pos1": { | ||
"x": 300, | ||
"y": 10 | ||
}, | ||
"pos2": { | ||
"x": 300, | ||
"y": 140 | ||
} | ||
}, | ||
{ | ||
"pos1": { | ||
"x": 1000, | ||
"y": 50 | ||
}, | ||
"pos2": { | ||
"x": 800, | ||
"y": 150 | ||
} | ||
}, | ||
{ | ||
"pos1": { | ||
"x": 850, | ||
"y": 300 | ||
}, | ||
"pos2": { | ||
"x": 650, | ||
"y": 300 | ||
} | ||
}, | ||
{ | ||
"pos1": { | ||
"x": 1000, | ||
"y": 700 | ||
}, | ||
"pos2": { | ||
"x": 800, | ||
"y": 580 | ||
} | ||
}, | ||
{ | ||
"pos1": { | ||
"x": 500, | ||
"y": 750 | ||
}, | ||
"pos2": { | ||
"x": 500, | ||
"y": 600 | ||
} | ||
}, | ||
{ | ||
"pos1": { | ||
"x": 100, | ||
"y": 500 | ||
}, | ||
"pos2": { | ||
"x": 300, | ||
"y": 550 | ||
} | ||
}, | ||
{ | ||
"pos1": { | ||
"x": 430, | ||
"y": 270 | ||
}, | ||
"pos2": { | ||
"x": 600, | ||
"y": 200 | ||
} | ||
}, | ||
{ | ||
"pos1": { | ||
"x": 0, | ||
"y": 200 | ||
}, | ||
"pos2": { | ||
"x": 150, | ||
"y": 200 | ||
} | ||
} | ||
] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { CheckPoint } from "./checkPoint"; | ||
|
||
export class Map { | ||
constructor(readonly collisionMap: number[][], readonly checkPoints: CheckPoint[]) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module "*.json" { | ||
const value: any; | ||
export default value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters