11import Phaser from "phaser" ;
2+ import { Player } from "../Player" ;
23import { PlaceholderAssets } from "../createPlaceholderAssets" ;
34import { AnalogKey , AnalogReport } from "../../components/ConnectDevice" ;
45import { SpriteAssets } from "../createSpriteAssets" ;
56
67export class GameScene extends Phaser . Scene {
8+ private player ! : Player ;
9+
710 private switchy ! : Phaser . GameObjects . Sprite ;
811
912 private background ! : Phaser . GameObjects . TileSprite ;
@@ -59,8 +62,7 @@ export class GameScene extends Phaser.Scene {
5962 SpriteAssets . createSprites ( this ) ;
6063
6164 // Set up Switchy (the player character)
62- this . switchy = this . add . sprite ( gameWidth / 2 , gameHeight - 16 , "switchy" ) ;
63- this . switchy . play ( "switchy-walk" ) ;
65+ this . player = new Player ( this , gameWidth / 2 , gameHeight - 16 , "switchy" ) ;
6466
6567 // Collision optimizations
6668 // this.switchy.setCollideWorldBounds(true);
@@ -80,11 +82,7 @@ export class GameScene extends Phaser.Scene {
8082 // The A key moves from center to the left of the screen
8183 // The D key moves from center to the right of the screen
8284 // Update position according to horizontal
83- this . switchy . setPosition (
84- this . cameras . main . width / 2 +
85- ( this . horizontal * this . cameras . main . width ) / 2 ,
86- this . cameras . main . height - 16
87- ) ;
85+ this . player . update ( this . horizontal ) ;
8886
8987 // Jump when space is pressed or screen is tapped (handled via pointer events)
9088 // if (this.input.keyboard && Phaser.Input.Keyboard.JustDown(this.jumpKey)) {
0 commit comments