Jump to content

Code snippet: Add car turbo


Mike
 Share

Recommended Posts

So I've got little to no time, but i really like TypeScript and Phaser and i've just make a small edit to one of the demos:

    var car: Phaser.Sprite;    var miniCam: Phaser.Camera;    var turbo: bool = true;    var turboDuration: number = 5 * 1000;    var turboCooldown: number = 20 * 1000;

and then in the update function:

 

        if (myGame.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) {            if (turbo) {                var motion: Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 600);                car.velocity.copyFrom(motion);                                setTimeout(function () {                    turbo = false;                    setTimeout(function () {                        turbo = true;                    }, turboCooldown);                }, turboDuration);            }        }

 

 

So you can easily copy paste or just imagine the result.

 

My question is do you think, there is a better approach also i tough for making turbo, turboDuration, turboCooldown properties of car but TypeScript doesn't like adding  properties to objects later on like:

 

car.turbo = false;

 

 

Since compiler checks that car is of type Phaser.Sprite and that there isn't property "turbo"

 

So share your ideas :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...