/* global requestAnimationFrame */ import { canvas, ctx } from './canvas' import { Game } from './game' import { Player } from './player' import RES from './resource' const GameWidth = 1080 const GameHeight = 720 let playing = true let player = new Player(GameWidth / 2 - 30, 25, GameHeight - 80) let game = new Game(60, player, player.h + 60, GameWidth, GameHeight) // Retranslate score function player.score = function (obj) { /* eslint-disable no-useless-call */ game.scoredItem.call(game, obj) } function gameLoop () { playing && requestAnimationFrame(gameLoop) ctx.fillStyle = '#111' ctx.fillRect(0, 0, canvas.width, canvas.height) game.update() game.draw() } function start () { game.nextLevel() gameLoop() setInterval(function () { game.tick() }, 1000) } async function loadAll () { let images = ['static/hook_open.png', 'static/gold_1.png', 'static/gold_2.png', 'static/gold_3.png', 'static/rock_1.png', 'static/rock_2.png', 'static/rock_3.png', 'static/diamond.png', 'static/loot.png', 'static/tnt.png', 'static/barrel_piece.png', 'static/explosion.png'] for (let i in images) { await RES.loadImage(images[i]) } } loadAll().then(start)