added player falloff

respawns(teleports) the player if they fall off the map
This commit is contained in:
OfficialCHenry 2022-04-06 22:54:57 -04:00
parent d13a77e902
commit 4d04c27821

View File

@ -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, {}); this.sceneManager.changeToScene(MainMenu, {});
Input.enableInput(); 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);
}
}
} }