81 lines
2.2 KiB
JavaScript
81 lines
2.2 KiB
JavaScript
const asdf = require("asdf-games");
|
|
// eslint-disable-next-line no-unused-vars
|
|
const { Texture, Rect, Container, Text, TileSprite } = asdf;
|
|
|
|
const text = require(__dirname + "/../../res/lang/default.js");
|
|
const fillStyle = {fill: "#ffffff", font: "16px Minecraft"};
|
|
|
|
const textures = {
|
|
space: new Texture("../res/images/keys/space.png"),
|
|
arrows: new Texture("../res/images/keys/arrows.png"),
|
|
ctrl: new Texture("../res/images/keys/ctrl.png"),
|
|
interact: new Texture("../res/images/tutorial/interact.png")
|
|
};
|
|
|
|
class Tutorial extends Container {
|
|
constructor(game, keys, onEnd) {
|
|
super();
|
|
this.game = game;
|
|
this.keys = keys;
|
|
this.onEnd = onEnd;
|
|
|
|
this.pos = { x: 0, y: 0 };
|
|
this.children = [];
|
|
|
|
this.add(new Rect(this.game.w, this.game.h, { fill: "#333333" }));
|
|
|
|
const title = new Text("Tutorial", {fill: "#ffffff", font: "36px Minecraft"});
|
|
title.pos = { x: 12, y: 44 };
|
|
this.add(title);
|
|
|
|
this.images = [
|
|
new TileSprite(textures.arrows, 48, 32),
|
|
new TileSprite(textures.ctrl, 21, 16),
|
|
new TileSprite(textures.space, 64, 16),
|
|
new TileSprite(textures.interact, 64, 39)
|
|
];
|
|
|
|
this.instructions = [];
|
|
for (let index = 0; index < text.tutorial.length; index++) {
|
|
this.instructions.push(new Text(text.tutorial[index], fillStyle));
|
|
}
|
|
|
|
// Controls direction
|
|
this.images[0].pos = { x: 24, y: 60 };
|
|
this.instructions[0].pos = { x: 12, y: 108 };
|
|
|
|
// Controls sprint
|
|
this.images[1].pos = { x: 24, y: 116 };
|
|
this.instructions[1].pos = { x: 12, y: 148 };
|
|
|
|
// Controls action
|
|
this.images[2].pos = { x: 24, y: 156 };
|
|
this.instructions[2].pos = { x: 12, y: 188 };
|
|
|
|
// Interact
|
|
this.images[3].pos = { x: 24, y: 196 };
|
|
this.instructions[3].pos = { x: 12, y: 254 };
|
|
this.instructions[4].pos = { x: 12, y: 274 };
|
|
|
|
// Back to menu
|
|
this.instructions[5].pos = { x: 12, y: 308 };
|
|
|
|
for (let index = 0; index < this.instructions.length; index++) {
|
|
if (this.images[index]) {
|
|
this.add(this.images[index]);
|
|
}
|
|
this.add(this.instructions[index]);
|
|
}
|
|
}
|
|
|
|
update(dt, t) {
|
|
super.update(dt, t);
|
|
|
|
if (this.keys.action) {
|
|
this.onEnd();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
module.exports = Tutorial; |