From 2b88690cf5a30e37e595c2a94420cf122c6600a4 Mon Sep 17 00:00:00 2001 From: biglyderv Date: Mon, 25 Nov 2024 14:14:21 -0500 Subject: [PATCH] change game mechanics a lot --- common/player.js | 50 ++++++++++++++++++++++++++++++++--------------- common/shooter.js | 2 +- game.js | 2 +- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/common/player.js b/common/player.js index e028e46..3aa8f05 100644 --- a/common/player.js +++ b/common/player.js @@ -8,8 +8,8 @@ class Player extends Entity { this.camera = { x: -this.pos.x, y: -this.pos.y }; this.rot = 0; - this.dir = 1; - this.ticks = 0; + this.dir = 2; + this.ticks = 100; this.health = 100; @@ -38,15 +38,17 @@ class Player extends Entity { bump() { let player = this; - if (player.ticks < 15) { - player.dir *= -1; + if (player.ticks < 10) { + player.dir = -3 * Math.sign(player.dir); + } else { + player.dir = -0.005 * Math.sign(player.dir); } - player.vel.x *= 0.3; - player.vel.y *= 0.3; + player.vel.x *= 0.9; + player.vel.y *= 0.9; - player.vel.x += Math.sin(player.rot) * 12; - player.vel.y -= Math.cos(player.rot) * 12; + player.vel.x += Math.sin(player.rot) * 15; + player.vel.y -= Math.cos(player.rot) * 15; player.ticks = 0; } @@ -60,7 +62,17 @@ class Player extends Entity { dp /= Math.sqrt(dist + 0.1); - if (!(Math.sqrt(dist) < 128 && 1 / dp < -0.2)) return; + if (!(Math.sqrt(dist) < 128)) return; + + if (target.type == 'Shooter') { + let h = Math.floor((-dp -1.001)); + if (h < 0) { + this.health += h; + } + target.dir = (Math.PI / 2) + this.rot; + } + + if (!(1 / dp < -0.2)) return; let velness = Math.sqrt(this.vel.x ** 2 + this.vel.y ** 2); @@ -71,17 +83,17 @@ class Player extends Entity { this.rot = 1.2; } - if (target.type == 'Shooter') { - this.health -= 1; - } + let dmg = Math.floor((dp - 0.001) * 10); + if (target.immortal && target.type != 'Shooter') return; + target.vel.x += (target.pos.x - this.pos.x) * 0.1; + target.vel.y += (target.pos.y - this.pos.y) * 0.1; if (target.immortal) return; let oldHealth = target.health - let dmg = Math.floor((dp - 0.001) * 10); - target.health += Math.floor((dp - 0.001) * 10); + target.health += dmg; target.vel.x += (target.pos.x - this.pos.x) * 0.1; target.vel.y += (target.pos.y - this.pos.y) * 0.1; @@ -110,8 +122,8 @@ class Player extends Entity { this.bounce(game); - this.vel.x *= 0.9; - this.vel.y *= 0.9; + this.vel.x *= 0.85; + this.vel.y *= 0.85; this.rot += 0.03 * this.dir; this.rot = this.rot % (Math.PI * 10); @@ -124,6 +136,12 @@ class Player extends Entity { for (let target of entities) { this.handleInt(target); } + + if (this.dir == 0) { + this.dir = 0.01; + } + + this.dir = ((1.5 - Math.abs(this.dir)) * 0.005 + Math.abs(this.dir)) * Math.sign(this.dir); } } diff --git a/common/shooter.js b/common/shooter.js index 4bfdedd..a5cf30b 100644 --- a/common/shooter.js +++ b/common/shooter.js @@ -21,7 +21,7 @@ class Shooter extends Entity { this.ticks++; this.vel.x += Math.sin(this.dir) * 1; - this.vel.y += Math.cos(this.dir) * 1; + this.vel.y -= Math.cos(this.dir) * 1; this.vel.x *= 0.9; this.vel.y *= 0.9; diff --git a/game.js b/game.js index 673ce55..ff47223 100644 --- a/game.js +++ b/game.js @@ -201,7 +201,7 @@ class Game extends GameBasic { that.entities.push(new NPC(false, that)) } - for (let i = 0; i < 18; i++) { + for (let i = 0; i < 50; i++) { that.entities.push(new Shooter(false, that)) }