add entities
This commit is contained in:
parent
3ee8048bc9
commit
290879dafe
6 changed files with 93 additions and 52 deletions
Before Width: | Height: | Size: 361 B After Width: | Height: | Size: 361 B |
BIN
src/assets/images/stasis_lightSwitch.gif
Normal file
BIN
src/assets/images/stasis_lightSwitch.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 87 B |
50
src/entity.js
Normal file
50
src/entity.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
(function() {
|
||||
var entity = {};
|
||||
var allEntities = [];
|
||||
|
||||
entity.get = function(name) {
|
||||
for (var i in allEntities)
|
||||
if (allEntities[i].name === name)
|
||||
return allEntities[i];
|
||||
return false;
|
||||
};
|
||||
|
||||
entity.create = function(name, sprite) {
|
||||
allEntities.push({
|
||||
name: name,
|
||||
sprite: sprite,
|
||||
callbacks: []
|
||||
});
|
||||
return {
|
||||
addCallback: function(callback) {
|
||||
entity.get(name).callbacks.push(callback);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
entity.update = function() {
|
||||
var clickedOnASprite = false;
|
||||
allEntities.forEach(function(e) {
|
||||
e.sprite.update();
|
||||
if (muri.get('mouse').clickedOn(e.sprite)) {
|
||||
clickedOnASprite = true;
|
||||
e.callbacks.forEach(function(c) {
|
||||
c();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (clickedOnASprite)
|
||||
muri.get('mouse').releaseClick();
|
||||
};
|
||||
|
||||
entity.render = function() {
|
||||
allEntities.forEach(function(e) {
|
||||
e.sprite.render();
|
||||
});
|
||||
};
|
||||
|
||||
entity.name = 'entity';
|
||||
muri.modules.push(entity);
|
||||
}());
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
<script src="vendor/kontra.js"></script>
|
||||
<script src="muri.js"></script>
|
||||
<script src="entity.js"></script>
|
||||
<script src="bubble.js"></script>
|
||||
<script src="mouse.js"></script>
|
||||
<script src="stasis.js"></script>
|
||||
|
|
|
@ -68,7 +68,8 @@ var muri = (function() {
|
|||
kontra.assets.load(
|
||||
'room_stasis_dark.gif',
|
||||
'room_stasis.gif',
|
||||
'stasis_door-sheet.png'
|
||||
'stasis_doorSheet.png',
|
||||
'stasis_lightSwitch.gif'
|
||||
).then(function() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
muri.modules.forEach(function(m) {
|
||||
|
@ -88,8 +89,10 @@ var muri = (function() {
|
|||
render: function() {
|
||||
muri.room(muri.currentRoom).render();
|
||||
muri.modules.forEach(function(m) {
|
||||
if (m.render !== undefined) m.render();
|
||||
if (m.render !== undefined && m.name !== 'entity')
|
||||
m.render();
|
||||
});
|
||||
muri.get('entity').render();
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
(function() {
|
||||
var stasis = {};
|
||||
|
||||
var controlPanelSprite = kontra.sprite({x: 16, y: 13, width: 3, height: 2});
|
||||
var background, backgroundDark = null;
|
||||
var doorAnimationSheet = null;
|
||||
var doorSprite = null;
|
||||
|
@ -12,24 +11,13 @@
|
|||
|
||||
stasis.init = function() {
|
||||
doorAnimationSheet = kontra.spriteSheet({
|
||||
image: kontra.assets.images['stasis_door-sheet'],
|
||||
frameWidth: 24,
|
||||
frameHeight: 21,
|
||||
image: kontra.assets.images.stasis_doorSheet,
|
||||
frameWidth: 24, frameHeight: 21,
|
||||
animations: {
|
||||
closed: {
|
||||
frames: 0
|
||||
},
|
||||
opened: {
|
||||
frames: 2
|
||||
},
|
||||
open: {
|
||||
frames: '0..3',
|
||||
frameRate: 6,
|
||||
},
|
||||
close: {
|
||||
frames: '3..0',
|
||||
frameRate: 6,
|
||||
}
|
||||
closed: {frames: 0},
|
||||
opened: {frames: 2},
|
||||
open: {frames: '0..3', frameRate: 6},
|
||||
close: {frames: '3..0', frameRate: 6}
|
||||
}
|
||||
});
|
||||
doorSprite = kontra.sprite({
|
||||
|
@ -40,6 +28,24 @@
|
|||
background = muri.bg('stasis');
|
||||
backgroundDark = muri.bg('stasis_dark');
|
||||
|
||||
muri.get('entity')
|
||||
.create('stasis.lightSwitch',
|
||||
kontra.sprite({x: 16, y: 13, width: 3, height: 2,
|
||||
image: kontra.assets.images.stasis_lightSwitch}))
|
||||
.addCallback(function() {
|
||||
if (!roomState.isLightOn) {
|
||||
roomState.isLightOn = true;
|
||||
muri.get('bubble')
|
||||
.talk([
|
||||
'Ah, much better.',
|
||||
'Looks like something happened to my stasis capsule.'
|
||||
]);
|
||||
} else {
|
||||
muri.get('bubble')
|
||||
.talk(['No, I will not turn off the light again!']);
|
||||
}
|
||||
});
|
||||
|
||||
if (!roomState.isLightOn) {
|
||||
muri.get('bubble')
|
||||
.story([
|
||||
|
@ -51,10 +57,11 @@
|
|||
};
|
||||
|
||||
stasis.update = function() {
|
||||
doorSprite.update();
|
||||
if (roomState.isLightOn) {
|
||||
if (muri.get('mouse').clickedOn(doorSprite)) {
|
||||
muri.get('mouse').releaseClick();
|
||||
if (roomState.isLightOn &&
|
||||
!muri.get('entity').get('stasis.door')) {
|
||||
muri.get('entity')
|
||||
.create('stasis.door', doorSprite)
|
||||
.addCallback(function() {
|
||||
if (!roomState.isDoorOpen) {
|
||||
doorSprite.playAnimation('open');
|
||||
roomState.isDoorOpen = true;
|
||||
|
@ -62,23 +69,7 @@
|
|||
doorSprite.playAnimation('close');
|
||||
roomState.isDoorOpen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (muri.get('mouse').clickedOn(controlPanelSprite)) {
|
||||
muri.get('mouse').releaseClick();
|
||||
|
||||
if (!roomState.isLightOn) {
|
||||
roomState.isLightOn = true;
|
||||
muri.get('bubble')
|
||||
.talk([
|
||||
'Ah, much better.',
|
||||
'Looks like something happened to my stasis capsule.'
|
||||
]);
|
||||
} else {
|
||||
muri.get('bubble')
|
||||
.talk(['No, I will not turn off the light again!']);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -88,10 +79,6 @@
|
|||
} else {
|
||||
backgroundDark.render();
|
||||
}
|
||||
|
||||
if (roomState.isLightOn) {
|
||||
doorSprite.render();
|
||||
}
|
||||
};
|
||||
|
||||
stasis.name = 'stasis';
|
||||
|
|
Loading…
Reference in a new issue