I believe this is all the relevant code, if there’s more please let me know:
spawnRandomEnemies() {
this.spawns = this.physics.add.group();
this.spawns.defaults = {}; // https://phaser.discourse.group/t/setvelocity-vx-vy-not-working-as-excepted/8258/8
this.spawns.name = 'random spawns';
const monsters = [Bat,
Rat];
for (var i = 0; i < 30; i++) {
var x = Phaser.Math.RND.between(0, this.physics.world.bounds.width);
var y = Phaser.Math.RND.between(0, this.physics.world.bounds.height);
let newMonster = Phaser.Math.RND.pick(monsters);
this.spawns.add(
new newMonster(this, x, y, null, 0, i)
);
}
this.physics.add.collider(this.player, this.spawns, this.onMeetEnemy, this.enterBattleScene, this);
return this.spawns;
}
export default class Actor extends Phaser.Physics.Arcade.Sprite {
constructor(scene, x, y, texture, frame, name) {
super(scene, x, y, texture, frame);
this.name = name;
this.scene.physics.add.existing(this);
this.scene.add.existing(this);
this.setCollideWorldBounds(true, 0, 0, true);
this.collideExclusionLayers = true;
this.body.collideExclusionLayers = true;
this.setVelocity(0, 0);
this.trackingPlayer = false;
}
movementTimer(isCollision = false) {
if (isCollision) {
//this.setTint(0x000000);
}
if (!this.trackingPlayer) {
this.moveActor();
this.timedEvent = this.scene.time.addEvent(
{
delay: this.tdelayTime,
// how often moveActor is called
callback: this.automateActor,
callbackScope: this,
loop: true,
startAt: this.tstartAt
}
);
}
}
import { rollEnemyHP } from '../js/dice.js';
export default class Rat extends Actor {
constructor(scene, x, y, texture, frame) {
super(scene, x, y, 'ratEnemy', frame);
this.body.setSize(10, 10);
this.scene = scene;
this.setScale(2);
this.trackingPlayer = false;
//this.name = 'rat';
this.setData('name', 'rat');
// movement timer stuff
this.maxMoveTime = 10001; // maximum time to move
this.maxIdleTime = 1000; // maximum time to stand still before changing direction
this.tmoveTime = Phaser.Math.Between(this.maxMoveTime*.25, this.maxMoveTime);
this.tidleTime = Phaser.Math.Between(this.maxIdleTime*.25, this.maxIdleTime);
this.tdelayTime = this.tmoveTime + this.tidleTime;
this.tstartAt = Phaser.Math.Between(this.tdelayTime - 10, this.tdelayTime - 20);
this.movementTimer();
}
}