Costing and feel-related movement fixes
This commit is contained in:
		| @@ -105,6 +105,12 @@ export class Point { | ||||
|       lerp(y, Math.floor(this.y), Math.ceil(this.y)), | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   distance(other: Point) { | ||||
|     let dx = other.x - this.x; | ||||
|     let dy = other.y - this.y; | ||||
|     return Math.sqrt(dx * dx + dy * dy); | ||||
|   } | ||||
| } | ||||
|  | ||||
| export class Size { | ||||
|   | ||||
| @@ -62,16 +62,6 @@ export class HuntMode { | ||||
|     return this.depth; | ||||
|   } | ||||
|  | ||||
|   // == update logic == | ||||
|   #collectResources() { | ||||
|     let cell = this.map.get(this.gridifiedPlayer); | ||||
|  | ||||
|     let pickup = cell.pickup; | ||||
|     if (pickup != null) { | ||||
|       cell.pickup = null; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   #computeCostToClick(mapPosition: Point): number | null { | ||||
|     let present = this.map.get(mapPosition); | ||||
|  | ||||
| @@ -95,21 +85,6 @@ export class HuntMode { | ||||
|     return pickup.computeCostToClick(); | ||||
|   } | ||||
|  | ||||
|   /* | ||||
|   movePlayerTo(newPosition: Point) { | ||||
|     let oldX = this.player.x; | ||||
|     let newX = newPosition.x; | ||||
|     this.player = newPosition; | ||||
|     if (newX < oldX) { | ||||
|       this.faceLeft = true; | ||||
|     } | ||||
|     if (oldX < newX) { | ||||
|       this.faceLeft = false; | ||||
|     } | ||||
|     this.#collectResources(); | ||||
|   } | ||||
|    */ | ||||
|  | ||||
|   getZoneLabel(): string | null { | ||||
|     return this.map.get(this.gridifiedPlayer).zoneLabel; | ||||
|   } | ||||
| @@ -155,29 +130,45 @@ export class HuntMode { | ||||
|     let dx = this.velocity.x; | ||||
|     let dy = this.velocity.y; | ||||
|  | ||||
|     let amt = 0.005; | ||||
|     let amt = 0.006; | ||||
|  | ||||
|     if (I.isKeyDown("w")) { | ||||
|       dy -= amt; | ||||
|     } | ||||
|     if (I.isKeyDown("s")) { | ||||
|       dy += amt; | ||||
|     } | ||||
|     if (I.isKeyDown("a")) { | ||||
|       dx -= amt; | ||||
|     } | ||||
|     if (I.isKeyDown("d")) { | ||||
|       dx += amt; | ||||
|     if (getPlayerProgress().getBlood() > 0) { | ||||
|       if (I.isKeyDown("w")) { | ||||
|         dy -= amt; | ||||
|       } | ||||
|       if (I.isKeyDown("s")) { | ||||
|         dy += amt; | ||||
|       } | ||||
|       if (I.isKeyDown("a")) { | ||||
|         dx -= amt; | ||||
|       } | ||||
|       if (I.isKeyDown("d")) { | ||||
|         dx += amt; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     dx *= 0.9; | ||||
|     dy *= 0.9; | ||||
|     dx *= 0.87; | ||||
|     dy *= 0.87; | ||||
|  | ||||
|     if (Math.abs(dx) < 0.0001) { | ||||
|       dx = 0; | ||||
|     } | ||||
|     if (Math.abs(dy) < 0.0001) { | ||||
|       dy = 0; | ||||
|     } | ||||
|     if (dx < 0) { | ||||
|       this.faceLeft = true; | ||||
|     } | ||||
|     if (dx > 0) { | ||||
|       this.faceLeft = false; | ||||
|     } | ||||
|  | ||||
|     this.velocity = new Point(dx, dy); | ||||
|     let nSteps = 40; | ||||
|     let szX = 0.5; | ||||
|     let szY = 0.5; | ||||
|     let szY = 0.75; | ||||
|  | ||||
|     let initialXy = this.floatingPlayer; | ||||
|     for (let i = 0; i < nSteps; i++) { | ||||
|       let oldXy = this.floatingPlayer; | ||||
|       let newXy = oldXy.offset(new Point(this.velocity.x / nSteps, 0)); | ||||
| @@ -211,6 +202,8 @@ export class HuntMode { | ||||
|  | ||||
|       this.floatingPlayer = newXy; | ||||
|     } | ||||
|     let finalXy = this.floatingPlayer; | ||||
|     getPlayerProgress().spendBlood(finalXy.distance(initialXy) * 10); | ||||
|   } | ||||
|  | ||||
|   #updateFov() { | ||||
| @@ -296,7 +289,7 @@ export class HuntMode { | ||||
|         if (cost == null) { | ||||
|           highlighted = false; | ||||
|         } | ||||
|         if (!(pickup?.advertisesClickable() ?? true)) { | ||||
|         if (!pickup?.advertisesClickable()) { | ||||
|           highlighted = false; | ||||
|         } | ||||
|  | ||||
| @@ -321,12 +314,6 @@ export class HuntMode { | ||||
|           if (pickup?.onClick(cellData)) { | ||||
|             return; | ||||
|           } | ||||
|  | ||||
|           getPlayerProgress().spendBlood(cost); | ||||
|  | ||||
|           // TODO: This isn't a thing anymore | ||||
|           // this.movePlayerTo(mapPosition); | ||||
|           // getCheckModal().show(null, null); | ||||
|         }, | ||||
|         onSqueeze: () => { | ||||
|           // the cost _gates_ squeezes | ||||
|   | ||||
| @@ -83,7 +83,7 @@ export class BreakableBlockPickup { | ||||
|   } | ||||
|  | ||||
|   computeCostToClick() { | ||||
|     return 100; | ||||
|     return this.callbacks.cost; | ||||
|   } | ||||
|  | ||||
|   advertisesBadge() { | ||||
| @@ -121,6 +121,7 @@ export class BreakableBlockPickup { | ||||
|  | ||||
|   update(cellData: CellView) { | ||||
|     if (this.breakProgress >= 1.0) { | ||||
|       getPlayerProgress().spendBlood(this.callbacks.cost); | ||||
|       cellData.pickup = null; | ||||
|       this.callbacks.obtain(); | ||||
|     } | ||||
| @@ -147,6 +148,10 @@ export class StatPickupCallbacks { | ||||
|     this.#stat = stat; | ||||
|   } | ||||
|  | ||||
|   get cost(): number { | ||||
|     return 100; | ||||
|   } | ||||
|  | ||||
|   obtain() { | ||||
|     getPlayerProgress().add(this.#stat, 1); | ||||
|     getPlayerProgress().purloinItem(); | ||||
| @@ -168,6 +173,10 @@ export class StatPickupCallbacks { | ||||
| export class ExperiencePickupCallbacks { | ||||
|   constructor() {} | ||||
|  | ||||
|   get cost(): number { | ||||
|     return 100; | ||||
|   } | ||||
|  | ||||
|   obtain() { | ||||
|     getPlayerProgress().addExperience(250); | ||||
|     getPlayerProgress().purloinItem(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user