Tilemap loading, player sprite, collisions
BIN
moonlight/gfx/Macks-tilea1.png
Normal file
|
After Width: | Height: | Size: 370 KiB |
BIN
moonlight/gfx/Macks-tilea2.png
Normal file
|
After Width: | Height: | Size: 342 KiB |
BIN
moonlight/gfx/Macks-tilea3.png
Normal file
|
After Width: | Height: | Size: 182 KiB |
BIN
moonlight/gfx/Macks-tilea4.png
Normal file
|
After Width: | Height: | Size: 369 KiB |
BIN
moonlight/gfx/Macks-tilea5.png
Normal file
|
After Width: | Height: | Size: 237 KiB |
BIN
moonlight/gfx/Macks-tileb.png
Normal file
|
After Width: | Height: | Size: 456 KiB |
BIN
moonlight/gfx/Macks-tilec.png
Normal file
|
After Width: | Height: | Size: 313 KiB |
BIN
moonlight/gfx/Macks-tiled.png
Normal file
|
After Width: | Height: | Size: 361 KiB |
BIN
moonlight/gfx/Macks-tilee.png
Normal file
|
After Width: | Height: | Size: 399 KiB |
84
moonlight/gfx/junkmap.json
Normal file
BIN
moonlight/gfx/moogle.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
moonlight/gfx/moogle.pnmg.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
16
moonlight/index.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Phaser - Making your first game, part 1</title>
|
||||||
|
<script type="text/javascript" src="js/phaser.min.js"></script>
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" src="js/moonlight-skulk.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
16
moonlight/index.html~
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Phaser - Making your first game, part 1</title>
|
||||||
|
<script type="text/javascript" src="js/phaser.min.js"></script>
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" src="js/moonlight-skulk.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
93
moonlight/js/moonlight-skulk.js
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
|
||||||
|
|
||||||
|
var moonlightSettings = {
|
||||||
|
'map' : {
|
||||||
|
'tilesets': [
|
||||||
|
{ 'name': 'Macks-tilea2',
|
||||||
|
'path': 'gfx/Macks-tilea2.png'
|
||||||
|
},
|
||||||
|
{ 'name': 'Macks-tilea3',
|
||||||
|
'path': 'gfx/Macks-tilea3.png'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'collisionRange': [385, 512],
|
||||||
|
'path': 'gfx/junkmap.json'
|
||||||
|
},
|
||||||
|
'images': [
|
||||||
|
{ 'name': 'moogle',
|
||||||
|
'path': 'gfx/moogle.png'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'spritesheets': [
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
function preload()
|
||||||
|
{
|
||||||
|
console.log(moonlightSettings);
|
||||||
|
for (var k in moonlightSettings['map']['tilesets']) {
|
||||||
|
var ts = moonlightSettings['map']['tilesets'][k];
|
||||||
|
this.load.image(ts['name'], ts['path']);
|
||||||
|
}
|
||||||
|
for (var k in moonlightSettings['images']) {
|
||||||
|
var i = moonlightSettings['images'][k];
|
||||||
|
this.load.image(i['name'], i['path']);
|
||||||
|
}
|
||||||
|
this.load.tilemap('map',
|
||||||
|
moonlightSettings['map']['path'],
|
||||||
|
null,
|
||||||
|
Phaser.Tilemap.TILED_JSON);
|
||||||
|
}
|
||||||
|
|
||||||
|
function create()
|
||||||
|
{
|
||||||
|
map = this.add.tilemap('map');
|
||||||
|
for (var k in moonlightSettings['map']['tilesets']) {
|
||||||
|
var ts = moonlightSettings['map']['tilesets'][k];
|
||||||
|
map.addTilesetImage(ts['name']);
|
||||||
|
}
|
||||||
|
layer = map.createLayer('Tile Layer 1');
|
||||||
|
layer.resizeWorld();
|
||||||
|
map.setCollisionBetween(
|
||||||
|
moonlightSettings['map']['collisionRange'][0],
|
||||||
|
moonlightSettings['map']['collisionRange'][1]
|
||||||
|
);
|
||||||
|
|
||||||
|
player = this.add.sprite(10, 10, 'moogle');
|
||||||
|
this.physics.arcade.enable(player);
|
||||||
|
this.camera.follow(player, Phaser.Camera.FOLLOW_TOPDOWN);
|
||||||
|
controls = game.input.keyboard.createCursorKeys();
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_input()
|
||||||
|
{
|
||||||
|
if ( player.body.x < 0 )
|
||||||
|
player.body.x = 0;
|
||||||
|
if ( player.body.y < 0 )
|
||||||
|
player.body.y = 0;
|
||||||
|
if ( (player.body.x + player.body.width) > game.world.width )
|
||||||
|
player.body.x = ( game.world.width - player.body.width);
|
||||||
|
if ( (player.body.y + player.body.height) > game.world.height )
|
||||||
|
player.body.y = ( game.world.height - player.body.height);
|
||||||
|
|
||||||
|
player.body.velocity.x = 0;
|
||||||
|
player.body.velocity.y = 0;
|
||||||
|
|
||||||
|
if ( controls.up.isDown) {
|
||||||
|
player.body.velocity.y = -200;
|
||||||
|
} else if ( controls.down.isDown ) {
|
||||||
|
player.body.velocity.y = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( controls.left.isDown ) {
|
||||||
|
player.body.velocity.x = -200;
|
||||||
|
} else if ( controls.right.isDown ) {
|
||||||
|
player.body.velocity.x = 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function update()
|
||||||
|
{
|
||||||
|
check_input();
|
||||||
|
this.physics.arcade.collide(player, layer);
|
||||||
|
}
|
||||||
11
moonlight/js/moonlight-skulk.js~
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
function preload()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
function create()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
function update()
|
||||||
|
{
|
||||||
|
}
|
||||||