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

View file

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