From f1872c74ad1e97980f03c843e5688716a0ff5291 Mon Sep 17 00:00:00 2001 From: Nyeogmi Date: Sat, 22 Feb 2025 22:01:27 -0800 Subject: [PATCH] Hacky movement issue fix Maybe Kistaro can do better? This design has the problem that like most designs that don't move the player to a contact point, walking into a wall causes vibration. --- src/huntmode.ts | 65 +++++++++++++++++++++++++++++-------------------- src/pickups.ts | 10 +++----- src/thralls.ts | 34 +++++++++++++++++++------- 3 files changed, 68 insertions(+), 41 deletions(-) diff --git a/src/huntmode.ts b/src/huntmode.ts index 3ae9d03..881144d 100644 --- a/src/huntmode.ts +++ b/src/huntmode.ts @@ -196,34 +196,11 @@ export class HuntMode { this.faceLeft = false; } - let szX = 0.5; - let szY = 0.5; + let szX = 0.1; + let szY = 0.1; this.velocity = new Point(dx, dy); - // try to push us away from walls if we're close - for (let offset of CARDINAL_DIRECTIONS.values()) { - let bigBbox = new Rect( - this.floatingPlayer - .offset(offset.scale(new Size(0.12, 0.12))) - .offset(new Point(-szX / 2, -szY / 2)), - new Size(szX, szY), - ); - - let hitsWall = false; - for (let cell of bigBbox.overlappedCells(new Size(1, 1)).values()) { - if (this.#blocksMovement(cell.top)) { - hitsWall = true; - break; - } - } - if (hitsWall) { - this.velocity = this.velocity.offset( - offset.scale(new Point(0.005, 0.005)).negate(), - ); - } - } - let origin = new Point(szX / 2, szY / 2); let bbox = new Rect( this.floatingPlayer.offset(origin.negate()), @@ -233,8 +210,44 @@ export class HuntMode { this.isBlocked(b), ); this.floatingPlayer = this.floatingPlayer.offset(displacement); - this.velocity = dxy; + // this.velocity = dxy; getPlayerProgress().spendBlood(displacement.distance(new Point(0, 0)) * 10); + + // try to push us away from walls if we're close + for (let { dist, strength } of [ + { dist: 0.12, strength: 0.02 }, + { dist: 0.22, strength: 0.015 }, + { dist: 0.32, strength: 0.01 }, + ].values()) { + for (let offset of CARDINAL_DIRECTIONS.values()) { + let bigBbox = new Rect( + this.floatingPlayer + .offset(offset.scale(new Size(dist, dist))) + .offset(new Point(-szX / 2, -szY / 2)), + new Size(szX, szY), + ); + + let hitsWall = false; + for (let cell of bigBbox.overlappedCells(new Size(1, 1)).values()) { + if (this.#blocksMovement(cell.top)) { + hitsWall = true; + break; + } + } + if (hitsWall) { + bbox = new Rect( + this.floatingPlayer.offset(origin.negate()), + new Size(szX, szY), + ); + let { displacement } = displace( + bbox, + offset.scale(new Point(strength, strength)).negate(), + (b: Rect) => this.isBlocked(b), + ); + this.floatingPlayer = this.floatingPlayer.offset(displacement); + } + } + } } #updateFov() { diff --git a/src/pickups.ts b/src/pickups.ts index 460bd98..5316f71 100644 --- a/src/pickups.ts +++ b/src/pickups.ts @@ -665,12 +665,10 @@ export class ThrallCollectionPlatePickup { } else { callbacks = new StatPickupCallbacks(what); } - if (callbacks == null) { return; } - let floater = new Floater( - xy.offset(new Point(0.5, 0.5)), - 50, - callbacks, - ); + if (callbacks == null) { + return; + } + let floater = new Floater(xy.offset(new Point(0.5, 0.5)), 50, callbacks); let speed = 0.015; let direction = Math.random() * Math.PI * 2; floater.velocity = new Point( diff --git a/src/thralls.ts b/src/thralls.ts index 84ed49c..602a390 100644 --- a/src/thralls.ts +++ b/src/thralls.ts @@ -22,7 +22,7 @@ import { sprThrallStealth, } from "./sprites.ts"; import { Sprite } from "./engine/internal/sprite.ts"; -import {Stat} from "./datatypes.ts"; +import { Stat } from "./datatypes.ts"; export type Thrall = { id: number; @@ -133,7 +133,9 @@ export let thrallParty = table.add({ '"Oh, that? Yeah, I won it." And then lost it, apparently.\n\nHe\'s elated. He will never leave.', rewardMessage: "Garrett showers you with INT!", rewardCallback: (spawn) => { - for (let i = 0; i < 30; i++) { spawn("INT"); } + for (let i = 0; i < 30; i++) { + spawn("INT"); + } }, lifeStageText: { fresh: { @@ -205,7 +207,9 @@ export let thrallLore = table.add({ "Lupin looks at his own reflection -- with interest, confusion, dismissal, and then deep satisfaction. He loves it. He will never leave.", rewardMessage: "Lupin showers you with AGI!", rewardCallback: (spawn) => { - for (let i = 0; i < 30; i++) { spawn("AGI"); } + for (let i = 0; i < 30; i++) { + spawn("AGI"); + } }, lifeStageText: { fresh: { @@ -274,8 +278,12 @@ export let thrallBat = table.add({ 'Monica salivates. "This is... this is... simply exquisite!"\n\nShe is happy. She will never leave.', rewardMessage: "Monica showers you with CHA and INT!", rewardCallback: (spawn) => { - for (let i = 0; i < 15; i++) { spawn("CHA"); } - for (let i = 0; i < 15; i++) { spawn("INT"); } + for (let i = 0; i < 15; i++) { + spawn("CHA"); + } + for (let i = 0; i < 15; i++) { + spawn("INT"); + } }, lifeStageText: { fresh: { @@ -344,7 +352,9 @@ export let thrallCharm = table.add({ "Renfield inhales sharply and widens his stance, trying to hide his physical reaction to your face. He is elated and will never leave.", rewardMessage: "Renfield showers you with PSI!", rewardCallback: (spawn) => { - for (let i = 0; i < 24; i++) { spawn("PSI"); } + for (let i = 0; i < 24; i++) { + spawn("PSI"); + } }, lifeStageText: { fresh: { @@ -411,8 +421,12 @@ export let thrallStealth = table.add({ "\"That? That's not mine.\" But she wants it. Now it's hers. She will never leave.", rewardMessage: "Narthyss showers you with CHA and AGI!", rewardCallback: (spawn) => { - for (let i = 0; i < 15; i++) { spawn("CHA"); } - for (let i = 0; i < 15; i++) { spawn("AGI"); } + for (let i = 0; i < 15; i++) { + spawn("CHA"); + } + for (let i = 0; i < 15; i++) { + spawn("AGI"); + } }, lifeStageText: { fresh: { @@ -480,7 +494,9 @@ export let thrallStare = table.add({ "Ridley admires the gear but -- to your surprise -- refuses to jam it into its brain.\n\nThe pup is elated and will never leave.", rewardMessage: "Ridley showers you with EXP!", rewardCallback: (spawn) => { - for (let i = 0; i < 6; i++) { spawn("EXP"); } + for (let i = 0; i < 6; i++) { + spawn("EXP"); + } }, lifeStageText: { fresh: {