From 43f22907586e6088947e28ec6612e902f48de4aa Mon Sep 17 00:00:00 2001 From: Mal Date: Mon, 24 Feb 2020 21:18:45 +0100 Subject: [PATCH] Gisela faces MrCroc automatically. --- js/Gisela.js | 10 +++++++++- js/module.js | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/js/Gisela.js b/js/Gisela.js index a5ccec1..b91b7f4 100644 --- a/js/Gisela.js +++ b/js/Gisela.js @@ -6,6 +6,14 @@ export default class Gisela extends Movable { constructor() { const SCALE = 2; - super(new RetroAnimation(Setting.GRAPHICS_LOCATION + 'gisela-right.png', 1, SCALE, 1)); + super(new RetroAnimation(Setting.GRAPHICS_LOCATION + 'gisela-right.png', 1, SCALE, 0.01)); + this.addAnimation( + 'LOOK_LEFT', + new RetroAnimation(Setting.GRAPHICS_LOCATION + 'gisela-left.png', 1, SCALE, 0.01) + ); + this.addAnimation( + 'LOOK_RIGHT', + new RetroAnimation(Setting.GRAPHICS_LOCATION + 'gisela-right.png', 1, SCALE, 0.01) + ); } } \ No newline at end of file diff --git a/js/module.js b/js/module.js index 3155ef1..c1942e8 100644 --- a/js/module.js +++ b/js/module.js @@ -103,6 +103,12 @@ function MainLoop(timestamp) /* Drawing */ if (timestamp - lastRendered >= frameDuration) { + if (gisela.currentAnimation !== 'LOOK_LEFT' && mrCroc.position.x < gisela.position.x) { + gisela.currentAnimation = 'LOOK_LEFT'; + } else if (gisela.currentAnimation !== 'LOOK_RIGHT' && mrCroc.position.x >= gisela.position.x) { + gisela.currentAnimation = 'LOOK_RIGHT'; + } + context.clearRect(0, 0, window.innerWidth, window.innerHeight); architecture.draw(context, camera); mrCroc.draw(context, camera); @@ -171,6 +177,7 @@ loader.addImage(Setting.GRAPHICS_LOCATION + 'mr-croc-walk-right.png'); loader.addImage(Setting.GRAPHICS_LOCATION + 'mr-croc-walk-left.png'); loader.addImage(Setting.TILESET_LOCATION + GraphicSet[level.getTilesetId()].tileset); loader.addImage(Setting.GRAPHICS_LOCATION + 'gisela-right.png'); +loader.addImage(Setting.GRAPHICS_LOCATION + 'gisela-left.png'); new FrameRateMeasurer();