今天看到国外一位大神用 Claude Opus 5 构建了一个完整的第一人称射击游戏,只靠一个 HTML 文件就全部搞定。没有额外资源、没用任何构建工具,所有内容都由 AI 自动生成。

代码地址: https://github.com/StarKnightt/operation-ironhold
体验地址: https://starknightt.github.io/operation-ironhold/
游戏描述: 10 名敌对分子占领了 7 号区域的一个集装箱堆场。你有 3 分钟时间将其清除。
整个游戏——包括渲染器设置、世界生成、武器操控、敌人 AI、音频合成、后期处理和 HUD——仅用了约 6500 行 JavaScript 和 CSS 代码,全部塞进一个 290KB 的 index.html 文件里。唯一的外部调用是从 CDN 加载 three.js r128,其余所有内容都在运行时动态生成。
核心特性一目了然:
- 4 种武器,具备瞄准、后坐力和换弹效果
- 10 个 AI 敌人,会侧翼攻击、寻找掩体并报点
- 狙击镜具备屏息和晃动效果
- 可攀爬容器、二段跳和冲刺
- 所有纹理和音效均由代码生成
- 在浏览器中以 60fps 运行,文件仅 290KB,一个文件一个模型
在 3 分钟内消灭所有 10 名敌人。初始生命值 100,护甲值 50,护甲能吸收一半伤害直到耗尽。敌方会在头三秒停火,让你有时间确认方位;战斗指挥官会限制同一时间向你开火的敌人不超过两人,其余则持续机动。正是这一点,让交火清晰可控,避免了瞬间交叉火力带来的无力感。
死亡或时间归零都会结束回合。结算界面会显示击杀数、爆头数、命中率和生存时间。
4 种武器的参数与特性:

每个角色都拥有一个由基本几何体构成的模型,戴手套的手会随鼠标移动摆动,随脚步上下晃动,换弹时移出屏幕,弹壳会弹到水泥地上。枪口火焰是一个精灵图,背后是真实的点光源,并用光晕效果烘托。步枪的后坐力模式是固定的,而非随机散布,所以弹道扩散是可控的。
瞄准与狙击体验
右键点击可切换瞄准模式。每种武器需要 0.2 秒完成瞄准。


狙击枪会彻底改变屏幕显示。开镜后,准星变成全覆盖式瞄准镜,武器隐藏于镜片之后,复合着色器像真实光学瞄准镜那样对镜片进行模糊处理。视野以缓慢的双正弦曲线摆动;按住 Shift 键可稳定视野 3 秒钟,之后必须松开重新闭气。鼠标灵敏度随缩放倍率变化,从而让瞄准点在屏幕上始终保持稳定。枪栓拉栓需要 1.5 秒,一旦失手代价相当高昂。撤回或取消瞄准时,弹道扩散范围会缩小,但移动速度会降低 40%。
全程序化生成的内容
混凝土、波纹钢、胶合板、锈迹、砖块和铁丝网,就连集装箱侧面的印刷运输标记,都是由画布绘制的。武器、手和士兵由箱子、圆柱体和球体组合而成。天空被逐块分割,地平线上的工业天际线也是几何形状。
所有声音都通过 Web Audio API 合成:每种武器的枪声由枪响、身体撞击声和胸膛撞击声叠层组成;还有换弹声、脚步声、击中墙壁或肉体的不同冲击声、低生命值的心跳声,以及随机播放的、带有远处金属吱嘎声的工业环境嗡鸣。同时还用到了由生成的脉冲响应构建的卷积混响。
作者提供的提示词梳理
以下提示词按照给出顺序,展示了游戏的完整构建过程,包含需求规格、ADS 与狙击镜、Bug 修复、准星调整、敌方瞄准与天空材质等细节。
# Prompts
The prompts that specify the game, in the order they were given. Wording is unedited, typos
included.
---
## 1. The specification
Everything below arrived in one message.
```text
build a complete realistic FPS shooter game in a single HTML file. everything inline — JS and CSS in the same file. no external dependencies except three.js from CDN (https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js). no build tools, no npm.
**core gameplay:**
- first person shooter, single player vs AI enemies
- WASD movement, mouse look with pointer lock on click
- left click to shoot, R to reload, shift to sprint, ctrl to crouch, space to jump
- sprint adds FOV push effect and lowers weapon slightly
- crouch lowers camera height and reduces movement speed
- jump with landing camera shake
**weapons system (switch with 1, 2, 3):**
- slot 1: assault rifle — full auto, 30 round mag, moderate spread that increases with sustained fire, semi-auto toggle with V key
- slot 2: shotgun — pump action, 8 shells, wide spread, high damage up close, pump animation between shots
- slot 3: pistol — semi auto, 15 rounds, accurate, fast draw speed
- each weapon needs a visible 3D viewmodel at bottom right — build them from three.js geometry (boxes, cylinders). add gloved hands holding the weapon
- weapon sway on mouse movement, bob when walking synced to footsteps
- muzzle flash (point light + sprite) on every shot
- shell casings that eject and bounce on the ground with physics
- reload animation (weapon dips down off screen and comes back)
- draw animation when switching weapons
**enemies (10 total):**
- humanoid models built from three.js geometry (capsule body, sphere head, box limbs)
- each enemy has a floating name tag and health bar above their head
- enemy names: VIPER, GHOST, REAPER, HAVOC, STRIKER, COBRA, TALON, WOLF, DIESEL, SHADOW
- enemies patrol waypoints around the map using simple pathfinding
- when they spot you (line of sight + distance check), they stop, aim, and shoot with human-like reaction delay (300-800ms random)
- enemies strafe left/right during combat
- headshot detection — 2x damage on head hitbox
- hit reaction animation (flinch backward)
- death animation (ragdoll-style fall, weapon drops to ground)
- enemies deal damage to player with visible red screen flash
**map design — abandoned warehouse district:**
- 60x60 unit play area
- concrete floor with grid texture (procedural)
- shipping containers (large colored boxes) placed as cover throughout
- two story building on one side with accessible second floor via ramp — gives sniper advantage
- long corridor between container stacks (close quarters)
- open center area with a destroyed vehicle (boxes arranged as car shape)
- chain link fence sections around the perimeter (thin planes with alpha)
- barrel stacks that block sightlines
- crate clusters for cover
- directional lighting with shadows casting from a sun position
- fog in the distance for atmosphere
**HUD:**
- crosshair center screen (dynamic — expands when moving/shooting, contracts when still)
- health bar bottom left with number (starts at 100)
- armor bar below health (starts at 50, reduces damage by 50%)
- ammo counter bottom right: current mag / total reserve
- weapon name and icon next to ammo
- kill feed top right — shows "YOU killed ENEMY" with headshot icon when applicable
- hit marker (white X flash) when you land a shot
- damage direction indicator (red arc on screen edge showing where damage came from)
- minimap top left showing player position, enemy dots (red when spotted), and map walls
- round timer top center counting down from 3:00
- kill counter: "X / 10 eliminated"
**audio (all procedural Web Audio API, no external files):**
- gunshot sounds per weapon (rifle = sharp crack, shotgun = deep boom, pistol = snap)
- reload sound (metallic click)
- footsteps synced to movement (concrete sound)
- bullet impact sounds (different for wall vs enemy)
- enemy death sound
- hit confirmation beep
- low health heartbeat warning when under 20hp
- ambient industrial hum in background
**post processing:**
- bloom on muzzle flash and bright lights
- vignette darkening at screen edges
- slight color grading (desaturated, slightly blue shadows)
- screen shake on taking damage and on shooting shotgun
**game flow:**
- start screen: "PRESS TO START" with title
- pointer lock activates on click
- kill all 10 enemies to win
- die or run out of time to lose
- end screen shows: kills, headshots, accuracy percentage, time survived
- restart button on end screen
**performance:**
- use merged geometries where possible to reduce draw calls
- shadow maps at 2048
- keep it running 60fps on mid-range hardware
- use instanced mesh for repeated objects like crates and barrels
make it feel like a real game. weight to the movement, punch to the guns, tension in the combat. not a tech demo.
```
---
## 2. Aim down sights, the sniper, and parkour
Added the fourth weapon, the scope, and the ability to climb onto things.
```text
aim-down-sights (ADS) for all weapons on right click:
assault rifle: FOV goes from 75 to 55, weapon model moves to center screen, tighter spread while aiming
shotgun: FOV goes from 75 to 60, slight zoom, weapon centers
pistol: FOV goes from 75 to 50, weapon raises to center with iron sight alignment
sniper: FOV goes from 75 to 15, full scope overlay with dark circular vignette and mil-dot crosshair lines, subtle scope sway (slow sine wave on x and y), hold shift while scoped to hold breath (sway settles to near zero for 3 seconds)
smooth transition in and out (0.2 sec lerp) for all weapons
reduce movement speed by 40% while ADS
right click to toggle ADS on/off
disable normal crosshair while using sniper scope
sniper rifle as slot 4: bolt action, 5 round mag, one shot kill to body, headshot instant kill
bolt cycle animation between shots (1.5 sec delay)
loud crack sound, visible bullet tracer line
switch weapons with 1-4 and scroll wheel
parkour/mantle: when player jumps near a container or crate edge and holds space, auto-mantle onto it (camera lifts up smoothly to the top)
player can stand and walk on top of containers, crates, the vehicle, and barrel stacks
double jump: tap space twice quickly for extra height
increase base jump height slightly so player can reach container tops with mantle
add collision on top of all objects so player doesn't fall through
```
---
## 3. The bug list
The longest correction of the project. Collision, enemy AI and weapon reliability were all
rebuilt off the back of it.
```text
the game has major bugs that need fixing before this is shareable. go through everything and fix all of these:
**collision bugs (highest priority):**
- player can walk through some walls. every single wall, container, crate, barrel, and building must have solid collision. the player should never pass through any object. check every single object in the scene has a collider and that the collision detection actually works
- enemies are getting stuck inside containers and walls. add collision checks for enemy pathfinding so they navigate AROUND objects, never through them. if an enemy is stuck, teleport them to the nearest valid position outside any object
- enemies stuck inside containers can still shoot the player but player can't shoot back. fix this — if there's no clear line of sight between player and enemy (raycast hits a wall/container), the enemy cannot deal damage
**enemy AI fixes:**
- enemies should never walk into walls or containers. their pathfinding needs to respect all solid objects
- enemies should never stand still in the open doing nothing. if they're not in combat, they patrol. if they spot the player, they engage immediately
- enemies should take cover behind containers and crates during combat, not just stand in the open
- if an enemy can't reach the player, they should find an alternative path, not freeze
**weapon and shooting fixes:**
- make sure every weapon actually fires when clicking. if there's any delay or missed input, fix it
- muzzle flash needs to be visible and punchy — bright flash + point light for 2 frames
- bullet hit detection needs to be accurate. if crosshair is on the enemy, the bullet should hit. no phantom misses
- shell casings should eject properly from the right side of the weapon
- reload should feel smooth — weapon dips, mag change sound, weapon comes back
- ADS (aim down sights) on right click must work for every weapon. if it's broken, fix it
- sniper scope overlay must appear on right click with the sniper equipped
**general polish:**
- make sure the player cannot leave the map boundaries. add invisible walls at all edges
- fix any z-fighting or flickering textures
- make sure the minimap accurately shows wall positions and enemy dots
- death screen and win screen must work properly with accurate stats
- fix any console errors
test everything after fixing. walk along every wall. try to walk through every container. watch every enemy for 30 seconds to make sure they're not stuck. fire every weapon and confirm it works. this needs to feel like a finished game, not a broken prototype.
```
---
## 4. The crosshair
```text
replace the current crosshair with a valorant-style competitive crosshair:
**inner lines:**
- 4 lines (top, bottom, left, right)
- each line is 4px long, 2px thick
- offset 1px from center (small gap in the middle)
- color: white with thin black outline for visibility on any background
- no center dot
**outer lines:**
- 4 lines (top, bottom, left, right)
- each line is 3px long, 2px thick
- offset 2px from the end of the inner lines (gap between inner and outer)
- same white with black outline
**behavior:**
- crosshair stays static when standing still
- inner lines expand outward when moving or shooting (dynamic spread)
- inner lines return to default position when standing still and not firing (0.15 sec lerp back)
- outer lines don't move
- no firing error on outer lines
- no movement error on outer lines
- crosshair disappears when using sniper scope ADS
- crosshair stays visible for all other weapons during ADS
draw this with canvas overlay, not HTML elements. needs to be pixel-perfect and centered.
```
---
## 5. Enemy aim, the sky, and the M4 optic
Sent with two screenshots: one looking up at the zenith, one down a container lane.
```text
time to fix some bugs, enemeies guns are pointing backwards if you see while shooting and our sky looks pixelated like you can see here and one more thing zooming in in m4 carbine is like trash i mean theres' no use if i can't zoom in more and see enemy
```
谁说 AI 生成的游戏没法用?现在已经很好了,而且随着时间推移,AI 只会越来越强。接下来就等着 Claude Opus 5 生成的内容霸屏吧。云栈社区也会持续关注这些 AI 工具带来的开发新范式。