Fix the door

This commit is contained in:
Aaron Fischer 2017-08-24 22:00:19 +02:00
parent 5805c8daf5
commit 630d726a9d
2 changed files with 24 additions and 15 deletions

View file

@ -2,14 +2,17 @@
var act1 = {}; var act1 = {};
var controlPanelSprite = kontra.sprite({x: 16, y: 13, width: 3, height: 2}); var controlPanelSprite = kontra.sprite({x: 16, y: 13, width: 3, height: 2});
var doorSpriteSheet = null; var doorAnimationSheet = null;
var doorAnimation = null; var doorSprite = null;
var roomState = {
isDoorOpen: false
};
act1.init = function() { act1.init = function() {
doorSpriteSheet = kontra.spriteSheet({ doorAnimationSheet = kontra.spriteSheet({
image: kontra.assets.images['stasis_door-sheet'], image: kontra.assets.images['stasis_door-sheet'],
frameWidth: 23, frameWidth: 24,
frameHeight: 20, frameHeight: 21,
animations: { animations: {
closed: { closed: {
frames: 0 frames: 0
@ -18,18 +21,18 @@
frames: 2 frames: 2
}, },
open: { open: {
frames: '0..2', frames: '0..3',
frameRate: 6 frameRate: 6,
}, },
close: { close: {
frames: '2..0', frames: '3..0',
frameRate: 6 frameRate: 6,
} }
} }
}); });
doorAnimation = kontra.sprite({ doorSprite = kontra.sprite({
x: 72, y: 8, x: 72, y: 8,
animations: doorSpriteSheet.animations animations: doorAnimationSheet.animations
}); });
if (muri.currentRoom === 'stasis_dark') { if (muri.currentRoom === 'stasis_dark') {
@ -43,11 +46,17 @@
}; };
act1.update = function() { act1.update = function() {
doorSprite.update();
if (muri.currentRoom === 'stasis') { if (muri.currentRoom === 'stasis') {
doorAnimation.closed.update(); if (muri.get('mouse').clickedOn(doorSprite)) {
if (muri.get('mouse').clickedOn(doorAnimation)) {
muri.get('mouse').releaseClick(); 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() { act1.render = function() {
if (muri.currentRoom === 'stasis') { if (muri.currentRoom === 'stasis') {
doorAnimation.closed.render(); doorSprite.render();
} }
}; };

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 B

After

Width:  |  Height:  |  Size: 361 B