mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
89 lines
No EOL
2 KiB
JavaScript
89 lines
No EOL
2 KiB
JavaScript
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
function preload() {
|
|
|
|
game.load.image('phaser', 'assets/sprites/phaser-dude.png');
|
|
game.load.spritesheet('veggies', 'assets/sprites/fruitnveg32wh37.png', 32, 32);
|
|
|
|
}
|
|
|
|
var group;
|
|
var start = false;
|
|
var swapCount = 0;
|
|
var time = 0;
|
|
var test = 0;
|
|
|
|
function create() {
|
|
|
|
game.stage.backgroundColor = '#2d2d2d';
|
|
|
|
group = game.add.group();
|
|
|
|
for (var i = 0; i < 10; i++)
|
|
{
|
|
var c = group.create(100 + Math.random() * 700, game.world.randomY, 'veggies', game.rnd.integerInRange(0, 36));
|
|
c.name = 'veg' + i;
|
|
}
|
|
|
|
test = group.length;
|
|
|
|
game.input.onUp.add(toggleSwap, this);
|
|
|
|
}
|
|
|
|
function toggleSwap () {
|
|
|
|
if (start)
|
|
{
|
|
start = false;
|
|
}
|
|
else
|
|
{
|
|
start = true;
|
|
}
|
|
|
|
}
|
|
|
|
function update() {
|
|
|
|
if (start && game.time.now > time)
|
|
{
|
|
var a = group.getRandom();
|
|
var b = group.getRandom();
|
|
|
|
if (a.name !== b.name)
|
|
{
|
|
console.log('************************ NEW ROUND *********************');
|
|
group.dump(true);
|
|
console.log('Group Size: ' + group.length);
|
|
group.swap(a, b);
|
|
swapCount++;
|
|
|
|
if (group.length !== test)
|
|
{
|
|
start = false;
|
|
console.log('************************ SHIT *********************');
|
|
group.dump(true);
|
|
console.log('************************ SHIT *********************');
|
|
}
|
|
|
|
if (group.validate() == false)
|
|
{
|
|
start = false;
|
|
console.log('************************ VALIDATE FAIL *********************');
|
|
group.dump(true);
|
|
console.log('************************ VALIDATE FAIL *********************');
|
|
}
|
|
|
|
}
|
|
|
|
time = game.time.now + 100;
|
|
}
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
game.debug.renderText('Swap: ' + swapCount, 32, 32);
|
|
|
|
} |