Working Round + Enemies + Collisions

Guess we're about to making the damn game ;)
This commit is contained in:
Dallas DeBruin 2024-02-29 15:09:36 -05:00
parent 3e442a24b4
commit b6dd919fa6
14 changed files with 11656 additions and 11593 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

2
docs/bundle.min.js vendored

File diff suppressed because one or more lines are too long

11
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "3.0.0",
"license": "MIT",
"dependencies": {
"keyboardjs": "^2.7.0",
"phaser": "^3.70.0"
},
"devDependencies": {
@ -4506,6 +4507,11 @@
"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": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
@ -9989,6 +9995,11 @@
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
"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": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -0,0 +1,5 @@
import { Mouse } from "./Mouse.js"
export const AllEnemies = {
'Mouse': Mouse
};

9
src/enemies/Mouse.js Normal file
View 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');
}
}

View File

@ -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
View 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);
}
}

View File

@ -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
onCollide(Enemy)
{
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) {
@ -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 })

View File

@ -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++;
}

View File

@ -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,
}
]

View File

@ -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,
}
}
};

View File

@ -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 ()

View File

@ -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';