Add rooms
This commit is contained in:
parent
97788b9c39
commit
e71d8b0466
5 changed files with 18 additions and 18 deletions
BIN
src/assets/images/room_stasis.png
Normal file
BIN
src/assets/images/room_stasis.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 615 B |
BIN
src/assets/images/room_stasis_dark.png
Normal file
BIN
src/assets/images/room_stasis_dark.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 361 B |
Binary file not shown.
Before Width: | Height: | Size: 223 B |
|
@ -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>
|
||||
|
|
37
src/main.js
37
src/main.js
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue