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

View File

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

View File

@@ -738,8 +738,8 @@ const mech = {
}, },
throw () { throw () {
if ((keys[32] || game.mouseDownRight)) { if ((keys[32] || game.mouseDownRight)) {
if (this.fieldMeter > 0.0008) { if (this.fieldMeter > 0.0007) {
this.fieldMeter -= 0.0008; this.fieldMeter -= 0.0007;
this.throwCharge += this.throwChargeRate;; this.throwCharge += this.throwChargeRate;;
//draw charge //draw charge
const x = mech.pos.x + 15 * Math.cos(this.angle); 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"); if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "gun");
return; return;
} }
if (Math.random() < 0.004 * (7 - b.modCount)) { if (Math.random() < 0.0035 * (7 - b.modCount)) {
powerUps.spawn(x, y, "mod"); powerUps.spawn(x, y, "mod");
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "mod"); if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "mod");
return; return;
@@ -172,13 +172,13 @@ const powerUps = {
if (mech.fieldMode === 0) { if (mech.fieldMode === 0) {
powerUps.spawn(x, y, "field") powerUps.spawn(x, y, "field")
if (Math.random() < b.modMoreDrops) 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") powerUps.spawn(x, y, "mod")
if (Math.random() < b.modMoreDrops) 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"); powerUps.spawn(x, y, "field");
if (Math.random() < b.modMoreDrops) 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") powerUps.spawn(x, y, "gun")
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "gun") if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "gun")
} else if (mech.health < 0.6) { } else if (mech.health < 0.6) {

View File

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