Skip to content

Commit

Permalink
Gameover Scene 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
choar816 committed Jun 1, 2022
1 parent f3873b9 commit 11b0962
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import LoadingScene from "./scenes/LoadingScene";
import PlayingScene from "./scenes/PlayingScene";
import MainScene from "./scenes/MainScene";
// import GameoverScene from "./scenes/GameoverScene";
import GameoverScene from "./scenes/GameoverScene";

const Config = {
// 맵 크기
width: 800,
height: 600,
backgroundColor: 0x000000,
scene: [LoadingScene, PlayingScene, MainScene],
scene: [LoadingScene, PlayingScene, MainScene, GameoverScene],
pixelArt: true,
physics: {
default: "arcade",
Expand Down
2 changes: 2 additions & 0 deletions src/characters/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export default class Player extends Phaser.Physics.Arcade.Image {
this.m_hpBar.decrease(damage);
if (this.m_hpBar.m_currentHp <= 0) {
// 게임오버!
this.scene.m_gameoverSound.play();
this.scene.scene.start("gameoverScene", { enemyKilled: this.scene.m_score });
}

new Explosion(this.scene, this.x, this.y);
Expand Down
28 changes: 28 additions & 0 deletions src/scenes/GameoverScene.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Phaser from 'phaser';
import Config from "../Config";
import Button from "../ui/Button";

export default class GameoverScene extends Phaser.Scene {
constructor() {
super("gameoverScene");
}

init(data) {
this.enemyKilled = data.enemyKilled;
}

create() {
const bg = this.add.graphics();
bg.fillStyle(0x5c6bc0);
bg.fillRect(0, 0, Config.width, Config.height);
bg.setScrollFactor(0);

this.add.bitmapText(Config.width / 2, Config.height / 2 - 100, "pixelFont", 'Game Over', 40).setOrigin(0.5);

this.add.bitmapText(Config.width / 2, Config.height / 2, "pixelFont", `Enemy Killed : ${this.enemyKilled}`, 30).setOrigin(0.5);

const startButton = new Button(Config.width / 2, Config.height / 2 + 100, 'Go to Main', this,
() => this.scene.start("mainScene"),
);
}
}
2 changes: 1 addition & 1 deletion src/scenes/PlayingScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class PlayingScene extends Phaser.Scene {

// collisions
this.physics.add.overlap(this.m_attacks, this.m_enemies, (attack, enemy) => {
enemy.hit(attack, 10);
enemy.hit(attack, 5);
}, null, this);
this.physics.add.overlap(this.m_player, this.m_enemies, () => this.m_player.hitByEnemy(10), null, this);

Expand Down

0 comments on commit 11b0962

Please sign in to comment.