Added very simple textbox

This commit is contained in:
Arne van Iterson 2020-04-16 12:11:56 +02:00
parent dede46df34
commit 0ee8ca5b30
4 changed files with 40 additions and 2 deletions

View File

@ -31,7 +31,7 @@ function createWindow () {
win.loadFile(path.join("html/game.html"));
// Open the DevTools.
// win.webContents.openDevTools();
win.webContents.openDevTools();
}
// This method will be called when Electron has finished

View File

@ -8,6 +8,9 @@ const sounds = {
obtain: new Sound(__dirname + "/../../res/sounds/obtain.wav", { volume: 0.1 })
};
const TextBox = require(__dirname + "/../helpers/textbox.js");
const text = require(__dirname + "/../../res/lang/default.js");
const Pointer = require("./pointer.js");
const state = {
@ -68,6 +71,7 @@ class Chest extends TileSprite {
this.state = state.open;
this.pressed = true;
this.action();
this.level.entities.add(new TextBox(text.game.keyFind, 2.5));
sounds.obtain.play();
} else {
if (!sounds.forbidden.playing && !this.pressed) {

View File

@ -10,7 +10,7 @@ const sounds = {
var Pointer = require("./pointer.js");
class Portal extends TileSprite {
constructor(pos, player, keys, level, type, action, key) {
constructor(pos, player, keys, level, type, action, key = "") {
super(texture, 32, 32);
this.pos = pos;
this.scale = { x: 1, y: 1 };

34
src/helpers/textbox.js Normal file
View File

@ -0,0 +1,34 @@
var asdf = require("asdf-games");
// eslint-disable-next-line no-unused-vars
const { Container, Text, Rect } = asdf;
const fillStyle = {fill: "#ffffff", font: "16px Minecraft"};
class TextBox extends Container {
constructor(string, lifespan) {
super();
this.pos = { x: 0, y: 0 };
this.string = string;
this.lifespan = lifespan;
const background = new Rect(640, 24, {fill: "rgba(0,0,0,0.5)"});
background.pos = { x: 0, y: 0 };
this.add(background);
const text = new Text(string, fillStyle);
text.pos = { x: 8, y: 18 };
this.add(text);
}
update(dt) {
super.update(dt);
if (this.lifespan <= 0) {
this.dead = true;
} else {
this.lifespan -= dt;
}
}
}
module.exports = TextBox;