2013-12-05 18:12:16 +00:00
|
|
|
|
|
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
|
|
|
|
function preload() {
|
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
// game.load.tilemap('map', 'assets/maps/super_mario.json', null, Phaser.Tilemap.TILED_JSON);
|
|
|
|
// game.load.tileset('tiles', 'assets/maps/super_mario.png', 16, 16);
|
|
|
|
|
2014-01-13 19:45:15 +00:00
|
|
|
game.load.tilemap('map', 'assets/tilemaps/maps/features_test.json', null, Phaser.Tilemap.TILED_JSON);
|
2013-12-19 03:49:28 +00:00
|
|
|
|
|
|
|
// game.load.image('ground', 'assets/maps/ground_1x1.png');
|
|
|
|
|
2014-01-13 19:45:15 +00:00
|
|
|
game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png');
|
|
|
|
game.load.image('walls_1x2', 'assets/tilemaps/tiles/walls_1x2.png');
|
|
|
|
game.load.image('tiles2', 'assets/tilemaps/tiles/tiles2.png');
|
2013-12-19 03:49:28 +00:00
|
|
|
|
2013-12-10 12:23:42 +00:00
|
|
|
|
2013-12-17 05:07:00 +00:00
|
|
|
// game.load.tileset('tiles', 'assets/maps/ground_1x1.png', 32, 32);
|
2013-12-07 02:05:07 +00:00
|
|
|
// game.load.image('phaser', 'assets/sprites/phaser-ship.png');
|
2013-12-06 02:34:28 +00:00
|
|
|
// game.load.image('phaser', 'assets/sprites/mushroom2.png');
|
2014-01-29 17:10:13 +00:00
|
|
|
game.load.image('phaser', 'assets/sprites/wabbit.png');
|
|
|
|
// game.load.image('phaser', 'assets/sprites/arrow.png');
|
2013-12-22 04:27:12 +00:00
|
|
|
game.load.spritesheet('coin', 'assets/sprites/coin.png', 32, 32);
|
2013-12-06 04:34:27 +00:00
|
|
|
// game.load.image('phaser', 'assets/sprites/darkwing_crazy.png');
|
2013-12-05 18:12:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var cursors;
|
|
|
|
var map;
|
2013-12-22 04:27:12 +00:00
|
|
|
var coins;
|
2013-12-19 03:49:28 +00:00
|
|
|
|
2013-12-05 18:12:16 +00:00
|
|
|
var layer;
|
2013-12-06 04:34:27 +00:00
|
|
|
var layer2;
|
2013-12-19 03:49:28 +00:00
|
|
|
var layer3;
|
|
|
|
|
2013-12-05 18:12:16 +00:00
|
|
|
var sprite;
|
|
|
|
|
|
|
|
function create() {
|
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
map = game.add.tilemap('map');
|
2013-12-05 18:12:16 +00:00
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
map.addTilesetImage('ground_1x1');
|
|
|
|
map.addTilesetImage('walls_1x2');
|
|
|
|
map.addTilesetImage('tiles2');
|
2013-12-17 05:07:00 +00:00
|
|
|
|
2013-12-19 05:09:49 +00:00
|
|
|
map.setCollisionBetween(1, 12);
|
2013-12-19 03:49:28 +00:00
|
|
|
|
2013-12-19 05:09:49 +00:00
|
|
|
// mario tiles
|
2013-12-19 03:49:28 +00:00
|
|
|
// map.setCollisionByIndex(15);
|
|
|
|
// map.setCollisionByIndex(40);
|
|
|
|
// map.setCollisionByIndexRange(14, 16);
|
|
|
|
// map.setCollisionByIndexRange(20, 25);
|
|
|
|
// map.setCollisionByIndexRange(27, 29);
|
|
|
|
|
2013-12-22 03:46:08 +00:00
|
|
|
// layer3 = map.createLayer('Tile Layer 3');
|
|
|
|
// layer3.scrollFactorX = 0.5;
|
2013-12-19 05:09:49 +00:00
|
|
|
|
2013-12-22 03:46:08 +00:00
|
|
|
// layer2 = map.createLayer('Tile Layer 2');
|
|
|
|
// layer2.alpha = 0.5;
|
2013-12-19 05:09:49 +00:00
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
layer = map.createLayer('Tile Layer 1');
|
|
|
|
|
2014-01-29 17:10:13 +00:00
|
|
|
layer.debug = true;
|
2013-12-19 03:49:28 +00:00
|
|
|
|
|
|
|
layer.resizeWorld();
|
2013-12-18 00:44:04 +00:00
|
|
|
|
2013-12-22 04:27:12 +00:00
|
|
|
//coins =
|
2013-12-23 04:19:52 +00:00
|
|
|
map.createFromObjects('Object Layer 1', 34, 'coin', 0);
|
2013-12-06 04:34:27 +00:00
|
|
|
|
|
|
|
// layer2 = game.add.tilemapLayer(0, 0, 400, 600, null, map, 0);
|
2013-12-06 13:48:40 +00:00
|
|
|
// layer.cameraOffset.x = 400;
|
2013-12-07 02:05:07 +00:00
|
|
|
// layer.alpha = 0.5;
|
2013-12-05 18:12:16 +00:00
|
|
|
|
|
|
|
|
2013-12-06 04:34:27 +00:00
|
|
|
sprite = game.add.sprite(260, 100, 'phaser');
|
2014-01-29 17:10:13 +00:00
|
|
|
// sprite.anchor.setTo(0.5, 0.5);
|
2013-12-05 18:12:16 +00:00
|
|
|
|
2013-12-07 02:05:07 +00:00
|
|
|
// This adjusts the collision body size.
|
|
|
|
// 100x50 is the new width/height.
|
|
|
|
// 50, 25 is the X and Y offset of the newly sized box.
|
|
|
|
// In this case the box is 50px in and 25px down.
|
2014-01-29 17:10:13 +00:00
|
|
|
// sprite.body.setSize(16, 16, 8, 8);
|
2013-12-07 02:05:07 +00:00
|
|
|
|
2013-12-06 04:34:27 +00:00
|
|
|
// We'll set a lower max angular velocity here to keep it from going totally nuts
|
|
|
|
sprite.body.maxAngular = 500;
|
2013-12-05 18:12:16 +00:00
|
|
|
|
2013-12-06 04:34:27 +00:00
|
|
|
// Apply a drag otherwise the sprite will just spin and never slow down
|
|
|
|
sprite.body.angularDrag = 50;
|
|
|
|
|
|
|
|
// sprite.body.drag.x = 50;
|
|
|
|
// sprite.body.drag.y = 20;
|
|
|
|
|
|
|
|
// sprite.body.velocity.x = 50;
|
2013-12-05 18:12:16 +00:00
|
|
|
|
2013-12-06 04:34:27 +00:00
|
|
|
sprite.body.bounce.x = 0.8;
|
|
|
|
sprite.body.bounce.y = 0.8;
|
2013-12-05 18:12:16 +00:00
|
|
|
|
2013-12-06 04:34:27 +00:00
|
|
|
// sprite.angle = 35;
|
|
|
|
|
2014-01-29 17:10:13 +00:00
|
|
|
// game.camera.follow(sprite);
|
2013-12-06 04:34:27 +00:00
|
|
|
|
2014-01-29 17:10:13 +00:00
|
|
|
// game.input.onDown.add(getIt, this);
|
2013-12-06 04:34:27 +00:00
|
|
|
|
|
|
|
cursors = game.input.keyboard.createCursorKeys();
|
2013-12-05 18:12:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-06 04:34:27 +00:00
|
|
|
function getIt() {
|
2013-12-05 18:12:16 +00:00
|
|
|
|
2013-12-17 05:07:00 +00:00
|
|
|
// console.log('cam', game.camera.bounds);
|
|
|
|
// console.log('w', game.world.bounds);
|
2013-12-06 04:34:27 +00:00
|
|
|
// console.log(layer.getTiles(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height, true, true));
|
2013-12-05 18:12:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
2013-12-06 04:34:27 +00:00
|
|
|
/*
|
2013-12-05 18:12:16 +00:00
|
|
|
if (cursors.left.isDown)
|
|
|
|
{
|
2013-12-06 04:34:27 +00:00
|
|
|
game.camera.x -= 1;
|
2013-12-05 18:12:16 +00:00
|
|
|
}
|
|
|
|
else if (cursors.right.isDown)
|
|
|
|
{
|
2013-12-06 04:34:27 +00:00
|
|
|
game.camera.x += 1;
|
2013-12-05 18:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cursors.up.isDown)
|
|
|
|
{
|
|
|
|
layer.scrollY -= 4;
|
|
|
|
}
|
|
|
|
else if (cursors.down.isDown)
|
|
|
|
{
|
|
|
|
layer.scrollY += 4;
|
|
|
|
}
|
2013-12-06 04:34:27 +00:00
|
|
|
*/
|
2013-12-19 05:09:49 +00:00
|
|
|
game.physics.collide(sprite, layer);
|
2013-12-05 18:12:16 +00:00
|
|
|
|
2013-12-06 04:34:27 +00:00
|
|
|
sprite.body.velocity.x = 0;
|
|
|
|
sprite.body.velocity.y = 0;
|
|
|
|
sprite.body.angularVelocity = 0;
|
|
|
|
|
|
|
|
// sprite.body.acceleration.x = 0;
|
|
|
|
// sprite.body.angularAcceleration = 0;
|
|
|
|
|
2014-01-29 17:10:13 +00:00
|
|
|
/*
|
2013-12-06 04:34:27 +00:00
|
|
|
if (cursors.left.isDown)
|
|
|
|
{
|
|
|
|
// sprite.body.acceleration.x = -200;
|
|
|
|
sprite.body.angularVelocity = -300;
|
|
|
|
// sprite.body.angularAcceleration -= 200;
|
|
|
|
}
|
|
|
|
else if (cursors.right.isDown)
|
|
|
|
{
|
|
|
|
// sprite.body.acceleration.x = 200;
|
|
|
|
sprite.body.angularVelocity = 300;
|
|
|
|
// sprite.body.angularAcceleration += 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursors.up.isDown)
|
|
|
|
{
|
|
|
|
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// game.physics.velocityFromAngle(sprite.angle, sprite.body.velocity, sprite.body.velocity);
|
|
|
|
}
|
2014-01-29 17:10:13 +00:00
|
|
|
*/
|
2013-12-06 04:34:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2013-12-05 18:12:16 +00:00
|
|
|
sprite.body.velocity.x = 0;
|
|
|
|
sprite.body.velocity.y = 0;
|
|
|
|
|
2013-12-06 02:34:28 +00:00
|
|
|
sprite.angle = sprite.angle + 1;
|
2014-01-29 17:10:13 +00:00
|
|
|
*/
|
2013-12-06 02:34:28 +00:00
|
|
|
|
2013-12-05 18:12:16 +00:00
|
|
|
if (cursors.up.isDown)
|
|
|
|
{
|
2014-01-29 17:10:13 +00:00
|
|
|
sprite.body.velocity.y = -100;
|
2013-12-05 18:12:16 +00:00
|
|
|
}
|
|
|
|
else if (cursors.down.isDown)
|
|
|
|
{
|
2014-01-29 17:10:13 +00:00
|
|
|
sprite.body.velocity.y = 100;
|
2013-12-05 18:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cursors.left.isDown)
|
|
|
|
{
|
2014-01-29 17:10:13 +00:00
|
|
|
sprite.body.velocity.x = -100;
|
2013-12-05 18:12:16 +00:00
|
|
|
}
|
|
|
|
else if (cursors.right.isDown)
|
|
|
|
{
|
2014-01-29 17:10:13 +00:00
|
|
|
sprite.body.velocity.x = 100;
|
2013-12-05 18:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
|
2013-12-06 02:34:28 +00:00
|
|
|
// game.debug.renderSpriteBody(sprite);
|
2014-01-29 17:10:13 +00:00
|
|
|
// game.debug.renderSpriteBounds(sprite);
|
|
|
|
game.debug.renderPhysicsBody(sprite.body);
|
|
|
|
|
|
|
|
// game.debug.renderText(sprite.deltaX, 32, 32);
|
|
|
|
// game.debug.renderText(sprite.deltaY, 32, 48);
|
|
|
|
// game.debug.renderText(sprite.body.deltaX(), 232, 32);
|
|
|
|
// game.debug.renderText(sprite.body.deltaY(), 232, 48);
|
2013-12-05 18:12:16 +00:00
|
|
|
|
2014-01-29 17:10:13 +00:00
|
|
|
// game.debug.renderText(sprite.body.left, 32, 32);
|
|
|
|
// game.debug.renderText(sprite.body.right, 32, 48);
|
2013-12-06 04:34:27 +00:00
|
|
|
|
2014-01-29 17:10:13 +00:00
|
|
|
game.debug.renderSpriteCoords(sprite, 32, 32);
|
2013-12-05 18:12:16 +00:00
|
|
|
|
|
|
|
}
|