2014-01-22 16:16:53 +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.tilemap('map', 'assets/tilemaps/maps/platform.json', null, Phaser.Tilemap.TILED_JSON);
|
|
|
|
game.load.image('platformer_tiles', 'assets/tilemaps/tiles/platformer_tiles.png');
|
|
|
|
game.load.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
|
2014-01-23 01:50:43 +00:00
|
|
|
game.load.spritesheet('balls', 'assets/sprites/balls.png', 17, 17);
|
2014-01-22 16:16:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var map;
|
|
|
|
var layer;
|
|
|
|
var sprite;
|
2014-01-23 01:50:43 +00:00
|
|
|
var sprite2;
|
|
|
|
var balls;
|
2014-01-29 17:10:13 +00:00
|
|
|
var cursors;
|
2014-01-22 16:16:53 +00:00
|
|
|
|
|
|
|
function create() {
|
|
|
|
|
|
|
|
game.stage.backgroundColor = '#124184';
|
|
|
|
|
|
|
|
map = game.add.tilemap('map');
|
|
|
|
|
|
|
|
map.addTilesetImage('platformer_tiles');
|
|
|
|
|
2014-01-23 01:50:43 +00:00
|
|
|
map.setCollisionBetween(21, 53);
|
2014-01-22 16:16:53 +00:00
|
|
|
|
|
|
|
layer = map.createLayer('Tile Layer 1');
|
|
|
|
|
2014-01-28 06:52:56 +00:00
|
|
|
layer.debug = true;
|
2014-01-22 16:16:53 +00:00
|
|
|
|
2014-01-29 17:10:13 +00:00
|
|
|
// game.physics.gravity.y = 150;
|
2014-01-23 01:50:43 +00:00
|
|
|
|
2014-01-28 17:13:07 +00:00
|
|
|
/*
|
2014-01-23 01:50:43 +00:00
|
|
|
balls = game.add.group();
|
|
|
|
|
2014-01-27 09:25:12 +00:00
|
|
|
for (var i = 0; i < 30; i++)
|
2014-01-23 01:50:43 +00:00
|
|
|
{
|
2014-01-23 21:45:35 +00:00
|
|
|
var s = balls.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(100, 200), 'balls', game.rnd.integerInRange(0, 6));
|
2014-01-23 01:50:43 +00:00
|
|
|
s.body.velocity.x = game.rnd.integerInRange(-400, 400);
|
|
|
|
s.body.velocity.y = game.rnd.integerInRange(-100, -200);
|
|
|
|
s.name = 'ball' + i;
|
|
|
|
}
|
|
|
|
|
|
|
|
balls.setAll('body.collideWorldBounds', true);
|
|
|
|
balls.setAll('body.bounce.x', 0.8);
|
|
|
|
balls.setAll('body.bounce.y', 0.9);
|
2014-01-23 21:45:35 +00:00
|
|
|
balls.setAll('body.minBounceVelocity', 0.9);
|
2014-02-05 05:54:25 +00:00
|
|
|
balls.setAll('body.linearDamping', 0.5);
|
2014-01-28 17:13:07 +00:00
|
|
|
*/
|
2014-01-22 16:16:53 +00:00
|
|
|
|
2014-01-28 06:52:56 +00:00
|
|
|
sprite2 = game.add.sprite(340, 250, 'gameboy', 2);
|
2014-01-27 09:25:12 +00:00
|
|
|
sprite2.name = 'green';
|
|
|
|
sprite2.body.collideWorldBounds = true;
|
|
|
|
// sprite2.body.bounce.setTo(0.5, 0.5);
|
|
|
|
|
2014-01-28 17:13:07 +00:00
|
|
|
sprite = game.add.sprite(270, 100, 'gameboy', 0);
|
2014-01-22 16:16:53 +00:00
|
|
|
sprite.name = 'red';
|
|
|
|
sprite.body.collideWorldBounds = true;
|
2014-01-23 21:45:35 +00:00
|
|
|
sprite.body.minBounceVelocity = 0.9;
|
|
|
|
sprite.body.bounce.setTo(0.5, 0.9);
|
2014-02-05 05:54:25 +00:00
|
|
|
sprite.body.linearDamping = 0.5;
|
2014-01-22 16:16:53 +00:00
|
|
|
|
2014-01-23 01:50:43 +00:00
|
|
|
|
2014-01-22 16:16:53 +00:00
|
|
|
game.input.onDown.add(launch, this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function launch() {
|
|
|
|
|
2014-01-28 06:52:56 +00:00
|
|
|
// sprite.body.velocity.x = -200;
|
|
|
|
// sprite.body.velocity.y = -200;
|
|
|
|
|
|
|
|
sprite2.body.velocity.x = -200;
|
|
|
|
sprite2.body.velocity.y = -200;
|
2014-01-22 16:16:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function hit(face, body1, body2) {
|
|
|
|
|
|
|
|
console.log('hit', face);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-23 01:50:43 +00:00
|
|
|
var flag = false;
|
|
|
|
|
2014-01-22 16:16:53 +00:00
|
|
|
function update() {
|
|
|
|
|
2014-01-28 17:13:07 +00:00
|
|
|
// game.physics.collide(balls, layer);
|
2014-01-22 16:16:53 +00:00
|
|
|
game.physics.collide(sprite, layer);
|
2014-01-23 01:50:43 +00:00
|
|
|
game.physics.collide(sprite2, layer);
|
|
|
|
game.physics.collide(sprite, sprite2);
|
2014-01-27 09:25:12 +00:00
|
|
|
|
2014-01-22 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
|
2014-01-28 06:52:56 +00:00
|
|
|
game.debug.renderBodyInfo(sprite2, 32, 32);
|
2014-01-28 17:13:07 +00:00
|
|
|
game.debug.renderPhysicsBody(sprite2.body);
|
2014-01-28 06:52:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
// game.debug.renderText(sprite2.body.left, 32, 30);
|
|
|
|
// game.debug.renderText(sprite2.body.right, 32, 50);
|
|
|
|
// game.debug.renderText(sprite2.body.top, 32, 70);
|
|
|
|
// game.debug.renderText(sprite2.body.bottom, 32, 90);
|
2014-01-27 09:25:12 +00:00
|
|
|
|
2014-01-28 17:13:07 +00:00
|
|
|
|
|
|
|
// for (var i = 0; i < balls._container.length; i++)
|
|
|
|
// {
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
2014-01-27 09:25:12 +00:00
|
|
|
// if (sprite)
|
|
|
|
// {
|
|
|
|
// // game.debug.renderBodyInfo(sprite, 20, 30);
|
|
|
|
// game.debug.renderBodyInfo(sprite2, 20, 230);
|
|
|
|
// }
|
2014-01-22 16:16:53 +00:00
|
|
|
|
|
|
|
}
|