2021-07-02 18:29:14 +00:00
|
|
|
import { Juego, State as AllState } from "./main";
|
2021-06-30 23:16:45 +00:00
|
|
|
import { Sprite } from "./sprite";
|
2021-07-01 22:33:51 +00:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
boxCollision,
|
|
|
|
drawText,
|
|
|
|
isMobile,
|
|
|
|
isTouching,
|
2021-07-06 17:09:21 +00:00
|
|
|
posInBox,
|
2021-07-01 22:33:51 +00:00
|
|
|
randomFromArray,
|
2021-07-06 17:09:21 +00:00
|
|
|
share,
|
2021-07-01 22:33:51 +00:00
|
|
|
} from "./utils";
|
2021-07-06 17:09:21 +00:00
|
|
|
import * as welcome from "./welcome";
|
2021-06-30 23:16:45 +00:00
|
|
|
|
|
|
|
const ENEMIES_NUM = 12;
|
2021-07-06 21:58:10 +00:00
|
|
|
const SEED_COOLDOWN = 150;
|
2021-06-30 23:16:45 +00:00
|
|
|
const MAP_MIN = 1000;
|
2021-07-02 18:17:35 +00:00
|
|
|
const MAP_MAX = 10000;
|
2021-06-30 23:16:45 +00:00
|
|
|
const MAP_SIZE = MAP_MAX - MAP_MIN;
|
2021-07-02 18:17:35 +00:00
|
|
|
const SIGNATURES_TO_WIN = 20000;
|
|
|
|
const CITIZENS = SIGNATURES_TO_WIN / 1000;
|
2021-06-30 23:16:45 +00:00
|
|
|
const TIME = 2 * 60 * 1000;
|
2021-07-01 21:16:00 +00:00
|
|
|
const TIME_LOST_WHEN_HIT = 20 * 1000;
|
2021-06-28 19:20:41 +00:00
|
|
|
|
2021-07-02 18:17:35 +00:00
|
|
|
type Citizen = { x: number; sprite: Sprite };
|
|
|
|
|
2021-06-28 18:01:45 +00:00
|
|
|
export type State = {
|
2021-06-30 23:16:45 +00:00
|
|
|
current: "jugando";
|
2021-07-05 16:13:36 +00:00
|
|
|
has: "lost" | "won" | null;
|
2021-07-06 21:38:25 +00:00
|
|
|
playing: boolean;
|
2021-06-30 23:16:45 +00:00
|
|
|
pos: { x: number };
|
|
|
|
view: { x: number };
|
|
|
|
side: "left" | "right";
|
2021-07-01 20:45:37 +00:00
|
|
|
enemies: { x: number; sprite: Sprite }[];
|
2021-06-30 23:16:45 +00:00
|
|
|
seeds: { x: number; velocity: { x: number } }[];
|
|
|
|
trees: { x: number; sprite: Sprite }[];
|
2021-07-02 18:17:35 +00:00
|
|
|
citizens: Citizen[];
|
|
|
|
signatures: number;
|
2021-07-06 17:58:08 +00:00
|
|
|
justSigned: number;
|
2021-06-30 23:16:45 +00:00
|
|
|
time: number;
|
|
|
|
seedCooldown: number;
|
|
|
|
};
|
2021-06-28 18:01:45 +00:00
|
|
|
|
2021-07-02 18:17:35 +00:00
|
|
|
export function createJugandoState(juego: Juego<any>): State {
|
|
|
|
let citizens = [];
|
|
|
|
for (let i = 0; i < CITIZENS; i++) {
|
|
|
|
citizens.push({
|
|
|
|
x: MAP_MIN + (i + 1) * (MAP_SIZE / CITIZENS),
|
|
|
|
sprite: randomFromArray([
|
|
|
|
juego.sprites.ciudadanx1,
|
|
|
|
juego.sprites.ciudadanx2,
|
|
|
|
juego.sprites.ciudadanx3,
|
|
|
|
]),
|
|
|
|
});
|
|
|
|
}
|
2021-06-30 23:16:45 +00:00
|
|
|
return {
|
|
|
|
current: "jugando",
|
2021-07-05 16:13:36 +00:00
|
|
|
has: null,
|
2021-07-06 21:38:25 +00:00
|
|
|
playing: false,
|
2021-07-02 18:17:35 +00:00
|
|
|
pos: { x: MAP_MIN + 100 },
|
2021-06-30 23:16:45 +00:00
|
|
|
view: { x: 0 },
|
|
|
|
side: "right",
|
|
|
|
enemies: [],
|
|
|
|
seeds: [],
|
|
|
|
trees: [],
|
2021-07-02 18:17:35 +00:00
|
|
|
signatures: 0,
|
|
|
|
citizens,
|
2021-07-06 17:58:08 +00:00
|
|
|
justSigned: 0,
|
2021-06-30 23:16:45 +00:00
|
|
|
time: TIME,
|
|
|
|
seedCooldown: 0,
|
|
|
|
};
|
2021-06-28 18:01:45 +00:00
|
|
|
}
|
|
|
|
|
2021-07-01 22:33:51 +00:00
|
|
|
function touchControls(juego: Juego<State>): {
|
|
|
|
left: Box;
|
|
|
|
right: Box;
|
|
|
|
center: Box;
|
|
|
|
} {
|
|
|
|
return {
|
|
|
|
left: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: juego.canvas.width / 7,
|
|
|
|
height: juego.canvas.height,
|
|
|
|
},
|
|
|
|
right: {
|
|
|
|
x: juego.canvas.width - juego.canvas.width / 7,
|
|
|
|
y: 0,
|
|
|
|
width: juego.canvas.width / 7,
|
|
|
|
height: juego.canvas.height,
|
|
|
|
},
|
|
|
|
center: {
|
|
|
|
x: juego.canvas.width / 7,
|
|
|
|
y: 0,
|
|
|
|
width: juego.canvas.width - (juego.canvas.width / 7) * 2,
|
|
|
|
height: juego.canvas.height,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-06 17:09:21 +00:00
|
|
|
function shareButton(juego: Juego<State>): {
|
|
|
|
box: Box;
|
|
|
|
sprite: Sprite;
|
|
|
|
} {
|
|
|
|
const sprite =
|
|
|
|
juego.state.has === "won"
|
|
|
|
? juego.sprites.botonCompartirFelicitaciones
|
|
|
|
: juego.sprites.botonCompartirPerdiste;
|
|
|
|
|
|
|
|
const width = sprite.getWidth(juego);
|
|
|
|
const height = sprite.getHeight(juego);
|
|
|
|
return {
|
|
|
|
box: {
|
2021-07-06 20:19:47 +00:00
|
|
|
x: juego.canvas.width - width - 5,
|
|
|
|
y: juego.canvas.height * 0.85 - height,
|
2021-07-06 17:09:21 +00:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
},
|
|
|
|
sprite,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-28 18:01:45 +00:00
|
|
|
export function update(juego: Juego<State>, dt: number) {
|
2021-07-06 17:09:21 +00:00
|
|
|
if (juego.state.has) {
|
|
|
|
const button = shareButton(juego);
|
|
|
|
if (
|
|
|
|
isTouching(juego, button.box) ||
|
|
|
|
(juego.mouse.down && posInBox(button.box, juego.mouse))
|
|
|
|
) {
|
|
|
|
share();
|
|
|
|
(juego as Juego<AllState>).state = welcome.createState();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-07-05 16:13:36 +00:00
|
|
|
|
2021-07-06 21:38:25 +00:00
|
|
|
if (!juego.state.playing) {
|
|
|
|
juego.assets.fondo.play();
|
|
|
|
juego.state.playing = true;
|
|
|
|
}
|
2021-07-06 20:47:00 +00:00
|
|
|
|
2021-06-30 23:16:45 +00:00
|
|
|
juego.state.time -= dt;
|
|
|
|
if (juego.state.time < 0) {
|
2021-07-05 16:13:36 +00:00
|
|
|
juego.state.has = "lost";
|
2021-06-30 23:16:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const playerSpeed = juego.canvas.width * 0.15;
|
|
|
|
const enemySpeed = juego.canvas.width * 0.05;
|
2021-07-01 22:33:51 +00:00
|
|
|
const { left, right, center } = touchControls(juego);
|
|
|
|
if (
|
|
|
|
juego.keyboard.keys.d ||
|
|
|
|
juego.keyboard.keys.ArrowRight ||
|
|
|
|
isTouching(juego, right)
|
|
|
|
) {
|
2021-06-30 23:16:45 +00:00
|
|
|
juego.state.side = "right";
|
|
|
|
juego.state.pos.x += (dt / 1000) * playerSpeed;
|
|
|
|
}
|
2021-07-01 22:33:51 +00:00
|
|
|
if (
|
|
|
|
juego.keyboard.keys.a ||
|
|
|
|
juego.keyboard.keys.ArrowLeft ||
|
|
|
|
isTouching(juego, left)
|
|
|
|
) {
|
2021-06-30 23:16:45 +00:00
|
|
|
juego.state.side = "left";
|
|
|
|
juego.state.pos.x -= (dt / 1000) * playerSpeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (juego.state.pos.x < MAP_MIN) juego.state.pos.x = MAP_MIN;
|
|
|
|
if (juego.state.pos.x > MAP_MAX) juego.state.pos.x = MAP_MAX;
|
|
|
|
|
|
|
|
juego.state.seedCooldown -= dt;
|
2021-07-06 17:58:08 +00:00
|
|
|
juego.state.justSigned -= dt;
|
2021-07-02 18:17:35 +00:00
|
|
|
|
|
|
|
const citizen = detectCitizen(juego);
|
|
|
|
|
|
|
|
if (juego.keyboard.keys[" "] || isTouching(juego, center)) {
|
|
|
|
if (citizen) {
|
|
|
|
juego.state.signatures += 1000;
|
|
|
|
juego.state.citizens = juego.state.citizens.filter((c) => c != citizen);
|
2021-07-06 21:13:52 +00:00
|
|
|
juego.state.justSigned = 1000;
|
2021-07-02 18:17:35 +00:00
|
|
|
} else {
|
|
|
|
if (juego.state.seedCooldown < 0) {
|
|
|
|
const seedSpeed = juego.canvas.width * 0.7;
|
|
|
|
juego.state.seeds.push({
|
|
|
|
x: juego.state.pos.x,
|
|
|
|
velocity: { x: juego.state.side === "left" ? -seedSpeed : seedSpeed },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-06-30 23:16:45 +00:00
|
|
|
juego.state.seedCooldown = SEED_COOLDOWN;
|
|
|
|
}
|
2021-07-02 18:17:35 +00:00
|
|
|
|
2021-06-30 23:16:45 +00:00
|
|
|
for (const seed of juego.state.seeds) {
|
|
|
|
seed.x += (dt / 1000) * seed.velocity.x;
|
|
|
|
seed.velocity.x *= 0.97;
|
2021-06-28 19:26:27 +00:00
|
|
|
for (const enemy of juego.state.enemies) {
|
2021-06-30 23:16:45 +00:00
|
|
|
if (
|
|
|
|
boxCollision(
|
2021-07-02 18:17:35 +00:00
|
|
|
getFlooredBox(juego, juego.sprites.semilla, seed.x),
|
|
|
|
getFlooredBox(juego, enemy.sprite, enemy.x)
|
2021-06-30 23:16:45 +00:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
juego.state.seeds = juego.state.seeds.filter((s) => s.x !== seed.x);
|
|
|
|
juego.state.enemies = juego.state.enemies.filter(
|
|
|
|
(e) => e.x !== enemy.x
|
|
|
|
);
|
|
|
|
juego.state.trees.push({
|
|
|
|
x: enemy.x,
|
|
|
|
sprite: randomFromArray([juego.sprites.arbol1, juego.sprites.arbol2]),
|
|
|
|
});
|
|
|
|
}
|
2021-06-28 19:26:27 +00:00
|
|
|
}
|
2021-06-30 23:16:45 +00:00
|
|
|
if (Math.abs(seed.velocity.x) < 100)
|
|
|
|
juego.state.seeds = juego.state.seeds.filter(
|
|
|
|
(s) => s.velocity.x !== seed.velocity.x
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-02 18:17:35 +00:00
|
|
|
if (juego.state.signatures >= SIGNATURES_TO_WIN) {
|
2021-07-05 16:13:36 +00:00
|
|
|
juego.state.has = "won";
|
2021-06-30 23:16:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (juego.state.enemies.length < ENEMIES_NUM) {
|
2021-07-06 21:44:15 +00:00
|
|
|
const x = Math.random() * 6000 + juego.state.pos.x;
|
2021-06-30 23:16:45 +00:00
|
|
|
// Don't spawn enemies too close
|
|
|
|
if (Math.abs(juego.state.pos.x - x) < 300) continue;
|
2021-07-01 20:45:37 +00:00
|
|
|
juego.state.enemies.push({
|
|
|
|
x,
|
|
|
|
sprite: randomFromArray([
|
|
|
|
juego.sprites.larreta,
|
|
|
|
juego.sprites.millonarioMalo,
|
|
|
|
]),
|
|
|
|
});
|
2021-06-30 23:16:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const enemy of juego.state.enemies) {
|
|
|
|
const distance = enemy.x - juego.state.pos.x;
|
|
|
|
if (distance < 0) {
|
|
|
|
enemy.x += (dt / 1000) * enemySpeed;
|
|
|
|
} else {
|
|
|
|
enemy.x -= (dt / 1000) * enemySpeed;
|
|
|
|
}
|
2021-07-01 21:16:00 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
boxCollision(
|
2021-07-02 18:17:35 +00:00
|
|
|
getFlooredBox(juego, juego.sprites.jugadorx, juego.state.pos.x),
|
|
|
|
getFlooredBox(juego, enemy.sprite, enemy.x)
|
2021-07-01 21:16:00 +00:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
juego.state.enemies = juego.state.enemies.filter((e) => e.x !== enemy.x);
|
|
|
|
juego.state.time -= TIME_LOST_WHEN_HIT;
|
|
|
|
}
|
2021-06-30 23:16:45 +00:00
|
|
|
}
|
2021-06-28 19:26:27 +00:00
|
|
|
|
2021-06-30 23:16:45 +00:00
|
|
|
juego.state.view.x =
|
|
|
|
-juego.state.pos.x +
|
|
|
|
juego.canvas.width / 2 -
|
|
|
|
juego.sprites.jugadorx.getWidth(juego) / 2;
|
2021-06-28 18:01:45 +00:00
|
|
|
}
|
|
|
|
|
2021-07-02 18:17:35 +00:00
|
|
|
function getFlooredBox(juego: Juego<State>, sprite: Sprite, x: number): Box {
|
|
|
|
const height = sprite.getHeight(juego);
|
|
|
|
return {
|
|
|
|
x,
|
|
|
|
y: getFloorY(juego) - height,
|
|
|
|
width: sprite.getWidth(juego),
|
|
|
|
height,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function detectCitizen(juego: Juego<State>): Citizen | undefined {
|
|
|
|
const jugadorxBox = getFlooredBox(
|
|
|
|
juego,
|
|
|
|
juego.sprites.jugadorx,
|
|
|
|
juego.state.pos.x
|
|
|
|
);
|
|
|
|
return juego.state.citizens.find((c) =>
|
|
|
|
boxCollision(jugadorxBox, getFlooredBox(juego, c.sprite, c.x))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-28 19:02:12 +00:00
|
|
|
function drawJugadorx(juego: Juego<State>) {
|
2021-06-30 23:16:45 +00:00
|
|
|
const floorY = getFloorY(juego);
|
2021-07-06 17:58:08 +00:00
|
|
|
const width = juego.sprites.jugadorx.getWidth(juego);
|
|
|
|
const height = juego.sprites.jugadorx.getHeight(juego);
|
2021-06-30 23:16:45 +00:00
|
|
|
juego.sprites.jugadorx.draw(
|
|
|
|
juego,
|
|
|
|
juego.state.pos.x + juego.state.view.x,
|
2021-07-06 17:58:08 +00:00
|
|
|
floorY - height,
|
2021-06-30 23:16:45 +00:00
|
|
|
0,
|
|
|
|
juego.state.side === "left"
|
|
|
|
);
|
2021-07-06 17:58:08 +00:00
|
|
|
if (juego.state.justSigned > 0) {
|
|
|
|
juego.sprites.dialogoFirma.draw(
|
|
|
|
juego,
|
|
|
|
juego.state.pos.x + juego.state.view.x + width,
|
|
|
|
floorY - height - juego.sprites.dialogoFirma.getHeight(juego)
|
|
|
|
);
|
|
|
|
}
|
2021-06-28 18:01:45 +00:00
|
|
|
}
|
|
|
|
|
2021-06-28 19:35:49 +00:00
|
|
|
function drawTrees(juego: Juego<State>) {
|
2021-06-30 23:16:45 +00:00
|
|
|
const floorY = getFloorY(juego);
|
|
|
|
for (const tree of juego.state.trees) {
|
|
|
|
const height = tree.sprite.getHeight(juego);
|
|
|
|
tree.sprite.draw(juego, tree.x + juego.state.view.x, floorY - height);
|
|
|
|
}
|
2021-06-28 19:35:49 +00:00
|
|
|
}
|
2021-06-28 19:02:12 +00:00
|
|
|
function drawEnemies(juego: Juego<State>) {
|
2021-06-30 23:16:45 +00:00
|
|
|
const floorY = getFloorY(juego);
|
|
|
|
for (const enemy of juego.state.enemies) {
|
2021-07-01 20:45:37 +00:00
|
|
|
const height = enemy.sprite.getHeight(juego);
|
|
|
|
enemy.sprite.draw(juego, enemy.x + juego.state.view.x, floorY - height);
|
2021-06-30 23:16:45 +00:00
|
|
|
}
|
2021-06-28 18:01:45 +00:00
|
|
|
}
|
2021-07-02 18:17:35 +00:00
|
|
|
function drawCitizens(juego: Juego<State>) {
|
|
|
|
const floorY = getFloorY(juego);
|
|
|
|
for (const citizen of juego.state.citizens) {
|
|
|
|
const height = citizen.sprite.getHeight(juego);
|
|
|
|
citizen.sprite.draw(juego, citizen.x + juego.state.view.x, floorY - height);
|
|
|
|
}
|
|
|
|
}
|
2021-06-28 18:01:45 +00:00
|
|
|
|
2021-06-28 19:02:12 +00:00
|
|
|
function drawSeeds(juego: Juego<State>) {
|
2021-06-30 23:16:45 +00:00
|
|
|
const height = juego.sprites.semilla.getHeight(juego);
|
|
|
|
const floorY = getFloorY(juego);
|
|
|
|
for (const seed of juego.state.seeds) {
|
|
|
|
juego.sprites.semilla.draw(
|
|
|
|
juego,
|
|
|
|
seed.x + juego.state.view.x,
|
|
|
|
floorY - height
|
|
|
|
);
|
|
|
|
}
|
2021-06-28 19:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getFloorY(juego: Juego<State>): number {
|
2021-06-30 23:16:45 +00:00
|
|
|
return (juego.canvas.height * 65) / 96;
|
2021-06-28 19:02:12 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 15:49:06 +00:00
|
|
|
export function drawBackground(
|
|
|
|
juego: Juego<AllState>,
|
2021-06-30 23:16:45 +00:00
|
|
|
y: number,
|
|
|
|
height: number,
|
|
|
|
img: HTMLImageElement,
|
2021-07-05 15:49:06 +00:00
|
|
|
offset: number = 0,
|
2021-07-01 21:08:19 +00:00
|
|
|
sourceBox?: Box,
|
|
|
|
opacity?: number
|
2021-06-30 22:58:55 +00:00
|
|
|
) {
|
2021-06-30 23:16:45 +00:00
|
|
|
const aspect = img.width / img.height;
|
|
|
|
const width = height * aspect;
|
2021-07-01 21:08:19 +00:00
|
|
|
if (opacity !== undefined) {
|
|
|
|
juego.ctx.globalAlpha = opacity;
|
|
|
|
}
|
2021-07-05 16:01:35 +00:00
|
|
|
for (let i = 0; i < 50; i++) {
|
2021-06-30 23:16:45 +00:00
|
|
|
if (sourceBox) {
|
|
|
|
juego.ctx.drawImage(
|
|
|
|
img,
|
|
|
|
sourceBox.x,
|
|
|
|
sourceBox.y,
|
|
|
|
sourceBox.width,
|
|
|
|
sourceBox.height,
|
2021-07-05 15:49:06 +00:00
|
|
|
i * (width - (opacity === undefined ? 1 : 0)) + offset,
|
2021-06-30 23:16:45 +00:00
|
|
|
y,
|
|
|
|
width,
|
|
|
|
height
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
juego.ctx.drawImage(
|
|
|
|
img,
|
2021-07-05 15:49:06 +00:00
|
|
|
i * (width - (opacity === undefined ? 1 : 0)) + offset,
|
2021-06-30 23:16:45 +00:00
|
|
|
y,
|
|
|
|
width,
|
|
|
|
height
|
|
|
|
);
|
2021-06-30 22:58:55 +00:00
|
|
|
}
|
2021-06-30 23:16:45 +00:00
|
|
|
}
|
2021-07-01 21:08:19 +00:00
|
|
|
if (opacity !== undefined) {
|
|
|
|
juego.ctx.globalAlpha = 1;
|
|
|
|
}
|
2021-06-30 22:58:55 +00:00
|
|
|
}
|
2021-06-28 18:01:45 +00:00
|
|
|
|
2021-06-30 22:58:55 +00:00
|
|
|
export function draw(juego: Juego<State>, timestamp: number) {
|
2021-07-05 15:49:06 +00:00
|
|
|
drawBackground(
|
|
|
|
juego,
|
|
|
|
0,
|
|
|
|
juego.canvas.height,
|
|
|
|
juego.assets.cieloRioCalle,
|
|
|
|
-juego.state.pos.x
|
|
|
|
);
|
|
|
|
drawBackground(
|
|
|
|
juego,
|
|
|
|
0,
|
|
|
|
getFloorY(juego),
|
|
|
|
juego.assets.edificios,
|
|
|
|
-juego.state.pos.x,
|
|
|
|
{
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 89,
|
|
|
|
height: 48,
|
|
|
|
}
|
|
|
|
);
|
2021-06-30 23:16:45 +00:00
|
|
|
|
2021-07-01 21:08:19 +00:00
|
|
|
drawBackground(
|
|
|
|
juego,
|
|
|
|
0,
|
|
|
|
juego.canvas.height,
|
|
|
|
juego.assets.cielo,
|
2021-07-05 15:49:06 +00:00
|
|
|
-juego.state.pos.x,
|
2021-07-01 21:08:19 +00:00
|
|
|
undefined,
|
2021-07-02 18:17:35 +00:00
|
|
|
juego.state.signatures / SIGNATURES_TO_WIN
|
2021-07-01 21:08:19 +00:00
|
|
|
);
|
|
|
|
drawBackground(
|
|
|
|
juego,
|
|
|
|
0,
|
|
|
|
juego.canvas.height,
|
|
|
|
juego.assets.parquePublicoRio,
|
2021-07-05 15:49:06 +00:00
|
|
|
-juego.state.pos.x,
|
2021-07-01 21:08:19 +00:00
|
|
|
undefined,
|
2021-07-02 18:17:35 +00:00
|
|
|
juego.state.signatures / SIGNATURES_TO_WIN
|
2021-07-01 21:08:19 +00:00
|
|
|
);
|
|
|
|
|
2021-06-30 23:16:45 +00:00
|
|
|
drawTrees(juego);
|
2021-07-02 18:17:35 +00:00
|
|
|
drawCitizens(juego);
|
2021-06-30 23:16:45 +00:00
|
|
|
drawEnemies(juego);
|
|
|
|
|
|
|
|
drawJugadorx(juego);
|
|
|
|
drawSeeds(juego);
|
|
|
|
|
2021-07-05 16:13:36 +00:00
|
|
|
if (isMobile(juego) && !juego.state.has) {
|
2021-07-01 22:33:51 +00:00
|
|
|
const { left, right } = touchControls(juego);
|
|
|
|
|
|
|
|
juego.ctx.fillStyle = "rgba(0, 0, 0, 0.3)";
|
|
|
|
juego.ctx.fillRect(left.x, left.y, left.width, left.height);
|
|
|
|
juego.ctx.fillRect(right.x, right.y, right.width, right.height);
|
2021-06-30 23:16:45 +00:00
|
|
|
|
2021-07-01 22:33:51 +00:00
|
|
|
const width = juego.sprites.flecha.getWidth(juego);
|
|
|
|
const height = juego.sprites.flecha.getHeight(juego);
|
|
|
|
juego.sprites.flecha.draw(
|
|
|
|
juego,
|
|
|
|
left.x + left.width - width,
|
|
|
|
left.height / 2 - height / 2,
|
|
|
|
0,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
juego.sprites.flecha.draw(
|
|
|
|
juego,
|
|
|
|
right.x,
|
|
|
|
right.height / 2 - height / 2,
|
|
|
|
0,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
juego.ctx.fillStyle = "white";
|
2021-07-02 18:17:35 +00:00
|
|
|
const firmasBox = drawText(
|
2021-06-30 23:16:45 +00:00
|
|
|
juego,
|
2021-07-02 18:17:35 +00:00
|
|
|
`Firmas: ${juego.state.signatures}/${SIGNATURES_TO_WIN}`,
|
2021-06-30 23:16:45 +00:00
|
|
|
{ x: juego.canvas.width - 10, y: 10 },
|
|
|
|
{ bold: true, align: "right" }
|
|
|
|
);
|
|
|
|
|
|
|
|
const tiempoBox = drawText(
|
|
|
|
juego,
|
|
|
|
`Tiempo restante`,
|
|
|
|
{ x: 10, y: 10 },
|
|
|
|
{ bold: false, align: "left" }
|
|
|
|
);
|
|
|
|
|
|
|
|
juego.ctx.fillRect(
|
|
|
|
10,
|
|
|
|
tiempoBox.y + tiempoBox.height,
|
2021-07-02 18:17:35 +00:00
|
|
|
(juego.canvas.width - firmasBox.width - 20) * (juego.state.time / TIME),
|
2021-06-30 23:16:45 +00:00
|
|
|
30
|
|
|
|
);
|
2021-07-02 18:20:19 +00:00
|
|
|
|
|
|
|
if (detectCitizen(juego)) {
|
|
|
|
drawText(
|
|
|
|
juego,
|
|
|
|
`¡Apreta para recolectar firmas!`,
|
|
|
|
{ x: juego.canvas.width / 2, y: juego.canvas.height * 0.7 },
|
|
|
|
{ align: "center", maxWidth: juego.canvas.width }
|
|
|
|
);
|
|
|
|
}
|
2021-07-05 16:13:36 +00:00
|
|
|
|
|
|
|
if (juego.state.has) {
|
2021-07-06 20:19:47 +00:00
|
|
|
juego.sprites.logoFPGFDTBlanco.draw(
|
|
|
|
juego,
|
|
|
|
0,
|
|
|
|
juego.canvas.height - juego.sprites.logoFPGFDTBlanco.getHeight(juego) - 10
|
|
|
|
);
|
2021-07-05 16:13:36 +00:00
|
|
|
if (juego.state.has === "lost") {
|
2021-07-06 20:26:34 +00:00
|
|
|
juego.sprites.placaPerdiste.draw(juego, 10, juego.canvas.height * 0.1);
|
2021-07-06 18:12:35 +00:00
|
|
|
juego.sprites.baldosa.draw(
|
|
|
|
juego,
|
|
|
|
juego.canvas.width - juego.sprites.baldosa.getWidth(juego) - 30,
|
2021-07-06 20:26:34 +00:00
|
|
|
juego.canvas.height * 0.3
|
2021-07-06 18:12:35 +00:00
|
|
|
);
|
2021-07-05 16:13:36 +00:00
|
|
|
} else if (juego.state.has === "won") {
|
|
|
|
const width = juego.sprites.placaFelicitaciones.getWidth(juego);
|
|
|
|
juego.sprites.placaFelicitaciones.draw(
|
|
|
|
juego,
|
|
|
|
juego.canvas.width / 2 - width / 2,
|
|
|
|
juego.canvas.height * 0.1
|
|
|
|
);
|
|
|
|
}
|
2021-07-06 17:09:21 +00:00
|
|
|
const button = shareButton(juego);
|
|
|
|
button.sprite.draw(juego, button.box.x, button.box.y);
|
2021-07-05 16:13:36 +00:00
|
|
|
}
|
2021-06-28 18:01:45 +00:00
|
|
|
}
|