Add rooms

This commit is contained in:
Aaron Fischer 2017-08-15 15:57:32 +02:00
parent 97788b9c39
commit e71d8b0466
5 changed files with 18 additions and 18 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 223 B

View file

@ -4,6 +4,7 @@
<p>a js13kgame by <a href="https://aaron-fischer.net/">Aaron Fischer</a> (2017)</p>
<canvas width="100" height="50" id="js13k-2017"></canvas>
<p id="loading">loading game ...</p>
<script src="vendor/kontra.js"></script>
<script src="main.js"></script>

View file

@ -46,31 +46,30 @@
(function() {
kontra.init('js13k-2017');
kontra.assets.load(
'assets/images/test.png'
).then(function() {
var image = new Image();
image.src = 'assets/images/test.png';
kontra.assets.imagePath = 'assets/images';
var sprite = kontra.sprite({
x: 10,
y: 20,
width: 16,
height: 16,
dx: 0,
image: image
});
kontra.assets.load(
'room_stasis_dark.png',
'room_stasis.png'
).then(function() {
document.getElementById('loading').style.display = 'none';
if (kontra.store.get('current-room') === null)
kontra.store.set('current-room', 'stasis_dark');
var rooms = {
stasis_dark: kontra.sprite({x: 0, y: 0, image: kontra.assets.images.room_stasis_dark}),
stasis: kontra.sprite({x: 0, y: 0, image: kontra.assets.images.room_stasis})
};
var loop = kontra.gameLoop({
update: function() {
sprite.update();
if (sprite.x > kontra.canvas.width) {
sprite.x = -sprite.width;
}
var currentRoom = kontra.store.get('current-room');
rooms[currentRoom].update();
},
render: function() {
sprite.render();
var currentRoom = kontra.store.get('current-room');
rooms[currentRoom].render();
}
});