2013-06-13 16:15:16 +00:00
|
|
|
/// <reference path="../../Phaser/Game.ts" />
|
|
|
|
/// <reference path="../../Phaser/physics/advanced/Manager.ts" />
|
2013-06-14 03:13:00 +00:00
|
|
|
/// <reference path="../../Phaser/physics/advanced/ShapeBox.ts" />
|
|
|
|
/// <reference path="../../Phaser/physics/advanced/ShapeCircle.ts" />
|
2013-06-13 16:15:16 +00:00
|
|
|
(function () {
|
|
|
|
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
|
|
|
function init() {
|
|
|
|
game.load.image('atari', 'assets/sprites/atari800xl.png');
|
|
|
|
game.load.image('card', 'assets/sprites/mana_card.png');
|
|
|
|
game.load.start();
|
|
|
|
}
|
|
|
|
var atari;
|
|
|
|
var card;
|
2013-06-14 03:13:00 +00:00
|
|
|
var physics;
|
|
|
|
var circle;
|
2013-06-14 14:18:41 +00:00
|
|
|
var ground;
|
2013-06-13 16:15:16 +00:00
|
|
|
function create() {
|
2013-06-14 03:13:00 +00:00
|
|
|
atari = game.add.sprite(200, 100, 'atari');
|
2013-06-13 16:15:16 +00:00
|
|
|
//card = game.add.sprite(500, 300, 'card');
|
2013-06-14 03:13:00 +00:00
|
|
|
physics = new Phaser.Physics.Advanced.Manager(game);
|
|
|
|
var walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC);
|
|
|
|
walls.game = game;
|
2013-06-14 14:18:41 +00:00
|
|
|
ground = walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 500, 800, 20));
|
|
|
|
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 0.2, 20.48, 0.4));
|
|
|
|
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 15.16, 20.48, 0.4));
|
|
|
|
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(-10.04, 7.68, 0.4, 14.56));
|
|
|
|
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(10.04, 7.68, 0.4, 14.56));
|
2013-06-14 03:13:00 +00:00
|
|
|
walls.resetMassData();
|
|
|
|
physics.space.addBody(walls);
|
|
|
|
// Add a circle
|
2013-06-14 14:18:41 +00:00
|
|
|
circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, physics.pixelsToMeters(300), physics.pixelsToMeters(200));
|
2013-06-14 03:13:00 +00:00
|
|
|
circle.game = game;
|
|
|
|
var shape = new Phaser.Physics.Advanced.ShapeCircle(0.4, 0, 0);
|
|
|
|
shape.elasticity = 0.5;
|
|
|
|
shape.friction = 1.0;
|
|
|
|
shape.density = 1;
|
|
|
|
circle.addShape(shape);
|
|
|
|
circle.resetMassData();
|
|
|
|
physics.space.addBody(circle);
|
2013-06-13 16:15:16 +00:00
|
|
|
}
|
|
|
|
function update() {
|
2013-06-14 03:13:00 +00:00
|
|
|
physics.update();
|
2013-06-14 14:18:41 +00:00
|
|
|
atari.x = physics.metersToPixels(circle.position.x);
|
|
|
|
atari.y = physics.metersToPixels(circle.position.y);
|
|
|
|
//console.log(circle.velocity.x, circle.velocity.y);
|
|
|
|
//console.log('p', circle.position.x, circle.position.y);
|
|
|
|
}
|
2013-06-13 16:15:16 +00:00
|
|
|
function render() {
|
2013-06-14 03:13:00 +00:00
|
|
|
game.stage.context.fillStyle = 'rgb(255,255,0)';
|
|
|
|
game.stage.context.fillText('x: ' + circle.position.x + ' y: ' + circle.position.y, 32, 32);
|
|
|
|
game.stage.context.fillText('vx: ' + circle.velocity.x + ' vy: ' + circle.velocity.y, 32, 64);
|
2013-06-13 16:15:16 +00:00
|
|
|
}
|
|
|
|
})();
|