1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
const game = new Phaser.Game(360, 600, Phaser.AUTO, 'game'); game.states = {};
let multipleX = 1, multipleY = 1;
let isBGMPlay = true;
const sourcesList = { background: "background", startButton: "startButton", startBGM: "startBackgroundMusic", playBGM: "playBackgroundMusic", gameOverMusic: "gameOverMusic", beAttackedMusic: "beAttackedMusic", playerExplodeMusic: "playerBeAttackedMusic", getAwardMusic: "getAwardMusic", myShot: "myShot",
myPlane: "myPlane", myBullet: "myBullet", myExplode: "myExplode", enemyBullet: "enemyBullet", enemy1: "enemy1", enemy2: "enemy2", enemy3: "enemy3", enemyExplode1: "enemyExplode1", enemyExplode2: "enemyExplode2", enemyExplode3: "enemyExplode3", boss: "boss", bossExplode: "bossExplode",
startMusicButton: "startBackgroundMusic", stopMusicButton: "stopBackgroundMusic",
killAward: "killAward", lifeAward: "lifeAward", levelAward: "levelAward",
menuButtonAudio: "menuButtonAudio", startButtonAudio: "startButtonAudio", replayButton: "replayButton", shareButton: "shareButton" };
game.states.preload = function () { this.preload = function () { game.load.image(sourcesList.background, "assets/image/bg.png"); game.load.spritesheet(sourcesList.startButton, "assets/image/startButton.png", 100, 40, 2); game.load.spritesheet(sourcesList.myPlane, "assets/image/myPlane.png", 32, 40, 4); game.load.image(sourcesList.startMusicButton, "assets/image/startMusic.png"); game.load.image(sourcesList.stopMusicButton, "assets/image/stopMusic.png");
game.load.image(sourcesList.killAward, "assets/image/award_kill.png"); game.load.image(sourcesList.lifeAward, "assets/image/award_life.png"); game.load.image(sourcesList.levelAward, "assets/image/award_level.png");
game.load.audio(sourcesList.startBGM, "assets/music/bgm.mp3"); game.load.audio(sourcesList.startButtonAudio, 'assets/music/button.mp3'); game.load.audio(sourcesList.menuButtonAudio, 'assets/music/button1.mp3'); };
this.create = function () { this.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT;
multipleX = document.body.clientWidth / game.width; multipleY = document.body.clientHeight / game.height;
const bg = game.add.tileSprite(0, 0, game.width, game.height, sourcesList.background); bg.autoScroll(0, 60);
this.startButton = game.add.button(125, 330, sourcesList.startButton, this.StartClick, this, 1, 1, 0);
this.myplane = game.add.sprite(157, 150, sourcesList.myPlane); this.myplane.animations.add("fly"); this.myplane.animations.play("fly", 14, true);
this.backgroundMusicPlayer = game.add.audio(sourcesList.startBGM, 0.2, true); if (isBGMPlay) this.backgroundMusicPlayer.play();
this.stopMusicButton = game.add.button(335, 10, sourcesList.stopMusicButton, function () { if (this.backgroundMusicPlayer.isPlaying) { isBGMPlay = false; this.backgroundMusicPlayer.stop(); } }, this, 0, 0, 0);
this.startMusicButton = game.add.button(310, 10, sourcesList.startMusicButton, function () { if (!this.backgroundMusicPlayer.isPlaying) { isBGMPlay = true; this.backgroundMusicPlayer.play(); } }, this, 0, 0, 0); };
this.StartClick = function () { game.add.audio(sourcesList.menuButtonAudio, 1, false).play(); this.backgroundMusicPlayer.stop(); game.state.start("help"); }; }
game.states.help = function () { this.create = function () { const bg = game.add.tileSprite(0, 0, game.width, game.height, sourcesList.background); bg.autoScroll(0, 60);
this.myplane = game.add.sprite(80, 135, sourcesList.myPlane); this.myplane.animations.add("fly"); this.myplane.animations.play("fly", 14, true);
const style = {font: "12px 宋体", fill: "#ff0000"}; game.add.text(125, 150, "玩家飞机,初始生命为10,等级为5", style);
game.add.sprite(80, 175, sourcesList.killAward); game.add.text(125, 185, "获得后清除所有可见敌人", style);
game.add.sprite(85, 210, sourcesList.lifeAward); game.add.text(125, 220, "获得后随机增加生命或护盾", style);
game.add.sprite(85, 250, sourcesList.levelAward); game.add.text(125, 260, "获得后等级+1", style);
game.add.text(50, 320, "★玩家与敌人碰撞或每10个敌人逃脱均会减少生命\n进入Boss关卡时判定区域为飞机中间的红点", style);
this.startButton = game.add.button(125, 430, sourcesList.startButton, this.StartClick, this, 1, 1, 0); };
this.StartClick = function () { game.add.audio(sourcesList.startButtonAudio, 1, false).play(); game.state.start("main"); }; };
game.states.main = function () { this.create = function () {
}
this.update = function () {
} };
game.states.end = function () { this.create = function () {
}; };
game.state.add("preload", game.states.preload); game.state.add("help", game.states.help); game.state.add("main", game.states.main); game.state.add("end", game.states.end);
game.state.start("preload");
|