change game mechanics a lot

This commit is contained in:
biglyderv 2024-11-25 14:14:21 -05:00
parent f0afee03ab
commit 2b88690cf5
3 changed files with 36 additions and 18 deletions

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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))
}