need you
This commit is contained in:
parent
1f311679f7
commit
7ebabb5cc3
|
|
@ -6,17 +6,20 @@ import { randomId } from "../shared/utils.js"
|
||||||
import { setStatus, addOutput } from "./scrollback.js"
|
import { setStatus, addOutput } from "./scrollback.js"
|
||||||
import { browserCommands } from "./commands.js"
|
import { browserCommands } from "./commands.js"
|
||||||
|
|
||||||
|
const FPS = 30
|
||||||
let oldMode = "cinema"
|
let oldMode = "cinema"
|
||||||
let stopGame = false
|
let stopGame = false
|
||||||
let canvas: HTMLCanvasElement
|
let canvas: HTMLCanvasElement
|
||||||
type Game = { init?: () => void, update?: (delta: number, input: InputState) => void, draw?: (ctx: GameContext) => void }
|
type Game = { init?: () => void, update?: (delta: number, input: InputState) => void, draw?: (ctx: GameContext) => void }
|
||||||
|
|
||||||
const pressedStack = new Set()
|
const pressedStack = new Set<string>()
|
||||||
|
|
||||||
let pressed: InputState = {
|
let pressed: InputState = {
|
||||||
key: "",
|
key: "",
|
||||||
shift: false,
|
shift: false,
|
||||||
ctrl: false,
|
ctrl: false,
|
||||||
meta: false,
|
meta: false,
|
||||||
|
pressed: pressedStack
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleGameStart(msg: Message) {
|
export async function handleGameStart(msg: Message) {
|
||||||
|
|
@ -86,7 +89,7 @@ function gameLoop(ctx: GameContext, game: Game) {
|
||||||
if (stopGame) return
|
if (stopGame) return
|
||||||
|
|
||||||
const delta = ts - last
|
const delta = ts - last
|
||||||
if (delta >= 1000 / 30) {
|
if (delta >= 1000 / FPS) {
|
||||||
if (game.update) game.update(delta, pressed)
|
if (game.update) game.update(delta, pressed)
|
||||||
if (game.draw) game.draw(ctx)
|
if (game.draw) game.draw(ctx)
|
||||||
last = ts
|
last = ts
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user