These 32 files and commands come from the same configuration used by the download.
Entry point: src/main.ts
import { createUI } from "./ui"
import Phaser from "phaser"
import "./style.css"
import { advanceScore } from "./score"
import { createSimulation } from "./simulation"
import { createInput } from "./input"
class GameScene extends Phaser.Scene {
private player!: Phaser.GameObjects.Rectangle
private collectible!: Phaser.GameObjects.Arc
private controls!: ReturnType<typeof createInput>
private simulation = createSimulation({ x: 400, y: 280, speed: 250, minX: 14, maxX: 786, minY: 14, maxY: 546 })
private score = 0
private ui = createUI()
create() {
this.add.grid(400, 280, 800, 560, 40, 40, 0x101e29, 1, 0x213844, 0.7)
this.player = this.add.rectangle(400, 280, 28, 28, 0xb5f46a)
this.collectible = this.add.circle(580, 280, 11, 0xffc77a)
this.game.canvas.tabIndex = 0
this.game.canvas.setAttribute("aria-label", "Game. Use arrow keys to collect gold.")
const ball = this.add.circle(150, 60, 15, 0xa78bfa)
const floor = this.add.rectangle(150, 500, 200, 20, 0x475569)
this.physics.add.existing(ball)
this.physics.add.existing(floor, true)
;(ball.body as Phaser.Physics.Arcade.Body).setBounce(0.8)
this.physics.add.collider(ball, floor)
this.controls = createInput(this.game.canvas)
this.events.once("shutdown", () => this.ui.dispose())
}
update(_time: number, delta: number) {
this.physics.world.isPaused = this.ui.isPaused()
if (!this.controls || this.ui.isPaused()) return
const position = this.simulation.step(this.controls.read(), delta / 1000)
this.player.setPosition(position.x, position.y)
if (Phaser.Math.Distance.Between(this.player.x, this.player.y, this.collectible.x, this.collectible.y) < 28) {
this.score = advanceScore(this.score)
const label = document.querySelector("#score")
if (label) label.textContent = "Collected: " + this.score
this.collectible.setPosition(Phaser.Math.Between(35, 765), Phaser.Math.Between(70, 525))
}
}
}
const game = new Phaser.Game({ type: Phaser.AUTO, parent: "game", width: 800, height: 560, backgroundColor: "#101e29", input: { keyboard: false }, physics: { default: "arcade", arcade: { gravity: { x: 0, y: 500 } } }, scale: { mode: Phaser.Scale.FIT, autoCenter: Phaser.Scale.CENTER_BOTH }, scene: GameScene })
window.addEventListener("pagehide", () => game.destroy(true), { once: true })