create-threenative 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +283 -0
- package/dist/threenative.d.ts +6 -0
- package/dist/threenative.js +757 -0
- package/package.json +44 -0
- package/templates/action-rpg/.mcp.json +16 -0
- package/templates/action-rpg/AGENTS.md +40 -0
- package/templates/action-rpg/CLAUDE.md +42 -0
- package/templates/action-rpg/index.html +13 -0
- package/templates/action-rpg/kit.json +7 -0
- package/templates/action-rpg/package.json +47 -0
- package/templates/action-rpg/playtests/combat.playtest.json +61 -0
- package/templates/action-rpg/playtests/fail.playtest.json +21 -0
- package/templates/action-rpg/playtests/inventory.playtest.json +111 -0
- package/templates/action-rpg/playtests/progress.playtest.json +99 -0
- package/templates/action-rpg/playtests/survives.playtest.json +32 -0
- package/templates/action-rpg/playtests/win.playtest.json +30 -0
- package/templates/action-rpg/public/favicon.svg +5 -0
- package/templates/action-rpg/src/abilities/Ability.ts +45 -0
- package/templates/action-rpg/src/entities/Enemy.ts +143 -0
- package/templates/action-rpg/src/entities/Player.ts +83 -0
- package/templates/action-rpg/src/game.ts +40 -0
- package/templates/action-rpg/src/items/Inventory.ts +163 -0
- package/templates/action-rpg/src/loot/drops.ts +40 -0
- package/templates/action-rpg/src/main.ts +15 -0
- package/templates/action-rpg/src/physics.ts +40 -0
- package/templates/action-rpg/src/playtest-events.ts +15 -0
- package/templates/action-rpg/src/progress.ts +35 -0
- package/templates/action-rpg/src/render/camera.ts +26 -0
- package/templates/action-rpg/src/render/lighting.ts +30 -0
- package/templates/action-rpg/src/render/loading.ts +90 -0
- package/templates/action-rpg/src/render/materials.ts +40 -0
- package/templates/action-rpg/src/render/palette.ts +9 -0
- package/templates/action-rpg/src/render/postprocessing.ts +18 -0
- package/templates/action-rpg/src/render/shapes.ts +110 -0
- package/templates/action-rpg/src/render/sky.ts +18 -0
- package/templates/action-rpg/src/render/types.ts +3 -0
- package/templates/action-rpg/src/scenes/Boot.ts +12 -0
- package/templates/action-rpg/src/scenes/Play.ts +449 -0
- package/templates/action-rpg/src/state.ts +40 -0
- package/templates/action-rpg/src/stats/StatBlock.ts +57 -0
- package/templates/action-rpg/src/style.css +32 -0
- package/templates/action-rpg/src/ui/AbilityBar.tsx +28 -0
- package/templates/action-rpg/src/ui/App.tsx +21 -0
- package/templates/action-rpg/src/ui/CharacterPanel.tsx +31 -0
- package/templates/action-rpg/src/ui/Hud.tsx +29 -0
- package/templates/action-rpg/src/ui/InventoryPanel.tsx +37 -0
- package/templates/action-rpg/tailwind.config.ts +7 -0
- package/templates/action-rpg/threenative.config.ts +29 -0
- package/templates/action-rpg/tsconfig.json +17 -0
- package/templates/action-rpg/vite.config.ts +8 -0
- package/templates/defense/.mcp.json +16 -0
- package/templates/defense/AGENTS.md +53 -0
- package/templates/defense/CLAUDE.md +55 -0
- package/templates/defense/README.md +9 -0
- package/templates/defense/index.html +13 -0
- package/templates/defense/kit.json +7 -0
- package/templates/defense/package.json +46 -0
- package/templates/defense/playtests/leak.playtest.json +18 -0
- package/templates/defense/playtests/placement.playtest.json +40 -0
- package/templates/defense/playtests/scan.playtest.json +20 -0
- package/templates/defense/playtests/survive.playtest.json +26 -0
- package/templates/defense/playtests/survives.playtest.json +36 -0
- package/templates/defense/public/favicon.svg +5 -0
- package/templates/defense/src/attackers/Attacker.ts +104 -0
- package/templates/defense/src/board/Route.ts +80 -0
- package/templates/defense/src/economy.ts +36 -0
- package/templates/defense/src/entities/Player.ts +44 -0
- package/templates/defense/src/game.ts +30 -0
- package/templates/defense/src/main.ts +15 -0
- package/templates/defense/src/physics.ts +43 -0
- package/templates/defense/src/placement/Buildable.ts +49 -0
- package/templates/defense/src/playtest-events.ts +15 -0
- package/templates/defense/src/render/camera.ts +10 -0
- package/templates/defense/src/render/lighting.ts +32 -0
- package/templates/defense/src/render/loading.ts +89 -0
- package/templates/defense/src/render/materials.ts +13 -0
- package/templates/defense/src/render/palette.ts +21 -0
- package/templates/defense/src/render/postprocessing.ts +14 -0
- package/templates/defense/src/render/shapes.ts +89 -0
- package/templates/defense/src/render/sky.ts +45 -0
- package/templates/defense/src/scenes/Boot.ts +12 -0
- package/templates/defense/src/scenes/Defense.ts +165 -0
- package/templates/defense/src/state.ts +50 -0
- package/templates/defense/src/style.css +32 -0
- package/templates/defense/src/towers/Tower.ts +96 -0
- package/templates/defense/src/towers/targeting.ts +53 -0
- package/templates/defense/src/ui/App.tsx +17 -0
- package/templates/defense/src/ui/Hud.tsx +61 -0
- package/templates/defense/src/ui/Menu.tsx +7 -0
- package/templates/defense/src/waves.ts +40 -0
- package/templates/defense/tailwind.config.ts +1 -0
- package/templates/defense/threenative.config.ts +29 -0
- package/templates/defense/tsconfig.json +17 -0
- package/templates/defense/vite.config.ts +5 -0
- package/templates/minimal/.mcp.json +16 -0
- package/templates/minimal/AGENTS.md +400 -0
- package/templates/minimal/CLAUDE.md +402 -0
- package/templates/minimal/assets/.gitkeep +0 -0
- package/templates/minimal/index.html +14 -0
- package/templates/minimal/kit.json +7 -0
- package/templates/minimal/package.json +40 -0
- package/templates/minimal/playtests/play.playtest.json +32 -0
- package/templates/minimal/playtests/survives.playtest.json +32 -0
- package/templates/minimal/public/.gitkeep +0 -0
- package/templates/minimal/public/favicon.svg +4 -0
- package/templates/minimal/public/icon.png +0 -0
- package/templates/minimal/src/entities/Player.ts +66 -0
- package/templates/minimal/src/game.ts +28 -0
- package/templates/minimal/src/main.ts +17 -0
- package/templates/minimal/src/render/camera.ts +11 -0
- package/templates/minimal/src/render/hud.ts +53 -0
- package/templates/minimal/src/render/lighting.ts +46 -0
- package/templates/minimal/src/render/loading.ts +113 -0
- package/templates/minimal/src/render/materials.ts +16 -0
- package/templates/minimal/src/render/palette.ts +9 -0
- package/templates/minimal/src/render/postprocessing.ts +20 -0
- package/templates/minimal/src/render/sky.ts +41 -0
- package/templates/minimal/src/scenes/Boot.ts +5 -0
- package/templates/minimal/src/scenes/Play.ts +65 -0
- package/templates/minimal/src/state.ts +1 -0
- package/templates/minimal/src/style.css +41 -0
- package/templates/minimal/threenative.config.ts +32 -0
- package/templates/minimal/tsconfig.json +16 -0
- package/templates/minimal/vite.config.ts +3 -0
- package/templates/platformer/.mcp.json +16 -0
- package/templates/platformer/AGENTS.md +199 -0
- package/templates/platformer/CLAUDE.md +201 -0
- package/templates/platformer/assets/.gitkeep +0 -0
- package/templates/platformer/index.html +13 -0
- package/templates/platformer/kit.json +7 -0
- package/templates/platformer/package.json +50 -0
- package/templates/platformer/playtests/avoidance.playtest.json +23 -0
- package/templates/platformer/playtests/buffer.playtest.json +17 -0
- package/templates/platformer/playtests/chase.playtest.json +21 -0
- package/templates/platformer/playtests/collect.playtest.json +56 -0
- package/templates/platformer/playtests/collision-layers.playtest.json +36 -0
- package/templates/platformer/playtests/coyote.playtest.json +21 -0
- package/templates/platformer/playtests/damage.playtest.json +31 -0
- package/templates/platformer/playtests/dash.playtest.json +21 -0
- package/templates/platformer/playtests/jump.playtest.json +21 -0
- package/templates/platformer/playtests/oneway.playtest.json +17 -0
- package/templates/platformer/playtests/patrol.playtest.json +13 -0
- package/templates/platformer/playtests/performance.playtest.json +21 -0
- package/templates/platformer/playtests/physics.playtest.json +14 -0
- package/templates/platformer/playtests/respawn.playtest.json +31 -0
- package/templates/platformer/playtests/stomp-rise.playtest.json +41 -0
- package/templates/platformer/playtests/stomp.playtest.json +34 -0
- package/templates/platformer/playtests/survives.playtest.json +32 -0
- package/templates/platformer/playtests/terminal-loop-fail.playtest.json +29 -0
- package/templates/platformer/playtests/terminal-loop-win.playtest.json +52 -0
- package/templates/platformer/public/.gitkeep +0 -0
- package/templates/platformer/public/favicon.svg +4 -0
- package/templates/platformer/public/icon.png +0 -0
- package/templates/platformer/src/entities/Character.ts +218 -0
- package/templates/platformer/src/entities/Chaser.ts +118 -0
- package/templates/platformer/src/entities/Patrol.ts +88 -0
- package/templates/platformer/src/entities/Pickup.ts +72 -0
- package/templates/platformer/src/game.ts +27 -0
- package/templates/platformer/src/level/Checkpoints.ts +66 -0
- package/templates/platformer/src/level/Platform.ts +34 -0
- package/templates/platformer/src/main.ts +14 -0
- package/templates/platformer/src/playtest-events.ts +15 -0
- package/templates/platformer/src/render/camera.ts +8 -0
- package/templates/platformer/src/render/lighting.ts +38 -0
- package/templates/platformer/src/render/loading.ts +113 -0
- package/templates/platformer/src/render/materials.ts +11 -0
- package/templates/platformer/src/render/palette.ts +54 -0
- package/templates/platformer/src/render/postprocessing.ts +18 -0
- package/templates/platformer/src/render/rig.ts +60 -0
- package/templates/platformer/src/render/sky.ts +47 -0
- package/templates/platformer/src/render/terrain.ts +31 -0
- package/templates/platformer/src/render/touch-controls.ts +157 -0
- package/templates/platformer/src/render/touch-layout.ts +63 -0
- package/templates/platformer/src/scenes/Boot.ts +12 -0
- package/templates/platformer/src/scenes/Level.ts +176 -0
- package/templates/platformer/src/state.ts +23 -0
- package/templates/platformer/src/style.css +31 -0
- package/templates/platformer/src/ui/App.tsx +17 -0
- package/templates/platformer/src/ui/Hud.tsx +41 -0
- package/templates/platformer/src/ui/Menu.tsx +7 -0
- package/templates/platformer/tailwind.config.ts +2 -0
- package/templates/platformer/threenative.config.ts +32 -0
- package/templates/platformer/tsconfig.json +17 -0
- package/templates/platformer/vite.config.ts +5 -0
- package/templates/racing/.mcp.json +16 -0
- package/templates/racing/AGENTS.md +48 -0
- package/templates/racing/CLAUDE.md +50 -0
- package/templates/racing/index.html +13 -0
- package/templates/racing/kit.json +7 -0
- package/templates/racing/package.json +46 -0
- package/templates/racing/playtests/boost.playtest.json +45 -0
- package/templates/racing/playtests/outcome.playtest.json +78 -0
- package/templates/racing/playtests/ranking.playtest.json +37 -0
- package/templates/racing/playtests/rescue.playtest.json +28 -0
- package/templates/racing/playtests/reverse.playtest.json +37 -0
- package/templates/racing/playtests/shortcut.playtest.json +44 -0
- package/templates/racing/playtests/survives.playtest.json +32 -0
- package/templates/racing/public/favicon.svg +6 -0
- package/templates/racing/src/entities/RacingCar.ts +114 -0
- package/templates/racing/src/entities/Rival.ts +46 -0
- package/templates/racing/src/game.ts +29 -0
- package/templates/racing/src/kart/boost.ts +38 -0
- package/templates/racing/src/main.ts +15 -0
- package/templates/racing/src/playtest-events.ts +15 -0
- package/templates/racing/src/render/camera.ts +28 -0
- package/templates/racing/src/render/lighting.ts +32 -0
- package/templates/racing/src/render/loading.ts +58 -0
- package/templates/racing/src/render/materials.ts +15 -0
- package/templates/racing/src/render/palette.ts +30 -0
- package/templates/racing/src/render/postprocessing.ts +14 -0
- package/templates/racing/src/render/shapes.ts +37 -0
- package/templates/racing/src/render/sky.ts +45 -0
- package/templates/racing/src/scenes/Boot.ts +12 -0
- package/templates/racing/src/scenes/Race.ts +180 -0
- package/templates/racing/src/state.ts +35 -0
- package/templates/racing/src/style.css +32 -0
- package/templates/racing/src/track/Checkline.ts +19 -0
- package/templates/racing/src/track/Lap.ts +104 -0
- package/templates/racing/src/track/Ranking.ts +35 -0
- package/templates/racing/src/track/Track.ts +229 -0
- package/templates/racing/src/track/TrackSector.ts +77 -0
- package/templates/racing/src/track/rescue.ts +21 -0
- package/templates/racing/src/ui/App.tsx +17 -0
- package/templates/racing/src/ui/Hud.tsx +71 -0
- package/templates/racing/src/ui/Menu.tsx +7 -0
- package/templates/racing/tailwind.config.ts +2 -0
- package/templates/racing/threenative.config.ts +29 -0
- package/templates/racing/tsconfig.json +17 -0
- package/templates/racing/vite.config.ts +5 -0
- package/templates/shooter/.mcp.json +16 -0
- package/templates/shooter/AGENTS.md +69 -0
- package/templates/shooter/CLAUDE.md +71 -0
- package/templates/shooter/index.html +13 -0
- package/templates/shooter/kit.json +7 -0
- package/templates/shooter/package.json +46 -0
- package/templates/shooter/playtests/fail.playtest.json +30 -0
- package/templates/shooter/playtests/shooter.playtest.json +89 -0
- package/templates/shooter/playtests/survives.playtest.json +32 -0
- package/templates/shooter/public/favicon.svg +4 -0
- package/templates/shooter/src/combat/damage.ts +41 -0
- package/templates/shooter/src/entities/Pickup.ts +70 -0
- package/templates/shooter/src/entities/Player.ts +93 -0
- package/templates/shooter/src/entities/Target.ts +103 -0
- package/templates/shooter/src/game.ts +36 -0
- package/templates/shooter/src/level/SpawnPoints.ts +28 -0
- package/templates/shooter/src/main.ts +26 -0
- package/templates/shooter/src/physics.ts +49 -0
- package/templates/shooter/src/playtest-events.ts +15 -0
- package/templates/shooter/src/render/camera.ts +29 -0
- package/templates/shooter/src/render/lighting.ts +38 -0
- package/templates/shooter/src/render/loading.ts +86 -0
- package/templates/shooter/src/render/materials.ts +38 -0
- package/templates/shooter/src/render/palette.ts +9 -0
- package/templates/shooter/src/render/postprocessing.ts +19 -0
- package/templates/shooter/src/render/shapes.ts +194 -0
- package/templates/shooter/src/render/sky.ts +37 -0
- package/templates/shooter/src/render/types.ts +3 -0
- package/templates/shooter/src/render/ui.css +212 -0
- package/templates/shooter/src/render/ui.ts +59 -0
- package/templates/shooter/src/scenes/Boot.ts +12 -0
- package/templates/shooter/src/scenes/Play.ts +428 -0
- package/templates/shooter/src/state.ts +29 -0
- package/templates/shooter/src/ui/App.tsx +25 -0
- package/templates/shooter/src/ui/Hud.tsx +49 -0
- package/templates/shooter/src/ui/Menu.tsx +26 -0
- package/templates/shooter/src/waves.ts +50 -0
- package/templates/shooter/src/weapons/Hitscan.ts +43 -0
- package/templates/shooter/src/weapons/Projectile.ts +76 -0
- package/templates/shooter/tailwind.config.ts +5 -0
- package/templates/shooter/threenative.config.ts +29 -0
- package/templates/shooter/tsconfig.json +17 -0
- package/templates/shooter/vite.config.ts +8 -0
- package/templates/starter/.mcp.json +16 -0
- package/templates/starter/AGENTS.md +450 -0
- package/templates/starter/CLAUDE.md +452 -0
- package/templates/starter/assets/.gitkeep +0 -0
- package/templates/starter/index.html +13 -0
- package/templates/starter/kit.json +7 -0
- package/templates/starter/package.json +49 -0
- package/templates/starter/playtests/buffer.playtest.json +29 -0
- package/templates/starter/playtests/coyote.playtest.json +35 -0
- package/templates/starter/playtests/forward.playtest.json +15 -0
- package/templates/starter/playtests/hot-reload.playtest.json +28 -0
- package/templates/starter/playtests/look.playtest.json +43 -0
- package/templates/starter/playtests/monitoring.playtest.json +41 -0
- package/templates/starter/playtests/pause.playtest.json +33 -0
- package/templates/starter/playtests/play.playtest.json +16 -0
- package/templates/starter/playtests/respawn.playtest.json +28 -0
- package/templates/starter/playtests/restart.playtest.json +36 -0
- package/templates/starter/playtests/seed.playtest.json +18 -0
- package/templates/starter/playtests/survives.playtest.json +32 -0
- package/templates/starter/public/.gitkeep +0 -0
- package/templates/starter/public/favicon.svg +4 -0
- package/templates/starter/public/icon.png +0 -0
- package/templates/starter/public/native-proof.glb +0 -0
- package/templates/starter/public/native-proof.png +0 -0
- package/templates/starter/public/pickup.ogg +0 -0
- package/templates/starter/src/entities/Crate.ts +34 -0
- package/templates/starter/src/entities/Player.ts +80 -0
- package/templates/starter/src/game.ts +30 -0
- package/templates/starter/src/main.ts +15 -0
- package/templates/starter/src/render/camera.ts +57 -0
- package/templates/starter/src/render/lighting.ts +55 -0
- package/templates/starter/src/render/materials.ts +12 -0
- package/templates/starter/src/render/palette.ts +9 -0
- package/templates/starter/src/render/postprocessing.ts +18 -0
- package/templates/starter/src/render/shapes.ts +147 -0
- package/templates/starter/src/render/sky.ts +56 -0
- package/templates/starter/src/scenes/Play.ts +161 -0
- package/templates/starter/src/state.ts +10 -0
- package/templates/starter/src/style.css +45 -0
- package/templates/starter/src/ui/App.tsx +19 -0
- package/templates/starter/src/ui/Hud.tsx +37 -0
- package/templates/starter/src/ui/Menu.tsx +43 -0
- package/templates/starter/tailwind.config.ts +2 -0
- package/templates/starter/threenative.config.ts +31 -0
- package/templates/starter/tsconfig.json +17 -0
- package/templates/starter/vite.config.ts +8 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { type ICtx, Scene, type SceneFrame } from "@threenative/core";
|
|
2
|
+
import { CollisionShape3D, type IPhysicsContext, RigidBody3D } from "@threenative/physics";
|
|
3
|
+
import { type Object3D, type PerspectiveCamera, Vector3 } from "three";
|
|
4
|
+
import { Ability } from "../abilities/Ability.js";
|
|
5
|
+
import { Enemy } from "../entities/Enemy.js";
|
|
6
|
+
import { HOSTILE_LAYER, PLAYER_LAYER, Player, WORLD_LAYER } from "../entities/Player.js";
|
|
7
|
+
import { ITEMS, Inventory, type ItemId, type ItemStack } from "../items/Inventory.js";
|
|
8
|
+
import { describeDrops, rollDrops } from "../loot/drops.js";
|
|
9
|
+
import { directSpaceState } from "../physics.js";
|
|
10
|
+
import { emitPlaytestEvent } from "../playtest-events.js";
|
|
11
|
+
import { loadProgress, saveProgress } from "../progress.js";
|
|
12
|
+
import { createDungeonCamera } from "../render/camera.js";
|
|
13
|
+
import { setupLighting } from "../render/lighting.js";
|
|
14
|
+
import { createLoadingScreen } from "../render/loading.js";
|
|
15
|
+
import { createMaterials } from "../render/materials.js";
|
|
16
|
+
import { setupPost } from "../render/postprocessing.js";
|
|
17
|
+
import { createDungeon, createLootVisual } from "../render/shapes.js";
|
|
18
|
+
import { setupSky } from "../render/sky.js";
|
|
19
|
+
import type { GameState } from "../state.js";
|
|
20
|
+
import { StatBlock } from "../stats/StatBlock.js";
|
|
21
|
+
|
|
22
|
+
export type GameCtx = ICtx<GameState, IPhysicsContext>;
|
|
23
|
+
|
|
24
|
+
const SPAWN = new Vector3(-8, 0.78, 0);
|
|
25
|
+
const ATTACK_SHAPE = CollisionShape3D.sphere(2.2);
|
|
26
|
+
const DROP_SEED = 93_093;
|
|
27
|
+
|
|
28
|
+
function roomFor(x: number): number {
|
|
29
|
+
return Math.min(3, Math.max(1, Math.floor((x + 12) / 12) + 1));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function itemId(value: string): value is ItemId {
|
|
33
|
+
return Object.values(ITEMS).some((item) => item.id === value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class Play extends Scene<GameState, IPhysicsContext> {
|
|
37
|
+
static override readonly initialState: GameState = {
|
|
38
|
+
abilityCooldown: 0,
|
|
39
|
+
abilityUses: 0,
|
|
40
|
+
baseDamage: 12,
|
|
41
|
+
damage: 12,
|
|
42
|
+
damageHits: 0,
|
|
43
|
+
deaths: 0,
|
|
44
|
+
dropProof: 0,
|
|
45
|
+
dropSequence: "",
|
|
46
|
+
enemiesDefeated: 0,
|
|
47
|
+
equippedItem: "",
|
|
48
|
+
gameOver: 0,
|
|
49
|
+
gameWon: 0,
|
|
50
|
+
health: 100,
|
|
51
|
+
inventory: [],
|
|
52
|
+
inventoryFullRefused: 0,
|
|
53
|
+
inventorySlots: [],
|
|
54
|
+
lastDamage: 0,
|
|
55
|
+
lastDrop: "",
|
|
56
|
+
lineOfSightBlocked: 0,
|
|
57
|
+
modifierActive: 0,
|
|
58
|
+
pendingLoot: "",
|
|
59
|
+
pendingLootItem: "",
|
|
60
|
+
pendingLootQuantity: 0,
|
|
61
|
+
phase: "playing",
|
|
62
|
+
playerX: SPAWN.x,
|
|
63
|
+
playerY: SPAWN.y,
|
|
64
|
+
playerZ: SPAWN.z,
|
|
65
|
+
room: 1,
|
|
66
|
+
saveCount: 0,
|
|
67
|
+
visibleEnemyAggro: 0,
|
|
68
|
+
wallEnemyAggro: 0,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
override enter(ctx: GameCtx): SceneFrame<GameState, IPhysicsContext> {
|
|
72
|
+
const restored = loadProgress(Play.initialState);
|
|
73
|
+
ctx.state.set(restored);
|
|
74
|
+
ctx.state.flush();
|
|
75
|
+
|
|
76
|
+
const camera = ctx.camera as PerspectiveCamera;
|
|
77
|
+
const materials = createMaterials();
|
|
78
|
+
setupSky(ctx.scene);
|
|
79
|
+
setupLighting(ctx.scene, ctx.renderer.raw as Parameters<typeof setupLighting>[1]);
|
|
80
|
+
setupPost(ctx.renderer, ctx.scene, camera);
|
|
81
|
+
const loading = createLoadingScreen(ctx);
|
|
82
|
+
ctx.add(camera);
|
|
83
|
+
const cameraRig = createDungeonCamera(camera);
|
|
84
|
+
ctx.viewport.resize();
|
|
85
|
+
|
|
86
|
+
const dungeon = createDungeon(materials);
|
|
87
|
+
ctx.add(dungeon.group);
|
|
88
|
+
const fixed = (object: Object3D, shape: CollisionShape3D) =>
|
|
89
|
+
new RigidBody3D({
|
|
90
|
+
collisionLayer: WORLD_LAYER,
|
|
91
|
+
collisionMask: PLAYER_LAYER | HOSTILE_LAYER,
|
|
92
|
+
object,
|
|
93
|
+
physics: ctx.physics,
|
|
94
|
+
shape,
|
|
95
|
+
type: "fixed",
|
|
96
|
+
});
|
|
97
|
+
fixed(dungeon.floor, CollisionShape3D.box(36, 0.3, 12));
|
|
98
|
+
for (const [index, wall] of dungeon.walls.entries()) {
|
|
99
|
+
fixed(
|
|
100
|
+
wall,
|
|
101
|
+
index < 2 ? CollisionShape3D.box(36, 2.8, 0.35) : CollisionShape3D.box(0.35, 2.8, 12),
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
for (const pillar of dungeon.roomPillars) fixed(pillar, CollisionShape3D.box(0.7, 3.6, 1.2));
|
|
105
|
+
fixed(dungeon.lineOfSightWall, CollisionShape3D.box(2.4, 2.1, 0.5));
|
|
106
|
+
|
|
107
|
+
const inventory = new Inventory(6);
|
|
108
|
+
const savedSlots = restored.inventorySlots.filter(
|
|
109
|
+
(slot): slot is ItemStack =>
|
|
110
|
+
itemId(slot.itemId) && Number.isInteger(slot.quantity) && slot.quantity > 0,
|
|
111
|
+
);
|
|
112
|
+
const savedEquipped = itemId(restored.equippedItem) ? restored.equippedItem : undefined;
|
|
113
|
+
if (savedSlots.length > 0 || savedEquipped !== undefined) {
|
|
114
|
+
inventory.restore(savedSlots, savedEquipped);
|
|
115
|
+
} else {
|
|
116
|
+
inventory.add("rusted-blade", 1);
|
|
117
|
+
inventory.add("ember-blade", 1);
|
|
118
|
+
inventory.add("potion", 2);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const playerRef: { value?: Player } = {};
|
|
122
|
+
const player = new Player(
|
|
123
|
+
ctx,
|
|
124
|
+
materials,
|
|
125
|
+
new Vector3(restored.playerX, restored.playerY, restored.playerZ),
|
|
126
|
+
restored.health,
|
|
127
|
+
(amount) => {
|
|
128
|
+
const current = playerRef.value;
|
|
129
|
+
ctx.state.set({ health: current?.health ?? 0, lastDamage: amount });
|
|
130
|
+
emitPlaytestEvent({ amount, entity: "player", name: "damaged" });
|
|
131
|
+
},
|
|
132
|
+
() => {
|
|
133
|
+
const state = ctx.state.getState();
|
|
134
|
+
ctx.state.set({
|
|
135
|
+
deaths: state.deaths + 1,
|
|
136
|
+
gameOver: 1,
|
|
137
|
+
health: 0,
|
|
138
|
+
phase: "lost",
|
|
139
|
+
});
|
|
140
|
+
emitPlaytestEvent({ entity: "player", name: "died" });
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
playerRef.value = player;
|
|
144
|
+
player.equippedItem = inventory.equipped?.itemId ?? "";
|
|
145
|
+
ctx.entities.add("player", player);
|
|
146
|
+
|
|
147
|
+
const enemies = new Map<number, Enemy>();
|
|
148
|
+
const enemyIds = new Map<number, string>();
|
|
149
|
+
const damageStats = new StatBlock(Play.initialState.baseDamage);
|
|
150
|
+
let elapsed = 0;
|
|
151
|
+
let saveRequested = false;
|
|
152
|
+
let enemyIndex = 0;
|
|
153
|
+
let currentRoom = roomFor(player.mesh.position.x);
|
|
154
|
+
const pendingStacks: ItemStack[] = [];
|
|
155
|
+
const pendingVisuals: Array<ReturnType<typeof createLootVisual>> = [];
|
|
156
|
+
let lastDropSeed: number | undefined;
|
|
157
|
+
|
|
158
|
+
const syncInventory = (): void => {
|
|
159
|
+
const equipped = inventory.equipped?.itemId ?? "";
|
|
160
|
+
ctx.state.set({
|
|
161
|
+
equippedItem: equipped,
|
|
162
|
+
inventory: inventory.labels(),
|
|
163
|
+
inventorySlots: inventory.snapshot(),
|
|
164
|
+
});
|
|
165
|
+
player.equippedItem = equipped;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const syncPendingLoot = (): void => {
|
|
169
|
+
const first = pendingStacks[0];
|
|
170
|
+
ctx.state.set({
|
|
171
|
+
pendingLoot: describeDrops(pendingStacks),
|
|
172
|
+
pendingLootItem: first?.itemId ?? "",
|
|
173
|
+
pendingLootQuantity: pendingStacks.reduce((total, stack) => total + stack.quantity, 0),
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const retainLoot = (stack: ItemStack): void => {
|
|
178
|
+
const visual = createLootVisual(materials);
|
|
179
|
+
visual.name = `pending-loot-${stack.itemId}`;
|
|
180
|
+
visual.position
|
|
181
|
+
.copy(player.mesh.position)
|
|
182
|
+
.add(new Vector3(pendingVisuals.length * 0.8, 0, 1.2));
|
|
183
|
+
ctx.add(visual);
|
|
184
|
+
pendingStacks.push(stack);
|
|
185
|
+
pendingVisuals.push(visual);
|
|
186
|
+
syncPendingLoot();
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const retainOrSwapPendingLoot = (
|
|
190
|
+
index: number,
|
|
191
|
+
stack: ItemStack,
|
|
192
|
+
remainder: number,
|
|
193
|
+
): boolean => {
|
|
194
|
+
const displaced = inventory.swapFirst({ itemId: stack.itemId, quantity: remainder });
|
|
195
|
+
if (displaced === undefined) {
|
|
196
|
+
pendingStacks[index] = { ...stack, quantity: remainder };
|
|
197
|
+
return remainder !== stack.quantity;
|
|
198
|
+
}
|
|
199
|
+
pendingStacks[index] = displaced;
|
|
200
|
+
const visual = pendingVisuals[index];
|
|
201
|
+
if (visual !== undefined) visual.name = `pending-loot-${displaced.itemId}`;
|
|
202
|
+
return true;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const collectPendingLoot = (): boolean => {
|
|
206
|
+
let changed = false;
|
|
207
|
+
for (let index = 0; index < pendingStacks.length; ) {
|
|
208
|
+
const stack = pendingStacks[index];
|
|
209
|
+
if (stack === undefined) break;
|
|
210
|
+
const remainder = inventory.add(stack.itemId, stack.quantity);
|
|
211
|
+
if (remainder > 0) {
|
|
212
|
+
changed = retainOrSwapPendingLoot(index, stack, remainder) || changed;
|
|
213
|
+
index += 1;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
pendingStacks.splice(index, 1);
|
|
217
|
+
pendingVisuals[index]?.removeFromParent();
|
|
218
|
+
pendingVisuals.splice(index, 1);
|
|
219
|
+
changed = true;
|
|
220
|
+
}
|
|
221
|
+
if (changed) {
|
|
222
|
+
syncInventory();
|
|
223
|
+
syncPendingLoot();
|
|
224
|
+
}
|
|
225
|
+
return changed;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
syncPendingLoot();
|
|
229
|
+
|
|
230
|
+
const syncEquipmentStat = (): void => {
|
|
231
|
+
damageStats.remove("equipment");
|
|
232
|
+
const equipped = inventory.equipped?.itemId;
|
|
233
|
+
const equippedDefinition =
|
|
234
|
+
equipped === undefined
|
|
235
|
+
? undefined
|
|
236
|
+
: Object.values(ITEMS).find((item) => item.id === equipped);
|
|
237
|
+
const bonus =
|
|
238
|
+
equippedDefinition !== undefined && "attackBonus" in equippedDefinition
|
|
239
|
+
? (equippedDefinition.attackBonus ?? 0)
|
|
240
|
+
: 0;
|
|
241
|
+
if (bonus !== 0) damageStats.apply({ add: bonus, source: "equipment" }, elapsed);
|
|
242
|
+
syncInventory();
|
|
243
|
+
};
|
|
244
|
+
syncEquipmentStat();
|
|
245
|
+
|
|
246
|
+
const onEnemyDeath = (enemy: Enemy): void => {
|
|
247
|
+
const id = enemyIds.get(enemy.body.body.id);
|
|
248
|
+
enemies.delete(enemy.body.body.id);
|
|
249
|
+
enemyIds.delete(enemy.body.body.id);
|
|
250
|
+
if (id !== undefined && ctx.entities.get(id) !== undefined) ctx.entities.remove(id);
|
|
251
|
+
const seed = DROP_SEED + enemyIndex++;
|
|
252
|
+
lastDropSeed = seed;
|
|
253
|
+
const drops = rollDrops(seed);
|
|
254
|
+
let refused = false;
|
|
255
|
+
for (const drop of drops) {
|
|
256
|
+
const remainder = inventory.add(drop.itemId, drop.quantity);
|
|
257
|
+
if (remainder > 0) {
|
|
258
|
+
refused = true;
|
|
259
|
+
retainLoot({ itemId: drop.itemId, quantity: remainder });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const state = ctx.state.getState();
|
|
263
|
+
ctx.state.set({
|
|
264
|
+
enemiesDefeated: state.enemiesDefeated + 1,
|
|
265
|
+
inventoryFullRefused: refused ? 1 : state.inventoryFullRefused,
|
|
266
|
+
lastDrop: describeDrops(drops),
|
|
267
|
+
});
|
|
268
|
+
syncInventory();
|
|
269
|
+
emitPlaytestEvent({ entity: "enemy", name: "defeated" });
|
|
270
|
+
if (enemy.boss) {
|
|
271
|
+
ctx.state.set({ gameWon: 1, phase: "won" });
|
|
272
|
+
saveRequested = true;
|
|
273
|
+
emitPlaytestEvent({ entity: "boss", name: "defeated" });
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const addEnemy = (
|
|
278
|
+
id: string,
|
|
279
|
+
position: Vector3,
|
|
280
|
+
options: { readonly boss?: boolean; readonly health?: number } = {},
|
|
281
|
+
): Enemy => {
|
|
282
|
+
const enemy = new Enemy(ctx, materials, position, player.body.body, {
|
|
283
|
+
...options,
|
|
284
|
+
onAttack: (amount) => player.takeDamage(amount),
|
|
285
|
+
onDeath: onEnemyDeath,
|
|
286
|
+
});
|
|
287
|
+
enemies.set(enemy.body.body.id, enemy);
|
|
288
|
+
enemyIds.set(enemy.body.body.id, id);
|
|
289
|
+
ctx.entities.add(id, enemy);
|
|
290
|
+
return enemy;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const visibleEnemy = addEnemy("enemy.visible", new Vector3(-6.3, 0.78, 0.8), { health: 60 });
|
|
294
|
+
const wallEnemy = addEnemy("enemy.behind-wall", new Vector3(-8, 0.78, -3), { health: 30 });
|
|
295
|
+
addEnemy("enemy.room-two", new Vector3(3, 0.78, 0), { health: 24 });
|
|
296
|
+
addEnemy("enemy.room-three", new Vector3(11.5, 0.78, 0), { health: 30 });
|
|
297
|
+
const boss = addEnemy("boss", new Vector3(16, 0.78, 0), { boss: true, health: 64 });
|
|
298
|
+
|
|
299
|
+
const strike = (amount: number): void => {
|
|
300
|
+
const hits = directSpaceState(ctx.physics).intersectShape({
|
|
301
|
+
collisionMask: HOSTILE_LAYER,
|
|
302
|
+
maxResults: 16,
|
|
303
|
+
position: player.attackOrigin(),
|
|
304
|
+
shape: ATTACK_SHAPE,
|
|
305
|
+
});
|
|
306
|
+
let hitCount = 0;
|
|
307
|
+
for (const hit of hits) {
|
|
308
|
+
const enemy = enemies.get(hit.body.id);
|
|
309
|
+
if (enemy === undefined) continue;
|
|
310
|
+
enemy.takeDamage(amount);
|
|
311
|
+
hitCount += 1;
|
|
312
|
+
}
|
|
313
|
+
const state = ctx.state.getState();
|
|
314
|
+
ctx.state.set({
|
|
315
|
+
damageHits: state.damageHits + hitCount,
|
|
316
|
+
lastDamage: Math.round(amount),
|
|
317
|
+
});
|
|
318
|
+
emitPlaytestEvent({ amount: Math.round(amount), entity: "player", name: "attack" });
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const ability = new Ability({
|
|
322
|
+
cooldown: 3,
|
|
323
|
+
duration: 1,
|
|
324
|
+
onExpire: () => {
|
|
325
|
+
damageStats.expire(elapsed);
|
|
326
|
+
ctx.state.set({ modifierActive: 0 });
|
|
327
|
+
emitPlaytestEvent({ entity: "player", name: "ability-expired" });
|
|
328
|
+
},
|
|
329
|
+
onStart: () => {
|
|
330
|
+
damageStats.apply({ add: 6, duration: 1, source: "arcane-surge" }, elapsed);
|
|
331
|
+
ctx.state.set({ abilityUses: ctx.state.getState().abilityUses + 1, modifierActive: 1 });
|
|
332
|
+
strike(20);
|
|
333
|
+
emitPlaytestEvent({ entity: "player", name: "ability" });
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
const fillInventory = (): void => {
|
|
338
|
+
inventory.fill("potion");
|
|
339
|
+
syncInventory();
|
|
340
|
+
ctx.state.set({ inventoryFullRefused: pendingStacks.length > 0 ? 1 : 0 });
|
|
341
|
+
};
|
|
342
|
+
const tryFullLoot = (): void => {
|
|
343
|
+
if (pendingStacks.length > 0) {
|
|
344
|
+
const collected = collectPendingLoot();
|
|
345
|
+
ctx.state.set({ inventoryFullRefused: pendingStacks.length > 0 ? 1 : 0 });
|
|
346
|
+
emitPlaytestEvent({
|
|
347
|
+
entity: "loot",
|
|
348
|
+
name: collected ? "loot-collected" : "loot-refused",
|
|
349
|
+
});
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const remainder = inventory.add("ember-blade", 1);
|
|
353
|
+
const state = ctx.state.getState();
|
|
354
|
+
if (remainder > 0) retainLoot({ itemId: "ember-blade", quantity: remainder });
|
|
355
|
+
ctx.state.set({
|
|
356
|
+
inventoryFullRefused: remainder > 0 ? 1 : state.inventoryFullRefused,
|
|
357
|
+
});
|
|
358
|
+
syncInventory();
|
|
359
|
+
emitPlaytestEvent({
|
|
360
|
+
entity: "player",
|
|
361
|
+
name: remainder > 0 ? "loot-refused" : "loot-added",
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
const proveDrops = (): void => {
|
|
365
|
+
const expected = describeDrops(rollDrops(DROP_SEED));
|
|
366
|
+
const before = ctx.state.getState().enemiesDefeated;
|
|
367
|
+
if (visibleEnemy.alive) visibleEnemy.takeDamage(visibleEnemy.health);
|
|
368
|
+
const actual = ctx.state.getState();
|
|
369
|
+
ctx.state.set({
|
|
370
|
+
dropProof:
|
|
371
|
+
actual.enemiesDefeated > before &&
|
|
372
|
+
lastDropSeed === DROP_SEED &&
|
|
373
|
+
actual.lastDrop === expected
|
|
374
|
+
? 1
|
|
375
|
+
: 0,
|
|
376
|
+
dropSequence: actual.lastDrop,
|
|
377
|
+
});
|
|
378
|
+
emitPlaytestEvent({ entity: "loot", name: "seeded" });
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
cameraRig.snap(player.mesh.position);
|
|
382
|
+
let lastSavedRoom = currentRoom;
|
|
383
|
+
return (frameCtx, dt) => {
|
|
384
|
+
loading.update();
|
|
385
|
+
elapsed += dt;
|
|
386
|
+
if (frameCtx.input.justPressed("restart")) {
|
|
387
|
+
void frameCtx.goto("play");
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (frameCtx.input.justPressed("lethal")) player.takeDamage(player.health + 1);
|
|
391
|
+
if (frameCtx.input.justPressed("damage")) player.takeDamage(18);
|
|
392
|
+
if (frameCtx.input.justPressed("attack")) strike(Math.round(damageStats.value(elapsed)));
|
|
393
|
+
if (frameCtx.input.justPressed("ability")) ability.cast();
|
|
394
|
+
if (frameCtx.input.justPressed("equip")) {
|
|
395
|
+
if (inventory.equip("ember-blade")) {
|
|
396
|
+
syncEquipmentStat();
|
|
397
|
+
saveRequested = true;
|
|
398
|
+
emitPlaytestEvent({ entity: "player", name: "equipped" });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (frameCtx.input.justPressed("unequip")) {
|
|
402
|
+
if (inventory.unequip()) {
|
|
403
|
+
syncEquipmentStat();
|
|
404
|
+
saveRequested = true;
|
|
405
|
+
emitPlaytestEvent({ entity: "player", name: "unequipped" });
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (frameCtx.input.justPressed("fill")) fillInventory();
|
|
409
|
+
if (frameCtx.input.justPressed("loot")) tryFullLoot();
|
|
410
|
+
if (frameCtx.input.justPressed("dropProbe")) proveDrops();
|
|
411
|
+
if (frameCtx.input.justPressed("save")) saveRequested = true;
|
|
412
|
+
|
|
413
|
+
player.update(frameCtx, dt);
|
|
414
|
+
ability.update(dt);
|
|
415
|
+
for (const enemy of enemies.values()) enemy.update(frameCtx, dt, player.mesh.position);
|
|
416
|
+
|
|
417
|
+
currentRoom = roomFor(player.mesh.position.x);
|
|
418
|
+
frameCtx.state.set({
|
|
419
|
+
abilityCooldown: Number(ability.cooldownRemaining.toFixed(3)),
|
|
420
|
+
baseDamage: damageStats.base,
|
|
421
|
+
damage: Math.round(damageStats.value(elapsed)),
|
|
422
|
+
health: player.health,
|
|
423
|
+
lineOfSightBlocked: wallEnemy.lineOfSightBlocked ? 1 : 0,
|
|
424
|
+
modifierActive: ability.active ? 1 : 0,
|
|
425
|
+
playerX: Number(player.mesh.position.x.toFixed(3)),
|
|
426
|
+
playerY: Number(player.mesh.position.y.toFixed(3)),
|
|
427
|
+
playerZ: Number(player.mesh.position.z.toFixed(3)),
|
|
428
|
+
room: currentRoom,
|
|
429
|
+
visibleEnemyAggro:
|
|
430
|
+
visibleEnemy.state === "aggro" || visibleEnemy.state === "attack" ? 1 : 0,
|
|
431
|
+
wallEnemyAggro: wallEnemy.state === "aggro" || wallEnemy.state === "attack" ? 1 : 0,
|
|
432
|
+
});
|
|
433
|
+
if (currentRoom !== lastSavedRoom) {
|
|
434
|
+
lastSavedRoom = currentRoom;
|
|
435
|
+
saveRequested = true;
|
|
436
|
+
}
|
|
437
|
+
if (saveRequested) {
|
|
438
|
+
const next = frameCtx.state.getState().saveCount + 1;
|
|
439
|
+
frameCtx.state.set({ saveCount: next });
|
|
440
|
+
frameCtx.state.flush();
|
|
441
|
+
saveProgress(frameCtx.state);
|
|
442
|
+
saveRequested = false;
|
|
443
|
+
}
|
|
444
|
+
cameraRig.follow(player.mesh.position, dt);
|
|
445
|
+
if (boss.alive === false) frameCtx.state.set({ gameWon: 1, phase: "won" });
|
|
446
|
+
if (player.dead) frameCtx.state.set({ gameOver: 1, phase: "lost" });
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type GamePhase = "playing" | "won" | "lost";
|
|
2
|
+
|
|
3
|
+
export type InventoryProjection = {
|
|
4
|
+
readonly itemId: string;
|
|
5
|
+
readonly quantity: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type GameState = {
|
|
9
|
+
abilityCooldown: number;
|
|
10
|
+
abilityUses: number;
|
|
11
|
+
baseDamage: number;
|
|
12
|
+
damage: number;
|
|
13
|
+
damageHits: number;
|
|
14
|
+
deaths: number;
|
|
15
|
+
dropProof: number;
|
|
16
|
+
dropSequence: string;
|
|
17
|
+
enemiesDefeated: number;
|
|
18
|
+
equippedItem: string;
|
|
19
|
+
gameOver: number;
|
|
20
|
+
gameWon: number;
|
|
21
|
+
health: number;
|
|
22
|
+
inventory: string[];
|
|
23
|
+
inventoryFullRefused: number;
|
|
24
|
+
inventorySlots: InventoryProjection[];
|
|
25
|
+
lastDamage: number;
|
|
26
|
+
lastDrop: string;
|
|
27
|
+
lineOfSightBlocked: number;
|
|
28
|
+
modifierActive: number;
|
|
29
|
+
pendingLoot: string;
|
|
30
|
+
pendingLootItem: string;
|
|
31
|
+
pendingLootQuantity: number;
|
|
32
|
+
phase: GamePhase;
|
|
33
|
+
playerX: number;
|
|
34
|
+
playerY: number;
|
|
35
|
+
playerZ: number;
|
|
36
|
+
room: number;
|
|
37
|
+
saveCount: number;
|
|
38
|
+
visibleEnemyAggro: number;
|
|
39
|
+
wallEnemyAggro: number;
|
|
40
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface IStatModifier {
|
|
2
|
+
readonly add?: number;
|
|
3
|
+
readonly duration?: number;
|
|
4
|
+
readonly multiply?: number;
|
|
5
|
+
readonly source: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type ActiveModifier = IStatModifier & { readonly expiresAt?: number };
|
|
9
|
+
|
|
10
|
+
export class StatBlock {
|
|
11
|
+
readonly base: number;
|
|
12
|
+
#layers = new Map<string, ActiveModifier>();
|
|
13
|
+
|
|
14
|
+
constructor(base: number) {
|
|
15
|
+
if (!Number.isFinite(base)) throw new TypeError("StatBlock base must be finite.");
|
|
16
|
+
this.base = base;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
apply(modifier: IStatModifier, now = 0): void {
|
|
20
|
+
if (modifier.source.length === 0) throw new Error("StatBlock modifiers need a source.");
|
|
21
|
+
if (modifier.add !== undefined && !Number.isFinite(modifier.add))
|
|
22
|
+
throw new TypeError("StatBlock additive modifiers must be finite.");
|
|
23
|
+
if (modifier.multiply !== undefined && !Number.isFinite(modifier.multiply))
|
|
24
|
+
throw new TypeError("StatBlock multiplicative modifiers must be finite.");
|
|
25
|
+
const expiresAt =
|
|
26
|
+
modifier.duration === undefined ? undefined : now + Math.max(0, modifier.duration);
|
|
27
|
+
this.#layers.set(modifier.source, {
|
|
28
|
+
...modifier,
|
|
29
|
+
...(expiresAt === undefined ? {} : { expiresAt }),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
remove(source: string): boolean {
|
|
34
|
+
return this.#layers.delete(source);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
expire(now: number): void {
|
|
38
|
+
for (const [source, modifier] of this.#layers) {
|
|
39
|
+
if (modifier.expiresAt !== undefined && modifier.expiresAt <= now)
|
|
40
|
+
this.#layers.delete(source);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
value(now = 0): number {
|
|
45
|
+
this.expire(now);
|
|
46
|
+
let result = this.base;
|
|
47
|
+
for (const modifier of this.#layers.values()) {
|
|
48
|
+
result = (result + (modifier.add ?? 0)) * (modifier.multiply ?? 1);
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
has(source: string, now = 0): boolean {
|
|
54
|
+
this.expire(now);
|
|
55
|
+
return this.#layers.has(source);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
|
|
3
|
+
@source "../index.html";
|
|
4
|
+
@source "./";
|
|
5
|
+
|
|
6
|
+
@theme {
|
|
7
|
+
--color-void: #080b12;
|
|
8
|
+
--color-panel: #111a25;
|
|
9
|
+
--color-line: #2b3a4b;
|
|
10
|
+
--color-amber: #e8b86a;
|
|
11
|
+
--color-cyan: #71d1c4;
|
|
12
|
+
--color-red: #d96572;
|
|
13
|
+
--color-text: #dce5e8;
|
|
14
|
+
--color-dim: #7d8b99;
|
|
15
|
+
--font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
html,
|
|
19
|
+
body,
|
|
20
|
+
#root {
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
margin: 0;
|
|
24
|
+
overflow: hidden;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
body {
|
|
28
|
+
background: var(--color-void);
|
|
29
|
+
color: var(--color-text);
|
|
30
|
+
font-family: var(--font-mono);
|
|
31
|
+
-webkit-font-smoothing: antialiased;
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IGame } from "@threenative/core";
|
|
2
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
3
|
+
import { useGameState } from "@threenative/ui";
|
|
4
|
+
import type { GameState } from "../state.js";
|
|
5
|
+
|
|
6
|
+
export function AbilityBar({ game }: { game: IGame<GameState, IPhysicsContext> }) {
|
|
7
|
+
const cooldown = useGameState(game, (state) => state.abilityCooldown);
|
|
8
|
+
const active = useGameState(game, (state) => state.modifierActive);
|
|
9
|
+
const uses = useGameState(game, (state) => state.abilityUses);
|
|
10
|
+
const ready = cooldown <= 0;
|
|
11
|
+
return (
|
|
12
|
+
<footer className="pointer-events-none absolute bottom-6 left-6 w-72 border border-line bg-panel/90 p-3 text-[10px] uppercase tracking-[0.14em]">
|
|
13
|
+
<div className="flex justify-between text-amber">
|
|
14
|
+
<span>arcane surge</span>
|
|
15
|
+
<span className={ready ? "text-cyan" : "text-dim"}>
|
|
16
|
+
{ready ? "ready" : cooldown.toFixed(1)}
|
|
17
|
+
</span>
|
|
18
|
+
</div>
|
|
19
|
+
<div className="mt-2 h-1 bg-void">
|
|
20
|
+
<i
|
|
21
|
+
className={`block h-full ${active === 1 ? "bg-amber" : "bg-cyan"}`}
|
|
22
|
+
style={{ width: `${Math.max(0, Math.min(100, (1 - cooldown / 3) * 100))}%` }}
|
|
23
|
+
/>
|
|
24
|
+
</div>
|
|
25
|
+
<div className="mt-2 text-dim">E cast · Q equip · U unequip · C save · uses {uses}</div>
|
|
26
|
+
</footer>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IGame } from "@threenative/core";
|
|
2
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
3
|
+
import { DebugOverlay, GameCanvas } from "@threenative/ui";
|
|
4
|
+
import type { GameState } from "../state.js";
|
|
5
|
+
import { AbilityBar } from "./AbilityBar.js";
|
|
6
|
+
import { CharacterPanel } from "./CharacterPanel.js";
|
|
7
|
+
import { Hud } from "./Hud.js";
|
|
8
|
+
import { InventoryPanel } from "./InventoryPanel.js";
|
|
9
|
+
|
|
10
|
+
export function App({ game }: { game: IGame<GameState, IPhysicsContext> }) {
|
|
11
|
+
return (
|
|
12
|
+
<main className="relative h-screen w-screen overflow-hidden bg-void">
|
|
13
|
+
<GameCanvas className="absolute inset-0" game={game} />
|
|
14
|
+
<Hud game={game} />
|
|
15
|
+
<CharacterPanel game={game} />
|
|
16
|
+
<InventoryPanel game={game} />
|
|
17
|
+
<AbilityBar game={game} />
|
|
18
|
+
<DebugOverlay />
|
|
19
|
+
</main>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IGame } from "@threenative/core";
|
|
2
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
3
|
+
import { useGameState } from "@threenative/ui";
|
|
4
|
+
import type { GameState } from "../state.js";
|
|
5
|
+
|
|
6
|
+
export function CharacterPanel({ game }: { game: IGame<GameState, IPhysicsContext> }) {
|
|
7
|
+
const health = useGameState(game, (state) => state.health);
|
|
8
|
+
const damage = useGameState(game, (state) => state.damage);
|
|
9
|
+
const equipped = useGameState(game, (state) => state.equippedItem);
|
|
10
|
+
const lastDamage = useGameState(game, (state) => state.lastDamage);
|
|
11
|
+
return (
|
|
12
|
+
<aside className="pointer-events-none absolute right-6 top-5 w-52 border border-line bg-panel/90 p-3 text-[10px] uppercase tracking-[0.14em]">
|
|
13
|
+
<div className="text-amber">character</div>
|
|
14
|
+
<div className="mt-3 flex justify-between text-dim">
|
|
15
|
+
<span>health</span>
|
|
16
|
+
<span className="text-cyan">{Math.round(health)} / 100</span>
|
|
17
|
+
</div>
|
|
18
|
+
<div className="mt-1 h-1 bg-void">
|
|
19
|
+
<i className="block h-full bg-cyan" style={{ width: `${Math.max(0, health)}%` }} />
|
|
20
|
+
</div>
|
|
21
|
+
<div className="mt-3 flex justify-between text-dim">
|
|
22
|
+
<span>damage</span>
|
|
23
|
+
<span className="text-text">{Math.round(damage)}</span>
|
|
24
|
+
</div>
|
|
25
|
+
<div className="mt-2 border-t border-line pt-2 text-dim">
|
|
26
|
+
weapon <span className="text-text">{equipped || "none"}</span>
|
|
27
|
+
</div>
|
|
28
|
+
<div className="mt-1 text-dim">last hit {Math.round(lastDamage)}</div>
|
|
29
|
+
</aside>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IGame } from "@threenative/core";
|
|
2
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
3
|
+
import { useGameState } from "@threenative/ui";
|
|
4
|
+
import type { GameState } from "../state.js";
|
|
5
|
+
|
|
6
|
+
export function Hud({ game }: { game: IGame<GameState, IPhysicsContext> }) {
|
|
7
|
+
const room = useGameState(game, (state) => state.room);
|
|
8
|
+
const phase = useGameState(game, (state) => state.phase);
|
|
9
|
+
const enemies = useGameState(game, (state) => state.enemiesDefeated);
|
|
10
|
+
const blocked = useGameState(game, (state) => state.lineOfSightBlocked);
|
|
11
|
+
return (
|
|
12
|
+
<section className="pointer-events-none absolute left-6 top-5 w-72 text-[10px] uppercase tracking-[0.16em]">
|
|
13
|
+
<div className="text-dim">dungeon / action rpg</div>
|
|
14
|
+
<div className="mt-2 text-3xl leading-none text-amber">room {room} / 3</div>
|
|
15
|
+
<div className="mt-2 text-cyan">boss clear · death fails</div>
|
|
16
|
+
<div className="mt-2 flex justify-between border-t border-line pt-2 text-dim">
|
|
17
|
+
<span>defeated {enemies}</span>
|
|
18
|
+
<span>wall ray {blocked === 1 ? "blocked" : "clear"}</span>
|
|
19
|
+
</div>
|
|
20
|
+
{phase !== "playing" && (
|
|
21
|
+
<div
|
|
22
|
+
className={`mt-4 border px-3 py-2 text-center text-sm tracking-[0.28em] ${phase === "won" ? "border-amber text-amber" : "border-red text-red"}`}
|
|
23
|
+
>
|
|
24
|
+
{phase === "won" ? "boss defeated" : "run failed"}
|
|
25
|
+
</div>
|
|
26
|
+
)}
|
|
27
|
+
</section>
|
|
28
|
+
);
|
|
29
|
+
}
|