2014-02-18 03:01:51 +00:00
|
|
|
|
|
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
// var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
|
|
|
|
function preload() {
|
|
|
|
|
|
|
|
game.load.tilemap('map', 'assets/tilemaps/maps/collision_test.json', null, Phaser.Tilemap.TILED_JSON);
|
|
|
|
game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png');
|
|
|
|
game.load.image('tiles2', 'assets/tilemaps/tiles/tiles2.png');
|
|
|
|
game.load.image('ufo', 'assets/sprites/ufo.png');
|
|
|
|
game.load.image('ship', 'assets/sprites/thrust_ship2.png');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var ship;
|
|
|
|
var map;
|
|
|
|
var layer;
|
|
|
|
var cursors;
|
|
|
|
var dump;
|
|
|
|
|
|
|
|
function create() {
|
|
|
|
|
|
|
|
game.stage.backgroundColor = '#2d2d2d';
|
|
|
|
|
2014-02-19 15:43:05 +00:00
|
|
|
// map = game.add.tilemap('map');
|
2014-02-18 03:01:51 +00:00
|
|
|
|
2014-02-19 15:43:05 +00:00
|
|
|
// map.addTilesetImage('ground_1x1');
|
|
|
|
// map.addTilesetImage('tiles2');
|
2014-02-18 03:01:51 +00:00
|
|
|
|
2014-02-19 15:43:05 +00:00
|
|
|
// map.setCollisionBetween(1, 12);
|
2014-02-18 03:01:51 +00:00
|
|
|
|
2014-02-19 15:43:05 +00:00
|
|
|
// layer = map.createLayer('Tile Layer 1');
|
2014-02-18 03:01:51 +00:00
|
|
|
|
2014-02-19 15:43:05 +00:00
|
|
|
// layer.resizeWorld();
|
2014-02-18 03:01:51 +00:00
|
|
|
|
2014-02-19 15:43:05 +00:00
|
|
|
// dump = map.generateCollisionData(layer);
|
2014-02-18 03:01:51 +00:00
|
|
|
|
|
|
|
ship = game.add.sprite(200, 200, 'ship');
|
|
|
|
ship.physicsEnabled = true;
|
|
|
|
// We do this because our ship is shaped like a triangle, not a square :)
|
|
|
|
ship.body.addPolygon({}, 29, 23 , 0, 23 , 14, 1);
|
2014-02-19 15:43:05 +00:00
|
|
|
// ship.body.setCircle(32);
|
|
|
|
// ship.body.setCircle(32, 20, 20);
|
2014-02-18 03:01:51 +00:00
|
|
|
|
|
|
|
game.camera.follow(ship);
|
|
|
|
|
|
|
|
cursors = game.input.keyboard.createCursorKeys();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
|
|
|
if (cursors.left.isDown)
|
|
|
|
{
|
|
|
|
ship.body.rotateLeft(100);
|
|
|
|
}
|
|
|
|
else if (cursors.right.isDown)
|
|
|
|
{
|
|
|
|
ship.body.rotateRight(100);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ship.body.setZeroRotation();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursors.up.isDown)
|
|
|
|
{
|
|
|
|
ship.body.thrust(400);
|
|
|
|
}
|
|
|
|
else if (cursors.down.isDown)
|
|
|
|
{
|
|
|
|
ship.body.reverse(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
|
2014-02-19 15:43:05 +00:00
|
|
|
// for (var i = 0, len = dump.length; i < len; i++)
|
|
|
|
// {
|
2014-02-18 03:01:51 +00:00
|
|
|
// game.debug.renderPhysicsBody(dump[i]);
|
2014-02-19 15:43:05 +00:00
|
|
|
// }
|
2014-02-18 03:01:51 +00:00
|
|
|
|
2014-02-19 15:43:05 +00:00
|
|
|
game.debug.renderPhysicsBody(ship.body);
|
2014-02-18 03:01:51 +00:00
|
|
|
|
|
|
|
}
|