2014-01-20 20:14:34 +00:00
|
|
|
|
|
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
|
|
|
|
function preload() {
|
|
|
|
|
|
|
|
game.load.image('arrow', 'assets/sprites/asteroids_ship.png');
|
|
|
|
game.load.image('ball', 'assets/sprites/shinyball.png');
|
2014-01-21 16:12:50 +00:00
|
|
|
game.load.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
|
2014-01-20 20:14:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:12:50 +00:00
|
|
|
var gameboy;
|
2014-01-20 20:14:34 +00:00
|
|
|
var sprites;
|
|
|
|
var bmd;
|
|
|
|
|
|
|
|
function create() {
|
|
|
|
|
|
|
|
game.stage.backgroundColor = '#124184';
|
|
|
|
|
|
|
|
bmd = game.add.bitmapData(800, 600);
|
|
|
|
bmd.fillStyle('#ffffff');
|
|
|
|
var bg = game.add.sprite(0, 0, bmd);
|
|
|
|
bg.body.moves = false;
|
|
|
|
|
|
|
|
game.physics.gravity.y = 250;
|
2014-01-22 14:31:18 +00:00
|
|
|
// game.physics.gravity.x = 250;
|
2014-01-20 20:14:34 +00:00
|
|
|
|
|
|
|
sprites = game.add.group();
|
|
|
|
|
2014-01-22 14:31:18 +00:00
|
|
|
for (var i = 0; i < 20; i++)
|
2014-01-20 20:14:34 +00:00
|
|
|
{
|
|
|
|
var s = sprites.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(32, 200), 'ball');
|
|
|
|
s.body.velocity.x = game.rnd.integerInRange(-400, 400);
|
|
|
|
s.body.velocity.y = game.rnd.integerInRange(-200, 200);
|
2014-01-21 16:12:50 +00:00
|
|
|
s.name = 'ball' + i;
|
2014-01-20 20:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sprites.setAll('body.collideWorldBounds', true);
|
2014-01-21 16:12:50 +00:00
|
|
|
sprites.setAll('body.bounce.x', 0.9);
|
|
|
|
sprites.setAll('body.bounce.y', 0.9);
|
2014-01-20 20:14:34 +00:00
|
|
|
sprites.setAll('body.minBounceVelocity', 0.8);
|
|
|
|
|
2014-01-21 16:12:50 +00:00
|
|
|
gameboy = game.add.sprite(300, 50, 'gameboy', 0);
|
|
|
|
gameboy.name = 'gameboy';
|
|
|
|
gameboy.body.collideWorldBounds = true;
|
|
|
|
gameboy.body.bounce.setTo(0.9, 0.9);
|
|
|
|
gameboy.body.velocity.x = game.rnd.integerInRange(-400, 400);
|
|
|
|
gameboy.body.velocity.y = game.rnd.integerInRange(-200, 200);
|
|
|
|
|
2014-01-20 20:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
2014-01-22 10:54:49 +00:00
|
|
|
game.physics.collide(gameboy, sprites);
|
2014-01-21 16:12:50 +00:00
|
|
|
game.physics.collide(sprites);
|
2014-01-20 20:14:34 +00:00
|
|
|
|
|
|
|
// sprite.rotation = sprite.body.angle;
|
|
|
|
|
|
|
|
// if (sprite)
|
|
|
|
// {
|
|
|
|
// bmd.fillStyle('#ffff00');
|
|
|
|
// bmd.fillRect(sprite.body.center.x, sprite.body.center.y, 2, 2);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (sprite2)
|
|
|
|
// {
|
|
|
|
// bmd.fillStyle('#ff00ff');
|
|
|
|
// bmd.fillRect(sprite2.body.center.x, sprite2.body.center.y, 2, 2);
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|