added win screen and level system

Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
2020-07-17 03:20:59 +02:00
parent cea1740792
commit 13e7c24b65
16 changed files with 404 additions and 87 deletions
+1 -1
View File
@@ -76,7 +76,7 @@ export default class GUI extends Phaser.Scene {
repeat: -1
});
this.scene.start('Game');
this.scene.start('Game', {level: 'lvl1'});
})
});
}
+32 -9
View File
@@ -12,6 +12,7 @@ import DamageEntity from "../entities/Enemys/DamageEntity";
import Zombie from "../entities/Enemys/Zombie";
import Skeleton from "../entities/Enemys/Skeleton";
import Chest from "../entities/Chest";
import Arrow from "../entities/Enemys/Arrow";
export default class Game extends Phaser.Scene {
@@ -24,7 +25,7 @@ export default class Game extends Phaser.Scene {
default: 'arcade',
arcade: {
gravity: {y: 300},
// debug: true
debug: true
}
}
});
@@ -107,6 +108,26 @@ export default class Game extends Phaser.Scene {
frameRate: 20
});
this.anims.create({
key: 'skeleton_attack_start',
frames: this.anims.generateFrameNames('skeleton', {
start: 1,
end: 9,
prefix: 'skeleton_archer_style_A/attack/frame'
}),
frameRate: 20
});
this.anims.create({
key: 'skeleton_attack_end',
frames: this.anims.generateFrameNames('skeleton', {
start: 9,
end: 20,
prefix: 'skeleton_archer_style_A/attack/frame'
}),
frameRate: 20
});
this.anims.create({
key: 'zombie_die',
frames: this.anims.generateFrameNumbers('zombie', {start: 128, end: 159}),
@@ -231,7 +252,7 @@ export default class Game extends Phaser.Scene {
});
const mapKey = "map";
const mapKey = this.scene.settings.data.level;
const mapTilesetKey = "tiles";
@@ -313,14 +334,18 @@ export default class Game extends Phaser.Scene {
}
});
this.physics.add.overlap(this.player, this.enemys, (p, e) => {
if (e.getData('active'))
this.player.hit(e.getData('dmg'));
this.physics.add.overlap(this.player, this.wins, (p, w) => {
this.scene.pause();
this.music.pause();
this.scene.launch('GUI', {key: 'Win'}).bringToTop('GUI');
})
this.physics.add.overlap(this.player, this.enemys, (p, e) => {
if (e.getData('active'))
this.player.hit(e.getData('dmg'));
if (e instanceof Arrow)
e.die();
})
this.physics.add.overlap(this.player, this.environment, (p, e) => {
@@ -339,7 +364,6 @@ export default class Game extends Phaser.Scene {
this.keyA = this.input.keyboard.addKey(controls.w_left.bind);
this.keyD = this.input.keyboard.addKey(controls.w_right.bind);
this.keySpace = this.input.keyboard.addKey(controls.attack.bind);
// this.keyDie = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.C);
this.keyPickup = this.input.keyboard.addKey(controls.pickup.bind);
this.keyAction1 = this.input.keyboard.addKey(controls.use_left.bind);
this.keyAction2 = this.input.keyboard.addKey(controls.use_right.bind);
@@ -354,7 +378,6 @@ export default class Game extends Phaser.Scene {
map.objects[0].objects.filter(obj => obj.type === "text").forEach(s => {
console.log(s);
new TextElement(this, s);
});
@@ -365,9 +388,9 @@ export default class Game extends Phaser.Scene {
.setOrigin(0, 0));
}
this.music = this.sound.add('background_start', {volume: 0.5})
this.music = this.sound.add('background_start', {volume: 0.1})
.once('complete', () => {
this.music = this.sound.add('background_loop', {loop: true, volume: 0.5});
this.music = this.sound.add('background_loop', {loop: true, volume: 0.1});
this.music.play();
})
this.music.play();
+6 -2
View File
@@ -4,7 +4,8 @@
*/
import logoImg from "../../public/favicon.png";
import map from "../assets/lvl1.json";
import lvl1 from "../assets/lvl1.json";
import tutorial from "../assets/tutorial.json";
import menu from "../assets/menu.json";
import skeletonAtlas from "../assets/skeleton.json";
import skeletonSprite from "../assets/skeleton.png";
@@ -27,6 +28,7 @@ import speed from "../assets/items/speed.png";
import storm from "../assets/items/storm.png";
import heart from "../assets/heart.png";
import chest from "../assets/chest.png";
import arrow from "../assets/arrow.png";
import menu_click from "../assets/audio/menu_click.wav";
import menu_hover from "../assets/audio/menu_hover.wav";
@@ -48,6 +50,7 @@ export default class Preload extends Phaser.Scene {
this.load.image("item_02", item_02);
this.load.image("item_03", item_03);
this.load.image("heart", heart);
this.load.image("arrow", arrow);
this.load.spritesheet('charA', charA, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2});
this.load.spritesheet('charB', charB, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2});
this.load.spritesheet('charC', charC, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2});
@@ -63,7 +66,8 @@ export default class Preload extends Phaser.Scene {
this.load.spritesheet('storm', storm, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2});
this.load.spritesheet('speed', speed, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2});
this.load.spritesheet('slow', slow, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2});
this.load.tilemapTiledJSON("map", map);
this.load.tilemapTiledJSON("lvl1", lvl1);
this.load.tilemapTiledJSON("tutorial", tutorial);
this.load.tilemapTiledJSON("menu", menu);
this.load.atlas({key: 'skeleton', textureURL: skeletonSprite, atlasURL: skeletonAtlas});