diff --git a/js/bullets.js b/js/bullets.js index bfeba43..bce930e 100644 --- a/js/bullets.js +++ b/js/bullets.js @@ -1039,7 +1039,7 @@ const b = { name: "super balls", //4 description: "fire balls that bounce with no momentum loss", ammo: 0, - ammoPack: 11, + ammoPack: 14, have: false, isStarterGun: true, fire() { @@ -1050,12 +1050,12 @@ const b = { for (let i = 0; i < 3; i++) { const me = bullet.length; bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 7 * b.modBulletSize, b.fireAttributes(dir, false)); - b.fireProps(mech.crouch ? 40 : 20, mech.crouch ? 34 : 26, dir, me); //cd , speed + b.fireProps(mech.crouch ? 30 : 12, mech.crouch ? 38 : 30, dir, me); //cd , speed Matter.Body.setDensity(bullet[me], 0.0001); - bullet[me].endCycle = game.cycle + Math.floor(360 * b.isModBulletsLastLonger); - bullet[me].dmg = 0.5 + b.modExtraDmg; + bullet[me].endCycle = game.cycle + Math.floor(300 * b.isModBulletsLastLonger); + bullet[me].dmg = 0.25 + b.modExtraDmg; bullet[me].minDmgSpeed = 0; - bullet[me].restitution = 0.96; + bullet[me].restitution = 0.98; bullet[me].friction = 0; bullet[me].do = function () { this.force.y += this.mass * 0.001; @@ -1737,7 +1737,7 @@ const b = { fire() { const me = bullet.length; const dir = mech.angle + 0.2 * (Math.random() - 0.5) - const RADIUS = (6 + 16 * Math.random()) * b.modBulletSize + const RADIUS = (8 + 16 * Math.random()) * b.modBulletSize bullet[me] = Bodies.polygon(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 25, RADIUS, { angle: dir, density: 0.000005, // 0.001 is normal density @@ -1749,19 +1749,30 @@ const b = { classType: "bullet", collisionFilter: { category: cat.bullet, - mask: cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield + mask: cat.map | cat.body | cat.mob | cat.mobShield }, minDmgSpeed: 0, endCycle: Infinity, //game.cycle + Math.floor(265 * b.isModBulletsLastLonger), count: 0, radius: RADIUS, target: null, - targetSub: null, + targetVertex: null, onDmg(who) { if (!this.target && who.alive && who.dropPowerUp) { this.target = who; - // this.targetSub = Matter.Vector.sub(this.position, this.target.position) - this.collisionFilter.category = 0; + this.collisionFilter.category = cat.body; + this.collisionFilter.mask = cat.player + + let bestVertexDistance = Infinity + let bestVertex = null + for (let i = 0; i < this.target.vertices.length; i++) { + const dist = Matter.Vector.magnitude(Matter.Vector.sub(this.position, this.target.vertices[i])); + if (dist < bestVertexDistance) { + bestVertex = i + bestVertexDistance = dist + } + } + this.targetVertex = bestVertex } }, onEnd() {}, @@ -1773,6 +1784,7 @@ const b = { if (!mech.isBodiesAsleep) { //if time dilation isn't active this.force.y += this.mass * 0.00006; //gravity + if (this.count < 17) { this.count++ //grow @@ -1781,21 +1793,21 @@ const b = { this.radius *= SCALE; } else { //shrink - const SCALE = 1 - 0.007 / b.isModBulletsLastLonger + const SCALE = 1 - 0.006 / b.isModBulletsLastLonger Matter.Body.scale(this, SCALE, SCALE); this.radius *= SCALE; if (this.radius < 11) this.endCycle = 0; } if (this.target && this.target.alive) { //if stuck to a target - // Matter.Body.setPosition(this, Matter.Vector.add(this.target.position, this.targetSub)) - Matter.Body.setPosition(this, this.target.position) + Matter.Body.setPosition(this, this.target.vertices[this.targetVertex]) Matter.Body.setVelocity(this.target, Matter.Vector.mult(this.target.velocity, 0.94)) Matter.Body.setAngularVelocity(this.target, this.target.angularVelocity * 0.94) - this.target.damage(b.dmgScale * 0.0045); + this.target.damage(b.dmgScale * 0.0025); } else if (this.target !== null) { //look for a new target this.target = null this.collisionFilter.category = cat.bullet; + this.collisionFilter.mask = cat.map | cat.body | cat.mob | cat.mobBullet | cat.mobShield } } } @@ -1807,7 +1819,6 @@ const b = { x: SPEED * Math.cos(dir), y: SPEED * Math.sin(dir) }); - // bullet[me].direction = Matter.Vector.perp(bullet[me].velocity) } }, // { diff --git a/js/game.js b/js/game.js index c283588..f91e311 100644 --- a/js/game.js +++ b/js/game.js @@ -287,36 +287,49 @@ const game = { } else { this.testing = true; } - } else if (this.testing) { - //only in testing mode - - if (keys[70]) { //cycle fields with F + } + //in testing mode + if (this.testing) { + if (keys[49]) { // give power ups with 1 + powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "heal"); + } else if (keys[50]) { // 2 + powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "ammo"); + } else if (keys[51]) { // 3 + powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "gun"); + } else if (keys[52]) { // 4 + powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "field"); + } else if (keys[53]) { // 5 + powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "mod"); + } else if (keys[54]) { // 6 spawn mob + const pick = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)]; + spawn[pick](game.mouseInGame.x, game.mouseInGame.y); + } else if (keys[55]) { // 7 spawn body + index = body.length + spawn.bodyRect(game.mouseInGame.x, game.mouseInGame.y, 50, 50); + body[index].collisionFilter.category = cat.body; + body[index].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet + body[index].classType = "body"; + World.add(engine.world, body[index]); //add to world + } else if (keys[70]) { //cycle fields with F if (mech.fieldMode === mech.fieldUpgrades.length - 1) { mech.fieldUpgrades[0].effect() } else { mech.fieldUpgrades[mech.fieldMode + 1].effect() } - } - if (keys[71]) { // give all guns with G + } else if (keys[71]) { // give all guns with G // b.giveGuns("all", 1000) powerUps.gun.effect() - } - if (keys[72]) { // power ups with H - powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "gun"); - powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "ammo"); - powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "field"); - powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "heal"); - powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "mod"); - } - if (keys[89]) { //add all mods with y + } else if (keys[72]) { // power ups with H + mech.addHealth(Infinity) + } else if (keys[89]) { //add all mods with y powerUps.mod.effect() - } - if (keys[82]) { // teleport to mouse with R + } else if (keys[82]) { // teleport to mouse with R Matter.Body.setPosition(player, this.mouseInGame); Matter.Body.setVelocity(player, { x: 0, y: 0 }); + // game.noCameraScroll() } } }, @@ -326,6 +339,16 @@ const game = { game.zoomScale = zoomScale game.zoom = canvas.height / zoomScale; //sets starting zoom scale }, + noCameraScroll() { + // makes the camera not scroll after changing locations + mech.pos.x = player.position.x; + mech.pos.y = playerBody.position.y - mech.yOff; + const scale = 0.8; + mech.transSmoothX = canvas.width2 - mech.pos.x - (game.mouse.x - canvas.width2) * scale; + mech.transSmoothY = canvas.height2 - mech.pos.y - (game.mouse.y - canvas.height2) * scale; + mech.transX += (mech.transSmoothX - mech.transX) * 1; + mech.transY += (mech.transSmoothY - mech.transY) * 1; + }, zoomTransition(newZoomScale, step = 2) { const isBigger = (newZoomScale - game.zoomScale > 0) ? true : false; requestAnimationFrame(zLoop); @@ -649,7 +672,9 @@ const game = { line += 20; ctx.fillText("G: give all guns", x, line); line += 20; - ctx.fillText("H: spawn power ups", x, line); + ctx.fillText("H: heal", x, line); + line += 20; + ctx.fillText("1-7: spawn things", x, line); line += 30; ctx.fillText("cycle: " + game.cycle, x, line); diff --git a/js/level.js b/js/level.js index a6e82cc..1ccbde0 100644 --- a/js/level.js +++ b/js/level.js @@ -14,7 +14,7 @@ const level = { start() { if (level.levelsCleared === 0) { // game.difficulty = 6; //for testing to simulate possible mobs spawns - b.giveGuns(12) + // b.giveGuns(15) // mech.fieldUpgrades[1].effect(); // b.giveMod(21) @@ -32,6 +32,7 @@ const level = { level[level.levels[level.onLevel]](); //picks the current map from the the levels array level.levelAnnounce(); } + game.noCameraScroll(); game.setZoom(); level.addToWorld(); //add bodies to game engine game.draw.setPaths(); diff --git a/js/player.js b/js/player.js index 5cad0a9..7dc5415 100644 --- a/js/player.js +++ b/js/player.js @@ -98,6 +98,8 @@ const mech = { player.force.y = 0; Matter.Body.setPosition(player, this.spawnPos); Matter.Body.setVelocity(player, this.spawnVel); + // mech.transX = -player.position.x + // mech.transY = player.position.y }, Sy: 0, //adds a smoothing effect to vertical only Vx: 0, @@ -995,17 +997,14 @@ const mech = { pickUp() { //triggers when a hold target exits and field button is released this.isHolding = true; + //conserve momentum when player mass changes + totalMomentum = Matter.Vector.add(Matter.Vector.mult(player.velocity, player.mass), Matter.Vector.mult(this.holdingTarget.velocity, this.holdingTarget.mass)) + Matter.Body.setVelocity(player, Matter.Vector.mult(totalMomentum, 1 / (mech.defaultMass + this.holdingTarget.mass))); + this.definePlayerMass(mech.defaultMass + this.holdingTarget.mass * this.holdingMassScale) - //collide with nothing + //make block collide with nothing this.holdingTarget.collisionFilter.category = 0; this.holdingTarget.collisionFilter.mask = 0; - // combine momentum // this doesn't feel right in game - // const px = player.velocity.x * player.mass + this.holdingTarget.velocity.x * this.holdingTarget.mass; - // const py = player.velocity.y * player.mass + this.holdingTarget.velocity.y * this.holdingTarget.mass; - // Matter.Body.setVelocity(player, { - // x: px / (player.mass + this.holdingTarget.mass), - // y: py / (player.mass + this.holdingTarget.mass) - // }); }, wakeCheck() { if (mech.isBodiesAsleep) {