From ef47202450ef019c965bebfd60d65db439a7a316 Mon Sep 17 00:00:00 2001 From: landgreen Date: Fri, 8 Nov 2019 06:53:33 -0800 Subject: [PATCH] defensive drones --- js/bullets.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++++-- js/level.js | 11 ++++---- js/player.js | 1 + 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/js/bullets.js b/js/bullets.js index 0d53915..d3bfc13 100644 --- a/js/bullets.js +++ b/js/bullets.js @@ -746,7 +746,7 @@ const b = { name: "fléchettes", description: "fire an accurate high speed needle
", ammo: 0, - ammoPack: 14, + ammoPack: 16, have: false, fire() { const me = bullet.length; @@ -1157,7 +1157,7 @@ const b = { } }, { - name: "drones", + name: "hunter drones", description: "release drones that seek out targets
if no targets are found, drones move towards mouse
", ammo: 0, ammoPack: 20, @@ -1250,5 +1250,72 @@ const b = { b.drawOneBullet(bullet[me].vertices); } }, + { + name: "defense drones", + description: "release drones that defend the space around the player", + ammo: 0, + ammoPack: 3, + have: false, + fire() { + const THRUST = 0.0015 + const dir = mech.angle + 0.2 * (Math.random() - 0.5); + const me = bullet.length; + const RADIUS = (10 + 6 * Math.random()) * b.modBulletSize + bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), RADIUS, { + angle: dir, + inertia: Infinity, + friction: 0, + frictionAir: 0.001, + restitution: 1, + dmg: 0.14, //damage done in addition to the damage from momentum + lookFrequency: 27 + Math.floor(37 * Math.random()), + endCycle: game.cycle + Math.floor((2400 + 1800 * Math.random()) * b.modBulletsLastLonger), + classType: "bullet", + collisionFilter: { + category: 0x000100, + mask: 0x000110 //self collide + }, + minDmgSpeed: 0, + range: 450 + 150 * Math.random(), + lockedOn: null, + isFollowMouse: true, + onDmg() { + this.lockedOn = null + }, + 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); + if (DIST < this.range && DIST < closeDist) { + 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) + } else if (distanceToPlayer > 0.2 * this.range) { + this.force = Matter.Vector.mult(Matter.Vector.normalise(Matter.Vector.sub(this.position, mech.pos)), -this.mass * THRUST * 0.5) + } + + // speed cap instead of friction to give more agility + if (this.speed > 12) { + Matter.Body.setVelocity(this, { + x: this.velocity.x * 0.97, + y: this.velocity.y * 0.97 + }); + } + } + }) + b.fireProps(mech.crouch ? 80 : 60, mech.crouch ? 35 : 10, dir, me); //cd , speed + b.drawOneBullet(bullet[me].vertices); + } + }, ] }; \ No newline at end of file diff --git a/js/level.js b/js/level.js index a8d887e..9dbe94d 100644 --- a/js/level.js +++ b/js/level.js @@ -14,12 +14,12 @@ const level = { if (game.levelsCleared === 0) { // game.levelsCleared = 16; //for testing to simulate possible mobs spawns // b.giveGuns("all", 1000) - b.giveGuns(6) // set a starting gun for testing + b.giveGuns(13) // set a starting gun for testing // mech.fieldUpgrades[2].effect(); //give a field power up for testing // b.giveMod(7) - this.intro(); //starting level - // this.testingMap(); + // this.intro(); //starting level + this.testingMap(); // this.bosses(); // this.aerie(); // this.rooftops(); @@ -46,7 +46,6 @@ const level = { //****************************************************************************************************************** testingMap() { //start with all guns - b.giveGuns("all", 1000) game.zoomScale = 1400 //1400 is normal spawn.setSpawnList(); game.levelsCleared = 3; //for testing to simulate all possible mobs spawns @@ -121,8 +120,8 @@ const level = { // powerUps.spawn(450, -400, "mod", false); // spawn.bodyRect(-45, -100, 40, 50); // spawn.focuser(800, -1150); - // spawn.groupBoss(-600, -550); - spawn.striker(800, -150); + spawn.groupBoss(-600, -550); + // spawn.hopper(800, -150); // spawn.beamer(800, -150); // spawn.grower(800, -250); // spawn.blinker(800, -250, 40); diff --git a/js/player.js b/js/player.js index a28cbfb..5d6a59a 100644 --- a/js/player.js +++ b/js/player.js @@ -750,6 +750,7 @@ const mech = { ctx.fillStyle = "rgba(110,170,200," + (0.02 + mech.fieldMeter * (0.15 + 0.15 * Math.random())) + ")"; ctx.strokeStyle = "rgba(110, 200, 235, " + (0.6 + 0.2 * Math.random()) + ")" //"#9bd" //"rgba(110, 200, 235, " + (0.5 + 0.1 * Math.random()) + ")" } + // const off = 2 * Math.cos(game.cycle * 0.1) const range = this.grabRange - 20; ctx.beginPath(); ctx.arc(mech.pos.x, mech.pos.y, range, mech.angle - Math.PI * mech.fieldArc, mech.angle + Math.PI * mech.fieldArc, false);