Badges on available manor objects
This commit is contained in:
		| @@ -1,8 +1,16 @@ | ||||
| import {Point} from "./engine/datatypes.ts"; | ||||
| import {Point, Size} from "./engine/datatypes.ts"; | ||||
| import {DrawPile} from "./drawpile.ts"; | ||||
| import {D} from "./engine/public.ts"; | ||||
| import {sprThrallLore} from "./sprites.ts"; | ||||
| import {BG_INSET, BG_WALL_OR_UNREVEALED, FG_BOLD, FG_MOULDING, FG_TEXT, FG_TOO_EXPENSIVE,} from "./colors.ts"; | ||||
| import { | ||||
|   BG_INSET, | ||||
|   BG_WALL_OR_UNREVEALED, | ||||
|   FG_BOLD, | ||||
|   FG_MOULDING, | ||||
|   FG_TEXT, | ||||
|   FG_TEXT_ENDORSED, | ||||
|   FG_TOO_EXPENSIVE, | ||||
| } from "./colors.ts"; | ||||
| import {getPlayerProgress} from "./playerprogress.ts"; | ||||
| import {Architecture, LoadedNewMap} from "./newmap.ts"; | ||||
| import {FLOOR_CELL_SIZE, GridArt} from "./gridart.ts"; | ||||
| @@ -112,6 +120,8 @@ export class HuntMode { | ||||
|     } | ||||
|     this.#drawPlayer(globalOffset); | ||||
|  | ||||
|     this.#drawBadges(globalOffset); | ||||
|  | ||||
|     this.drawpile.executeOnClick(); | ||||
|   } | ||||
|  | ||||
| @@ -134,9 +144,7 @@ export class HuntMode { | ||||
|         ); | ||||
|       }, | ||||
|       ([x, y]: [number, number]) => { | ||||
|         let dx = x - this.player.x; | ||||
|         let dy = y - this.player.y; | ||||
|         if (dx * dx + dy * dy >= 13) { | ||||
|         if (!this.#inVisibilityRange(x, y)) { | ||||
|           return; | ||||
|         } | ||||
|         this.map.get(new Point(x, y)).revealed = true; | ||||
| @@ -144,6 +152,13 @@ export class HuntMode { | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   #inVisibilityRange(x: number, y: number): boolean { | ||||
|     let dx = x - this.player.x; | ||||
|     let dy = y - this.player.y; | ||||
|     return dx * dx + dy * dy < 13; | ||||
|  | ||||
|   } | ||||
|  | ||||
|   #draw() { | ||||
|     this.drawpile.draw(); | ||||
|   } | ||||
| @@ -208,11 +223,9 @@ export class HuntMode { | ||||
|           return; | ||||
|         } | ||||
|  | ||||
|         if (cost != null) { | ||||
|           getPlayerProgress().spendBlood(cost); | ||||
|           this.movePlayerTo(mapPosition); | ||||
|           getCheckModal().show(null, null); | ||||
|         } | ||||
|         getPlayerProgress().spendBlood(cost); | ||||
|         this.movePlayerTo(mapPosition); | ||||
|         getCheckModal().show(null, null); | ||||
|       }, | ||||
|     ); | ||||
|  | ||||
| @@ -285,13 +298,51 @@ export class HuntMode { | ||||
|       this.player.x * FLOOR_CELL_SIZE.w, | ||||
|       this.player.y * FLOOR_CELL_SIZE.h, | ||||
|     ).offset(globalOffset.negate()); | ||||
|     this.drawpile.add(this.player.y, () => { | ||||
|     this.drawpile.add(0, () => { | ||||
|       D.drawSprite(sprThrallLore, cellOffset, 1, { | ||||
|         xScale: this.faceLeft ? -2 : 2, | ||||
|         yScale: 2, | ||||
|       }); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   #drawBadges(globalOffset: Point) { | ||||
|     for (let y = 0; y < this.map.size.h; y += 1) { | ||||
|       for (let x = 0; x < this.map.size.w; x += 1) { | ||||
|         this.#drawBadge(globalOffset, new Point(x, y)); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   #drawBadge(globalOffset: Point, cell: Point) { | ||||
|     if (!this.map.get(cell).pickup?.advertisesBadge()) { return; } | ||||
|  | ||||
|     // NOTE: This doesn't think of visibility at all | ||||
|     let badgePosition = cell.offset(new Size(-0.25, -0.25)); | ||||
|     badgePosition = badgePosition.offset(new Point( | ||||
|       Math.cos(cell.x * 2 + this.frame / 720 * 2 * Math.PI) * 0.05, | ||||
|       Math.sin(cell.y + this.frame / 480 * 2 * Math.PI) * 0.10 | ||||
|     )); | ||||
|     let cellOffset = new Point( | ||||
|       badgePosition.x * FLOOR_CELL_SIZE.w, | ||||
|       badgePosition.y * FLOOR_CELL_SIZE.h | ||||
|     ).offset(globalOffset.negate()); | ||||
|  | ||||
|     let center = new Point(192, 192); | ||||
|     cellOffset = cellOffset.offset(center.negate()); | ||||
|  | ||||
|     let dist = Math.sqrt(cellOffset.x * cellOffset.x + cellOffset.y * cellOffset.y); | ||||
|     let ang = Math.atan2(cellOffset.y, cellOffset.x) | ||||
|     // console.log(dist, ang); | ||||
|     dist = Math.min(dist, 128); | ||||
|     cellOffset = new Point(Math.cos(ang) * dist, Math.sin(ang) * dist); | ||||
|     cellOffset = cellOffset.offset(center); | ||||
|  | ||||
|     this.drawpile.add(1024, () => { | ||||
|       // draw badge | ||||
|       D.fillRect(cellOffset.offset(new Point(-4, -4)), new Size(8, 8), FG_TEXT_ENDORSED) | ||||
|     }); | ||||
|   } | ||||
| } | ||||
|  | ||||
| let active: HuntMode | null = null; | ||||
|   | ||||
| @@ -1,21 +1,16 @@ | ||||
| import { getThralls, ItemStage, LifeStage, Thrall } from "./thralls.ts"; | ||||
| import { CellView, CheckData } from "./newmap.ts"; | ||||
| import { getPlayerProgress } from "./playerprogress.ts"; | ||||
| import { getHuntMode, HuntMode, initHuntMode } from "./huntmode.ts"; | ||||
| import { generateMap } from "./mapgen.ts"; | ||||
| import { ALL_STATS, Stat } from "./datatypes.ts"; | ||||
| import { D } from "./engine/public.ts"; | ||||
| import { | ||||
|   sprLadder, | ||||
|   sprLock, | ||||
|   sprResourcePickup, | ||||
|   sprStatPickup, | ||||
| } from "./sprites.ts"; | ||||
| import { GridArt } from "./gridart.ts"; | ||||
| import { getCheckModal } from "./checkmodal.ts"; | ||||
| import { Point, Size } from "./engine/datatypes.ts"; | ||||
| import { choose } from "./utils.ts"; | ||||
| import { FG_TEXT } from "./colors.ts"; | ||||
| import {getThralls, ItemStage, LifeStage, Thrall} from "./thralls.ts"; | ||||
| import {CellView, CheckData} from "./newmap.ts"; | ||||
| import {getPlayerProgress} from "./playerprogress.ts"; | ||||
| import {getHuntMode, HuntMode, initHuntMode} from "./huntmode.ts"; | ||||
| import {generateMap} from "./mapgen.ts"; | ||||
| import {ALL_STATS, Stat} from "./datatypes.ts"; | ||||
| import {D} from "./engine/public.ts"; | ||||
| import {sprLadder, sprLock, sprResourcePickup, sprStatPickup,} from "./sprites.ts"; | ||||
| import {GridArt} from "./gridart.ts"; | ||||
| import {getCheckModal} from "./checkmodal.ts"; | ||||
| import {Point, Size} from "./engine/datatypes.ts"; | ||||
| import {choose} from "./utils.ts"; | ||||
| import {FG_TEXT} from "./colors.ts"; | ||||
|  | ||||
| export type Pickup = | ||||
|   | LockPickup | ||||
| @@ -37,6 +32,10 @@ export class LockPickup { | ||||
|     return 0; | ||||
|   } | ||||
|  | ||||
|   advertisesBadge() { | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   advertisesClickable() { | ||||
|     return true; | ||||
|   } | ||||
| @@ -72,6 +71,10 @@ export class StatPickup { | ||||
|     return 100; | ||||
|   } | ||||
|  | ||||
|   advertisesBadge() { | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   advertisesClickable() { | ||||
|     return true; | ||||
|   } | ||||
| @@ -105,6 +108,10 @@ export class ExperiencePickup { | ||||
|     return 100; | ||||
|   } | ||||
|  | ||||
|   advertisesBadge() { | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   advertisesClickable() { | ||||
|     return true; | ||||
|   } | ||||
| @@ -138,6 +145,10 @@ export class LadderPickup { | ||||
|     return 0; | ||||
|   } | ||||
|  | ||||
|   advertisesBadge() { | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   advertisesClickable() { | ||||
|     return true; | ||||
|   } | ||||
| @@ -172,6 +183,10 @@ export class ThrallPickup { | ||||
|     return 0; | ||||
|   } | ||||
|  | ||||
|   advertisesBadge() { | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   advertisesClickable() { | ||||
|     return true; | ||||
|   } | ||||
| @@ -210,6 +225,10 @@ export class ThrallPosterPickup { | ||||
|     return 0; | ||||
|   } | ||||
|  | ||||
|   advertisesBadge() { | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   advertisesClickable() { | ||||
|     return true; | ||||
|   } | ||||
| @@ -236,10 +255,12 @@ export class ThrallPosterPickup { | ||||
|  | ||||
| export class ThrallRecruitedPickup { | ||||
|   thrall: Thrall; | ||||
|   spokenTo: boolean; | ||||
|   bitten: boolean; | ||||
|  | ||||
|   constructor(thrall: Thrall) { | ||||
|     this.thrall = thrall; | ||||
|     this.spokenTo = false; | ||||
|     this.bitten = false; | ||||
|   } | ||||
|  | ||||
| @@ -247,6 +268,10 @@ export class ThrallRecruitedPickup { | ||||
|     return 0; | ||||
|   } | ||||
|  | ||||
|   advertisesBadge() { | ||||
|     return !this.spokenTo; | ||||
|   } | ||||
|  | ||||
|   advertisesClickable() { | ||||
|     return !this.bitten; | ||||
|   } | ||||
| @@ -277,6 +302,7 @@ export class ThrallRecruitedPickup { | ||||
|   } | ||||
|  | ||||
|   onClick(_cell: CellView): boolean { | ||||
|     this.spokenTo = true; | ||||
|     if (this.bitten) { | ||||
|       return true; | ||||
|     } | ||||
| @@ -336,6 +362,23 @@ export class ThrallCollectionPlatePickup { | ||||
|     return 0; | ||||
|   } | ||||
|  | ||||
|   advertisesBadge() { | ||||
|     let lifeStage = getPlayerProgress().getThrallLifeStage(this.thrall); | ||||
|     let itemStage = getPlayerProgress().getThrallItemStage(this.thrall); | ||||
|     if (itemStage == ItemStage.Obtained) { | ||||
|       // the player should deliver it! make sure they see a badge informing them of that | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
|     if (itemStage == ItemStage.Delivered && lifeStage != LifeStage.Dead && !this.rewarded) { | ||||
|       // the player should collect it! make sure they see a badge informing them of that | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
|     // OK, the only interaction is to get a hint | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   advertisesClickable() { | ||||
|     return !this.rewarded; | ||||
|   } | ||||
| @@ -433,6 +476,10 @@ export class ThrallItemPickup { | ||||
|     return 0; | ||||
|   } | ||||
|  | ||||
|   advertisesBadge() { | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   advertisesClickable() { | ||||
|     return true; | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user