TextBox implemented and cleaning.

This commit is contained in:
Mal
2020-02-24 00:19:21 +01:00
parent bd5ec13ea3
commit 3ffc786989
7 changed files with 220 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ import ImageLoader from "./ImageLoader.js";
import Level from "./Level.js";
import InterfaceEvent from "./events/InterfaceEvent.js";
import UrlParam from "./UrlParam.js";
import TextBox from "./TextBox.js";
function MainLoop(timestamp)
{
@@ -101,11 +102,14 @@ function MainLoop(timestamp)
/* Drawing */
if (timestamp - lastRendered >= frameDuration) {
context.clearRect(0, 0, window.innerWidth, window.innerHeight);
architecture.draw(context, camera);
mrCroc.draw(context, camera);
gisela.draw(context, camera);
if (gameFinished) {
textBoxGameFinished.draw(context, window.innerWidth * 0.5, window.innerHeight - 100);
}
lastRendered = timestamp;
}
@@ -118,8 +122,7 @@ function MainLoop(timestamp)
KeyJump.pressed = false;
lastTimestamp = undefined;
lastRendered = undefined;
alert('Gisela: "Thanks for showing up, Mr. Croc, but I\'m not in danger."');
textBoxGameFinished.animate();
}
window.requestAnimationFrame(MainLoop);
@@ -153,6 +156,7 @@ let mrCroc, gisela, architecture;
let camera = new Camera();
let gameFinished = false;
let hasPlayerLeftArchitecture = false;
let textBoxGameFinished;
let KeyLeft = new Key('ArrowLeft');
let KeyRight = new Key('ArrowRight');
@@ -192,6 +196,20 @@ window.addEventListener(
);
context = canvas.getContext('2d');
textBoxGameFinished = new TextBox(
'Gisela: "Thanks for showing up, Mr. Croc, but I\'m not in danger."',
window.innerWidth - 40,
context
);
textBoxGameFinished.font = 'Silkscreen';
textBoxGameFinished.verticalAlignment = 'bottom';
textBoxGameFinished.alignment = 1;
textBoxGameFinished.hasShadow = true;
textBoxGameFinished.textSize = 48;
textBoxGameFinished.hasBorder = true;
textBoxGameFinished.colorText = 'yellow';
textBoxGameFinished.colorBorder = 'black';
textBoxGameFinished.updateLines(window.innerWidth - 40, context);
architecture = RetroArchitecture.createFromData(level);
camera.borderRight = architecture.columns * architecture.tileWidth;
@@ -206,7 +224,6 @@ window.addEventListener(
window.addEventListener(
InterfaceEvent.FRAME_RATE_MEASURED,
(event) => {
console.log(event);
fps = event.frameRate;
frameDuration = 1000 / fps;
window.requestAnimationFrame(MainLoop);