From 4d04c2782115ad6ddadbc9e61ef495a1a67887ec Mon Sep 17 00:00:00 2001 From: OfficialCHenry Date: Wed, 6 Apr 2022 22:54:57 -0400 Subject: [PATCH] added player falloff respawns(teleports) the player if they fall off the map --- src/shattered_sword/Scenes/GameLevel.ts | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/shattered_sword/Scenes/GameLevel.ts b/src/shattered_sword/Scenes/GameLevel.ts index 5f18633..6bd85aa 100644 --- a/src/shattered_sword/Scenes/GameLevel.ts +++ b/src/shattered_sword/Scenes/GameLevel.ts @@ -95,6 +95,22 @@ export default class GameLevel extends Scene { } } + + + //handle collisions + + + //move background + + + // Get the viewport center and padded size + const viewportCenter = this.viewport.getCenter().clone(); + const baseViewportSize = this.viewport.getHalfSize().scaled(2); + //check position of player + this.playerFalloff(viewportCenter, baseViewportSize); + + + } /** @@ -269,4 +285,20 @@ export default class GameLevel extends Scene { this.sceneManager.changeToScene(MainMenu, {}); Input.enableInput(); } + + + + /** + * + * handles the player falling off the map + * + * @param viewportCenter The center of the viewport + * @param viewportSize The size of the viewport + */ + playerFalloff(viewportCenter: Vec2, viewportSize: Vec2):void{ + if(this.player.position.y >= viewportCenter.y +viewportSize.y/2.0){ + + this.player.position.set(this.playerSpawn.x,this.playerSpawn.y); + } + } } \ No newline at end of file