added laser bot

This commit is contained in:
landgreen
2019-12-07 13:38:39 -08:00
committed by GitHub
parent 53b7cf7bc6
commit 7508b52d91
9 changed files with 9615 additions and 9596 deletions

View File

@@ -100,7 +100,7 @@ const b = {
},
{
name: "ceramic plating",
description: "protection from to high <strong>temperatures</strong><br>5x less <strong class='color-d'>damage</strong> from <strong class='color-e'>explosions</strong> and lasers",
description: "protection from to high <strong>temperatures</strong><br>5x less <strong class='color-d'>damage</strong> from <strong class='color-e'>explosions</strong>, lasers",
have: false, //5
effect: () => {
b.isModTempResist = true; //good for guns with explosions
@@ -1567,7 +1567,7 @@ const b = {
name: "drones", //13
description: "deploy <strong>drones</strong> that seek out enemies<br>collisions reduce drone <strong>cycles</strong> by 1 second",
ammo: 0,
ammoPack: 20,
ammoPack: 17,
have: false,
isStarterGun: true,
fire() {
@@ -1667,74 +1667,111 @@ const b = {
b.drawOneBullet(bullet[me].vertices);
}
},
// {
// name: "laser-bot", //14
// description: "deploy <strong>bots</strong> that fire <strong>lasers</strong> at nearby enemies<br><em>bots last for one level</em>",
// ammo: 0,
// ammoPack: 1,
// have: false,
// isStarterGun: false,
// fire() {
// const THRUST = 0.004
// const dir = mech.angle;
// const me = bullet.length;
// const RADIUS = (15 + 8 * Math.random()) * b.modBulletSize
// const LENGTH = 0.6 + 0.8 * Math.random()
{
name: "laser-bot", //14
description: "deploy bots that <strong>defend</strong> against close threats<br>lasts one level, but drains <strong class='color-f'>energy</strong>",
ammo: 0,
ammoPack: 1,
have: false,
isStarterGun: false,
fire() {
const dir = mech.angle;
const me = bullet.length;
const RADIUS = (22 + 5 * Math.random()) * b.modBulletSize
const LENGTH = 0.7 + Math.random()
// bullet[me] = Bodies.rectangle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), RADIUS * LENGTH, RADIUS / LENGTH, {
// angle: dir,
// // inertia: Infinity,
// // friction: 0,
// density: 0.001, //normal is 0.001
// frictionAir: 0.06,
// restitution: 0.8,
// dmg: b.modExtraDmg, // 0.14 //damage done in addition to the damage from momentum
// minDmgSpeed: 2,
// lookFrequency: 7 + Math.floor(17 * Math.random()),
// endCycle: Infinity,
// classType: "bullet",
// collisionFilter: {
// category: 0x000100,
// mask: 0x010111 //self, mob,map,body collide
// },
// range: 300,
// lockedOn: null,
// onDmg() {
// this.lockedOn = null
// // this.endCycle -= 120; //lose 2 seconds after damage is done
// },
// onEnd() {},
// do() {
// if (!(game.cycle % this.lookFrequency)) {
// this.lockedOn = null;
// let closeDist = Infinity;
// for (let i = 0, len = mob.length; i < len; ++i) {
// const TARGET_VECTOR = Matter.Vector.sub(mech.pos, mob[i].position)
// const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
// // DIST - mob[i].radius < this.range &&
// if (DIST < closeDist && Matter.Query.ray(map, this.position, mob[i].position).length === 0) {
// closeDist = DIST;
// this.lockedOn = mob[i]
// }
// }
// }
bullet[me] = Bodies.rectangle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), RADIUS * LENGTH, RADIUS / LENGTH, {
angle: dir,
friction: 0,
frictionStatic: 0,
restitution: 0.8,
dmg: b.modExtraDmg, // 0.14 //damage done in addition to the damage from momentum
minDmgSpeed: 2,
lookFrequency: 47 + Math.floor(37 * Math.random()),
range: 450 + Math.floor(200 * Math.random()),
endCycle: Infinity,
modulus: Math.floor(2 * Math.random()), //offsets the modulus so the bullets don't all fire at the same time
classType: "bullet",
collisionFilter: {
category: 0x000100,
mask: 0x010111 //self, mob,map,body collide
},
lockedOn: null,
onDmg() {
this.lockedOn = null
},
onEnd() {},
do() {
if (!(game.cycle % this.lookFrequency)) {
this.lockedOn = null;
let closeDist = this.range;
for (let i = 0, len = mob.length; i < len; ++i) {
const TARGET_VECTOR = Matter.Vector.sub(this.vertices[0], mob[i].position)
const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
if (DIST - mob[i].radius < closeDist &&
Matter.Query.ray(map, this.vertices[0], mob[i].position).length === 0 &&
Matter.Query.ray(body, this.vertices[0], mob[i].position).length === 0) {
closeDist = DIST;
this.lockedOn = mob[i]
}
}
}
// const distanceToPlayer = Matter.Vector.magnitude(Matter.Vector.sub(this.position, mech.pos))
// if (this.lockedOn) { //accelerate towards mobs
// this.force = Matter.Vector.mult(Matter.Vector.normalise(Matter.Vector.sub(this.position, this.lockedOn.position)), -this.mass * THRUST)
// this.frictionAir = 0.06
// } else if (distanceToPlayer > 100) {
// this.force = Matter.Vector.mult(Matter.Vector.normalise(Matter.Vector.sub(this.position, mech.pos)), -this.mass * THRUST * 0.3)
// this.frictionAir = 0.02
// } else { //must be close to player //add some random motion
// this.frictionAir = 0
// }
// }
// })
// b.fireProps(mech.crouch ? 5 : 10, 15, dir, me); //cd , speed
// b.drawOneBullet(bullet[me].vertices);
// }
// },
if (!((game.cycle + this.modulus) % 2)) {
const FIELD_DRAIN = 0.006
if (this.lockedOn && this.lockedOn.alive && mech.fieldMeter > FIELD_DRAIN) { //hit target with laser
mech.fieldMeter -= FIELD_DRAIN
//make sure you can still see target
const TARGET_VECTOR = Matter.Vector.sub(this.vertices[0], this.lockedOn.position)
const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
if (DIST - this.lockedOn.radius < this.range + 200 &&
Matter.Query.ray(map, this.vertices[0], this.lockedOn.position).length === 0 &&
Matter.Query.ray(body, this.vertices[0], this.lockedOn.position).length === 0) {
//find the closest vertex
let bestVertexDistance = Infinity
let bestVertex = null
for (let i = 0; i < this.lockedOn.vertices.length; i++) {
const dist = Matter.Vector.magnitude(Matter.Vector.sub(this.vertices[0], this.lockedOn.vertices[i]));
if (dist < bestVertexDistance) {
bestVertex = i
bestVertexDistance = dist
}
}
const dmg = b.dmgScale * 0.10;
this.lockedOn.damage(dmg);
this.lockedOn.locatePlayer();
//draw laser
ctx.beginPath();
ctx.moveTo(this.vertices[0].x, this.vertices[0].y);
ctx.lineTo(this.lockedOn.vertices[bestVertex].x, this.lockedOn.vertices[bestVertex].y);
ctx.strokeStyle = "#f00";
ctx.lineWidth = "2"
ctx.lineDashOffset = 300 * Math.random()
ctx.setLineDash([50 + 100 * Math.random(), 100 * Math.random()]);
ctx.stroke();
ctx.setLineDash([0, 0]);
ctx.beginPath();
ctx.arc(this.lockedOn.vertices[bestVertex].x, this.lockedOn.vertices[bestVertex].y, Math.sqrt(dmg) * 100, 0, 2 * Math.PI);
ctx.fillStyle = "#f00"
ctx.fill();
}
}
}
const distanceToPlayer = Matter.Vector.magnitude(Matter.Vector.sub(this.position, mech.pos))
if (distanceToPlayer > this.range * 0.25) { //if far away move towards player
this.force = Matter.Vector.mult(Matter.Vector.normalise(Matter.Vector.sub(mech.pos, this.position)), this.mass * 0.002)
this.frictionAir = 0.02
} else { //close to player
this.frictionAir = 0
}
}
})
b.fireProps(mech.crouch ? 60 : 30, 15, dir, me); //cd , speed
b.drawOneBullet(bullet[me].vertices);
}
},
// {
// name: "dwarf star", //14
// description: "drop a mine that gravitational pulls in matter",

View File

@@ -14,10 +14,9 @@ const level = {
start() {
if (level.levelsCleared === 0) {
// game.difficulty = 6; //for testing to simulate possible mobs spawns
// b.giveGuns(1)
b.giveGuns(14)
// mech.fieldUpgrades[2].effect();
// b.giveMod(5)
// spawn.pickList = ["ghoster", "ghoster"]
this.intro(); //starting level
// this.testingMap();
@@ -29,6 +28,7 @@ const level = {
// this.office();
} else {
spawn.setSpawnList(); //picks a couple mobs types for a themed random mob spawns
// spawn.pickList = ["focuser", "focuser"]
level[level.levels[level.onLevel]](); //picks the current map from the the levels array
level.levelAnnounce();
}
@@ -106,26 +106,6 @@ const level = {
// spawn.lineBoss(-500, -600, spawn.allowedBossList[Math.floor(Math.random() * spawn.allowedBossList.length)]);
// spawn.bodyRect(-135, -50, 50, 50);
// spawn.bodyRect(-140, -100, 50, 50);
// spawn.bodyRect(-145, -150, 60, 50);
// spawn.bodyRect(-140, -200, 50, 50);
// spawn.bodyRect(-95, -50, 40, 50);
// spawn.bodyRect(-90, -100, 60, 50);
// spawn.bodyRect(300, -150, 140, 50);
// spawn.bodyRect(300, -150, 30, 30);
// spawn.bodyRect(300, -150, 20, 20);
// spawn.bodyRect(300, -150, 40, 100);
// spawn.bodyRect(300, -150, 40, 90);
// spawn.bodyRect(300, -150, 30, 60);
// spawn.bodyRect(300, -150, 40, 70);
// spawn.bodyRect(300, -150, 40, 60);
// spawn.bodyRect(300, -150, 20, 20);
// spawn.bodyRect(500, -150, 140, 110);
// spawn.bodyRect(600, -150, 140, 100);
// spawn.bodyRect(400, -150, 140, 160);
// spawn.bodyRect(500, -150, 110, 110);
// powerUps.spawn(340, -400, "heal", false);
// powerUps.spawn(370, -400, "gun", false);
// powerUps.spawn(400, -400, "field", false, 2);
// powerUps.spawn(420, -400, "ammo", false);
powerUps.spawn(450, -400, "mod", false, 6);
// powerUps.spawn(450, -400, "mod", false);
@@ -342,10 +322,12 @@ const level = {
// powerUps.spawn(2050, -150, "field", false); //starting gun
powerUps.spawn(2300, -150, "gun", false); //starting gun
if (game.isEasyMode) {
powerUps.spawn(2050, -150, "mod", false); //starting gun
powerUps.spawn(2050, -150, "mod", false); //starting gun
// powerUps.spawn(2050, -150, "mod", false); //starting gun
// powerUps.spawn(2050, -150, "mod", false); //starting gun
// powerUps.spawn(-100, -150, "ammo", false); //starting gun
powerUps.spawn(-100, 0, "heal", false); //starting gun
}
spawn.wireFoot();
spawn.wireFootLeft();
spawn.wireKnee();

View File

@@ -738,8 +738,8 @@ const mech = {
},
throw () {
if ((keys[32] || game.mouseDownRight)) {
if (this.fieldMeter > 0.0008) {
this.fieldMeter -= 0.0008;
if (this.fieldMeter > 0.0007) {
this.fieldMeter -= 0.0007;
this.throwCharge += this.throwChargeRate;;
//draw charge
const x = mech.pos.x + 15 * Math.cos(this.angle);

View File

@@ -157,7 +157,7 @@ const powerUps = {
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "gun");
return;
}
if (Math.random() < 0.004 * (7 - b.modCount)) {
if (Math.random() < 0.0035 * (7 - b.modCount)) {
powerUps.spawn(x, y, "mod");
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "mod");
return;
@@ -172,13 +172,13 @@ const powerUps = {
if (mech.fieldMode === 0) {
powerUps.spawn(x, y, "field")
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "field")
} else if (Math.random() < 0.3) {
} else if (Math.random() < 0.27) {
powerUps.spawn(x, y, "mod")
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "mod")
} else if (Math.random() < 0.3) {
} else if (Math.random() < 0.27) {
powerUps.spawn(x, y, "field");
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "field");
} else if (Math.random() < 0.3) {
} else if (Math.random() < 0.27) {
powerUps.spawn(x, y, "gun")
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "gun")
} else if (mech.health < 0.6) {

View File

@@ -595,7 +595,7 @@ const spawn = {
me.restitution = 0;
me.laserPos = me.position; //required for laserTracking
me.repulsionRange = 1200000; //squared
me.accelMag = 0.0002 * game.accelScale;
me.accelMag = 0.00009 * game.accelScale;
me.frictionStatic = 0;
me.friction = 0;
me.onDamage = function () {