phaser/wip/phaser clean up/aabb vs aabb 1.ts

82 lines
2 KiB
TypeScript
Raw Normal View History

2013-05-30 22:03:56 +00:00
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('atari', 'assets/sprites/atari800xl.png');
game.load.image('card', 'assets/sprites/mana_card.png');
game.load.start();
2013-05-30 22:03:56 +00:00
}
var atari: Phaser.Sprite;
var card: Phaser.Sprite;
function create() {
//atari = game.add.sprite(350, 100, 'atari');
//atari = game.add.sprite(350, 500, 'atari');
atari = game.add.sprite(0, 310, 'atari');
card = game.add.sprite(400, 300, 'card');
//card.body.immovable = true;
2013-05-30 22:03:56 +00:00
//atari.texture.alpha = 0.5;
//atari.scale.setTo(1.5, 1.5);
//atari.body.shape.setSize(150, 50);
//atari.body.shape.offset.setTo(50, 25);
2013-05-30 22:03:56 +00:00
//atari.body.gravity.setTo(0, 2);
atari.body.bounce.setTo(1, 1);
//atari.body.drag.setTo(10, 10);
2013-05-30 22:03:56 +00:00
card.body.bounce.setTo(0.7, 0.7);
//card.body.velocity.x = -50;
2013-05-30 22:03:56 +00:00
}
function update() {
atari.body.acceleration.x = 0;
atari.body.acceleration.y = 0;
2013-05-30 22:03:56 +00:00
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
atari.body.acceleration.x = -150;
2013-05-30 22:03:56 +00:00
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
atari.body.acceleration.x = 150;
2013-05-30 22:03:56 +00:00
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
atari.body.acceleration.y = -150;
2013-05-30 22:03:56 +00:00
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
atari.body.acceleration.y = 150;
2013-05-30 22:03:56 +00:00
}
// collide?
game.collide(atari, card);
2013-05-30 22:03:56 +00:00
}
function render() {
atari.body.renderDebugInfo(16, 16);
card.body.renderDebugInfo(200, 16);
2013-05-30 22:03:56 +00:00
Phaser.DebugUtils.renderSpritePhysicsBody(atari);
Phaser.DebugUtils.renderSpritePhysicsBody(card);
2013-05-30 22:03:56 +00:00
}
})();