js/MainScene.js
/**
     * Here go the code to create a balloon
     */
Here go the code to create a balloon
Here go the code to create a balloon
createBallon() {
        this.getParams(false);
        this.scaleBalloon = this.isHorizontal
            ? this.game.scale.gameSize.width * 0.0002 * this.ballonSize
            : this.game.scale.gameSize.width * 0.0001 * this.ballonSize;
        let colorBalloon;
        let gameMode;
        if (this.choice == 'balloons') {
            gameMode = 1;
        } else {
            gameMode = 2;
        }
        colorBalloon = gameMode == 1 ? this.color : Phaser.Math.Between(0, 7);
        var xGravity = Phaser.Math.Between(0, this.isHorizontal ? -this.gravity / 5 : -this.gravity / 10);
        var balloon = this.balloons.create(
            Phaser.Math.Between(0 + 100, this.game.scale.gameSize.width - 100),
            this.game.scale.gameSize.height + 100,
            'balloons',
            colorBalloon
        );
        balloon.setScale(this.scaleBalloon);
        balloon.allowGravity = true;
        balloon.setInteractive();
        balloon.setGravityY(this.gravity);
        balloon.setGravityX(balloon.body.x > this.game.scale.gameSize.width / 2 ? -xGravity : xGravity);
        balloon.once(
            'pointerdown',
            function () {
                balloon.destroy();
                if (gameMode == 1) {
                    this.score++;
                    this.clickBalloonSound.play();
                } else {
                    if (this.color == colorBalloon) {
                        this.score++;
                        this.clickBalloonSound.play();
                    } else {
                        this.lifesLosts++;
                        this.errorSound.play();
                    }
                }
                document.getElementById('scoreDisplay').style.width = (this.score / this.maxScore) * 100 + '%';
                document.getElementById('chanceDisplay').innerHTML = this.life - this.lifesLosts;
            },
            this
        );
    }
createBallon ( ) { this . getParams ( false ) ; this . scaleBalloon = this . isHorizontal ? this . game . scale . gameSize . width * 0.0002 * this . ballonSize : this . game . scale . gameSize . width * 0.0001 * this . ballonSize ; let colorBalloon ; let gameMode ; if ( this . choice == 'balloons' ) { gameMode = 1 ; } else { gameMode = 2 ; } colorBalloon = gameMode == 1 ? this . color : Phaser . Math . Between ( 0 , 7 ) ; var xGravity = Phaser . Math . Between ( 0 , this . isHorizontal ? - this . gravity / 5 : - this . gravity / 10 ) ; var balloon = this . balloons . create ( Phaser . Math . Between ( 0 + 100 , this . game . scale . gameSize . width - 100 ) , this . game . scale . gameSize . height + 100 , 'balloons' , colorBalloon ) ; balloon . setScale ( this . scaleBalloon ) ; balloon . allowGravity = true ; balloon . setInteractive ( ) ; balloon . setGravityY ( this . gravity ) ; balloon . setGravityX ( balloon . body . x > this . game . scale . gameSize . width / 2 ? - xGravity : xGravity ) ; balloon . once ( 'pointerdown' , function ( ) { balloon . destroy ( ) ; if ( gameMode == 1 ) { this . score ++ ; this . clickBalloonSound . play ( ) ; } else { if ( this . color == colorBalloon ) { this . score ++ ; this . clickBalloonSound . play ( ) ; } else { this . lifesLosts ++ ; this . errorSound . play ( ) ; } } document . getElementById ( 'scoreDisplay' ) . style . width = ( this . score / this . maxScore ) * 100 + '%' ; document . getElementById ( 'chanceDisplay' ) . innerHTML = this . life - this . lifesLosts ; } , this ) ; }
Here go the code to create a balloon
Here go the code to create a balloon
// Actualize ballons params // Set balloon scale // Instantiate variables // Manage mode difference for instance balloon // Generate color target or random based on game mode // Set a random gravity X // Initialize instance balloon // Set gravity to balloon instance // Interaction click in balloon