-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add moving platforms and players with more levels and less gravity
- Loading branch information
1 parent
fc25def
commit 7d9b86b
Showing
15 changed files
with
277 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Vector } from 'kontra'; | ||
|
||
import { acc } from './constants'; | ||
import { lineIntersection } from './utils'; | ||
|
||
export class BounceBoard { | ||
p1; | ||
p2; | ||
level; | ||
|
||
constructor({ p1, p2, level }) { | ||
this.p1 = Vector(p1.x, p1.y); | ||
this.p2 = Vector(p2.x, p2.y); | ||
this.level = level; | ||
} | ||
update() { | ||
this.handlePlayerCollision(this.level.player); | ||
} | ||
|
||
render(ctx) { | ||
ctx.beginPath(); | ||
ctx.lineWidth = 4; | ||
ctx.strokeStyle = acc; | ||
// TODO (johnedvard) add bounce effect when hitting line | ||
ctx.moveTo(this.p1.x, this.p1.y); | ||
ctx.lineTo(this.p2.x, this.p2.y); | ||
|
||
ctx.stroke(); | ||
ctx.restore(); | ||
} | ||
|
||
handlePlayerCollision(player) { | ||
const intersectionPoint = lineIntersection( | ||
this.p1, | ||
this.p2, | ||
player.oldPos, | ||
player.currPos | ||
); | ||
if (intersectionPoint) { | ||
player.oldPos = Vector(player.oldPos.x - 100, player.oldPos.y + 100); | ||
player.currPos = Vector(player.oldPos.x + 100, player.oldPos.y - 100); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.