Working Round + Enemies + Collisions
Guess we're about to making the damn game ;)
This commit is contained in:
parent
3e442a24b4
commit
b6dd919fa6
BIN
docs/assets/enemies/Mouse.png
Normal file
BIN
docs/assets/enemies/Mouse.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
2
docs/bundle.min.js
vendored
2
docs/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
11
package-lock.json
generated
11
package-lock.json
generated
@ -9,6 +9,7 @@
|
|||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"keyboardjs": "^2.7.0",
|
||||||
"phaser": "^3.70.0"
|
"phaser": "^3.70.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -4506,6 +4507,11 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/keyboardjs": {
|
||||||
|
"version": "2.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/keyboardjs/-/keyboardjs-2.7.0.tgz",
|
||||||
|
"integrity": "sha512-3tiQuAoLM1M5Xyo/eQVaqsq9joByTRkB0Byga+0S7BYJvY4HIlfW0SofOj4a20YSAFjv0SIFU/lw+Qjp6KYHPA=="
|
||||||
|
},
|
||||||
"node_modules/kind-of": {
|
"node_modules/kind-of": {
|
||||||
"version": "6.0.3",
|
"version": "6.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
|
||||||
@ -9989,6 +9995,11 @@
|
|||||||
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
|
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"keyboardjs": {
|
||||||
|
"version": "2.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/keyboardjs/-/keyboardjs-2.7.0.tgz",
|
||||||
|
"integrity": "sha512-3tiQuAoLM1M5Xyo/eQVaqsq9joByTRkB0Byga+0S7BYJvY4HIlfW0SofOj4a20YSAFjv0SIFU/lw+Qjp6KYHPA=="
|
||||||
|
},
|
||||||
"kind-of": {
|
"kind-of": {
|
||||||
"version": "6.0.3",
|
"version": "6.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
|
||||||
|
BIN
public/assets/enemies/Mouse.png
Normal file
BIN
public/assets/enemies/Mouse.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
5
src/enemies/AllEnemies.js
Normal file
5
src/enemies/AllEnemies.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { Mouse } from "./Mouse.js"
|
||||||
|
|
||||||
|
export const AllEnemies = {
|
||||||
|
'Mouse': Mouse
|
||||||
|
};
|
9
src/enemies/Mouse.js
Normal file
9
src/enemies/Mouse.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { Enemy } from "../key_classes/Enemy.js"
|
||||||
|
|
||||||
|
export class Mouse extends Enemy
|
||||||
|
{
|
||||||
|
constructor(scene, lane) {
|
||||||
|
super(scene, lane, 30, 10);
|
||||||
|
this.setTexture('Mouse');
|
||||||
|
}
|
||||||
|
}
|
@ -32,7 +32,9 @@ export class Building extends Phaser.GameObjects.Sprite
|
|||||||
scene.add.existing(this);
|
scene.add.existing(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(time, delta) {}
|
onCollide(Enemy)
|
||||||
|
{
|
||||||
activation(keyButton) {}
|
console.log("Building Hit!");
|
||||||
|
Enemy.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
27
src/key_classes/Enemy.js
Normal file
27
src/key_classes/Enemy.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Class: Enemy (Sprite)
|
||||||
|
// Desc: Implements:
|
||||||
|
// - Spirte texture
|
||||||
|
// - healthbar?
|
||||||
|
// - collisions with keyButtons
|
||||||
|
// - walkSpeed
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export class Enemy extends Phaser.GameObjects.Sprite
|
||||||
|
{
|
||||||
|
constructor(scene, lane, speed, startHealth) {
|
||||||
|
super(scene, 1920, lane*120+120/2+160, '');
|
||||||
|
this.speed = speed;
|
||||||
|
this.startHealth = startHealth;
|
||||||
|
scene.add.existing(this);
|
||||||
|
scene.physics.add.existing(this);
|
||||||
|
|
||||||
|
this.body.setAllowGravity(false);
|
||||||
|
this.body.setVelocityX(-speed);
|
||||||
|
this.body.setSize(100, 100, false);
|
||||||
|
this.body.setOffset(35,10);
|
||||||
|
this.body.setBoundsRectangle();
|
||||||
|
this.body.setImmovable(true);
|
||||||
|
}
|
||||||
|
}
|
@ -45,15 +45,19 @@ export class KeyButton extends Phaser.GameObjects.Sprite {
|
|||||||
|
|
||||||
//turn on mouse clicks and keydowns
|
//turn on mouse clicks and keydowns
|
||||||
this.enableInput(scene);
|
this.enableInput(scene);
|
||||||
|
|
||||||
|
//enable collisions
|
||||||
|
this.scene.physics.add.existing(this, true);
|
||||||
|
this.body.setSize(120, 120, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeBuilding(building) {
|
changeBuilding(building) {
|
||||||
this.building = building;
|
this.building = building;
|
||||||
if(building != null) {
|
// if(building != null) {
|
||||||
this.enableCollisions();
|
// this.enableCollisions();
|
||||||
} else {
|
// } else {
|
||||||
this.disableCollisions();
|
// this.disableCollisions();
|
||||||
}
|
// }
|
||||||
this.rebuildTexture();
|
this.rebuildTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,16 +70,11 @@ export class KeyButton extends Phaser.GameObjects.Sprite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
collision(otherObject) {
|
onCollide(Enemy)
|
||||||
//TODO
|
{
|
||||||
|
if(this.building != null) {
|
||||||
|
this.building.onCollide(Enemy);
|
||||||
}
|
}
|
||||||
|
|
||||||
enableCollisions() {
|
|
||||||
//TODO
|
|
||||||
//this.scene.physics.arcade.enableBody(this);
|
|
||||||
//this.body.setCollideCallback(() => {
|
|
||||||
// your collision logic here
|
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enableInput(scene) {
|
enableInput(scene) {
|
||||||
@ -94,11 +93,6 @@ export class KeyButton extends Phaser.GameObjects.Sprite {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
disableCollisions() {
|
|
||||||
//TODO
|
|
||||||
//this.scene.physics.arcade.disableBody(this); ??
|
|
||||||
}
|
|
||||||
|
|
||||||
buildBaseTexture(scene) {
|
buildBaseTexture(scene) {
|
||||||
//build baseTexture
|
//build baseTexture
|
||||||
let text = scene.add.text(0,0,this.keyText, {fontFamily: '"Bungee"', fontSize: '20px', color: this.textColor })
|
let text = scene.add.text(0,0,this.keyText, {fontFamily: '"Bungee"', fontSize: '20px', color: this.textColor })
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { constants } from './constants.js';
|
import { constants } from './constants.js';
|
||||||
|
import { AllEnemies } from '../enemies/AllEnemies.js';
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
@ -81,8 +82,14 @@ export class RoundManager extends Phaser.GameObjects.Sprite
|
|||||||
|
|
||||||
spawnEnemies()
|
spawnEnemies()
|
||||||
{
|
{
|
||||||
console.log("spawned " + this.getEnemy().howMany + " " + this.getEnemy().what);
|
for(let i = 0; i < this.getEnemy().howMany;i++) {
|
||||||
//TODO actually spawn them
|
let lane = Math.floor(Math.random() * 4) + 1;
|
||||||
|
console.log(lane);
|
||||||
|
let enemy = new AllEnemies[this.getEnemy().enemy](this.scene, lane);
|
||||||
|
this.scene.physics.add.collider(enemy, this.scene.keyButtons, (enemy, keyButton) => {
|
||||||
|
keyButton.onCollide(enemy);
|
||||||
|
})
|
||||||
|
}
|
||||||
this.enemyNum++;
|
this.enemyNum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import keyboard from 'keyboardjs';
|
import keyboard from 'keyboardjs';
|
||||||
import { AllBuildings } from '../buildings/AllBuildings';
|
import { AllBuildings } from '../buildings/AllBuildings.js';
|
||||||
|
|
||||||
const textColors = [
|
const textColors = [
|
||||||
'#000000',
|
'#000000',
|
||||||
@ -60,15 +60,15 @@ const Rounds = [
|
|||||||
enemies: [
|
enemies: [
|
||||||
{
|
{
|
||||||
timePoint: 1000,
|
timePoint: 1000,
|
||||||
what: 'mouse',
|
enemy: 'Mouse',
|
||||||
howMany: 1,
|
howMany: 1,
|
||||||
},{
|
},{
|
||||||
timePoint: 2000,
|
timePoint: 2000,
|
||||||
what: 'mouse',
|
enemy: 'Mouse',
|
||||||
howMany: 1,
|
howMany: 1,
|
||||||
},{
|
},{
|
||||||
timePoint: 2500,
|
timePoint: 2500,
|
||||||
what: 'mouse',
|
enemy: 'Mouse',
|
||||||
howMany: 1,
|
howMany: 1,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -78,15 +78,15 @@ const Rounds = [
|
|||||||
enemies: [
|
enemies: [
|
||||||
{
|
{
|
||||||
timePoint: 0,
|
timePoint: 0,
|
||||||
what: 'mouse',
|
enemy: 'Mouse',
|
||||||
howMany: 1,
|
howMany: 1,
|
||||||
},{
|
},{
|
||||||
timePoint: 1000,
|
timePoint: 1000,
|
||||||
what: 'mouse',
|
enemy: 'Mouse',
|
||||||
howMany: 2,
|
howMany: 2,
|
||||||
},{
|
},{
|
||||||
timePoint: 2000,
|
timePoint: 2000,
|
||||||
what: 'mouse',
|
enemy: 'Mouse',
|
||||||
howMany: 3,
|
howMany: 3,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -96,7 +96,7 @@ const Rounds = [
|
|||||||
enemies: [
|
enemies: [
|
||||||
{
|
{
|
||||||
timePoint: 0,
|
timePoint: 0,
|
||||||
what: 'BOSS',
|
enemy: 'Mouse',
|
||||||
howMany: 1,
|
howMany: 1,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -5,7 +5,7 @@ import { Game } from './scenes/Game';
|
|||||||
// Find out more information about the Game Config at:
|
// Find out more information about the Game Config at:
|
||||||
// https://newdocs.phaser.io/docs/3.70.0/Phaser.Types.Core.GameConfig
|
// https://newdocs.phaser.io/docs/3.70.0/Phaser.Types.Core.GameConfig
|
||||||
const config = {
|
const config = {
|
||||||
type: Phaser.AUTO,
|
type: Phaser.WEBGL,
|
||||||
width: 1920,
|
width: 1920,
|
||||||
height: 1080,
|
height: 1080,
|
||||||
parent: 'game-container',
|
parent: 'game-container',
|
||||||
@ -16,7 +16,11 @@ const config = {
|
|||||||
},
|
},
|
||||||
backgroundColor: 0x000000, // Black background color
|
backgroundColor: 0x000000, // Black background color
|
||||||
physics: {
|
physics: {
|
||||||
default: 'arcade'
|
default: 'arcade',
|
||||||
|
arcade: {
|
||||||
|
gravity: {x:0,y:0},
|
||||||
|
debug: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,10 +29,13 @@ export class AssetLoader extends Scene
|
|||||||
this.load.image('meterBack', 'assets/kmanager/meterBack.png');
|
this.load.image('meterBack', 'assets/kmanager/meterBack.png');
|
||||||
this.load.image('meterYellow', 'assets/kmanager/meterYellow.png');
|
this.load.image('meterYellow', 'assets/kmanager/meterYellow.png');
|
||||||
|
|
||||||
//buildings
|
// Buildings
|
||||||
this.load.image('Castle', 'assets/buildings/Castle4.png');
|
this.load.image('Castle', 'assets/buildings/Castle4.png');
|
||||||
this.load.image('Blacksmith', 'assets/buildings/Blacksmith.png');
|
this.load.image('Blacksmith', 'assets/buildings/Blacksmith.png');
|
||||||
this.load.image('Fire', 'assets/buildings/fire-sm.png');
|
this.load.image('Fire', 'assets/buildings/fire-sm.png');
|
||||||
|
|
||||||
|
// Enemies
|
||||||
|
this.load.image('Mouse', 'assets/enemies/Mouse.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
create ()
|
create ()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { constants } from '../key_classes/constants.js';
|
import { constants } from '../key_classes/constants.js';
|
||||||
import { Scene } from 'phaser';
|
import { Scene } from 'phaser';
|
||||||
import { KeyButton } from '../key_classes/KeyButton.js';
|
import { KeyButton } from '../key_classes/KeyButton.js';
|
||||||
|
import { Enemy } from '../key_classes/Enemy.js';
|
||||||
import { KingdomManager } from '../key_classes/KingdomManager.js';
|
import { KingdomManager } from '../key_classes/KingdomManager.js';
|
||||||
import { Castle } from '../buildings/Castle.js';
|
import { Castle } from '../buildings/Castle.js';
|
||||||
import { RoundManager } from '../key_classes/RoundManager.js';
|
import { RoundManager } from '../key_classes/RoundManager.js';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user