2021-07-01 22:33:51 +00:00
|
|
|
import { isTouching, posInBox } from "./utils";
|
2021-06-30 23:16:45 +00:00
|
|
|
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);
|
2021-07-01 22:33:51 +00:00
|
|
|
if (
|
|
|
|
(juego.mouse.down && posInBox(btn, juego.mouse)) ||
|
|
|
|
isTouching(juego, btn)
|
|
|
|
) {
|
2021-07-02 18:17:35 +00:00
|
|
|
(juego as Juego<any>).state = createJugandoState(juego);
|
2021-06-30 23:16:45 +00:00
|
|
|
}
|
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
|
|
|
}
|