phaser/Tests/camera fx/flash.js

47 lines
1.7 KiB
JavaScript
Raw Normal View History

/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../build/phaser-fx.d.ts" />
2013-04-12 17:19:56 +01:00
(function () {
2013-04-18 14:16:18 +01:00
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
2013-04-12 17:19:56 +01:00
function init() {
myGame.loader.addImageFile('background', 'assets/pics/large-color-wheel.png');
myGame.loader.addImageFile('car', 'assets/sprites/car90.png');
myGame.loader.load();
}
var car;
var flash;
2013-04-12 17:19:56 +01:00
function create() {
myGame.createSprite(0, 0, 'background');
car = myGame.createSprite(400, 300, 'car');
// Add our effect to the camera
flash = myGame.camera.fx.add(Phaser.FX.Camera.Flash);
2013-04-12 17:19:56 +01:00
}
function update() {
car.velocity.x = 0;
car.velocity.y = 0;
car.angularVelocity = 0;
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
2013-04-12 17:19:56 +01:00
car.angularVelocity = -200;
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
2013-04-12 17:19:56 +01:00
car.angularVelocity = 200;
}
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
car.velocity.copyFrom(myGame.motion.velocityFromAngle(car.angle, 300));
2013-04-12 17:19:56 +01:00
}
// Flash when the car hits the edges, a different colour per edge
if(car.x < 0) {
flash.start(0xffffff, 1);
2013-04-12 17:19:56 +01:00
car.x = 0;
} else if(car.x > myGame.world.width) {
flash.start(0xff0000, 2);
2013-04-12 17:19:56 +01:00
car.x = myGame.world.width - car.width;
}
if(car.y < 0) {
flash.start(0xffff00, 2);
2013-04-12 17:19:56 +01:00
car.y = 0;
} else if(car.y > myGame.world.height) {
flash.start(0xff00ff, 3);
2013-04-12 17:19:56 +01:00
car.y = myGame.world.height - car.height;
}
}
})();