class Boot extends Phaser.Scene { constructor(father) { super('Boot'); this.father = father; } preload() { let progressBar = this.add.graphics(); let progressBox = this.add.graphics(); let width = 320; let height = 50; let x = WIDTH_WINDOW / 2 - width / 2; let y = HEIGHT_WINDOW / 2 - height / 2; progressBox.fillStyle(0x222222, 0.8); progressBox.fillRect(x, y, 320, height); this.load.on('progress', function (value) { progressBar.clear(); progressBar.fillStyle(0xffffff, 1); progressBar.fillRect(x + 10, y + 10, (width - 20) * value, height - 20); }); this.load.on('complete', function () { progressBar.destroy(); progressBox.destroy(); }); this.load.audio('shot', 'assets/sounds/shot.ogg'); this.load.audio('hit', 'assets/sounds/hit.ogg'); this.loadImage('en', 'flags/', true); this.loadImage('fr', 'flags/', true); this.loadImage('bonusSpeed0', 'bonus/', true); this.loadImage('bonusSpeed1', 'bonus/', true); this.loadImage('bonusSpeed2', 'bonus/', true); this.loadSprite('playLetter', 550, 150, 'buttons/'); this.loadSprite('cancel', 550, 150, 'buttons/'); this.loadSprite('add', 550, 150, 'buttons/'); this.loadSprite('home', 550, 150, 'buttons/'); this.loadSprite('next', 550, 150, 'buttons/'); this.loadSprite('retry', 550, 150, 'buttons/'); this.loadSprite('duel', 269, 262, 'buttons/'); this.loadSprite('last', 269, 262, 'buttons/'); this.loadSprite('team', 269, 262, 'buttons/'); this.loadSprite('flag', 269, 262, 'buttons/'); this.loadSprite('map', 269, 262, 'buttons/'); this.loadSprite('play', 100, 100, 'buttons/'); this.loadSprite('bin', 100, 100, 'buttons/'); this.loadSprite('plus', 100, 100, 'buttons/'); this.loadSprite('pencil', 100, 100, 'buttons/'); this.loadSprite('speed', 100, 100, 'buttons/'); this.loadSprite('back', 200, 200, 'buttons/'); this.loadSprite('shortRange', 300, 150, 'buttons/'); this.loadSprite('mediumRange', 300, 150, 'buttons/'); this.loadSprite('longRange', 300, 150, 'buttons/'); this.loadSprite('shield0', 300, 150, 'buttons/'); this.loadSprite('shield33', 300, 150, 'buttons/'); this.loadSprite('shield66', 300, 150, 'buttons/'); this.loadSprite('shield100', 300, 150, 'buttons/'); this.loadSprite('myself', 300, 150, 'buttons/'); this.loadSprite('enemyBot', 300, 150, 'buttons/'); this.loadSprite('bonus', 300, 150, 'buttons/'); this.loadSprite('moveToward', 300, 150, 'buttons/'); this.loadSprite('fleeFrom', 300, 150, 'buttons/'); this.loadSprite('attackNode', 180, 190, 'nodes/', true); this.loadSprite('moveNode', 180, 190, 'nodes/', true); this.loadSprite('conditionNode', 180, 190, 'nodes/', true); this.loadImage('background'); this.loadImage('bullet'); this.loadImage('logoWaria'); this.loadImage('attack', 'nodes/', true); this.loadImage('move', 'nodes/', true); this.loadImage('condition', 'nodes/', true); } create() { let style = {font: '200px stencil', fill: "#e2e2e2"}; this.add.text(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 3, "WARIA", style).setOrigin(0.5, 0.5); let btn = this.add.sprite(WIDTH_WINDOW / 2, (HEIGHT_WINDOW / 3) * 2, 'playLetter').setInteractive(); //btn.setFrame(0); btn.on('pointerout', () => btn.setFrame(0)); btn.on('pointerover', () => btn.setFrame(1)); btn.on('pointerdown', () => this.clickPlay(btn)); this.createFlags(); } createFlags() { this.diffXFlag = 0; this.createFlag('fr'); this.createFlag('en'); } createFlag(name) { let flag = this.add.image(WIDTH_WINDOW - 10 - this.diffXFlag, 10, name).setOrigin(1, 0).setInteractive(); flag.displayHeight = 40; flag.scaleX = flag.scaleY; this.diffXFlag = this.diffXFlag + flag.displayWidth + 10; flag.on('pointerdown', () => this.setLang(name)); } setLang(lang) { if (lang !== LANG) { LANG = lang; console.log('Set Lang : ' + lang); this.scene.restart(); } } clickPlay(btn) { btn.setFrame(2); console.log("Play"); this.father.scene.add('Type', new Type(this.father)); this.scene.start('Type'); } loadSprite(name, width, height, folder = '', force = false) { this.deleteLoad(name); if (force) { this.load.spritesheet(name, 'assets/' + folder + name + '.png', { frameWidth: width, frameHeight: height }); } else { this.load.spritesheet(name, 'assets/' + LANG + '/' + folder + name + '.png', { frameWidth: width, frameHeight: height }); } } loadImage(name, folder = '', force = false) { this.deleteLoad(name); if (force) { this.load.image(name, 'assets/' + folder + name + '.png'); } else { this.load.image(name, 'assets/' + LANG + '/' + folder + name + '.png'); } } deleteLoad(name) { if (this.textures.exists(name)) { this.textures.remove(name); } } }