JSFiddle - React, Tailwind, and code Playground

by chongdashu

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.4.4/phaser.js"></script>

JavaScript

var game = new Phaser.Game(640, 480, Phaser.AUTO, '', {
    preload: preload,
    create: create,
    update: update,
    render: render,
    collectCoin: function () {
        coin.kill();
    },
});

function preload() {

    game.load.crossOrigin = 'anonymous';
    game.load.image('ship', 'http://i.imgur.com/CD5TrXo.png');
    game.load.image('beam1', 'http://i.imgur.com/9e9tX9W.png');
}

var myShip;
var emitter;
var bunEngines = false;
var text;

function create() {

    game.physics.startSystem(Phaser.Physics.Arcade);
    game.world.setBounds(-320, -240, 640, 480);

    myShip = game.add.sprite(0, 0, "ship");
    myShip.anchor.set(0.5, 0.5);
    game.physics.arcade.enable(myShip);
    
    text = game.add.text(0,200,"", {"fill": "white", font: "bold 12pt Consolas",});
    text.anchor.set(0.5, 0.5)

    startEngines();

}

//EMITTER
function startEngines() {

    emitter = game.add.emitter(game.world.centerX, game.world.centerY, 200);
    // emitter.anchor.set(0.5, 0.5);
    emitter.makeParticles('beam1');
    emitter.gravity = 0;
    emitter.emitX = myShip.x - 25;
    emitter.emitY = myShip.y;
    emitter.setAlpha(1, 0, 2000);
    emitter.setScale(0.5, 0, 0.5, 0, 5000);
    emitter.start(false, 3000, 3);

    // Note:
    // Some settings to make it clearer what the angle 
    // of the emitter is.
    // Right now it will just shoot right.
    emitter.setXSpeed(500);
    emitter.setYSpeed(0);
    
    this.burnEngines = true;
}

function update() {
    myShip.body.velocity.x = 0;
    myShip.body.velocity.y = 0;


    if (this.input.keyboard.isDown(Phaser.Keyboard.W)) {
        myShip.body.velocity.y = -100;
    }

    if (this.input.keyboard.isDown(Phaser.Keyboard.S)) {
        myShip.body.velocity.y = 100;
    }

    var iAmRotatingNow = false;
    
     myShip.body.angularVelocity = 0;
    
    
    if (this.input.keyboard.isDown(Phaser.Keyboard.A)) {
        myShip.body.angularVelocity = -200;
        iAmRotatingNow = true;
                  
        if...