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
23123
package-lock.json
generated
23123
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
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);
|
||||
}
|
||||
|
||||
update(time, delta) {}
|
||||
|
||||
activation(keyButton) {}
|
||||
onCollide(Enemy)
|
||||
{
|
||||
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
|
||||
this.enableInput(scene);
|
||||
|
||||
//enable collisions
|
||||
this.scene.physics.add.existing(this, true);
|
||||
this.body.setSize(120, 120, true);
|
||||
}
|
||||
|
||||
changeBuilding(building) {
|
||||
this.building = building;
|
||||
if(building != null) {
|
||||
this.enableCollisions();
|
||||
} else {
|
||||
this.disableCollisions();
|
||||
}
|
||||
// if(building != null) {
|
||||
// this.enableCollisions();
|
||||
// } else {
|
||||
// this.disableCollisions();
|
||||
// }
|
||||
this.rebuildTexture();
|
||||
}
|
||||
|
||||
@ -66,16 +70,11 @@ export class KeyButton extends Phaser.GameObjects.Sprite {
|
||||
}
|
||||
}
|
||||
|
||||
collision(otherObject) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
enableCollisions() {
|
||||
//TODO
|
||||
//this.scene.physics.arcade.enableBody(this);
|
||||
//this.body.setCollideCallback(() => {
|
||||
// your collision logic here
|
||||
//});
|
||||
onCollide(Enemy)
|
||||
{
|
||||
if(this.building != null) {
|
||||
this.building.onCollide(Enemy);
|
||||
}
|
||||
}
|
||||
|
||||
enableInput(scene) {
|
||||
@ -94,11 +93,6 @@ export class KeyButton extends Phaser.GameObjects.Sprite {
|
||||
});
|
||||
}
|
||||
|
||||
disableCollisions() {
|
||||
//TODO
|
||||
//this.scene.physics.arcade.disableBody(this); ??
|
||||
}
|
||||
|
||||
buildBaseTexture(scene) {
|
||||
//build baseTexture
|
||||
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 { AllEnemies } from '../enemies/AllEnemies.js';
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
@ -81,8 +82,14 @@ export class RoundManager extends Phaser.GameObjects.Sprite
|
||||
|
||||
spawnEnemies()
|
||||
{
|
||||
console.log("spawned " + this.getEnemy().howMany + " " + this.getEnemy().what);
|
||||
//TODO actually spawn them
|
||||
for(let i = 0; i < this.getEnemy().howMany;i++) {
|
||||
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++;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import keyboard from 'keyboardjs';
|
||||
import { AllBuildings } from '../buildings/AllBuildings';
|
||||
import { AllBuildings } from '../buildings/AllBuildings.js';
|
||||
|
||||
const textColors = [
|
||||
'#000000',
|
||||
@ -60,15 +60,15 @@ const Rounds = [
|
||||
enemies: [
|
||||
{
|
||||
timePoint: 1000,
|
||||
what: 'mouse',
|
||||
enemy: 'Mouse',
|
||||
howMany: 1,
|
||||
},{
|
||||
timePoint: 2000,
|
||||
what: 'mouse',
|
||||
enemy: 'Mouse',
|
||||
howMany: 1,
|
||||
},{
|
||||
timePoint: 2500,
|
||||
what: 'mouse',
|
||||
enemy: 'Mouse',
|
||||
howMany: 1,
|
||||
},
|
||||
]
|
||||
@ -78,15 +78,15 @@ const Rounds = [
|
||||
enemies: [
|
||||
{
|
||||
timePoint: 0,
|
||||
what: 'mouse',
|
||||
enemy: 'Mouse',
|
||||
howMany: 1,
|
||||
},{
|
||||
timePoint: 1000,
|
||||
what: 'mouse',
|
||||
enemy: 'Mouse',
|
||||
howMany: 2,
|
||||
},{
|
||||
timePoint: 2000,
|
||||
what: 'mouse',
|
||||
enemy: 'Mouse',
|
||||
howMany: 3,
|
||||
},
|
||||
]
|
||||
@ -96,7 +96,7 @@ const Rounds = [
|
||||
enemies: [
|
||||
{
|
||||
timePoint: 0,
|
||||
what: 'BOSS',
|
||||
enemy: 'Mouse',
|
||||
howMany: 1,
|
||||
}
|
||||
]
|
||||
|
@ -5,7 +5,7 @@ import { Game } from './scenes/Game';
|
||||
// Find out more information about the Game Config at:
|
||||
// https://newdocs.phaser.io/docs/3.70.0/Phaser.Types.Core.GameConfig
|
||||
const config = {
|
||||
type: Phaser.AUTO,
|
||||
type: Phaser.WEBGL,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
parent: 'game-container',
|
||||
@ -16,7 +16,11 @@ const config = {
|
||||
},
|
||||
backgroundColor: 0x000000, // Black background color
|
||||
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('meterYellow', 'assets/kmanager/meterYellow.png');
|
||||
|
||||
//buildings
|
||||
// Buildings
|
||||
this.load.image('Castle', 'assets/buildings/Castle4.png');
|
||||
this.load.image('Blacksmith', 'assets/buildings/Blacksmith.png');
|
||||
this.load.image('Fire', 'assets/buildings/fire-sm.png');
|
||||
|
||||
// Enemies
|
||||
this.load.image('Mouse', 'assets/enemies/Mouse.png');
|
||||
}
|
||||
|
||||
create ()
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { constants } from '../key_classes/constants.js';
|
||||
import { Scene } from 'phaser';
|
||||
import { KeyButton } from '../key_classes/KeyButton.js';
|
||||
import { Enemy } from '../key_classes/Enemy.js';
|
||||
import { KingdomManager } from '../key_classes/KingdomManager.js';
|
||||
import { Castle } from '../buildings/Castle.js';
|
||||
import { RoundManager } from '../key_classes/RoundManager.js';
|
||||
|
Loading…
x
Reference in New Issue
Block a user