working on healer mob type
This commit is contained in:
@@ -721,7 +721,7 @@ const b = {
|
|||||||
{
|
{
|
||||||
name: "spores",
|
name: "spores",
|
||||||
ammo: 0,
|
ammo: 0,
|
||||||
ammoPack: 6,
|
ammoPack: 7,
|
||||||
have: false,
|
have: false,
|
||||||
fire() {
|
fire() {
|
||||||
const me = bullet.length;
|
const me = bullet.length;
|
||||||
@@ -818,7 +818,7 @@ const b = {
|
|||||||
{
|
{
|
||||||
name: "drones",
|
name: "drones",
|
||||||
ammo: 0,
|
ammo: 0,
|
||||||
ammoPack: 22,
|
ammoPack: 25,
|
||||||
have: false,
|
have: false,
|
||||||
fire() {
|
fire() {
|
||||||
const MAX_SPEED = 6
|
const MAX_SPEED = 6
|
||||||
@@ -851,7 +851,7 @@ const b = {
|
|||||||
|
|
||||||
//find mob targets
|
//find mob targets
|
||||||
if (!(game.cycle % this.lookFrequency)) {
|
if (!(game.cycle % this.lookFrequency)) {
|
||||||
this.close = null;
|
// this.close = null;
|
||||||
this.lockedOn = null;
|
this.lockedOn = null;
|
||||||
this.isFollowMouse = true; //if no target is found default to follow mouse
|
this.isFollowMouse = true; //if no target is found default to follow mouse
|
||||||
let closeDist = Infinity;
|
let closeDist = Infinity;
|
||||||
@@ -865,7 +865,7 @@ const b = {
|
|||||||
const TARGET_VECTOR = Matter.Vector.sub(this.position, mob[i].position)
|
const TARGET_VECTOR = Matter.Vector.sub(this.position, mob[i].position)
|
||||||
const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
|
const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
|
||||||
if (DIST < closeDist) {
|
if (DIST < closeDist) {
|
||||||
this.close = mob[i].position;
|
// this.close = mob[i].position;
|
||||||
closeDist = DIST;
|
closeDist = DIST;
|
||||||
this.lockedOn = mob[i]
|
this.lockedOn = mob[i]
|
||||||
this.isFollowMouse = false;
|
this.isFollowMouse = false;
|
||||||
@@ -900,7 +900,7 @@ const b = {
|
|||||||
{
|
{
|
||||||
name: "wave beam",
|
name: "wave beam",
|
||||||
ammo: 0,
|
ammo: 0,
|
||||||
ammoPack: 110,
|
ammoPack: 120,
|
||||||
have: false,
|
have: false,
|
||||||
fire() {
|
fire() {
|
||||||
const me = bullet.length;
|
const me = bullet.length;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const level = {
|
|||||||
// game.zoomScale = 1400 //1400
|
// game.zoomScale = 1400 //1400
|
||||||
if (game.levelsCleared === 0) {
|
if (game.levelsCleared === 0) {
|
||||||
this.intro(); //starting level
|
this.intro(); //starting level
|
||||||
// b.giveGuns(12) // set a starting gun for testing
|
b.giveGuns(11) // set a starting gun for testing
|
||||||
// game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
|
// game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
|
||||||
// this.bosses();
|
// this.bosses();
|
||||||
// this.testingMap();
|
// this.testingMap();
|
||||||
@@ -353,6 +353,12 @@ const level = {
|
|||||||
spawn.wireKnee();
|
spawn.wireKnee();
|
||||||
spawn.wireKneeLeft();
|
spawn.wireKneeLeft();
|
||||||
spawn.wireHead();
|
spawn.wireHead();
|
||||||
|
|
||||||
|
spawn.healer(1600, -500)
|
||||||
|
spawn.healer(1600, -500)
|
||||||
|
spawn.healer(1900, -500)
|
||||||
|
spawn.healer(1000, -500)
|
||||||
|
spawn.healer(1000, -400)
|
||||||
},
|
},
|
||||||
|
|
||||||
rooftops() {
|
rooftops() {
|
||||||
|
|||||||
57
js/spawn.js
57
js/spawn.js
@@ -143,6 +143,63 @@ const spawn = {
|
|||||||
this.attraction();
|
this.attraction();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
healer(x, y, radius = 20) {
|
||||||
|
//easy mob for on level 1
|
||||||
|
mobs.spawn(x, y, 3, radius, "rgba(50,255,200,0.4)");
|
||||||
|
let me = mob[mob.length - 1];
|
||||||
|
me.frictionAir = 0.01;
|
||||||
|
me.accelMag = 0.0004;
|
||||||
|
me.lookFrequency = 100 + Math.floor(37 * Math.random())
|
||||||
|
me.lockedOn = null;
|
||||||
|
Matter.Body.setDensity(me, 0.003) // normal density is 0.001
|
||||||
|
|
||||||
|
me.do = function () {
|
||||||
|
this.healthBar();
|
||||||
|
|
||||||
|
if (!(game.cycle % this.seePlayerFreq)) {
|
||||||
|
//slow self heal
|
||||||
|
// this.health += 0.03;
|
||||||
|
// if (this.health > 1) this.health = 1;
|
||||||
|
|
||||||
|
//target mobs with low health
|
||||||
|
let closeDist = Infinity;
|
||||||
|
for (let i = 0; i < mob.length; i++) {
|
||||||
|
if (mob[i] != this && Matter.Query.ray(map, this.position, mob[i].position).length === 0) {
|
||||||
|
const TARGET_VECTOR = Matter.Vector.sub(this.position, mob[i].position)
|
||||||
|
const DIST = Matter.Vector.magnitude(TARGET_VECTOR) * mob[i].health * mob[i].health * mob[i].health; //distance is multiplied by mob health to prioritize low health mobs
|
||||||
|
if (DIST < closeDist) {
|
||||||
|
closeDist = DIST;
|
||||||
|
this.lockedOn = mob[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//move towards and heal locked on target
|
||||||
|
if (this.lockedOn) { //accelerate towards mobs
|
||||||
|
const TARGET_VECTOR = Matter.Vector.sub(this.position, this.lockedOn.position)
|
||||||
|
const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
|
||||||
|
if (DIST > 200) {
|
||||||
|
this.force = Matter.Vector.mult(Matter.Vector.normalise(TARGET_VECTOR), -this.mass * this.accelMag)
|
||||||
|
} else {
|
||||||
|
if (this.lockedOn.health < 1) {
|
||||||
|
this.lockedOn.health += 0.002;
|
||||||
|
if (this.lockedOn.health > 1) this.lockedOn.health = 1;
|
||||||
|
//draw heal
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(this.position.x, this.position.y);
|
||||||
|
ctx.lineTo(this.lockedOn.position.x, this.lockedOn.position.y);
|
||||||
|
ctx.lineWidth = 10
|
||||||
|
ctx.strokeStyle = "rgba(50,255,200,0.4)"
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//wander if no heal targets
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
},
|
||||||
chaser(x, y, radius = 35 + Math.ceil(Math.random() * 40)) {
|
chaser(x, y, radius = 35 + Math.ceil(Math.random() * 40)) {
|
||||||
mobs.spawn(x, y, 8, radius, "#2c9790");
|
mobs.spawn(x, y, 8, radius, "#2c9790");
|
||||||
let me = mob[mob.length - 1];
|
let me = mob[mob.length - 1];
|
||||||
|
|||||||
Reference in New Issue
Block a user