src/games/coronaGoGame/coronaGo/coronaGo.js
//init method it will do some starting procedures
init method it will do some starting procedures
init method it will do some starting procedures
init() {
        this.setState({
            score: 0,
            gameState: 0
        })
        let canvas = document.createElement("canvas");
        canvas.id = "coronaGoCanvas";
        let coronaGoGame = document.getElementById("coronaGoGame");
        let startUpBox = document.getElementById("startBox");
        this.canvas = canvas;
        this.ctx = canvas.getContext("2d")
        this.canvas.height = window.innerHeight;
        this.canvas.width = window.innerWidth;
        this.bulletArray = new BulletsArray(this.ctx, 4, 4, this.canvas.height, this.canvas.width);
        this.space = new Space(this.ctx, this.canvas.height, this.canvas.width);
        this.earth = this.space.earth;
        window.addEventListener("click", (e) => {
            let bulletOriginX = this.canvas.width / 2;
            let bulletOriginY = this.canvas.height / 2;
            let speed = this.calculateSpeed(e.clientX, e.clientY, bulletOriginX, bulletOriginY)
            this.bulletArray.addBullet(bulletOriginX, bulletOriginY, speed)
        })
           if(startUpBox != null)
        coronaGoGame.replaceChild(canvas, startUpBox);
        this.createCorona();
        this.startGame();
    }
init ( ) { this . setState ( { score : 0 , gameState : 0 } ) let canvas = document . createElement ( "canvas" ) ; canvas . id = "coronaGoCanvas" ; let coronaGoGame = document . getElementById ( "coronaGoGame" ) ; let startUpBox = document . getElementById ( "startBox" ) ; this . canvas = canvas ; this . ctx = canvas . getContext ( "2d" ) this . canvas . height = window . innerHeight ; this . canvas . width = window . innerWidth ; this . bulletArray = new BulletsArray ( this . ctx , 4 , 4 , this . canvas . height , this . canvas . width ) ; this . space = new Space ( this . ctx , this . canvas . height , this . canvas . width ) ; this . earth = this . space . earth ; window . addEventListener ( "click" , ( e ) => { let bulletOriginX = this . canvas . width / 2 ; let bulletOriginY = this . canvas . height / 2 ; let speed = this . calculateSpeed ( e . clientX , e . clientY , bulletOriginX , bulletOriginY ) this . bulletArray . addBullet ( bulletOriginX , bulletOriginY , speed ) } ) if ( startUpBox != null ) coronaGoGame . replaceChild ( canvas , startUpBox ) ; this . createCorona ( ) ; this . startGame ( ) ; }
init method it will do some starting procedures
init method it will do some starting procedures
//setup the canvas //start the game