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,428 @@
|
|
|
1
|
+
import { type ICtx, Scene, type SceneFrame } from "@threenative/core";
|
|
2
|
+
import { CollisionShape3D, type IPhysicsContext, RigidBody3D } from "@threenative/physics";
|
|
3
|
+
import { type Mesh, type PerspectiveCamera, Vector3 } from "three";
|
|
4
|
+
import { applyDirectDamage, applyRadiusDamage } from "../combat/damage.js";
|
|
5
|
+
import { Pickup } from "../entities/Pickup.js";
|
|
6
|
+
import {
|
|
7
|
+
FRIENDLY_LAYER,
|
|
8
|
+
HOSTILE_LAYER,
|
|
9
|
+
PLAYER_LAYER,
|
|
10
|
+
Player,
|
|
11
|
+
SPAWN,
|
|
12
|
+
WORLD_LAYER,
|
|
13
|
+
} from "../entities/Player.js";
|
|
14
|
+
import { Target } from "../entities/Target.js";
|
|
15
|
+
import { SpawnPoints } from "../level/SpawnPoints.js";
|
|
16
|
+
import { emitPlaytestEvent } from "../playtest-events.js";
|
|
17
|
+
import { createArenaCamera } from "../render/camera.js";
|
|
18
|
+
import { setupLighting } from "../render/lighting.js";
|
|
19
|
+
import { createLoadingScreen } from "../render/loading.js";
|
|
20
|
+
import { createMaterials } from "../render/materials.js";
|
|
21
|
+
import { setupPost } from "../render/postprocessing.js";
|
|
22
|
+
import { createArena, createFriendlyVisual, createWallVisual } from "../render/shapes.js";
|
|
23
|
+
import { setupSky } from "../render/sky.js";
|
|
24
|
+
import type { GameState } from "../state.js";
|
|
25
|
+
import { WaveDirector } from "../waves.js";
|
|
26
|
+
import { Hitscan } from "../weapons/Hitscan.js";
|
|
27
|
+
import { Projectile } from "../weapons/Projectile.js";
|
|
28
|
+
|
|
29
|
+
export type GameCtx = ICtx<GameState, IPhysicsContext>;
|
|
30
|
+
|
|
31
|
+
const AIM = new Vector3(0, 0, -1);
|
|
32
|
+
const DEMO_POSITION = new Vector3(0, 0.85, -4);
|
|
33
|
+
const WAVE_POSITION = new Vector3(0, 0.9, -9);
|
|
34
|
+
const SCAN_POSITION = new Vector3(3, 0.9, 0);
|
|
35
|
+
const BLAST_CENTRE = new Vector3(0, 0.85, -4);
|
|
36
|
+
const SPAWN_POINTS = new SpawnPoints([
|
|
37
|
+
new Vector3(-0.4, SPAWN.y, SPAWN.z),
|
|
38
|
+
SPAWN,
|
|
39
|
+
new Vector3(0.4, SPAWN.y, SPAWN.z),
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
type TargetEntry = { readonly id: string; readonly target: Target };
|
|
43
|
+
|
|
44
|
+
export class Play extends Scene<GameState, IPhysicsContext> {
|
|
45
|
+
static override readonly initialState: GameState = {
|
|
46
|
+
armor: 0,
|
|
47
|
+
deaths: 0,
|
|
48
|
+
demoTargetAlive: 1,
|
|
49
|
+
friendlyPassed: 0,
|
|
50
|
+
gameOver: 0,
|
|
51
|
+
gameWon: 0,
|
|
52
|
+
health: 100,
|
|
53
|
+
hitDistanceTenths: 0,
|
|
54
|
+
hitNormalXPercent: -101,
|
|
55
|
+
hitNormalYPercent: -101,
|
|
56
|
+
hitNormalZPercent: -101,
|
|
57
|
+
lives: 3,
|
|
58
|
+
pickups: 0,
|
|
59
|
+
radiusInsideDeaths: 0,
|
|
60
|
+
radiusMidAlive: 1,
|
|
61
|
+
radiusNearAlive: 1,
|
|
62
|
+
radiusOutsideAlive: -1,
|
|
63
|
+
respawns: 0,
|
|
64
|
+
scanCount: 0,
|
|
65
|
+
score: 0,
|
|
66
|
+
targetsRemaining: 1,
|
|
67
|
+
wave: 1,
|
|
68
|
+
wavesCleared: 0,
|
|
69
|
+
wallBlocked: 0,
|
|
70
|
+
phase: "playing",
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
override enter(ctx: GameCtx): SceneFrame<GameState, IPhysicsContext> {
|
|
74
|
+
const camera = ctx.camera as PerspectiveCamera;
|
|
75
|
+
const materials = createMaterials();
|
|
76
|
+
setupSky(ctx.scene);
|
|
77
|
+
setupLighting(ctx.scene, ctx.renderer.raw as Parameters<typeof setupLighting>[1]);
|
|
78
|
+
setupPost(ctx.renderer, ctx.scene, camera);
|
|
79
|
+
const loading = createLoadingScreen(ctx);
|
|
80
|
+
ctx.add(camera);
|
|
81
|
+
const rig = createArenaCamera(camera);
|
|
82
|
+
ctx.viewport.resize();
|
|
83
|
+
|
|
84
|
+
const arena = createArena(materials);
|
|
85
|
+
ctx.add(arena.group);
|
|
86
|
+
const arenaBody = (object: Mesh, shape: CollisionShape3D): RigidBody3D =>
|
|
87
|
+
new RigidBody3D({
|
|
88
|
+
collisionLayer: WORLD_LAYER,
|
|
89
|
+
collisionMask: PLAYER_LAYER | HOSTILE_LAYER | FRIENDLY_LAYER,
|
|
90
|
+
object,
|
|
91
|
+
physics: ctx.physics,
|
|
92
|
+
shape,
|
|
93
|
+
type: "fixed",
|
|
94
|
+
});
|
|
95
|
+
arenaBody(arena.floor, CollisionShape3D.box(22, 0.4, 20));
|
|
96
|
+
for (const wall of arena.walls) arenaBody(wall, CollisionShape3D.fromMesh(wall));
|
|
97
|
+
|
|
98
|
+
const playerRef: { value?: Player } = {};
|
|
99
|
+
const getPlayer = (): Player => {
|
|
100
|
+
if (playerRef.value === undefined) throw new Error("Shooter player is not initialized.");
|
|
101
|
+
return playerRef.value;
|
|
102
|
+
};
|
|
103
|
+
const targets = new Map<number, Target>();
|
|
104
|
+
const waveTargets: TargetEntry[] = [];
|
|
105
|
+
const projectiles: Array<{ readonly id: string; readonly value: Projectile }> = [];
|
|
106
|
+
let projectileIndex = 0;
|
|
107
|
+
const waveDirector = new WaveDirector();
|
|
108
|
+
const hitscan = new Hitscan();
|
|
109
|
+
const spawnPoints = SPAWN_POINTS;
|
|
110
|
+
const elapsed = { value: 0 };
|
|
111
|
+
|
|
112
|
+
const createEnemyProjectile = (origin: Vector3): void => {
|
|
113
|
+
const direction = getPlayer().mesh.position.clone().sub(origin).normalize();
|
|
114
|
+
const id = `projectile.enemy.${projectileIndex++}`;
|
|
115
|
+
const projectile = new Projectile(
|
|
116
|
+
ctx,
|
|
117
|
+
materials,
|
|
118
|
+
origin,
|
|
119
|
+
direction,
|
|
120
|
+
WORLD_LAYER | PLAYER_LAYER,
|
|
121
|
+
(hit) => {
|
|
122
|
+
if (hit.body.id === getPlayer().body.body.id) {
|
|
123
|
+
getPlayer().takeDamage(20);
|
|
124
|
+
emitPlaytestEvent({ entity: "player", name: "projectile-hit" });
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
projectiles.push({ id, value: projectile });
|
|
129
|
+
ctx.entities.add(id, projectile);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const registerTarget = (
|
|
133
|
+
id: string,
|
|
134
|
+
position: Vector3,
|
|
135
|
+
options: ConstructorParameters<typeof Target>[3] = {},
|
|
136
|
+
scan = true,
|
|
137
|
+
): Target => {
|
|
138
|
+
const target = new Target(ctx, materials, position, {
|
|
139
|
+
...options,
|
|
140
|
+
onFire: options.onFire ?? createEnemyProjectile,
|
|
141
|
+
});
|
|
142
|
+
targets.set(target.body.body.id, target);
|
|
143
|
+
ctx.entities.add(id, target);
|
|
144
|
+
if (scan) target.startScanning(ctx, getPlayer().body.body.id);
|
|
145
|
+
return target;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const removeEntity = (id: string): void => {
|
|
149
|
+
if (ctx.entities.get(id) !== undefined) ctx.entities.remove(id);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const onDamage = (amount: number): void => {
|
|
153
|
+
const previous = ctx.state.getState();
|
|
154
|
+
ctx.state.set({ health: getPlayer().health, score: previous.score, armor: 0 });
|
|
155
|
+
emitPlaytestEvent({ entity: "player", name: "damaged", amount });
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const onDeath = (): void => {
|
|
159
|
+
const previous = ctx.state.getState();
|
|
160
|
+
const lives = Math.max(0, previous.lives - 1);
|
|
161
|
+
const deaths = previous.deaths + 1;
|
|
162
|
+
ctx.state.set({
|
|
163
|
+
deaths,
|
|
164
|
+
gameOver: lives === 0 ? 1 : 0,
|
|
165
|
+
lives,
|
|
166
|
+
phase: lives === 0 ? "lost" : "dead",
|
|
167
|
+
});
|
|
168
|
+
emitPlaytestEvent({ entity: "player", name: "died", lives });
|
|
169
|
+
if (lives === 0) return;
|
|
170
|
+
ctx.after(0.5, () => {
|
|
171
|
+
waveDirector.reset();
|
|
172
|
+
const spawn = spawnPoints.furthestFrom(waveTargets.map(({ target }) => target));
|
|
173
|
+
getPlayer().respawn(spawn);
|
|
174
|
+
const state = ctx.state.getState();
|
|
175
|
+
ctx.state.set({
|
|
176
|
+
health: getPlayer().health,
|
|
177
|
+
phase: "playing",
|
|
178
|
+
respawns: state.respawns + 1,
|
|
179
|
+
wave: waveDirector.wave,
|
|
180
|
+
wavesCleared: waveDirector.cleared,
|
|
181
|
+
});
|
|
182
|
+
emitPlaytestEvent({ entity: "player", name: "respawned" });
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const player = new Player(ctx, materials, SPAWN.clone(), onDamage, onDeath);
|
|
187
|
+
playerRef.value = player;
|
|
188
|
+
ctx.entities.add("player", player);
|
|
189
|
+
|
|
190
|
+
const demo = registerTarget(
|
|
191
|
+
"demo-target",
|
|
192
|
+
DEMO_POSITION,
|
|
193
|
+
{ health: 20, onFire: () => undefined },
|
|
194
|
+
false,
|
|
195
|
+
);
|
|
196
|
+
registerTarget("scan-target", SCAN_POSITION, { health: 20, onFire: () => undefined });
|
|
197
|
+
const friendly = createFriendlyVisual(materials);
|
|
198
|
+
friendly.name = "friendly-drone";
|
|
199
|
+
friendly.position.set(0, 1, 2.2);
|
|
200
|
+
ctx.add(friendly);
|
|
201
|
+
const friendlyBody = new RigidBody3D({
|
|
202
|
+
collisionLayer: FRIENDLY_LAYER,
|
|
203
|
+
collisionMask: 0,
|
|
204
|
+
object: friendly,
|
|
205
|
+
physics: ctx.physics,
|
|
206
|
+
shape: CollisionShape3D.box(0.9, 1.4, 0.9),
|
|
207
|
+
type: "fixed",
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const wall = createWallVisual(materials);
|
|
211
|
+
wall.name = "probe-wall";
|
|
212
|
+
wall.position.set(4, 1.4, 5);
|
|
213
|
+
ctx.add(wall);
|
|
214
|
+
const wallBody = new RigidBody3D({
|
|
215
|
+
collisionLayer: WORLD_LAYER,
|
|
216
|
+
collisionMask: PLAYER_LAYER | FRIENDLY_LAYER,
|
|
217
|
+
object: wall,
|
|
218
|
+
physics: ctx.physics,
|
|
219
|
+
shape: CollisionShape3D.box(0.65, 2.8, 2.8),
|
|
220
|
+
type: "fixed",
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const radiusNear = registerTarget(
|
|
224
|
+
"radius.near",
|
|
225
|
+
new Vector3(0.8, 0.85, -4),
|
|
226
|
+
{ health: 30, onFire: () => undefined },
|
|
227
|
+
false,
|
|
228
|
+
);
|
|
229
|
+
const radiusMid = registerTarget(
|
|
230
|
+
"radius.mid",
|
|
231
|
+
new Vector3(-1.8, 0.85, -4),
|
|
232
|
+
{ health: 30, onFire: () => undefined },
|
|
233
|
+
false,
|
|
234
|
+
);
|
|
235
|
+
const radiusOutside = registerTarget(
|
|
236
|
+
"radius.outside",
|
|
237
|
+
new Vector3(6.5, 0.85, -4),
|
|
238
|
+
{ health: 30, onFire: () => undefined },
|
|
239
|
+
false,
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const pickup = new Pickup(
|
|
243
|
+
ctx,
|
|
244
|
+
materials,
|
|
245
|
+
new Vector3(-1.2, SPAWN.y, SPAWN.z),
|
|
246
|
+
player.body.body.id,
|
|
247
|
+
() => {
|
|
248
|
+
player.health = Math.min(player.maxHealth, player.health + 60);
|
|
249
|
+
const state = ctx.state.getState();
|
|
250
|
+
ctx.state.set({
|
|
251
|
+
armor: state.armor + 1,
|
|
252
|
+
health: player.health,
|
|
253
|
+
pickups: state.pickups + 1,
|
|
254
|
+
});
|
|
255
|
+
emitPlaytestEvent({ entity: "player", name: "collected" });
|
|
256
|
+
ctx.after(4, () => pickup.respawn());
|
|
257
|
+
},
|
|
258
|
+
);
|
|
259
|
+
ctx.entities.add("health-pickup", pickup);
|
|
260
|
+
|
|
261
|
+
const spawnWave = (wave: number): void => {
|
|
262
|
+
const target = registerTarget(`wave.target.${wave}`, WAVE_POSITION.clone(), {
|
|
263
|
+
health: 35,
|
|
264
|
+
wave,
|
|
265
|
+
});
|
|
266
|
+
waveTargets.push({ id: `wave.target.${wave}`, target });
|
|
267
|
+
ctx.state.set({ targetsRemaining: 1, wave });
|
|
268
|
+
emitPlaytestEvent({ entity: "wave", name: "started", wave });
|
|
269
|
+
};
|
|
270
|
+
waveDirector.start(spawnWave);
|
|
271
|
+
rig.snap(player.mesh.position);
|
|
272
|
+
|
|
273
|
+
const fireHitscan = (): void => {
|
|
274
|
+
const hit = hitscan.fire(ctx.physics, player.aimOrigin(), AIM, HOSTILE_LAYER);
|
|
275
|
+
if (hit === undefined) return;
|
|
276
|
+
const state = ctx.state.getState();
|
|
277
|
+
const target = targets.get(hit.body.id);
|
|
278
|
+
if (target !== undefined) applyDirectDamage(targets, hit.body.id, 40);
|
|
279
|
+
const demoHit = hit.body.id === demo.body.body.id;
|
|
280
|
+
ctx.state.set({
|
|
281
|
+
demoTargetAlive: demo.alive ? 1 : 0,
|
|
282
|
+
friendlyPassed: demoHit && friendlyBody.body.id !== hit.body.id ? 1 : state.friendlyPassed,
|
|
283
|
+
...(demoHit
|
|
284
|
+
? {
|
|
285
|
+
hitDistanceTenths: Math.round(hit.distance * 10),
|
|
286
|
+
hitNormalXPercent: Math.round(hit.normal.x * 100),
|
|
287
|
+
hitNormalYPercent: Math.round(hit.normal.y * 100),
|
|
288
|
+
hitNormalZPercent: Math.round(hit.normal.z * 100),
|
|
289
|
+
}
|
|
290
|
+
: {}),
|
|
291
|
+
});
|
|
292
|
+
emitPlaytestEvent({
|
|
293
|
+
entity: "player",
|
|
294
|
+
name: "hit",
|
|
295
|
+
distanceTenths: Math.round(hit.distance * 10),
|
|
296
|
+
});
|
|
297
|
+
if (target?.alive === false) emitPlaytestEvent({ entity: "target", name: "defeated" });
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const fireProjectile = (): void => {
|
|
301
|
+
const id = `projectile.player.${projectileIndex++}`;
|
|
302
|
+
const projectile = new Projectile(
|
|
303
|
+
ctx,
|
|
304
|
+
materials,
|
|
305
|
+
player.aimOrigin(),
|
|
306
|
+
AIM,
|
|
307
|
+
HOSTILE_LAYER | WORLD_LAYER,
|
|
308
|
+
(hit) => {
|
|
309
|
+
if (applyDirectDamage(targets, hit.body.id, 22))
|
|
310
|
+
emitPlaytestEvent({ entity: "player", name: "projectile-defeated" });
|
|
311
|
+
},
|
|
312
|
+
);
|
|
313
|
+
projectiles.push({ id, value: projectile });
|
|
314
|
+
ctx.entities.add(id, projectile);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const fireRadius = (): void => {
|
|
318
|
+
applyRadiusDamage(ctx.physics, BLAST_CENTRE, 3.5, 80, targets);
|
|
319
|
+
const insideDeaths = [radiusNear, radiusMid].filter(
|
|
320
|
+
(target) => target.alive === false,
|
|
321
|
+
).length;
|
|
322
|
+
ctx.state.set({
|
|
323
|
+
radiusInsideDeaths: insideDeaths,
|
|
324
|
+
radiusMidAlive: radiusMid.alive ? 1 : 0,
|
|
325
|
+
radiusNearAlive: radiusNear.alive ? 1 : 0,
|
|
326
|
+
radiusOutsideAlive: radiusOutside.alive ? 1 : 0,
|
|
327
|
+
});
|
|
328
|
+
emitPlaytestEvent({ entity: "player", name: "radius-damage", defeated: insideDeaths });
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const probeWall = (): void => {
|
|
332
|
+
const from = player.mesh.position.clone().add(new Vector3(0, 0.75, 0));
|
|
333
|
+
const to = from.clone().add(new Vector3(10, 0, 0));
|
|
334
|
+
const hit = hitscan.probe(ctx.physics, from, to, WORLD_LAYER | FRIENDLY_LAYER);
|
|
335
|
+
if (hit?.body.id !== wallBody.body.id) return;
|
|
336
|
+
ctx.state.set({ wallBlocked: 1 });
|
|
337
|
+
emitPlaytestEvent({ entity: "player", name: "wall-blocked" });
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const removeDeadTargets = (): void => {
|
|
341
|
+
if (!demo.alive && ctx.entities.get("demo-target") !== undefined) {
|
|
342
|
+
removeEntity("demo-target");
|
|
343
|
+
targets.delete(demo.body.body.id);
|
|
344
|
+
}
|
|
345
|
+
for (let index = waveTargets.length - 1; index >= 0; index -= 1) {
|
|
346
|
+
const entry = waveTargets[index];
|
|
347
|
+
if (entry?.target.alive !== false) continue;
|
|
348
|
+
removeEntity(entry.id);
|
|
349
|
+
targets.delete(entry.target.body.body.id);
|
|
350
|
+
waveTargets.splice(index, 1);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
const restart = (frameCtx: GameCtx): boolean => {
|
|
355
|
+
if (!frameCtx.input.justPressed("restart")) return false;
|
|
356
|
+
frameCtx.state.set(Play.initialState);
|
|
357
|
+
frameCtx.state.flush();
|
|
358
|
+
void frameCtx.goto("play");
|
|
359
|
+
return true;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const handleInput = (frameCtx: GameCtx): void => {
|
|
363
|
+
if (frameCtx.input.justPressed("fire")) fireHitscan();
|
|
364
|
+
if (frameCtx.input.justPressed("projectile")) fireProjectile();
|
|
365
|
+
if (frameCtx.input.justPressed("blast")) fireRadius();
|
|
366
|
+
if (frameCtx.input.justPressed("probe")) probeWall();
|
|
367
|
+
if (frameCtx.input.justPressed("damage")) player.takeDamage(35);
|
|
368
|
+
if (frameCtx.input.justPressed("lethal")) player.takeDamage(player.health + 1);
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
const updateProjectiles = (frameCtx: GameCtx, dt: number): void => {
|
|
372
|
+
for (const entry of [...projectiles]) {
|
|
373
|
+
entry.value.update(frameCtx, dt);
|
|
374
|
+
if (!entry.value.dead) continue;
|
|
375
|
+
removeEntity(entry.id);
|
|
376
|
+
projectiles.splice(projectiles.indexOf(entry), 1);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const updateWaves = (frameCtx: GameCtx): void => {
|
|
381
|
+
waveDirector.update(
|
|
382
|
+
frameCtx,
|
|
383
|
+
waveTargets.filter(({ target }) => target.alive).length,
|
|
384
|
+
spawnWave,
|
|
385
|
+
(wave) => {
|
|
386
|
+
const state = frameCtx.state.getState();
|
|
387
|
+
frameCtx.state.set({ score: state.score + 100, wavesCleared: waveDirector.cleared });
|
|
388
|
+
emitPlaytestEvent({ entity: "wave", name: "cleared", wave });
|
|
389
|
+
},
|
|
390
|
+
);
|
|
391
|
+
if (waveDirector.won) frameCtx.state.set({ gameWon: 1, phase: "won" });
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
const syncStateAndHud = (frameCtx: GameCtx): void => {
|
|
395
|
+
const liveTargets = waveTargets.filter(({ target }) => target.alive).length;
|
|
396
|
+
const currentScanCount = [...targets.values()].reduce(
|
|
397
|
+
(sum, target) => sum + target.scanCount,
|
|
398
|
+
0,
|
|
399
|
+
);
|
|
400
|
+
const previous = frameCtx.state.getState();
|
|
401
|
+
const scanCount = Math.max(previous.scanCount, currentScanCount);
|
|
402
|
+
frameCtx.state.set({
|
|
403
|
+
health: player.health,
|
|
404
|
+
scanCount,
|
|
405
|
+
targetsRemaining: liveTargets,
|
|
406
|
+
wave: waveDirector.wave,
|
|
407
|
+
wavesCleared: waveDirector.cleared,
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
return (frameCtx, dt) => {
|
|
412
|
+
loading.update();
|
|
413
|
+
elapsed.value += dt;
|
|
414
|
+
if (restart(frameCtx)) return;
|
|
415
|
+
handleInput(frameCtx);
|
|
416
|
+
|
|
417
|
+
player.update(frameCtx, dt);
|
|
418
|
+
hitscan.update(dt);
|
|
419
|
+
updateProjectiles(frameCtx, dt);
|
|
420
|
+
for (const target of targets.values()) target.update(dt);
|
|
421
|
+
pickup.update(dt);
|
|
422
|
+
removeDeadTargets();
|
|
423
|
+
updateWaves(frameCtx);
|
|
424
|
+
syncStateAndHud(frameCtx);
|
|
425
|
+
rig.follow(player.mesh.position, dt);
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type GamePhase = "playing" | "dead" | "won" | "lost";
|
|
2
|
+
|
|
3
|
+
export type GameState = {
|
|
4
|
+
armor: number;
|
|
5
|
+
deaths: number;
|
|
6
|
+
demoTargetAlive: number;
|
|
7
|
+
friendlyPassed: number;
|
|
8
|
+
gameOver: number;
|
|
9
|
+
gameWon: number;
|
|
10
|
+
health: number;
|
|
11
|
+
hitDistanceTenths: number;
|
|
12
|
+
hitNormalXPercent: number;
|
|
13
|
+
hitNormalYPercent: number;
|
|
14
|
+
hitNormalZPercent: number;
|
|
15
|
+
lives: number;
|
|
16
|
+
pickups: number;
|
|
17
|
+
radiusInsideDeaths: number;
|
|
18
|
+
radiusMidAlive: number;
|
|
19
|
+
radiusNearAlive: number;
|
|
20
|
+
radiusOutsideAlive: number;
|
|
21
|
+
respawns: number;
|
|
22
|
+
scanCount: number;
|
|
23
|
+
score: number;
|
|
24
|
+
targetsRemaining: number;
|
|
25
|
+
wave: number;
|
|
26
|
+
wavesCleared: number;
|
|
27
|
+
wallBlocked: number;
|
|
28
|
+
phase: GamePhase;
|
|
29
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IGame } from "@threenative/core";
|
|
2
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
3
|
+
import { DebugOverlay, GameCanvas } from "@threenative/ui";
|
|
4
|
+
import { shooterUi } from "../render/ui.js";
|
|
5
|
+
import type { GameState } from "../state.js";
|
|
6
|
+
import { Hud } from "./Hud.js";
|
|
7
|
+
import { Menu } from "./Menu.js";
|
|
8
|
+
|
|
9
|
+
type AppProps = {
|
|
10
|
+
game: IGame<GameState, IPhysicsContext>;
|
|
11
|
+
onRestart: () => void;
|
|
12
|
+
onTogglePause: () => void;
|
|
13
|
+
paused: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function App({ game, onRestart, onTogglePause, paused }: AppProps) {
|
|
17
|
+
return (
|
|
18
|
+
<main className={shooterUi.app.root}>
|
|
19
|
+
<GameCanvas className={shooterUi.app.canvas} game={game} />
|
|
20
|
+
<Hud game={game} />
|
|
21
|
+
<Menu onRestart={onRestart} onTogglePause={onTogglePause} paused={paused} />
|
|
22
|
+
<DebugOverlay />
|
|
23
|
+
</main>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { IGame } from "@threenative/core";
|
|
2
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
3
|
+
import { useGameState } from "@threenative/ui";
|
|
4
|
+
import { shooterUi } from "../render/ui.js";
|
|
5
|
+
import type { GameState } from "../state.js";
|
|
6
|
+
|
|
7
|
+
type MeterTone = keyof typeof shooterUi.hud.meter.fill;
|
|
8
|
+
|
|
9
|
+
function Meter({ label, value, tone }: { label: string; tone: MeterTone; value: number }) {
|
|
10
|
+
return (
|
|
11
|
+
<div className={shooterUi.hud.meter.root}>
|
|
12
|
+
<div className={shooterUi.hud.meter.label}>
|
|
13
|
+
<span>{label}</span>
|
|
14
|
+
<b className={shooterUi.hud.meter.value}>{Math.round(value)}</b>
|
|
15
|
+
</div>
|
|
16
|
+
<div className={shooterUi.hud.meter.track}>
|
|
17
|
+
<i
|
|
18
|
+
className={shooterUi.hud.meter.fill[tone]}
|
|
19
|
+
style={{ width: `${Math.max(0, Math.min(100, value))}%` }}
|
|
20
|
+
/>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function Hud({ game }: { game: IGame<GameState, IPhysicsContext> }) {
|
|
27
|
+
const health = useGameState(game, (state) => state.health);
|
|
28
|
+
const lives = useGameState(game, (state) => state.lives);
|
|
29
|
+
const wave = useGameState(game, (state) => state.wave);
|
|
30
|
+
const wavesCleared = useGameState(game, (state) => state.wavesCleared);
|
|
31
|
+
const targets = useGameState(game, (state) => state.targetsRemaining);
|
|
32
|
+
const phase = useGameState(game, (state) => state.phase);
|
|
33
|
+
return (
|
|
34
|
+
<section className={shooterUi.hud.root}>
|
|
35
|
+
<div className={shooterUi.hud.eyebrow}>{shooterUi.hud.copy.eyebrow}</div>
|
|
36
|
+
<div className={shooterUi.hud.wave}>{shooterUi.hud.copy.wave(wave)}</div>
|
|
37
|
+
<div className={shooterUi.hud.rules}>{shooterUi.hud.copy.rules}</div>
|
|
38
|
+
<Meter label={shooterUi.hud.copy.health} tone="cyan" value={health} />
|
|
39
|
+
<Meter label={shooterUi.hud.copy.lives} tone="amber" value={(lives / 3) * 100} />
|
|
40
|
+
<div className={shooterUi.hud.summary}>
|
|
41
|
+
<span>{shooterUi.hud.copy.targets(targets)}</span>
|
|
42
|
+
<span>{shooterUi.hud.copy.clear(wavesCleared)}</span>
|
|
43
|
+
</div>
|
|
44
|
+
{phase !== "playing" && (
|
|
45
|
+
<div className={shooterUi.hud.phase[phase]}>{shooterUi.hud.phaseCopy[phase]}</div>
|
|
46
|
+
)}
|
|
47
|
+
</section>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { shooterUi } from "../render/ui.js";
|
|
2
|
+
|
|
3
|
+
type MenuProps = {
|
|
4
|
+
onRestart: () => void;
|
|
5
|
+
onTogglePause: () => void;
|
|
6
|
+
paused: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function Menu({ onRestart, onTogglePause, paused }: MenuProps) {
|
|
10
|
+
return (
|
|
11
|
+
<footer className={shooterUi.menu.root}>
|
|
12
|
+
<div className={shooterUi.menu.help}>
|
|
13
|
+
<div className={shooterUi.menu.helpPrimary}>{shooterUi.menu.copy.primary}</div>
|
|
14
|
+
<div className={shooterUi.menu.helpSecondary}>{shooterUi.menu.copy.secondary}</div>
|
|
15
|
+
</div>
|
|
16
|
+
<div className={shooterUi.menu.actions}>
|
|
17
|
+
<button className={shooterUi.menu.button} onClick={onTogglePause} type="button">
|
|
18
|
+
{paused ? shooterUi.menu.copy.resume : shooterUi.menu.copy.pause}
|
|
19
|
+
</button>
|
|
20
|
+
<button className={shooterUi.menu.button} onClick={onRestart} type="button">
|
|
21
|
+
{shooterUi.menu.copy.restart}
|
|
22
|
+
</button>
|
|
23
|
+
</div>
|
|
24
|
+
</footer>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ICtx, ScheduleHandle } from "@threenative/core";
|
|
2
|
+
import type { GameState } from "./state.js";
|
|
3
|
+
|
|
4
|
+
type GameCtx = ICtx<GameState, unknown>;
|
|
5
|
+
|
|
6
|
+
export class WaveDirector {
|
|
7
|
+
static readonly MAX_WAVES = 5;
|
|
8
|
+
wave = 0;
|
|
9
|
+
cleared = 0;
|
|
10
|
+
won = false;
|
|
11
|
+
#pending = false;
|
|
12
|
+
#nextHandle: ScheduleHandle | undefined;
|
|
13
|
+
|
|
14
|
+
start(create: (wave: number) => void): void {
|
|
15
|
+
if (this.wave !== 0) throw new Error("WaveDirector can only start once.");
|
|
16
|
+
this.wave = 1;
|
|
17
|
+
create(this.wave);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
reset(): void {
|
|
21
|
+
this.#nextHandle?.cancel();
|
|
22
|
+
this.#nextHandle = undefined;
|
|
23
|
+
this.#pending = false;
|
|
24
|
+
this.cleared = 0;
|
|
25
|
+
this.wave = 1;
|
|
26
|
+
this.won = false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
update(
|
|
30
|
+
ctx: GameCtx,
|
|
31
|
+
liveTargets: number,
|
|
32
|
+
create: (wave: number) => void,
|
|
33
|
+
onClear: (wave: number) => void,
|
|
34
|
+
): void {
|
|
35
|
+
if (this.won || this.#pending || liveTargets > 0 || this.wave === 0) return;
|
|
36
|
+
this.cleared = Math.max(this.cleared, this.wave);
|
|
37
|
+
onClear(this.wave);
|
|
38
|
+
if (this.wave >= WaveDirector.MAX_WAVES) {
|
|
39
|
+
this.won = true;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.#pending = true;
|
|
43
|
+
this.#nextHandle = ctx.after(0.6, () => {
|
|
44
|
+
this.#nextHandle = undefined;
|
|
45
|
+
this.wave += 1;
|
|
46
|
+
this.#pending = false;
|
|
47
|
+
create(this.wave);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
2
|
+
import type { Vector3 } from "three";
|
|
3
|
+
import { type IRayHit, directSpaceState } from "../physics.js";
|
|
4
|
+
|
|
5
|
+
export class Hitscan {
|
|
6
|
+
readonly range: number;
|
|
7
|
+
readonly cooldown: number;
|
|
8
|
+
#cooldown = 0;
|
|
9
|
+
|
|
10
|
+
constructor(range = 24, cooldown = 0.22) {
|
|
11
|
+
this.range = range;
|
|
12
|
+
this.cooldown = cooldown;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
update(dt: number): void {
|
|
16
|
+
this.#cooldown = Math.max(0, this.#cooldown - dt);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
fire(
|
|
20
|
+
physics: IPhysicsContext,
|
|
21
|
+
from: Vector3,
|
|
22
|
+
direction: Vector3,
|
|
23
|
+
collisionMask: number,
|
|
24
|
+
): IRayHit | undefined {
|
|
25
|
+
if (this.#cooldown > 0) return undefined;
|
|
26
|
+
this.#cooldown = this.cooldown;
|
|
27
|
+
const to = from.clone().add(direction.clone().normalize().multiplyScalar(this.range));
|
|
28
|
+
return directSpaceState(physics).intersectRay({
|
|
29
|
+
collisionMask,
|
|
30
|
+
from,
|
|
31
|
+
to,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
probe(
|
|
36
|
+
physics: IPhysicsContext,
|
|
37
|
+
from: Vector3,
|
|
38
|
+
to: Vector3,
|
|
39
|
+
collisionMask: number,
|
|
40
|
+
): IRayHit | undefined {
|
|
41
|
+
return directSpaceState(physics).intersectRay({ collisionMask, from, to });
|
|
42
|
+
}
|
|
43
|
+
}
|