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>
|
<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>
|
||||||
|
|
37
src/main.js
37
src/main.js
|
@ -46,31 +46,30 @@
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
kontra.init('js13k-2017');
|
kontra.init('js13k-2017');
|
||||||
kontra.assets.load(
|
kontra.assets.imagePath = 'assets/images';
|
||||||
'assets/images/test.png'
|
|
||||||
).then(function() {
|
|
||||||
var image = new Image();
|
|
||||||
image.src = 'assets/images/test.png';
|
|
||||||
|
|
||||||
var sprite = kontra.sprite({
|
kontra.assets.load(
|
||||||
x: 10,
|
'room_stasis_dark.png',
|
||||||
y: 20,
|
'room_stasis.png'
|
||||||
width: 16,
|
).then(function() {
|
||||||
height: 16,
|
document.getElementById('loading').style.display = 'none';
|
||||||
dx: 0,
|
|
||||||
image: image
|
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({
|
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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue