+56
-17
@@ -7,6 +7,9 @@ import Player from "../entities/Player";
|
||||
import Bat from "../entities/Enemys/Bat";
|
||||
import Item from "../entities/Item";
|
||||
import Storage from "../Storage";
|
||||
import Win from "../entities/Win";
|
||||
import TextElement from "../TextElement";
|
||||
import DamageEntity from "../entities/Enemys/DamageEntity";
|
||||
|
||||
export default class Game extends Phaser.Scene {
|
||||
|
||||
@@ -14,6 +17,7 @@ export default class Game extends Phaser.Scene {
|
||||
super({
|
||||
key: "Game",
|
||||
pixelArt: true,
|
||||
roundPixels: true,
|
||||
physics: {
|
||||
default: 'arcade',
|
||||
arcade: {
|
||||
@@ -110,8 +114,8 @@ export default class Game extends Phaser.Scene {
|
||||
});
|
||||
|
||||
this.anims.create({
|
||||
key: 'attack_c',
|
||||
frames: this.anims.generateFrameNumbers('char', {start: 28, end: 41}),
|
||||
key: 'hit',
|
||||
frames: this.anims.generateFrameNumbers('char', {start: 70, end: 74}),
|
||||
frameRate: 15
|
||||
});
|
||||
|
||||
@@ -135,58 +139,87 @@ export default class Game extends Phaser.Scene {
|
||||
});
|
||||
|
||||
|
||||
const map = this.make.tilemap({key: "map"});
|
||||
const tileset = map.addTilesetImage("tileset", "tiles", 16, 16, 1, 2);
|
||||
|
||||
this.backLayer = map.createStaticLayer("Back", tileset, 0, 0);
|
||||
this.backLayer2 = map.createStaticLayer("Back2", tileset, 0, 0);
|
||||
|
||||
this.worldLayer = map.createDynamicLayer("Main", tileset, 0, 0);
|
||||
const mapKey = "map";
|
||||
const mapTilesetKey = "tiles";
|
||||
|
||||
|
||||
const spawnPoint = map.findObject("Objects", obj => obj.name === "player");
|
||||
const map = this.make.tilemap({key: mapKey});
|
||||
const tileset = map.addTilesetImage("tileset", mapTilesetKey, 16, 16, 1, 2);
|
||||
|
||||
this.Backgroundwall = map.createStaticLayer("Backgroundwall", tileset, 0, 0);
|
||||
this.FarBackground = map.createStaticLayer("FarBackground", tileset, 0, 0);
|
||||
this.FarNotSoBackground = map.createStaticLayer("FarNotSoBackground", tileset, 0, 0);
|
||||
this.Background = map.createStaticLayer("Background", tileset, 0, 0);
|
||||
this.NotSoBackground = map.createStaticLayer("NotSoBackground", tileset, 0, 0);
|
||||
|
||||
this.worldLayer = map.createDynamicLayer("Spielerebene", tileset, 0, 0);
|
||||
|
||||
|
||||
const spawnPoint = map.findObject("Player/Enemys", obj => obj.name === "player");
|
||||
|
||||
this.enemys = this.add.group();
|
||||
this.items = this.add.group();
|
||||
this.player = new Player(this, spawnPoint, 'char');
|
||||
|
||||
map.objects[0].objects.filter(obj => obj.name === "bat").forEach(s => {
|
||||
let bat = new Bat(this, s);
|
||||
this.enemys.add(bat)
|
||||
});
|
||||
|
||||
map.objects[0].objects.filter(obj => obj.type === "dmg").forEach(s => {
|
||||
this.enemys.add(new DamageEntity(this, s))
|
||||
});
|
||||
|
||||
map.objects[0].objects.filter(obj => obj.name === "item").forEach(s => {
|
||||
let item = new Item(this, s);
|
||||
this.items.add(item)
|
||||
});
|
||||
|
||||
this.wins = this.add.group();
|
||||
|
||||
this.worldLayer.setCollisionByProperty({collides: true});
|
||||
Game.setTileCollision(this.worldLayer, [29, 30, 31, 39], {
|
||||
map.objects[0].objects.filter(obj => obj.name === "win").forEach(s => {
|
||||
this.wins.add(new Win(this, s));
|
||||
});
|
||||
|
||||
this.player = new Player(this, spawnPoint, 'char');
|
||||
|
||||
|
||||
this.Foreground = map.createDynamicLayer("Foreground", tileset, 0, 0);
|
||||
|
||||
// this.worldLayer.setCollisionByProperty({collides: true});
|
||||
this.worldLayer.setCollisionByExclusion([-1]);
|
||||
Game.setTileCollision(this.worldLayer, [0, 1, 2], {
|
||||
top: true,
|
||||
bottom: false,
|
||||
right: false,
|
||||
left: false
|
||||
});
|
||||
|
||||
this.physics.world.bounds.width = this.backLayer.width;
|
||||
this.physics.world.bounds.height = this.backLayer.height;
|
||||
this.physics.world.bounds.width = this.Backgroundwall.width;
|
||||
this.physics.world.bounds.height = this.Backgroundwall.height;
|
||||
|
||||
this.cameras.main.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
|
||||
|
||||
|
||||
this.cameras.main.setBackgroundColor('#ccccff');
|
||||
|
||||
|
||||
this.cameras.main.startFollow(this.player);
|
||||
this.cameras.main.startFollow(this.player, true, 0.1, 0.1);
|
||||
|
||||
this.physics.add.collider(this.player, this.worldLayer);
|
||||
this.physics.add.collider(this.enemys, this.worldLayer);
|
||||
this.physics.add.overlap(this.player.attackHitbox, this.enemys, (h, b) => {
|
||||
if (h.getData('active') && h.overlap !== undefined) {
|
||||
h.overlap(b);
|
||||
}
|
||||
});
|
||||
|
||||
this.physics.add.overlap(this.player, this.enemys, (p, e) => {
|
||||
this.player.hit(e.getData('dmg'));
|
||||
})
|
||||
|
||||
this.physics.add.overlap(this.player, this.wins, (p, w) => {
|
||||
console.log("win!");
|
||||
})
|
||||
|
||||
let controls = Storage.get().controls;
|
||||
|
||||
this.keyW = this.input.keyboard.addKey(controls.jump.bind);
|
||||
@@ -204,6 +237,12 @@ export default class Game extends Phaser.Scene {
|
||||
this.keyPickup.reset();
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
map.objects[0].objects.filter(obj => obj.type === "text").forEach(s => {
|
||||
console.log(s);
|
||||
new TextElement(this, s);
|
||||
});
|
||||
}
|
||||
|
||||
update(time, delta) {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Antonio Martinez Casadesus and Pascal Syma.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
import TextElement from "../TextElement";
|
||||
|
||||
export default class MainMenu extends Phaser.Scene {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
key: "MainMenu",
|
||||
pixelArt: true,
|
||||
});
|
||||
}
|
||||
|
||||
create() {
|
||||
const map = this.make.tilemap({key: "menu"});
|
||||
const tileset = map.addTilesetImage("menu", "menutiles", 16, 16);
|
||||
|
||||
this.backLayer = map.createStaticLayer("MainMenu", tileset, 0, 0);
|
||||
|
||||
this.cameras.main.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
|
||||
|
||||
this.cameras.main.setBackgroundColor('#000');
|
||||
|
||||
map.objects[0].objects.filter(obj => obj.type === "text").forEach(s => {
|
||||
console.log(s);
|
||||
new TextElement(this, s);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,14 @@
|
||||
*/
|
||||
|
||||
import logoImg from "../../public/favicon.png";
|
||||
import map from "../assets/map.json";
|
||||
import map from "../assets/lvl1.json";
|
||||
import menu from "../assets/menu.json";
|
||||
import charA from "../assets/char_a/spritesheet.png";
|
||||
import charB from "../assets/char_b/spritesheet.png";
|
||||
import charC from "../assets/char_c/spritesheet.png";
|
||||
import charD from "../assets/char_d/spritesheet.png";
|
||||
import tiles from "../assets/tileset.png";
|
||||
import tiles from "../assets/newtiles.png";
|
||||
import menutiles from "../assets/menu.png";
|
||||
import batFly from "../assets/BatFly.png";
|
||||
import batDie from "../assets/BatDie.png";
|
||||
import item_01 from "../assets/items/itemshard_01.png";
|
||||
@@ -33,9 +35,11 @@ export default class Preload extends Phaser.Scene {
|
||||
this.load.spritesheet('charC', charC, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2});
|
||||
this.load.spritesheet('charD', charD, {frameWidth: 79, frameHeight: 63, margin: 1, spacing: 2});
|
||||
this.load.spritesheet('tiles', tiles, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2});
|
||||
this.load.spritesheet('menutiles', menutiles, {frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2});
|
||||
this.load.spritesheet('batFly', batFly, {frameWidth: 48, frameHeight: 32/*, margin: 1, spacing: 2*/});
|
||||
this.load.spritesheet('batDie', batDie, {frameWidth: 48, frameHeight: 32/*, margin: 1, spacing: 2*/});
|
||||
this.load.tilemapTiledJSON("map", map);
|
||||
this.load.tilemapTiledJSON("menu", menu);
|
||||
}
|
||||
|
||||
create() {
|
||||
|
||||
Reference in New Issue
Block a user