From 630d726a9d331d93da4cc3830d490295d3f20425 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Thu, 24 Aug 2017 22:00:19 +0200 Subject: [PATCH] Fix the door --- src/act1.js | 39 +++++++++++++++--------- src/assets/images/stasis_door-sheet.png | Bin 304 -> 361 bytes 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/act1.js b/src/act1.js index f919a9a..d1118a9 100644 --- a/src/act1.js +++ b/src/act1.js @@ -2,14 +2,17 @@ var act1 = {}; var controlPanelSprite = kontra.sprite({x: 16, y: 13, width: 3, height: 2}); - var doorSpriteSheet = null; - var doorAnimation = null; + var doorAnimationSheet = null; + var doorSprite = null; + var roomState = { + isDoorOpen: false + }; act1.init = function() { - doorSpriteSheet = kontra.spriteSheet({ + doorAnimationSheet = kontra.spriteSheet({ image: kontra.assets.images['stasis_door-sheet'], - frameWidth: 23, - frameHeight: 20, + frameWidth: 24, + frameHeight: 21, animations: { closed: { frames: 0 @@ -18,18 +21,18 @@ frames: 2 }, open: { - frames: '0..2', - frameRate: 6 + frames: '0..3', + frameRate: 6, }, close: { - frames: '2..0', - frameRate: 6 + frames: '3..0', + frameRate: 6, } } }); - doorAnimation = kontra.sprite({ + doorSprite = kontra.sprite({ x: 72, y: 8, - animations: doorSpriteSheet.animations + animations: doorAnimationSheet.animations }); if (muri.currentRoom === 'stasis_dark') { @@ -43,11 +46,17 @@ }; act1.update = function() { + doorSprite.update(); if (muri.currentRoom === 'stasis') { - doorAnimation.closed.update(); - if (muri.get('mouse').clickedOn(doorAnimation)) { + if (muri.get('mouse').clickedOn(doorSprite)) { muri.get('mouse').releaseClick(); - doorAnimation.playAnimation('open'); + if (!roomState.isDoorOpen) { + doorSprite.playAnimation('open'); + roomState.isDoorOpen = true; + } else { + doorSprite.playAnimation('close'); + roomState.isDoorOpen = false; + } } } @@ -70,7 +79,7 @@ act1.render = function() { if (muri.currentRoom === 'stasis') { - doorAnimation.closed.render(); + doorSprite.render(); } }; diff --git a/src/assets/images/stasis_door-sheet.png b/src/assets/images/stasis_door-sheet.png index 3e1523e9cf7d9a5d00a8c143ef5af98ad4856679..c97ef2a5dabbdeff5fdec02b7ca2e857e8593ef8 100644 GIT binary patch literal 361 zcmeAS@N?(olHy`uVBq!ia0vp^2|z5$!VDz6BfnJwDfIxK5ZCgGXlXf3ATKD$r#LZS z-jd~~UwmI=N_drFAB|(0{3=Yq3q=7g|-tI089jvk* zKn`btM`SSr1Gg{;GcwGYBLNg-FY)wsWq-&aAuMK8XSW`tZnvk4V~EA+yOVwSm<%~u zJ$Dtm_Xp@*@C%natz5y<|G<}(>z2Iln^P{66!nGeD$cMlaD*x|cTBtU<+w%Aq9grT zCmoF?LZAO?=m-%=7F+8O`1XKJU$&u_(#0uXr)Ff!X2>oOu3*V#cCi-tY{bARn?22? zIyTpL&wj>K;ST);kwOP_6-(t;=?U*+*;c-T@4#C2bNS^vc&5GEyYzB@*^l=B8#XfE xmu^p+bo+E!vwM+u=9ZA<0tc2b`Y%1e{Km(5b41hOZ9s1@c)I$ztaD0e0sw8De3bwI literal 304 zcmeAS@N?(olHy`uVBq!ia0vp^9zZP0!3-oXDM!QrDXjpX5LXv_M`<}tATKD$r@SJ% zI5A+}lI5pgd|zbb_n^BnB#VK;n8QrnJtd_k$ok}apgO*iAirRS|HvTR>$V6`X1S+} zV~9oX+bL&-nhiKwguexS{d@nqr$~fHvh`ofl4aF~>prkbv~m*_ zee)QUYu}{b$FFN;rQ_;4ymZ%_@eB) zhbH_n>+miL$nbUCxiwv@iu21xNnP;;rF>ECl6Uo@Za-U_Yj3dlfBl!YlAYb>F09Q| p`P5!}Wt+O($#;AAU;BEQ?}8q?#iuiV4L~O|c)I$ztaD0e0syr7e*FLd