2021-06-30 23:16:45 +00:00
|
|
|
import { posInBox } from "./utils";
|
|
|
|
import { createJugandoState } from "./jugando";
|
|
|
|
import { Juego } from "./main";
|
2021-06-28 18:01:45 +00:00
|
|
|
|
|
|
|
export type State = {
|
2021-06-30 23:16:45 +00:00
|
|
|
current: "welcome";
|
|
|
|
};
|
2021-06-28 18:01:45 +00:00
|
|
|
|
|
|
|
function startButton(juego: Juego<State>) {
|
2021-06-30 23:16:45 +00:00
|
|
|
const [width, height] = [
|
|
|
|
juego.assets.botonJugar.width / 4,
|
|
|
|
juego.assets.botonJugar.height / 4,
|
|
|
|
];
|
|
|
|
return {
|
|
|
|
x: juego.canvas.width - width - 30,
|
|
|
|
y: juego.canvas.height - height - 30,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
};
|
2021-06-28 18:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function update(juego: Juego<State>, dt: number) {
|
2021-06-30 23:16:45 +00:00
|
|
|
const btn = startButton(juego);
|
|
|
|
if (juego.mouse.down && posInBox(btn, juego.mouse)) {
|
|
|
|
(juego as Juego<any>).state = createJugandoState();
|
|
|
|
}
|
2021-06-28 18:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function draw(juego: Juego<State>, timestamp: number) {
|
2021-06-30 23:16:45 +00:00
|
|
|
const btn = startButton(juego);
|
|
|
|
juego.ctx.drawImage(
|
|
|
|
juego.assets.botonJugar,
|
|
|
|
btn.x,
|
|
|
|
btn.y,
|
|
|
|
btn.width,
|
|
|
|
btn.height
|
|
|
|
);
|
2021-06-28 18:01:45 +00:00
|
|
|
}
|