phaser/Tests/mini games/formula 1.ts

60 lines
1.5 KiB
TypeScript
Raw Normal View History

/// <reference path="../../Phaser/Game.ts" />
2013-04-12 16:19:56 +00:00
(function () {
2013-04-18 13:16:18 +00:00
var myGame = new Phaser.Game(this, 'game', 840, 400, init, create, update);
2013-04-12 16:19:56 +00:00
function init() {
myGame.loader.addImageFile('track', 'assets/games/f1/track.png');
myGame.loader.addImageFile('car', 'assets/games/f1/car1.png');
myGame.loader.load();
}
2013-04-18 13:16:18 +00:00
var car: Phaser.Sprite;
var bigCam: Phaser.Camera;
2013-04-12 16:19:56 +00:00
function create() {
myGame.camera.setBounds(0, 0, myGame.stage.width, myGame.stage.height);
myGame.createSprite(0, 0, 'track');
car = myGame.createSprite(180, 298, 'car');
car.rotation = 180;
car.maxVelocity.setTo(150, 150);
bigCam = myGame.createCamera(640, 0, 100, 200);
2013-04-18 13:16:18 +00:00
bigCam.follow(car, Phaser.Camera.STYLE_LOCKON);
2013-04-12 16:19:56 +00:00
bigCam.setBounds(0, 0, myGame.stage.width, myGame.stage.height);
bigCam.showBorder = true;
bigCam.borderColor = 'rgb(0,0,0)';
bigCam.scale.setTo(2, 2);
}
function update() {
2013-04-18 13:16:18 +00:00
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
2013-04-12 16:19:56 +00:00
{
car.rotation -= 4;
}
2013-04-18 13:16:18 +00:00
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
2013-04-12 16:19:56 +00:00
{
car.rotation += 4;
}
2013-04-18 13:16:18 +00:00
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
2013-04-12 16:19:56 +00:00
{
2013-04-18 13:16:18 +00:00
car.velocity.copyFrom(myGame.motion.velocityFromAngle(car.angle, 150));
2013-04-12 16:19:56 +00:00
}
else
{
2013-04-18 13:16:18 +00:00
car.velocity.copyFrom(myGame.motion.velocityFromAngle(car.angle, 60));
2013-04-12 16:19:56 +00:00
}
}
})();