const asdf = require("asdf-games"); // eslint-disable-next-line no-unused-vars const { Texture, Container, TileSprite, Text, AnimManager, Rect, Sprite } = asdf; const { shell } = require("electron"); const text = require(__dirname + "/../../res/lang/default.js"); const fillStyle = {fill: "#ffffff", font: "24px Minecraft"}; const textures = { space: new Texture("../res/images/keys/space.png"), t: new Texture("../res/images/keys/t.png"), q: new Texture("../res/images/keys/q.png"), s: new Texture("../res/images/keys/s.png"), logo: new Texture("../res/images/logo.png") }; class Title extends Container { constructor(game, keys, onStart, onTutorial, onQuit) { super(); this.game = game; this.keys = keys; this.onStart = onStart; this.onTutorial = onTutorial; this.onQuit = onQuit; this.keys.reset(); this.children = []; this.add(new Rect(this.game.w, this.game.h, { fill: "#333333" })); this.add(new Sprite(textures.logo)); this.keyCaps = [ new TileSprite(textures.space, 64, 16), new TileSprite(textures.t, 16, 16), new TileSprite(textures.q, 16, 16), new TileSprite(textures.s, 16, 16) ]; this.keyCaps.forEach(element => { element.scale = { x: 1.5, y: 1.5 }; element.anims = new AnimManager(element); element.anims.add("press", [0, 1].map(y => ({ x: 0, y })), 0.50); element.anims.play("press"); }); const textPos = { x: 160, y: 210 }; for (let index = 0; index < text.titleScreen.instructions.length; index++) { const keyCap = this.keyCaps[index]; if (index == 0) { keyCap.pos = { x: textPos.x - 120, y: textPos.y + (28 * index) - 18 }; } else { keyCap.pos = { x: textPos.x - 56, y: textPos.y + (28 * index) - 20 }; } const element = new Text(text.titleScreen.instructions[index], fillStyle); element.pos = { x: textPos.x, y: textPos.y + 28 * index }; this.add(keyCap); this.add(element); } } update(dt, t) { super.update(dt, t); if (this.keys.action) { this.onStart(); } if (this.keys.key(84)) { this.onTutorial(); } if (this.keys.key(81)) { this.onQuit(); } // Open source code on key s if (this.keys.key(83)) { shell.openExternal("https://gitea.arnweb.nl/Hecc-inc./caa-game"); this.keys.reset(); } } } module.exports = Title;