some fixes

This commit is contained in:
biglyderv 2024-10-01 18:41:44 -04:00
parent 3d4f76d6c8
commit be75df1d23
No known key found for this signature in database
GPG key ID: 33AC87E9ACE66954
3 changed files with 31 additions and 19 deletions

View file

@ -17,7 +17,12 @@ class NPC {
handleTick(game) {
let { entities } = game;
let rEntity = entities[Math.floor(Math.random() * entities.length)];
let rEntity, i = 0;
while ((!rEntity || rEntity.type != 'Player') && i < 100) {
rEntity = entities[Math.floor(Math.random() * entities.length)];
i++;
}
this.vel.x += (rEntity.pos.x - this.pos.x) * 0.0001;
this.vel.y += (rEntity.pos.y - this.pos.y) * 0.0001;

View file

@ -68,6 +68,8 @@ class Player {
ent.ticks++;
let velness = Math.sqrt(ent.vel.x ** 2 + ent.vel.y ** 2);
for (let target of entities) {
if (target.you == ent.you) continue;
@ -79,7 +81,7 @@ class Player {
dp /= Math.sqrt(dist + 0.1);
if (Math.sqrt(dist) < 128 && 1 / dp < -0.2) {
if (target.type == 'NPC') {
if (target.type == 'NPC' && velness > 0.2) {
ent.isMenu = true;
}
if (target.immortal) continue;

View file

@ -13,7 +13,7 @@ const legalTypes = {
Player,
NPC
}
const options = [
const emojis = [
'Troll',
'Exit',
'Elec Piano Loop',
@ -98,6 +98,12 @@ class Game extends GameBasic {
ctx.restore();
if (player.health <= 0 || player.isMenu) {
this.doMenu();
}
}
doMenu() {
let { ctx, player } = this;
ctx.fillStyle = 'rgba(0,0,0,0.5)';
ctx.fillRect(0, 0, cs, cs);
ctx.fillStyle = 'rgb(255,255,255)';
@ -106,11 +112,10 @@ class Game extends GameBasic {
ctx.font = "bold 48px sans-serif";
if (player.health <= 0) ctx.fillText('You died! Click to respawn', cs / 2, cs / 2);
if (player.isMenu) {
let r = Math.floor(Math.abs(player.rot / 1.2) % options.length);
ctx.fillText(`Click to react ${options[r]}`, cs / 2, cs / 2)
let r = Math.floor(Math.abs(player.rot / 1.2) % emojis.length);
ctx.fillText(`Click to react ${emojis[r]}`, cs / 2, cs / 2)
ctx.font = "bold 16px sans-serif";
ctx.fillText(`Wait for options ${options.join(', ')}`, cs / 2, cs / 2 + 50)
}
ctx.fillText(`Wait for emojis ${emojis.join(', ')}`, cs / 2, cs / 2 + 50)
}
}
click() {
@ -121,7 +126,7 @@ class Game extends GameBasic {
this.player = new Player(false, true);
this.entities.push(this.player);
} else if (player.isMenu) {
player.r = Math.floor(Math.abs(player.rot / 1.2) % options.length);
player.r = Math.floor(Math.abs(player.rot / 1.2) % emojis.length);
player.isMenu = false;
this.sync();
} else {
@ -147,7 +152,7 @@ class Game extends GameBasic {
let type = (Object.keys(legalTypes).indexOf(x.type) == -1) ? Player : legalTypes[x.type];
x.handleTick = type.prototype.handleTick;
if (x.r != 1) {
let a = new Audio(`assets/${options[x.r]}.wav`);
let a = new Audio(`assets/${emojis[x.r]}.wav`);
a.addEventListener('ended', () => {
if (x.you == you) {
that.player.playing = false;