2014-01-24 03:53:11 +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.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var sprite;
|
|
|
|
var sprite2;
|
|
|
|
var land;
|
2014-01-27 17:08:12 +00:00
|
|
|
var cursors;
|
2014-01-24 03:53:11 +00:00
|
|
|
|
|
|
|
function create() {
|
|
|
|
|
|
|
|
game.stage.backgroundColor = '#124184';
|
|
|
|
|
|
|
|
game.physics.gravity.y = 100;
|
|
|
|
|
2014-01-24 17:30:37 +00:00
|
|
|
sprite = game.add.sprite(200, 300, 'gameboy', 0);
|
2014-01-24 03:53:11 +00:00
|
|
|
sprite.name = 'red';
|
|
|
|
sprite.body.collideWorldBounds = true;
|
2014-01-24 17:30:37 +00:00
|
|
|
// sprite.body.bounce.setTo(0.9, 0.9);
|
2014-01-24 03:53:11 +00:00
|
|
|
|
|
|
|
// sprite2 = game.add.sprite(500, 200, 'gameboy', 2);
|
|
|
|
// sprite2.name = 'green';
|
|
|
|
// sprite2.body.collideWorldBounds = true;
|
|
|
|
// sprite2.body.bounce.setTo(0.9, 0.9);
|
|
|
|
|
|
|
|
land = game.add.sprite(10, 490);
|
|
|
|
land.name = 'land';
|
|
|
|
land.body.immovable = true;
|
|
|
|
land.body.allowGravity = false;
|
|
|
|
land.body.setSize(780, 100, 0, 0);
|
|
|
|
land.body.polygons = new SAT.Polygon(new SAT.Vector(10, 490), [
|
2014-01-24 17:30:37 +00:00
|
|
|
new SAT.Vector(0,50),
|
|
|
|
new SAT.Vector(300,0),
|
|
|
|
new SAT.Vector(780,50),
|
2014-01-24 03:53:11 +00:00
|
|
|
new SAT.Vector(780,100),
|
|
|
|
new SAT.Vector(0,100),
|
|
|
|
]);
|
2014-01-27 17:08:12 +00:00
|
|
|
|
2014-01-24 03:53:11 +00:00
|
|
|
console.log(land);
|
|
|
|
|
2014-01-27 17:08:12 +00:00
|
|
|
// sprite.body.velocity.x = 150;
|
|
|
|
|
|
|
|
cursors = game.input.keyboard.createCursorKeys();
|
|
|
|
// game.input.onDown.add(launch, this);
|
2014-01-24 03:53:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function launch() {
|
|
|
|
|
2014-01-24 17:30:37 +00:00
|
|
|
sprite.body.velocity.x = 100;
|
2014-01-24 03:53:11 +00:00
|
|
|
sprite.body.velocity.y = -300;
|
|
|
|
sprite2.body.velocity.x = 200;
|
|
|
|
sprite2.body.velocity.y = -200;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
2014-01-27 17:08:12 +00:00
|
|
|
game.physics.collide(sprite, land);
|
2014-01-24 03:53:11 +00:00
|
|
|
|
2014-01-27 17:08:12 +00:00
|
|
|
sprite.body.velocity.x = 0;
|
|
|
|
// sprite.body.velocity.y = 0;
|
2014-01-24 03:53:11 +00:00
|
|
|
|
2014-01-27 17:08:12 +00:00
|
|
|
if (cursors.left.isDown)
|
|
|
|
{
|
|
|
|
sprite.body.velocity.x = -100;
|
|
|
|
}
|
|
|
|
else if (cursors.right.isDown)
|
|
|
|
{
|
|
|
|
sprite.body.velocity.x = 100;
|
|
|
|
}
|
2014-01-24 03:53:11 +00:00
|
|
|
|
2014-01-27 17:08:12 +00:00
|
|
|
if (cursors.up.isDown)
|
|
|
|
{
|
|
|
|
sprite.body.velocity.y = -200;
|
|
|
|
}
|
2014-01-24 03:53:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
|
|
|
|
game.debug.renderPolygon(land.body.polygons);
|
|
|
|
|
|
|
|
if (sprite)
|
|
|
|
{
|
|
|
|
game.debug.renderBodyInfo(sprite, 16, 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sprite)
|
|
|
|
{
|
|
|
|
game.debug.renderPolygon(sprite.body.polygons);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sprite2)
|
|
|
|
{
|
|
|
|
game.debug.renderPolygon(sprite2.body.polygons);
|
|
|
|
}
|
|
|
|
|
2014-01-27 17:08:12 +00:00
|
|
|
// game.debug.renderRectangle(land.body);
|
2014-01-24 03:53:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|