diff --git a/main.js b/main.js index f8488cf..08901e5 100644 --- a/main.js +++ b/main.js @@ -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 diff --git a/src/entities/chest.js b/src/entities/chest.js index 40ab61d..8eae900 100644 --- a/src/entities/chest.js +++ b/src/entities/chest.js @@ -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) { diff --git a/src/entities/portal.js b/src/entities/portal.js index f1700e8..8f76438 100644 --- a/src/entities/portal.js +++ b/src/entities/portal.js @@ -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 }; diff --git a/src/helpers/textbox.js b/src/helpers/textbox.js new file mode 100644 index 0000000..0029249 --- /dev/null +++ b/src/helpers/textbox.js @@ -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; \ No newline at end of file