Created
November 18, 2026 06:44
-
-
Save senko/02b16d01e69eb519cb6b59ea103f478c to your computer and use it in GitHub Desktop.
Flying simulator by GPT-6.2 Astra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"> | |
| <link rel="icon" | |
| href="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 40 40%27%3E%3Crect width=%2740%27 height=%2740%27 rx=%278%27 fill=%27%2320231f%27/%3E%3Cpath d=%27m3 10 13 3 4 6 4-6 13-3-5 6-6 1-6 12-6-12-6-1z%27 fill=%27%23dfb57a%27/%3E%3C/svg%3E"> | |
| <meta name="theme-color" content="#20231f"> | |
| <title>Ironwing — Flight Simulator</title> | |
| <style> | |
| :root { | |
| color-scheme: dark; | |
| --ink: #20231f; | |
| --panel: rgba(28, 32, 28, .91); | |
| --paper: #f3efe1; | |
| --muted: #b0b2a5; | |
| --amber: #e3b877; | |
| --red: #d2694f; | |
| --line: rgba(226, 222, 197, .21); | |
| --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace; | |
| --sans: 'Inter', 'Helvetica Neue', Arial, sans-serif | |
| } | |
| * { | |
| box-sizing: border-box | |
| } | |
| [hidden] { | |
| display: none !important | |
| } | |
| #stage:focus { | |
| outline: none | |
| } | |
| html, | |
| body { | |
| margin: 0; | |
| width: 100%; | |
| height: 100%; | |
| overflow: hidden | |
| } | |
| body { | |
| display: flex; | |
| flex-direction: column; | |
| background: var(--ink); | |
| color: var(--paper); | |
| font-family: var(--sans); | |
| -webkit-user-select: none; | |
| user-select: none | |
| } | |
| button { | |
| font: inherit; | |
| color: inherit; | |
| cursor: pointer | |
| } | |
| button:focus-visible { | |
| outline: 2px solid var(--amber); | |
| outline-offset: 3px | |
| } | |
| button:hover { | |
| filter: brightness(1.18) | |
| } | |
| svg { | |
| display: block; | |
| fill: none; | |
| stroke: currentColor; | |
| stroke-width: 1.6; | |
| stroke-linecap: round; | |
| stroke-linejoin: round | |
| } | |
| .defs { | |
| width: 0; | |
| height: 0; | |
| position: absolute; | |
| overflow: hidden | |
| } | |
| .icon { | |
| width: 16px; | |
| height: 16px; | |
| flex: none | |
| } | |
| header { | |
| height: 66px; | |
| flex: none; | |
| background: #20231f; | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| padding: 0 29px; | |
| border-bottom: 1px solid #47493e; | |
| position: relative; | |
| z-index: 3 | |
| } | |
| .brand, | |
| .actions, | |
| .status, | |
| .tool, | |
| .panel-head, | |
| .obj, | |
| .view-btn, | |
| .legend, | |
| .readouts, | |
| .barrow, | |
| .loadout, | |
| .dialog-head { | |
| display: flex; | |
| align-items: center | |
| } | |
| .brand { | |
| gap: 13px | |
| } | |
| .brand svg { | |
| width: 44px; | |
| height: 36px; | |
| color: #dfb57a | |
| } | |
| .wordmark { | |
| font: italic 900 28px/1 'Arial Black', Arial, sans-serif; | |
| letter-spacing: -1.25px | |
| } | |
| .brand-sub, | |
| .small, | |
| .eyebrow, | |
| .status, | |
| .tag, | |
| .legend-title, | |
| .view-btn, | |
| .panel-head, | |
| .barrow, | |
| .unit, | |
| .dialog-kicker, | |
| .bearing, | |
| .keyname, | |
| .compass { | |
| font-family: var(--mono); | |
| font-size: 10px; | |
| font-weight: 600; | |
| letter-spacing: 1.4px; | |
| text-transform: uppercase | |
| } | |
| .brand-sub { | |
| color: #b1b2a3; | |
| padding-left: 18px; | |
| margin-left: 3px; | |
| border-left: 1px solid #535549; | |
| line-height: 20px; | |
| letter-spacing: 2px | |
| } | |
| .actions { | |
| gap: 8px | |
| } | |
| .status { | |
| gap: 8px; | |
| color: #d2d6c5; | |
| font-size: 10px; | |
| letter-spacing: 1.2px; | |
| margin-right: 14px | |
| } | |
| .light { | |
| width: 6px; | |
| height: 6px; | |
| border-radius: 50%; | |
| background: #a9c291; | |
| display: inline-block; | |
| box-shadow: 0 0 8px #adc49e33 | |
| } | |
| .tool { | |
| justify-content: center; | |
| gap: 8px; | |
| background: #30332e; | |
| border: 1px solid #50534a; | |
| border-radius: 4px; | |
| height: 32px; | |
| min-width: 34px; | |
| padding: 0 9px | |
| } | |
| .tool.wide { | |
| padding: 0 12px; | |
| font-size: 12px; | |
| font-weight: 600 | |
| } | |
| .tool .icon { | |
| width: 15px; | |
| height: 15px | |
| } | |
| .tool[aria-pressed=true] { | |
| border-color: var(--amber); | |
| color: var(--amber) | |
| } | |
| main { | |
| position: relative; | |
| flex: 1; | |
| min-height: 0; | |
| isolation: isolate; | |
| background: #b9c8c7; | |
| overflow: hidden; | |
| touch-action: none | |
| } | |
| #world, | |
| #overlay, | |
| .scene-effect { | |
| position: absolute; | |
| inset: 0; | |
| width: 100%; | |
| height: 100%; | |
| display: block | |
| } | |
| #overlay, | |
| .scene-effect, | |
| .panel, | |
| .compass { | |
| pointer-events: none | |
| } | |
| .scene-effect { | |
| background: radial-gradient(ellipse at 53% 43%, transparent 48%, rgba(42, 40, 20, .12) 100%) | |
| } | |
| .panel { | |
| position: absolute; | |
| background: var(--panel); | |
| border: 1px solid #c4c2a44d; | |
| border-radius: 5px; | |
| box-shadow: 0 3px 12px #171c171f; | |
| color: var(--paper) | |
| } | |
| .mission { | |
| top: 23px; | |
| left: 25px; | |
| width: 229px; | |
| padding: 17px 17px 13px | |
| } | |
| .panel-head, | |
| .eyebrow { | |
| display: flex; | |
| align-items: center; | |
| gap: 8px; | |
| font-weight: 600; | |
| font-size: 10px; | |
| color: var(--amber); | |
| letter-spacing: 1.55px | |
| } | |
| .panel-head .icon, | |
| .eyebrow .icon { | |
| width: 14px; | |
| height: 14px | |
| } | |
| .mission h1 { | |
| font-size: 27px; | |
| letter-spacing: -1.05px; | |
| margin: 9px 0 5px; | |
| line-height: 1.05; | |
| font-weight: 700 | |
| } | |
| .mission p { | |
| font-size: 12px; | |
| color: #d0d2c5; | |
| margin: 0 0 13px; | |
| line-height: 1.4 | |
| } | |
| .obj { | |
| border-top: 1px solid var(--line); | |
| padding-top: 10px; | |
| gap: 8px | |
| } | |
| .obj .small { | |
| letter-spacing: 1.05px; | |
| color: #bbbeb0; | |
| font-size: 9px | |
| } | |
| .count { | |
| white-space: nowrap; | |
| font-family: var(--mono); | |
| font-size: 12px; | |
| font-weight: 700; | |
| margin-left: auto | |
| } | |
| .count em { | |
| color: #999e91; | |
| font-style: normal | |
| } | |
| .diamonds { | |
| display: flex; | |
| gap: 5px | |
| } | |
| .diamonds i { | |
| width: 6px; | |
| height: 6px; | |
| border: 1px solid #b7b7a2; | |
| transform: rotate(45deg) | |
| } | |
| .diamonds i.done { | |
| background: var(--amber); | |
| border-color: var(--amber) | |
| } | |
| .compass { | |
| position: absolute; | |
| top: 20px; | |
| left: 50%; | |
| transform: translateX(-50%); | |
| width: 265px; | |
| height: 54px; | |
| color: #333d37; | |
| text-align: center; | |
| filter: drop-shadow(0 1px 1px #fff5) | |
| } | |
| #compassDial { | |
| width: 100%; | |
| height: 33px; | |
| display: block | |
| } | |
| .bearing { | |
| display: inline-flex; | |
| min-width: 45px; | |
| justify-content: center; | |
| align-items: center; | |
| padding: 3px 6px; | |
| color: #f2ecd8; | |
| background: #343b32dd; | |
| border-radius: 2px; | |
| font-size: 10px; | |
| letter-spacing: 1px | |
| } | |
| .map-panel { | |
| right: 25px; | |
| top: 23px; | |
| width: 160px; | |
| padding: 0; | |
| overflow: hidden | |
| } | |
| .map-panel .panel-head { | |
| height: 31px; | |
| justify-content: space-between; | |
| padding: 0 11px; | |
| font-size: 9px; | |
| letter-spacing: 1.3px; | |
| color: #d2d4c4 | |
| } | |
| .map-panel .panel-head>span:first-child { | |
| display: flex; | |
| align-items: center; | |
| gap: 6px | |
| } | |
| .map-panel .panel-head .icon { | |
| color: var(--amber); | |
| width: 13px; | |
| height: 13px | |
| } | |
| .map-panel .map-sector { | |
| color: #aaad9e; | |
| font-size: 9px | |
| } | |
| .map-wrap { | |
| height: 126px; | |
| border-top: 1px solid var(--line); | |
| position: relative; | |
| background: #353d35 | |
| } | |
| #map { | |
| display: block; | |
| width: 100%; | |
| height: 100% | |
| } | |
| .data { | |
| bottom: 22px; | |
| left: 25px; | |
| width: 249px; | |
| padding: 13px 15px 12px | |
| } | |
| .panel-head .line { | |
| height: 1px; | |
| background: var(--line); | |
| flex: 1 | |
| } | |
| .data .panel-head, | |
| .aircraft .panel-head { | |
| font-size: 9px | |
| } | |
| .readouts { | |
| margin: 12px 0 11px; | |
| gap: 18px | |
| } | |
| .readout { | |
| flex: 1 | |
| } | |
| .readout+.readout { | |
| border-left: 1px solid var(--line); | |
| padding-left: 17px | |
| } | |
| .keyname { | |
| font-size: 9px; | |
| letter-spacing: 1.25px; | |
| color: #bfc1b2; | |
| display: block | |
| } | |
| .number { | |
| display: inline-block; | |
| font-size: 29px; | |
| font-weight: 600; | |
| line-height: 1.13; | |
| letter-spacing: -1.5px; | |
| font-variant-numeric: tabular-nums | |
| } | |
| .unit { | |
| font-size: 9px; | |
| letter-spacing: .5px; | |
| color: #c9cbbd; | |
| margin-left: 4px | |
| } | |
| .barrow { | |
| border-top: 1px solid var(--line); | |
| padding-top: 10px; | |
| gap: 10px; | |
| font-size: 9px; | |
| letter-spacing: .8px; | |
| color: #c4c7ba | |
| } | |
| .meter { | |
| height: 6px; | |
| flex: 1; | |
| background: #4a4e43; | |
| overflow: hidden; | |
| position: relative | |
| } | |
| .meter i { | |
| height: 100%; | |
| background: var(--amber); | |
| display: block | |
| } | |
| .meter:after { | |
| content: ''; | |
| position: absolute; | |
| inset: 0; | |
| background: repeating-linear-gradient(90deg, transparent 0, transparent calc(10% - 2px), #30352d calc(10% - 2px), #30352d 10%) | |
| } | |
| .barrow b { | |
| color: var(--paper); | |
| font-weight: 600; | |
| font-variant-numeric: tabular-nums | |
| } | |
| .aircraft { | |
| right: 25px; | |
| bottom: 22px; | |
| width: 218px; | |
| padding: 13px 15px 12px | |
| } | |
| .loadout { | |
| gap: 10px; | |
| margin: 10px 0 12px | |
| } | |
| .plane-badge { | |
| width: 43px; | |
| height: 31px; | |
| color: #ddc29a; | |
| stroke-width: 1.3 | |
| } | |
| .plane-name { | |
| font-weight: 650; | |
| font-size: 18px; | |
| letter-spacing: -.6px | |
| } | |
| .model-line { | |
| font: 9px/1.4 var(--mono); | |
| letter-spacing: 1px; | |
| color: #bec0ae; | |
| margin-top: 2px | |
| } | |
| .aircraft .barrow { | |
| padding-top: 9px | |
| } | |
| .hull i { | |
| background: #9fb58f | |
| } | |
| .ammo { | |
| display: flex; | |
| align-items: center; | |
| gap: 6px; | |
| color: #e1dfcf; | |
| margin-left: auto; | |
| font: 11px var(--mono); | |
| letter-spacing: 0 | |
| } | |
| .ammo .icon { | |
| width: 14px; | |
| height: 14px | |
| } | |
| .aircraft .meter { | |
| margin-left: 2px | |
| } | |
| .aircraft .barrow b { | |
| min-width: 32px; | |
| text-align: right | |
| } | |
| footer { | |
| height: 48px; | |
| flex: none; | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| padding: 0 26px; | |
| background: #222520; | |
| border-top: 1px solid #565849; | |
| gap: 15px | |
| } | |
| .legend { | |
| gap: clamp(10px, 1.8vw, 28px) | |
| } | |
| .legend-title { | |
| font-size: 9px; | |
| color: #b5b7a7; | |
| display: flex; | |
| align-items: center; | |
| gap: 8px; | |
| margin-right: 2px | |
| } | |
| .legend-title .icon { | |
| width: 17px | |
| } | |
| .binding { | |
| display: flex; | |
| gap: 7px; | |
| align-items: center; | |
| white-space: nowrap; | |
| color: #c7c9bd; | |
| font-size: 11px | |
| } | |
| .keys { | |
| display: inline-flex; | |
| gap: 3px | |
| } | |
| kbd { | |
| display: inline-flex; | |
| align-items: center; | |
| justify-content: center; | |
| height: 19px; | |
| min-width: 19px; | |
| padding: 0 4px; | |
| border: 1px solid #65695b; | |
| border-bottom: 2px solid #686c5f; | |
| border-radius: 3px; | |
| background: #32362e; | |
| color: #edeede; | |
| font: 10px var(--mono); | |
| line-height: 1 | |
| } | |
| .view-btn { | |
| white-space: nowrap; | |
| gap: 8px; | |
| background: transparent; | |
| border: 0; | |
| color: #d4c8aa; | |
| font-size: 9px; | |
| letter-spacing: 1.05px; | |
| padding: 5px 0 5px 13px; | |
| border-left: 1px solid #4d5145 | |
| } | |
| .view-btn kbd { | |
| margin-left: 2px | |
| } | |
| .view-btn .icon { | |
| width: 14px; | |
| height: 14px | |
| } | |
| #message { | |
| position: absolute; | |
| left: 50%; | |
| bottom: 26px; | |
| transform: translateX(-50%); | |
| background: #242a22ec; | |
| border: 1px solid #b3ae8966; | |
| border-radius: 3px; | |
| padding: 8px 12px; | |
| color: #f3e9ce; | |
| font: 600 10px var(--mono); | |
| letter-spacing: 1px; | |
| text-align: center; | |
| pointer-events: none; | |
| opacity: 0; | |
| transition: opacity .16s; | |
| white-space: nowrap | |
| } | |
| #message.show { | |
| opacity: 1 | |
| } | |
| .veil { | |
| position: absolute; | |
| z-index: 4; | |
| inset: 0; | |
| background: #17201bc2; | |
| backdrop-filter: blur(4px); | |
| display: grid; | |
| place-items: center; | |
| padding: 16px | |
| } | |
| .veil[hidden] { | |
| display: none | |
| } | |
| .dialog { | |
| width: min(385px, 100%); | |
| max-height: 100%; | |
| overflow: auto; | |
| background: #242922; | |
| border: 1px solid #777c66; | |
| box-shadow: 0 15px 60px #0004; | |
| border-radius: 6px; | |
| padding: 25px | |
| } | |
| .dialog-kicker { | |
| color: var(--amber); | |
| margin-right: auto | |
| } | |
| .dialog-head .tool { | |
| height: 27px; | |
| min-width: 27px; | |
| padding: 4px | |
| } | |
| .dialog h2 { | |
| font-size: 31px; | |
| letter-spacing: -1px; | |
| margin: 12px 0 8px | |
| } | |
| .dialog p { | |
| font-size: 14px; | |
| line-height: 1.5; | |
| color: #c3c6b8; | |
| margin: 0 0 15px | |
| } | |
| .help-grid { | |
| margin: 13px 0 18px | |
| } | |
| .help-row { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| font-size: 13px; | |
| padding: 7px 0; | |
| border-bottom: 1px solid #555a4b80 | |
| } | |
| .dialog-buttons { | |
| display: flex; | |
| gap: 8px; | |
| margin-top: 18px | |
| } | |
| .dialog-buttons button { | |
| flex: 1; | |
| padding: 10px 6px; | |
| border: 1px solid #616654; | |
| border-radius: 3px; | |
| background: #33392f; | |
| font-size: 13px; | |
| font-weight: 600 | |
| } | |
| .dialog-buttons .primary { | |
| background: #e4bd85; | |
| color: #25281e; | |
| border-color: #e4bd85 | |
| } | |
| .touch-ui { | |
| display: none | |
| } | |
| .touch-ui button { | |
| touch-action: none | |
| } | |
| @media(max-width:850px) { | |
| header { | |
| padding: 0 17px; | |
| height: 55px | |
| } | |
| .brand { | |
| gap: 9px | |
| } | |
| .brand-sub { | |
| font-size: 8px; | |
| padding-left: 12px; | |
| letter-spacing: 1px | |
| } | |
| .legend { | |
| gap: 12px | |
| } | |
| .legend-title span { | |
| display: none | |
| } | |
| footer { | |
| padding: 0 16px | |
| } | |
| .mission, | |
| .data { | |
| left: 16px | |
| } | |
| .map-panel, | |
| .aircraft { | |
| right: 16px | |
| } | |
| .mission, | |
| .map-panel { | |
| top: 16px | |
| } | |
| .mission { | |
| width: 200px | |
| } | |
| .map-panel { | |
| width: 132px | |
| } | |
| .map-wrap { | |
| height: 103px | |
| } | |
| .compass { | |
| width: 206px; | |
| top: 15px | |
| } | |
| .data { | |
| width: 217px | |
| } | |
| .aircraft { | |
| width: 188px | |
| } | |
| .status { | |
| margin-right: 4px | |
| } | |
| } | |
| @media(max-width:640px) { | |
| header { | |
| height: 50px; | |
| padding: 0 12px | |
| } | |
| .brand svg { | |
| width: 32px; | |
| height: 28px | |
| } | |
| .wordmark { | |
| font-size: 22px | |
| } | |
| .brand-sub, | |
| .status, | |
| .legend-title, | |
| .legend .rudder, | |
| .legend .throttle { | |
| display: none | |
| } | |
| .actions { | |
| gap: 5px | |
| } | |
| .tool { | |
| height: 29px; | |
| min-width: 29px | |
| } | |
| .tool.wide { | |
| font-size: 11px; | |
| padding: 0 8px | |
| } | |
| .mission { | |
| width: 157px; | |
| padding: 10px 11px | |
| } | |
| .mission, | |
| .data { | |
| left: 10px | |
| } | |
| .map-panel, | |
| .aircraft { | |
| right: 10px | |
| } | |
| .mission, | |
| .map-panel { | |
| top: 10px | |
| } | |
| .mission h1 { | |
| font-size: 22px; | |
| margin-top: 6px | |
| } | |
| .mission p { | |
| font-size: 10px; | |
| margin-bottom: 7px | |
| } | |
| .obj { | |
| padding-top: 6px | |
| } | |
| .panel-head, | |
| .eyebrow { | |
| font-size: 8px | |
| } | |
| .obj .small { | |
| font-size: 8px | |
| } | |
| .map-panel { | |
| width: 103px | |
| } | |
| .map-panel .panel-head { | |
| font-size: 8px; | |
| height: 23px; | |
| padding: 0 6px | |
| } | |
| .map-wrap { | |
| height: 78px | |
| } | |
| .compass { | |
| width: 90px; | |
| top: 11px; | |
| left: 54% | |
| } | |
| .data, | |
| .aircraft { | |
| bottom: 10px; | |
| padding: 9px 10px | |
| } | |
| .data { | |
| width: 173px | |
| } | |
| .aircraft { | |
| width: 145px | |
| } | |
| .data .panel-head, | |
| .aircraft .panel-head { | |
| font-size: 8px | |
| } | |
| .readouts { | |
| gap: 8px; | |
| margin: 8px 0 | |
| } | |
| .readout+.readout { | |
| padding-left: 9px | |
| } | |
| .number { | |
| font-size: 23px | |
| } | |
| .barrow { | |
| font-size: 8px; | |
| gap: 5px; | |
| padding-top: 7px | |
| } | |
| .plane-badge { | |
| width: 27px | |
| } | |
| .plane-name { | |
| font-size: 15px | |
| } | |
| .model-line { | |
| font-size: 7px | |
| } | |
| .loadout { | |
| gap: 6px; | |
| margin: 8px 0 | |
| } | |
| .aircraft .ammo { | |
| font-size: 9px; | |
| gap: 3px | |
| } | |
| footer { | |
| height: 39px; | |
| padding: 0 10px | |
| } | |
| .legend { | |
| gap: 9px | |
| } | |
| .binding { | |
| font-size: 10px; | |
| gap: 4px | |
| } | |
| .view-btn { | |
| padding-left: 8px; | |
| letter-spacing: .4px; | |
| font-size: 8px | |
| } | |
| .view-btn kbd { | |
| display: none | |
| } | |
| .unit, | |
| .keyname { | |
| font-size: 8px | |
| } | |
| } | |
| @media (max-width: 640px) { | |
| .obj { gap: 5px } | |
| .diamonds { gap: 3px } | |
| .diamonds i { width: 5px; height: 5px } | |
| .obj .small { white-space: nowrap; font-size: 7px; letter-spacing: .6px } | |
| .map-panel .panel-head { white-space: nowrap; letter-spacing: .55px } | |
| .map-panel .panel-head .icon { display: none } | |
| } | |
| .touch-caption { display: none } | |
| @media(pointer:coarse) { | |
| .touch-ui { | |
| display: flex; | |
| position: absolute; | |
| bottom: 150px; | |
| left: 12px; | |
| right: 12px; | |
| justify-content: space-between; | |
| align-items: end; | |
| pointer-events: none | |
| } | |
| .stick, | |
| .touch-buttons button { | |
| pointer-events: auto | |
| } | |
| .stick { | |
| position: relative; | |
| width: 80px; | |
| height: 80px; | |
| border-radius: 50%; | |
| border: 1px solid #fff7; | |
| background: #242b2777; | |
| touch-action: none | |
| } | |
| .stick:after { | |
| content: '✥'; | |
| position: absolute; | |
| left: 50%; | |
| top: 50%; | |
| transform: translate(-50%, -50%); | |
| color: #f2ead0a6; | |
| font-size: 30px | |
| } | |
| .touch-buttons { | |
| display: grid; | |
| grid-template-columns: 34px 59px; | |
| gap: 5px | |
| } | |
| .touch-buttons button { | |
| border: 1px solid #d7d7ba80; | |
| background: #252a23bb; | |
| border-radius: 5px; | |
| font: bold 16px var(--mono); | |
| height: 32px | |
| } | |
| .touch-buttons .fire { | |
| grid-column: 2; | |
| grid-row: 1 /span 2; | |
| height: 100%; | |
| font-size: 12px; | |
| color: #eac69a | |
| } | |
| .legend { | |
| display: none | |
| } | |
| footer { | |
| justify-content: flex-end | |
| } | |
| .view-btn { | |
| border: 0 | |
| } | |
| .touch-caption { | |
| display: block; | |
| margin-right: auto; | |
| color: #c5c7b9; | |
| font: 10px var(--mono) | |
| } | |
| } | |
| @media(pointer:fine) { | |
| .touch-caption { | |
| display: none | |
| } | |
| } | |
| @media(max-height:480px) { | |
| header { | |
| height: 40px | |
| } | |
| footer { | |
| height: 30px | |
| } | |
| .mission { | |
| padding: 8px 12px | |
| } | |
| .mission h1 { | |
| font-size: 20px; | |
| margin: 4px 0 | |
| } | |
| .mission p, | |
| .mission .obj { | |
| display: none | |
| } | |
| .map-wrap { | |
| height: 61px | |
| } | |
| .map-panel { | |
| width: 103px | |
| } | |
| .data, | |
| .aircraft { | |
| bottom: 7px; | |
| padding: 7px 10px | |
| } | |
| .loadout, | |
| .readouts { | |
| margin: 3px 0 | |
| } | |
| .number { | |
| font-size: 21px | |
| } | |
| .data, | |
| .aircraft { | |
| width: 175px | |
| } | |
| .touch-ui { | |
| bottom: 90px | |
| } | |
| .dialog { | |
| padding: 13px 19px | |
| } | |
| .help-row { | |
| padding: 3px 0 | |
| } | |
| .help-grid { | |
| margin: 6px 0 | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <svg class="defs" aria-hidden="true"> | |
| <defs> | |
| <symbol id="wing" viewBox="0 0 50 36"> | |
| <path d="m1 5 19 3 5 7 5-7 19-3-5 6-12 2-7 12-7-12-12-2zM8 15l10 2 4 7-10-4zm34 0-10 2-4 7 10-4zM20 28l5-4 5 4-5 5z" | |
| fill="currentColor" stroke="none" /> | |
| </symbol> | |
| <symbol id="keyboard" viewBox="0 0 24 24"> | |
| <rect x="2" y="5" width="20" height="14" rx="2" /> | |
| <path d="M6 9h1m3 0h1m3 0h1m3 0h.1M6 12h1m3 0h1m3 0h1m3 0h.1M8 15h8" /> | |
| </symbol> | |
| <symbol id="soundOff" viewBox="0 0 24 24"> | |
| <path d="M3 9h4l5-4v14l-5-4H3zM16 9l5 6m0-6-5 6" /> | |
| </symbol> | |
| <symbol id="soundOn" viewBox="0 0 24 24"> | |
| <path d="M3 9h4l5-4v14l-5-4H3zM16 8q5 4 0 8m3-11q8 7 0 14" /> | |
| </symbol> | |
| <symbol id="pauseIcon" viewBox="0 0 24 24"> | |
| <path d="M7 5h3v14H7zm7 0h3v14h-3z" fill="currentColor" stroke="none" /> | |
| </symbol> | |
| <symbol id="playIcon" viewBox="0 0 24 24"> | |
| <path d="m7 4 12 8-12 8z" fill="currentColor" stroke="none" /> | |
| </symbol> | |
| <symbol id="flag" viewBox="0 0 24 24"> | |
| <path d="M5 21V3m0 1c5-4 9 4 15 0v10c-6 4-10-4-15 0" /> | |
| </symbol> | |
| <symbol id="radar" viewBox="0 0 24 24"> | |
| <circle cx="12" cy="12" r="9" /> | |
| <path d="M12 21a9 9 0 0 0 7-15l-7 6m-5 1a5 5 0 0 0 6 4" /> | |
| </symbol> | |
| <symbol id="activity" viewBox="0 0 24 24"> | |
| <path d="M1 13h5l3-8 5 15 3-9 2 2h4" /> | |
| </symbol> | |
| <symbol id="plane" viewBox="0 0 24 24"> | |
| <path d="M12 2c-1 0-2 2-2 4v3l-8 5v2l8-2v4l-3 2v1l5-1 5 1v-1l-3-2v-4l8 2v-2l-8-5V6c0-2-1-4-2-4z" /> | |
| </symbol> | |
| <symbol id="ammoIcon" viewBox="0 0 24 24"> | |
| <path d="M4 19V8l2-5 2 5v11zm8 0V8l2-5 2 5v11zM4 16h4m4 0h4" /> | |
| </symbol> | |
| <symbol id="sideplane" viewBox="0 0 55 33"> | |
| <path | |
| d="m4 18 37-1 5 2-4 3-26 1-12-4zM5 18V9q4-2 7 10m5-11 24-1 2 2-26 1zm-2 10 21-1m-15-7 5 8 5-8m6-1 2 8M21 22l7 5 6-6m11-12 1 17m-4-7 7-1" /> | |
| <circle cx="28" cy="27" r="3" /> | |
| </symbol> | |
| <symbol id="camera" viewBox="0 0 24 24"> | |
| <path d="M3 7h5l2-3h5l2 3h4v12H3z" /> | |
| <circle cx="12" cy="13" r="3" /> | |
| </symbol> | |
| </defs> | |
| </svg> | |
| <header> | |
| <div class="brand"><svg aria-hidden="true"> | |
| <use href="#wing" /> | |
| </svg><span class="wordmark">IRONWING</span><span class="brand-sub">Flight Simulator</span></div> | |
| <div class="actions"><span class="status"><i class="light"></i><span id="statusText">In flight</span></span><button | |
| id="audioBtn" class="tool" title="Enable sound (M)" aria-label="Enable sound" aria-pressed="false"><svg class="icon"> | |
| <use id="audioIcon" href="#soundOff" /> | |
| </svg></button><button id="helpBtn" class="tool" title="Flight controls (H)" aria-label="Flight controls"><svg | |
| class="icon"> | |
| <use href="#keyboard" /> | |
| </svg></button><button id="pauseBtn" class="tool wide"><svg class="icon"> | |
| <use id="pauseSymbol" href="#pauseIcon" /> | |
| </svg><span id="pauseLabel">Pause</span></button></div> | |
| </header> | |
| <main id="stage" tabindex="-1" aria-label="Ironwing flight simulator"><canvas id="world" | |
| aria-label="3D alpine valley and aircraft"></canvas> | |
| <div class="scene-effect"></div><canvas id="overlay" aria-hidden="true"></canvas> | |
| <section class="panel mission"> | |
| <div class="eyebrow"><svg class="icon"> | |
| <use href="#flag" /> | |
| </svg>Mission 01</div> | |
| <h1>Valley Patrol</h1> | |
| <p>Eliminate the enemy patrol.</p> | |
| <div class="obj"><span class="diamonds"><i></i><i></i><i></i></span><span class="small">Bandits down</span><span | |
| class="count"><span id="kills">0</span> <em>/ 3</em></span></div> | |
| </section> | |
| <div class="compass" aria-label="Compass"><canvas id="compassDial"></canvas><span id="bearing" class="bearing">000° N</span> | |
| </div> | |
| <section class="panel map-panel"> | |
| <div class="panel-head"><span><svg class="icon"> | |
| <use href="#radar" /> | |
| </svg>Tactical map</span><span class="map-sector">N ↑</span></div> | |
| <div class="map-wrap"><canvas id="map" aria-label="Tactical map with aircraft positions"></canvas></div> | |
| </section> | |
| <section class="panel data"> | |
| <div class="panel-head"><svg class="icon"> | |
| <use href="#activity" /> | |
| </svg>Flight data<span class="line"></span></div> | |
| <div class="readouts"> | |
| <div class="readout"><span class="keyname">Airspeed</span><span class="number" id="speed">164</span><span | |
| class="unit">km/h</span></div> | |
| <div class="readout"><span class="keyname">Altitude</span><span class="number" id="alt">360</span><span | |
| class="unit">m</span></div> | |
| </div> | |
| <div class="barrow">Throttle<div class="meter"><i id="throttleBar" style="width:72%"></i></div><b id="throttle">72%</b> | |
| </div> | |
| </section> | |
| <section class="panel aircraft"> | |
| <div class="panel-head"><svg class="icon"> | |
| <use href="#plane" /> | |
| </svg>Aircraft<span class="line"></span><span class="ammo" title="Rounds remaining"><svg class="icon"> | |
| <use href="#ammoIcon" /> | |
| </svg><span id="ammo">480</span></span></div> | |
| <div class="loadout"><svg class="plane-badge"> | |
| <use href="#sideplane" /> | |
| </svg> | |
| <div> | |
| <div class="plane-name">Kestrel F.1</div> | |
| <div class="model-line">SCOUT BIPLANE</div> | |
| </div> | |
| </div> | |
| <div class="barrow">Hull<div class="meter hull"><i id="hullBar" style="width:100%"></i></div><b id="hull">100%</b></div> | |
| </section> | |
| <div id="message" role="status"></div> | |
| <div class="touch-ui"> | |
| <div class="stick" id="stick" aria-label="Pitch and roll joystick"></div> | |
| <div class="touch-buttons"><button data-hold="KeyW" aria-label="Increase throttle">+</button><button data-hold="KeyS" | |
| aria-label="Decrease throttle">−</button><button class="fire" data-hold="Space">FIRE</button></div> | |
| </div> | |
| <div class="veil" id="veil" hidden> | |
| <section class="dialog" role="dialog" aria-modal="true" aria-labelledby="dialogTitle"> | |
| <div class="dialog-head"><span class="dialog-kicker">Ironwing / Flight deck</span><button type="button" id="closeDialog" | |
| class="tool" aria-label="Close dialog">×</button></div> | |
| <h2 id="dialogTitle">Flight paused</h2> | |
| <p id="dialogText"></p> | |
| <div class="help-grid" id="helpGrid" hidden></div> | |
| <div class="dialog-buttons"><button id="secondaryBtn">Restart mission</button><button id="primaryBtn" | |
| class="primary">Resume flight</button></div> | |
| </section> | |
| </div> | |
| </main> | |
| <footer> | |
| <div class="legend"><span class="legend-title"><svg class="icon"> | |
| <use href="#keyboard" /> | |
| </svg><span>Controls</span></span><span class="binding"><span | |
| class="keys"><kbd>↑</kbd><kbd>↓</kbd></span>Pitch</span><span class="binding"><span | |
| class="keys"><kbd>←</kbd><kbd>→</kbd></span>Roll</span><span class="binding rudder"><span | |
| class="keys"><kbd>A</kbd><kbd>D</kbd></span>Rudder</span><span class="binding throttle"><span | |
| class="keys"><kbd>W</kbd><kbd>S</kbd></span>Throttle</span><span class="binding"><kbd>SPACE</kbd>Fire</span></div><span | |
| class="touch-caption">Drag to steer</span><button class="view-btn" id="viewBtn" title="Change camera (C)"><svg class="icon"> | |
| <use href="#camera" /> | |
| </svg><span id="viewName">Chase cam</span><kbd>C</kbd></button> | |
| </footer> | |
| <script> | |
| 'use strict'; | |
| const $ = id => document.getElementById(id), | |
| TAU = 2 * Math.PI, | |
| rad = Math.PI / 180; | |
| const clamp = (x, a, b) => Math.min(b, Math.max(a, x)), | |
| mix = (a, b, t) => a + (b - a) * t; | |
| const smooth = (a, b, v) => { | |
| const t = clamp((v - a) / (b - a), 0, 1); | |
| return t * t * (3 - 2 * t); | |
| }; | |
| const add = (a, b) => a.map((x, i) => x + b[i]), | |
| sub = (a, b) => a.map((x, i) => x - b[i]), | |
| mul = (a, k) => a.map(x => x * k); | |
| const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2], | |
| cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]], | |
| unit = a => mul(a, 1 / (Math.hypot(...a) || 1)); | |
| const wrap = a => Math.atan2(Math.sin(a), Math.cos(a)); | |
| let seed = 18721; | |
| function random() { | |
| seed = Math.imul(1664525, seed) + 1013904223 >>> 0; | |
| return seed / 4294967296; | |
| } | |
| function hash(i, j) { | |
| let h = Math.imul(i, 374761393) + Math.imul(j, 668265263); | |
| h = Math.imul(h ^ h >>> 13, 1274126177); | |
| return ((h ^ h >>> 16) >>> 0) / 4294967295; | |
| } | |
| function noise(x, z) { | |
| const i = Math.floor(x), | |
| j = Math.floor(z), | |
| a = smooth(0, 1, x - i), | |
| b = smooth(0, 1, z - j); | |
| return mix(mix(hash(i, j), hash(i + 1, j), a), mix(hash(i, j + 1), hash(i + 1, j + 1), a), b); | |
| } | |
| function rgb(s) { | |
| const n = parseInt(s.slice(1), 16); | |
| return [(n >> 16) / 255, (n >> 8 & 255) / 255, (n & 255) / 255]; | |
| } | |
| const blend = (a, b, t) => a.map((v, i) => mix(v, b[i], t)), | |
| tint = (c, t) => c.map(v => clamp(v * t, 0, 1)); | |
| const ID = [1, 0, 0, 0, 1, 0, 0, 0, 1], | |
| origin = [0, 0, 0]; | |
| function axes(yaw, pitch, roll) { | |
| const sy = Math.sin(yaw), | |
| cy = Math.cos(yaw), | |
| sp = Math.sin(pitch), | |
| cp = Math.cos(pitch), | |
| sr = Math.sin(roll), | |
| cr = Math.cos(roll); | |
| return [cy * cr - sy * sp * sr, cp * sr, -sy * cr - cy * sp * sr, -cy * sr - sy * sp * cr, cp * cr, sy * sr - cy * sp * cr, sy * cp, sp, cy * cp]; | |
| } | |
| function rotate(v, m) { | |
| return [m[0] * v[0] + m[3] * v[1] + m[6] * v[2], m[1] * v[0] + m[4] * v[1] + m[7] * v[2], m[2] * v[0] + m[5] * v[1] + m[8] * v[2]]; | |
| } | |
| const sun = unit([-.62, .88, -.47]); | |
| class Geometry { | |
| constructor() { | |
| this.v = []; | |
| } | |
| tri(a, b, c, color, lit = 0) { | |
| let col = color; | |
| if (lit) { | |
| const normal = unit(cross(sub(b, a), sub(c, a))); | |
| col = tint(color, 1 + lit * dot(normal, sun)); | |
| } | |
| this.v.push(...a, ...col, ...b, ...col, ...c, ...col); | |
| } | |
| quad(a, b, c, d, col, lit = 0) { | |
| this.tri(a, b, c, col, lit); | |
| this.tri(a, c, d, col, lit); | |
| } | |
| rod(a, b, r, c, n = 6) { | |
| const dir = unit(sub(b, a)), | |
| u = mul(unit(cross(dir, Math.abs(dir[1]) > .9 ? [1, 0, 0] : [0, 1, 0])), r), | |
| v = cross(dir, u); | |
| let prev = u; | |
| for (let i = 1; i <= n; i++) { | |
| const t = TAU * i / n, | |
| next = add(mul(u, Math.cos(t)), mul(v, Math.sin(t))); | |
| this.quad(add(a, prev), add(a, next), add(b, next), add(b, prev), tint(c, .82 + .18 * Math.cos(t))); | |
| prev = next; | |
| } | |
| } | |
| ellipsoid(center, size, col, n = 12, k = 7) { | |
| const at = (i, j) => { | |
| const a = i * TAU / n, | |
| b = j * Math.PI / k - Math.PI / 2; | |
| return [center[0] + size[0] * Math.cos(a) * Math.cos(b), center[1] + size[1] * Math.sin(b), center[2] + size[2] * Math.sin(a) * Math.cos(b)]; | |
| }; | |
| for (let j = 0; j < k; j++) for (let i = 0; i < n; i++) { | |
| this.quad(at(i, j), at(i, j + 1), at(i + 1, j + 1), at(i + 1, j), col, .19); | |
| } | |
| } | |
| } | |
| const world = $('world'), | |
| gl = world.getContext('webgl', { | |
| alpha: true, | |
| antialias: true, | |
| depth: true, | |
| powerPreference: 'high-performance' | |
| }); | |
| let softCtx = null; | |
| if (!gl) softCtx = world.getContext('2d'); | |
| function mesh(g) { | |
| const data = new Float32Array(g.v); | |
| const m = { | |
| data, | |
| count: data.length / 6 | |
| }; | |
| if (gl) { | |
| m.buf = gl.createBuffer(); | |
| gl.bindBuffer(gl.ARRAY_BUFFER, m.buf); | |
| gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW); | |
| } | |
| return m; | |
| } | |
| let program, attrPos, attrCol, uc, ur, uu, uf, up, uo, um, ufog; | |
| if (gl) { | |
| const vs = 'attribute vec3 pos,col; uniform vec3 cam,right,up,forward,offset; uniform mat3 model;uniform vec2 proj;varying vec3 shade;varying float depth;void main(){vec3 d=model*pos+offset-cam;float z=dot(d,forward);gl_Position=vec4(dot(d,right)*proj.x,dot(d,up)*proj.y,z*1.00004-0.72,z);depth=z;shade=col;}'; | |
| const fs = 'precision mediump float; varying vec3 shade; varying float depth; uniform vec3 fog;void main(){float f=1.-exp(-max(depth-90.,0.)/4800.);gl_FragColor=vec4(mix(shade,fog,f),1.);}'; | |
| const shader = (type, src) => { | |
| const s = gl.createShader(type); | |
| gl.shaderSource(s, src); | |
| gl.compileShader(s); | |
| if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw Error(gl.getShaderInfoLog(s)); | |
| return s; | |
| }; | |
| program = gl.createProgram(); | |
| gl.attachShader(program, shader(gl.VERTEX_SHADER, vs)); | |
| gl.attachShader(program, shader(gl.FRAGMENT_SHADER, fs)); | |
| gl.linkProgram(program); | |
| gl.useProgram(program); | |
| attrPos = gl.getAttribLocation(program, 'pos'); | |
| attrCol = gl.getAttribLocation(program, 'col'); | |
| gl.enableVertexAttribArray(attrPos); | |
| gl.enableVertexAttribArray(attrCol); | |
| [uc, ur, uu, uf, up, uo, um, ufog] = ['cam', 'right', 'up', 'forward', 'proj', 'offset', 'model', 'fog'].map(x => gl.getUniformLocation(program, x)); | |
| gl.enable(gl.DEPTH_TEST); | |
| gl.clearColor(0, 0, 0, 0); | |
| } | |
| const sky = document.createElement('canvas'); | |
| sky.id = 'sky'; | |
| sky.style.cssText = 'position:absolute;inset:0;width:100%;height:100%'; | |
| world.before(sky); | |
| const skyCtx = sky.getContext('2d'), | |
| pano = document.createElement('canvas'); | |
| function paintSky() { | |
| pano.width = 4096; | |
| pano.height = 670; | |
| const c = pano.getContext('2d'), | |
| hor = 540; | |
| const grad = c.createLinearGradient(0, 0, 0, 670); | |
| [[0, '#5b97b8'], [.36, '#80b2c8'], [.6, '#b9d4d6'], [.75, '#ede3c6'], [.83, '#ffe1af'], [1, '#e6d3b2']].forEach(s => grad.addColorStop(...s)); | |
| c.fillStyle = grad; | |
| c.fillRect(0, 0, 4096, 670); | |
| function cloud(cx, cy, w, h, alpha) { | |
| const buf = document.createElement('canvas'); | |
| buf.width = Math.ceil(w); | |
| buf.height = Math.ceil(h); | |
| const ctx = buf.getContext('2d'), | |
| im = ctx.createImageData(buf.width, buf.height); | |
| const lobes = []; | |
| for (let i = 0; i < 10; i++) { | |
| const u = (i + .6) / 10, | |
| arc = Math.sin(u * Math.PI); | |
| lobes.push([u, .62 - arc * (.05 + random() * .22), .072 + random() * .094, .075 + arc * (.07 + random() * .25)]); | |
| } | |
| const phase = random() * 800; | |
| for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) { | |
| const u = x / w, | |
| v = y / h; | |
| let density = -3, | |
| illum = 0; | |
| for (const l of lobes) { | |
| const dx = (u - l[0]) / l[2], | |
| dy = (v - l[1]) / l[3], | |
| d = 1 - Math.sqrt(dx * dx + dy * dy), | |
| k = clamp(.5 + .5 * (d - density) / .54, 0, 1); | |
| illum = mix(illum, clamp(.5 - dy * .54 - dx * .21, 0, 1), k); | |
| density = mix(density, d, k) + .54 * k * (1 - k); | |
| } | |
| const n = noise(x * .065 + phase, y * .065 + phase) * .24 + noise(x * .17 + phase, y * .17) * .13 + noise(x * .023, y * .023 + phase) * .22 - .2; | |
| const a = smooth(-.11, .12, density + n) * smooth(0, .14, u) * smooth(1, .86, u); | |
| const lighting = clamp(.09 + v * .30 + (1 - illum) * .68 + noise(x * .055 + phase, y * .055) * .13, 0, 1); | |
| const i = (y * buf.width + x) * 4; | |
| im.data[i] = mix(255, 188, lighting); | |
| im.data[i + 1] = mix(249, 198, lighting); | |
| im.data[i + 2] = mix(224, 194, lighting); | |
| im.data[i + 3] = 255 * a * alpha; | |
| } | |
| ctx.putImageData(im, 0, 0); | |
| for (const dx of [-4096, 0, 4096]) c.drawImage(buf, cx - w / 2 + dx, cy - h / 2); | |
| } | |
| for (let i = 0; i < 39; i++) cloud(i * 107 + random() * 50, hor - 24 - random() * 26, 100 + random() * 210, 20 + random() * 30, .5 + random() * .3); | |
| for (let i = 0; i < 15; i++) cloud(i * 284 + 30 + random() * 110, hor - 80 - random() * 60, 150 + random() * 250, 47 + random() * 60, .88); | |
| cloud(1810, 356, 337, 100, .96); | |
| cloud(2190, 364, 284, 87, .97); | |
| cloud(2540, 398, 260, 75, .93); | |
| } | |
| paintSky(); | |
| const river = z => 100 + 285 * Math.sin(z / 635 - .85) + 230 * Math.sin(z / 1370 + 1) + 120 * Math.sin(z / 370 + .7); | |
| const riverWidth = z => 44 + 12 * Math.sin(z / 380) + 7 * Math.cos(z / 210); | |
| const peaks = [[-2050, 2200, 1020, 2250, 2100], [2360, 1800, 890, 1900, 2300], [-2850, 4300, 1730, 2450, 2300], [2100, 4750, 1370, 2600, 2100], [-830, 6500, 1370, 2450, 1650], [800, 7300, 1710, 1900, 2400], [-2300, 7600, 2450, 2800, 2450], [3250, 7200, 2500, 2350, 2550], [5800, 4200, 2180, 2200, 2850], [-5900, 1600, 2300, 3100, 3000], [-5100, -3400, 1630, 2500, 2400], [4550, -2650, 1520, 2600, 2300], [520, -7300, 2120, 3000, 2100], [-4000, -6800, 2400, 2800, 2100], [6300, -5900, 1900, 3400, 2100], [-6500, 8500, 2380, 3400, 2600], [6800, 9700, 2710, 3500, 3500]]; | |
| function elevation(x, z) { | |
| const d = Math.abs(x - river(z)) - riverWidth(z), | |
| shore = smooth(0, 100, d), | |
| inland = smooth(85, 1100, d); | |
| const n = noise(x / 540, z / 580), | |
| rough = noise(x / 230, z / 240); | |
| let mountain = 0; | |
| for (const [px, pz, h, rx, rz] of peaks) { | |
| const dx = (x - px) / rx, | |
| dz = (z - pz) / rz; | |
| const r = Math.sqrt(dx * dx + dz * dz); | |
| if (r < 1.65) { | |
| const ridge = clamp(1 - r * .83 + (noise(x / 700 + 4, z / 630) - .5) * .26 + (rough - .5) * .08, 0, 1.15); | |
| mountain = Math.max(mountain, h * ridge ** 1.38); | |
| } | |
| } | |
| return 11 + shore * (6 + 21 * n) + inland * (40 + 160 * n * n + 48 * rough) + mountain * (.71 + smooth(2700, 6800, Math.abs(z)) * .21) * smooth(0, 1350, d); | |
| } | |
| const grounds = [rgb('#617a4b'), rgb('#8d9d60'), rgb('#819b60'), rgb('#b5ad70')], | |
| rock1 = rgb('#667b70'), | |
| rock2 = rgb('#97a18b'); | |
| const geom = new Geometry(), | |
| riverG = new Geometry(), | |
| rows = [], | |
| nx = 95, | |
| nz = 239; | |
| const zAt = j => { | |
| const t = (j - 94) / 66; | |
| return (t < 0 ? -1 : 1) * (Math.abs(t) * 4020 + Math.abs(t) ** 3 * 620); | |
| }; | |
| for (let j = 0; j < nz; j++) { | |
| const points = [], | |
| zz = zAt(j); | |
| const rw = riverWidth(zz), | |
| mid = river(zz); | |
| for (let i = 0; i < nx; i++) { | |
| const u = i - 47; | |
| if (!u) { | |
| points.push([mid, 10.3, zz]); | |
| continue; | |
| } | |
| const k = Math.abs(u) - 1; | |
| const d = rw + k * 35 + Math.pow(k / 46, 2.55) * 10300; | |
| const x = mid + Math.sign(u) * (d + (k > 0 ? (hash(i, j) - .5) * Math.min(39, k * 7) : 0)); | |
| points.push([x, elevation(x, zz), zz]); | |
| } | |
| rows.push(points); | |
| } | |
| // Preserve both banks in the lower-detail terrain used by the software renderer. | |
| const terrainStride = gl ? 1 : 3; | |
| const columns = Array.from({length: nx}, (_, i) => i).filter(i => | |
| i % terrainStride === 0 || i === nx - 1 || Math.abs(i - 47) <= 1 | |
| ); | |
| for (let j = 0; j < nz - 1; j += terrainStride) for (let k = 0; k < columns.length - 1; k++) { | |
| const i = columns[k], next = columns[k + 1], row = Math.min(j + terrainStride, nz - 1); | |
| const a = rows[j][i], b = rows[row][i], c = rows[row][next], d = rows[j][next]; | |
| if (i === 46 || i === 47) { | |
| riverG.quad(a, b, c, d, blend(rgb('#669c9e'), rgb('#8cbbba'), noise(a[0] / 150, a[2] / 200) * .7)); | |
| continue; | |
| } | |
| const facet = (p, q, r) => { | |
| const n = unit(cross(sub(q, p), sub(r, p))), | |
| x = (p[0] + q[0] + r[0]) / 3, | |
| z = (p[2] + q[2] + r[2]) / 3, | |
| y = (p[1] + q[1] + r[1]) / 3, | |
| patch = noise(x / 290, z / 330); | |
| let col = blend(grounds[0], grounds[1], patch); | |
| col = blend(col, grounds[3], noise(x / 160 + 12, z / 180) * .26); | |
| const rocky = clamp((1 - n[1] - .081) * 4.8 + smooth(470, 1180, y) * .72, 0, 1); | |
| col = blend(col, blend(rock1, rock2, patch), rocky); | |
| const snow = smooth(1000, 1390, y + 200 * noise(x / 280, z / 390) + n[0] * 145); | |
| col = blend(col, rgb('#ece6d3'), snow * .97); | |
| const bank = Math.abs(x - river(z)) - riverWidth(z); | |
| if (bank < 20) col = blend(col, rgb('#b5b88a'), .5); | |
| const sunlight = dot(n, sun); | |
| col = blend(col, rgb('#6a8092'), clamp(.38 - sunlight * .55, 0, .35)); | |
| geom.tri(p, q, r, tint(col, .78 + sunlight * .36 + (hash(i * 11 + Math.round(p[0]), j) - .5) * .044)); | |
| }; | |
| facet(a, b, d); | |
| facet(b, c, d); | |
| } | |
| const terrain = mesh(geom), | |
| water = mesh(riverG); | |
| geom.v = []; | |
| riverG.v = []; | |
| function belowIndex(count, get, value) { | |
| let lo = 0, | |
| hi = count - 1; | |
| while (hi - lo > 1) { | |
| const mid = hi + lo >> 1; | |
| if (get(mid) <= value) lo = mid;else hi = mid; | |
| } | |
| return lo; | |
| } | |
| function ground(x, z) { | |
| const j = belowIndex(nz, k => rows[k][0][2], z), | |
| r = rows[j], | |
| s = rows[j + 1], | |
| v = clamp((z - r[0][2]) / (s[0][2] - r[0][2]), 0, 1); | |
| const lx = i => mix(r[i][0], s[i][0], v), | |
| i = belowIndex(nx, lx, x), | |
| edge = mix(r[i + 1][0], s[i][0], v); | |
| if (x <= edge) { | |
| const t = (x - mix(r[i][0], s[i][0], v)) / (r[i + 1][0] - r[i][0]); | |
| return r[i][1] + v * (s[i][1] - r[i][1]) + t * (r[i + 1][1] - r[i][1]); | |
| } | |
| const t = (mix(r[i + 1][0], s[i + 1][0], v) - x) / (s[i + 1][0] - s[i][0]); | |
| return s[i + 1][1] + (1 - v) * (r[i + 1][1] - s[i + 1][1]) + t * (s[i][1] - s[i + 1][1]); | |
| } | |
| const mountainsG = new Geometry(); | |
| for (let band = 0; band < 2; band++) { | |
| const pts = [], | |
| count = 240; | |
| for (let i = 0; i < count; i++) { | |
| const a = i * TAU / count, | |
| R = 10800 + band * 3000 + 600 * Math.sin(a * 7.1); | |
| const h = 1390 + band * 430 + 410 * Math.sin(5 * a + .8) + 390 * Math.sin(13 * a + .7) + 310 * Math.cos(24 * a) + random() * 240; | |
| pts.push([[Math.sin(a) * R, h, Math.cos(a) * R], [Math.sin(a) * (R - 450), h * .64, Math.cos(a) * (R - 450)], [Math.sin(a) * (R - 1400), 50, Math.cos(a) * (R - 1400)]]); | |
| } | |
| for (let i = 0; i < count; i++) { | |
| const a = pts[i], | |
| b = pts[(i + 1) % count]; | |
| mountainsG.quad(a[0], b[0], b[1], a[1], tint(rgb('#8cabb8'), .70 + random() * .43)); | |
| mountainsG.quad(a[1], b[1], b[2], a[2], rgb('#82969a')); | |
| } | |
| } | |
| const mountains = mesh(mountainsG); | |
| mountainsG.v = []; | |
| const sceneryG = new Geometry(); | |
| function surface(x, z, lift = 1) { | |
| return [x, ground(x, z) + lift, z]; | |
| } | |
| function groundPath(points, width, col) { | |
| for (let i = 1; i < points.length; i++) { | |
| const [x, z] = points[i - 1], | |
| [xx, zz] = points[i]; | |
| const dx = xx - x, | |
| dz = zz - z, | |
| len = Math.hypot(dx, dz); | |
| if (!len) continue; | |
| const nx = -dz / len * width * .5, | |
| nz = dx / len * width * .5; | |
| sceneryG.quad(surface(x + nx, z + nz), surface(xx + nx, zz + nz), surface(xx - nx, zz - nz), surface(x - nx, z - nz), col); | |
| } | |
| } | |
| const fieldColors = ['#b2aa65', '#c5af72', '#a3ac64', '#a5ad78', '#97a864', '#bea671', '#7d935d', '#95a667'].map(rgb); | |
| for (let z = -3500; z < 5200; z += 165) { | |
| for (const sign of [-1, 1]) for (let row = 0; row < 4; row++) { | |
| if (random() < .29) continue; | |
| const offset = 75 + row * 143, | |
| za = z + random() * 38, | |
| len = 92 + random() * 62, | |
| w = 64 + random() * 68, | |
| drift = (random() - .5) * 30; | |
| const xp = (s, t) => river(za + t * len) + sign * (offset + s * w + drift * t); | |
| if (ground(xp(.5, .5), za + len / 2) > 159) continue; | |
| const color = fieldColors[Math.floor(random() * fieldColors.length)], | |
| at = (s, t) => surface(xp(s, t), za + len * t, 1.05); | |
| for (let n = 0; n < 4; n++) for (let k = 0; k < 3; k++) sceneryG.quad(at(n / 4, k / 3), at(n / 4, (k + 1) / 3), at((n + 1) / 4, (k + 1) / 3), at((n + 1) / 4, k / 3), color); | |
| if (gl && random() < .27) for (let s = .07; s < 1; s += .09) { | |
| for (let k = 0; k < 3; k++) sceneryG.quad(at(s, k / 3).map((v, i) => v + (i === 1 ? .16 : 0)), at(s, (k + 1) / 3).map((v, i) => v + (i === 1 ? .16 : 0)), at(s + .013, (k + 1) / 3).map((v, i) => v + (i === 1 ? .16 : 0)), at(s + .013, k / 3).map((v, i) => v + (i === 1 ? .16 : 0)), tint(color, .94)); | |
| } | |
| } | |
| } | |
| const roadX = (z, side) => river(z) + side * (200 + 56 * Math.sin(z / 370 + side) + 28 * Math.cos(z / 180)); | |
| for (const side of [-1, 1]) { | |
| const p = []; | |
| for (let z = -4450; z < 6600; z += 17) p.push([roadX(z, side), z]); | |
| groundPath(p, 6, rgb('#c5bd96')); | |
| } | |
| function house(x, z, scale, angle, church = false) { | |
| const y = ground(x, z) - .2, | |
| co = Math.cos(angle), | |
| si = Math.sin(angle); | |
| const pt = (a, b, c) => [x + (a * co + c * si) * scale, y + b * scale, z + (c * co - a * si) * scale]; | |
| const w = church ? 5 : 4 + random() * 3, | |
| l = church ? 11 : 5 + random() * 4, | |
| h = church ? 10 : 4 + random() * 3; | |
| const pale = blend(rgb('#d7c9a8'), rgb('#acb09a'), random() * .65), | |
| roof = church ? rgb('#555e60') : blend(rgb('#814e3b'), rgb('#a37459'), random()); | |
| const a = pt(-w, 0, -l), | |
| b = pt(w, 0, -l), | |
| c = pt(w, 0, l), | |
| d = pt(-w, 0, l), | |
| A = pt(-w, h, -l), | |
| B = pt(w, h, -l), | |
| C = pt(w, h, l), | |
| D = pt(-w, h, l), | |
| t = pt(0, h + 3.2, -l), | |
| T = pt(0, h + 3.2, l); | |
| sceneryG.quad(a, b, B, A, pale); | |
| sceneryG.quad(b, c, C, B, tint(pale, .84)); | |
| sceneryG.quad(c, d, D, C, pale); | |
| sceneryG.quad(d, a, A, D, tint(pale, .95)); | |
| sceneryG.tri(A, B, t, pale); | |
| sceneryG.tri(C, D, T, pale); | |
| sceneryG.quad(A, t, T, D, roof); | |
| sceneryG.quad(t, B, C, T, tint(roof, .79)); | |
| if (church) { | |
| const a = pt(-3, 0, l), | |
| b = pt(3, 0, l), | |
| c = pt(3, 0, l + 6), | |
| d = pt(-3, 0, l + 6), | |
| r = pt(-3, 19, l), | |
| s = pt(3, 19, l), | |
| t = pt(3, 19, l + 6), | |
| u = pt(-3, 19, l + 6), | |
| v = pt(0, 32, l + 3); | |
| sceneryG.quad(a, b, s, r, pale); | |
| sceneryG.quad(b, c, t, s, tint(pale, .78)); | |
| sceneryG.quad(c, d, u, t, pale); | |
| sceneryG.quad(d, a, r, u, pale); | |
| sceneryG.tri(r, s, v, roof); | |
| sceneryG.tri(s, t, v, tint(roof, .7)); | |
| sceneryG.tri(t, u, v, roof); | |
| sceneryG.tri(u, r, v, tint(roof, .8)); | |
| } | |
| } | |
| for (const [z0, side, n] of [[670, 1, 26], [1170, -1, 39], [2260, 1, 26], [2700, -1, 17], [-180, -1, 15], [-1520, 1, 33], [3840, -1, 35]]) { | |
| const p = []; | |
| for (let i = -10; i <= 10; i++) { | |
| const zz = z0 + i * 10; | |
| p.push([roadX(zz, side) + i * 5, zz]); | |
| } | |
| groundPath(p, 6, rgb('#c8bf9b')); | |
| for (let i = 0; i < n; i++) { | |
| const zz = z0 + (random() - .5) * 200, | |
| x = roadX(zz, side) + (random() - .5) * 117; | |
| house(x, zz, .75 + random() * .55, random() * .55 + i % 2 * 1.56, i === 0); | |
| } | |
| } | |
| for (const z of [990, 3150, -1350]) { | |
| const x = river(z), | |
| w = riverWidth(z) + 24; | |
| const path = []; | |
| for (let i = -22; i <= 22; i++) path.push([x + i * 11, z + i * 1.8]); | |
| groundPath(path, 7, rgb('#c5bd96')); | |
| const bankY = Math.max(ground(x - w, z), ground(x + w, z)) + 2; | |
| sceneryG.quad([x - w, bankY, z - 4], [x + w, bankY, z - 4], [x + w, bankY, z + 4], [x - w, bankY, z + 4], rgb('#ad9e7d')); | |
| for (const dz of [-4, 4]) { | |
| sceneryG.quad([x - w, bankY, z + dz], [x + w, bankY, z + dz], [x + w, bankY + 1.5, z + dz], [x - w, bankY + 1.5, z + dz], rgb('#817d67')); | |
| for (let n = -1; n <= 1; n++) sceneryG.quad([x + n * w * .5 - 1.4, 10, z + dz], [x + n * w * .5 + 1.4, 10, z + dz], [x + n * w * .5 + 1.4, bankY, z + dz], [x + n * w * .5 - 1.4, bankY, z + dz], rgb('#797965')); | |
| } | |
| } | |
| for (let i = 0; i < 680; i++) { | |
| const z = random() * 7500 - 2700, | |
| x = river(z) + (random() - .5) * riverWidth(z) * 1.55, | |
| w = .45 + random() * .8, | |
| l = 3 + random() * 8; | |
| const y = 10.9; | |
| sceneryG.quad([x - w, y, z], [x, y, z - l], [x + w, y, z], [x, y, z + l], tint(rgb('#a2c9c6'), .92 + random() * .08)); | |
| } | |
| function pine(x, z, h) { | |
| const y = ground(x, z), | |
| r = h * (.15 + random() * .085), | |
| phase = random() * 3; | |
| const base = blend(rgb('#274e3a'), rgb('#58784d'), random() * .85); | |
| const point = (i, s, dy) => [x + Math.cos(phase + i * TAU / 5) * r * s, y + dy * h, z + Math.sin(phase + i * TAU / 5) * r * s]; | |
| for (let i = 0; i < 5; i++) { | |
| const col = tint(base, .86 + .16 * Math.cos(phase + i * TAU / 5 + 2)); | |
| sceneryG.tri(point(i, 1, .13), point(i + 1, 1, .13), [x, y + h * .76, z], col); | |
| sceneryG.tri(point(i, .76, .40), point(i + 1, .76, .40), [x, y + h, z], tint(col, 1.06)); | |
| } | |
| sceneryG.quad([x - r * .10, y, z], [x + r * .12, y, z], [x + r * .12, y + h * .25, z], [x - r * .10, y + h * .25, z], rgb('#60583d')); | |
| const shadow = rgb('#697a4d'); | |
| sceneryG.tri(surface(x - r * .6, z, .4), surface(x + r * .7, z - r * .45, .4), surface(x + r * 1.6, z + r * 1.25, .4), shadow); | |
| } | |
| for (let cluster = 0; cluster < (gl ? 650 : 210); cluster++) { | |
| const z = random() * 11500 - 4600, | |
| x = river(z) + (random() - .5) * 6500; | |
| const span = 28 + random() * 155; | |
| let size = 9 + random() * 13; | |
| if (Math.abs(x - river(z)) < 600 && random() < .55) continue; | |
| for (let j = 0; j < size; j++) { | |
| const xx = x + (random() + random() - 1) * span, | |
| zz = z + (random() + random() - 1) * span; | |
| if (Math.abs(xx - river(zz)) < riverWidth(zz) + 13 || ground(xx, zz) > 1150 || Math.abs(xx - roadX(zz, x > river(zz) ? 1 : -1)) < 8) continue; | |
| pine(xx, zz, 14 + random() * 23); | |
| } | |
| } | |
| function broadleaf(x, z, h) { | |
| const floor = ground(x, z), | |
| radius = h * (.23 + random() * .1), | |
| crown = h * .64, | |
| phase = random() * TAU; | |
| const bark = rgb('#62583e'), | |
| leaf = blend(rgb('#587044'), rgb('#819452'), random()); | |
| sceneryG.rod([x, floor, z], [x, floor + crown, z], h * .042, bark, 4); | |
| const mid = [], | |
| high = []; | |
| for (let i = 0; i < 7; i++) { | |
| const a = TAU * i / 7 + phase, | |
| r = radius * (.87 + random() * .24); | |
| mid.push([x + Math.cos(a) * r, floor + crown + h * (random() - .5) * .12, z + Math.sin(a) * r]); | |
| high.push([x + Math.cos(a + .24) * r * .70, floor + h * (.82 + random() * .06), z + Math.sin(a + .24) * r * .70]); | |
| } | |
| for (let i = 0; i < 7; i++) { | |
| const j = (i + 1) % 7, | |
| shade = .84 + .14 * Math.cos(TAU * i / 7 + phase + 2); | |
| sceneryG.tri([x, floor + h * .36, z], mid[j], mid[i], tint(leaf, shade * .91)); | |
| sceneryG.quad(mid[i], mid[j], high[j], high[i], tint(leaf, shade)); | |
| sceneryG.tri(high[i], high[j], [x - radius * .13, floor + h, z], tint(leaf, shade * 1.09)); | |
| } | |
| } | |
| for (let i = 0; i < (gl ? 86 : 18); i++) { | |
| const z = -1300 + random() * 5700, | |
| side = random() < .5 ? -1 : 1, | |
| offset = 64 + random() * 260, | |
| n = 4 + Math.floor(random() * 13); | |
| for (let j = 0; j < n; j++) { | |
| const zz = z + j * (9 + random() * 5), | |
| x = river(zz) + side * offset + (random() - .5) * 8; | |
| if (ground(x, zz) < 190) broadleaf(x, zz, 8 + random() * 10); | |
| } | |
| } | |
| const scenery = mesh(sceneryG); | |
| sceneryG.v = []; | |
| // The airfoil sections, ribs, cables and roundels share the aircraft's local coordinate system. | |
| function airplane(enemy = false) { | |
| if (!gl && enemy) { | |
| const model = new Geometry(), fabric = rgb('#a24f40'), shadow = tint(fabric, .72); | |
| for (const y of [1.12, -.42]) model.quad([-5, y, -.55], [5, y, -.55], [5, y, 1], [-5, y, 1], fabric); | |
| model.quad([-1.6, 0, -3.6], [1.6, 0, -3.6], [.55, 0, -2.8], [-.55, 0, -2.8], fabric); | |
| model.ellipsoid([0, 0, -.55], [.55, .5, 2.9], shadow, 6, 3); | |
| model.tri([0, 0, -2.7], [0, 1.3, -3.6], [0, -.1, -3.8], fabric); | |
| for (const x of [-3.4, 3.4]) model.rod([x, -.4, -.3], [x, 1.12, .42], .045, shadow, 3); | |
| return mesh(model); | |
| } | |
| const g = new Geometry(), | |
| linen = rgb(enemy ? '#a85143' : '#ead5a6'), | |
| cream = rgb('#e8d8b3'), | |
| red = rgb(enemy ? '#6b3b35' : '#ad4133'), | |
| bright = rgb('#bb4a39'), | |
| wood = rgb('#785b3b'), | |
| metal = rgb('#45483e'), | |
| navy = rgb('#35464c'), | |
| seam = tint(linen, .83); | |
| function wing(half, y, z, chord, top) { | |
| const sections = [-1, -.98, -.93, -.84, -.76, -.68, -.60, -.52, -.44, -.36, -.28, -.20, -.12, -.05, 0, .05, .12, .20, .28, .36, .44, .52, .60, .68, .76, .84, .93, .98, 1]; | |
| const profile = [[0, .026], [.18, .103], [.43, .096], [1, .003], [.45, -.035], [.09, -.022]]; | |
| const pos = (s, u, h) => { | |
| const tip = smooth(.89, 1, Math.abs(s)), | |
| sweep = .16 * s * s; | |
| return [half * s, y + h + Math.abs(s) * .065, z + chord * (.48 - u) * (1 - tip * .36) - sweep]; | |
| }; | |
| for (let i = 0; i < sections.length - 1; i++) { | |
| const s = sections[i], | |
| t = sections[i + 1]; | |
| for (let k = 0; k < profile.length; k++) { | |
| const [u, h] = profile[k], | |
| [v, j] = profile[(k + 1) % profile.length]; | |
| let paint = Math.abs((s + t) / 2) > .83 || enemy && Math.abs(s + t) < .28 ? red : linen; | |
| g.quad(pos(s, u, h), pos(t, u, h), pos(t, v, j), pos(s, v, j), tint(paint, [1.025, 1.01, .987, .74, .79, .89][k])); | |
| } | |
| if (top && Math.abs(s) < .95 && Math.abs(s) > .05) { | |
| for (let k = 0; k < 3; k++) { | |
| const [u, h] = profile[k], | |
| [v, j] = profile[k + 1]; | |
| g.quad(pos(s, u, h + .002), pos(s + .0028, u, h + .002), pos(s + .0028, v, j + .002), pos(s, v, j + .002), Math.abs(s) > .83 ? tint(red, .88) : seam); | |
| } | |
| } | |
| } | |
| for (const s of [-1, 1]) { | |
| for (let j = 1; j < profile.length - 1; j++) { | |
| g.tri(pos(s, ...profile[0]), pos(s, ...profile[j]), pos(s, ...profile[j + 1]), red); | |
| } | |
| } | |
| // Thin aileron hinge lines on the outer panels. | |
| for (const sign of [-1, 1]) g.quad(pos(sign * .50, .77, .048), pos(sign * .937, .77, .048), pos(sign * .937, .779, .048), pos(sign * .50, .779, .048), tint(linen, .59)); | |
| if (top) for (const s of [-.70, .70]) { | |
| const center = pos(s, .52, .10), | |
| r = .54; | |
| const ringCols = enemy ? [red, cream, red] : [navy, cream, bright]; | |
| for (let j = 0; j < 3; j++) { | |
| const rad = r * [1, .68, .34][j], | |
| Y = center[1] + .009 * j; | |
| for (let k = 0; k < 32; k++) { | |
| const a = k * TAU / 32, | |
| b = (k + 1) * TAU / 32; | |
| g.tri([center[0], Y, center[2]], [center[0] + Math.cos(a) * rad, Y + Math.sin(a) * rad * .042, center[2] + Math.sin(a) * rad], [center[0] + Math.cos(b) * rad, Y + Math.sin(b) * rad * .042, center[2] + Math.sin(b) * rad], ringCols[j]); | |
| } | |
| } | |
| } | |
| } | |
| if (!enemy) { | |
| const stencil = ['1110111', '1010001', '1010010', '1010010', '1110010']; | |
| const mark = (x, z) => [x, 1.13 + .065 * Math.abs(x) / 5.35 + .10 + (.55 - z) * -.064 + .024, z]; | |
| for (let j = 0; j < 5; j++) for (let i = 0; i < 7; i++) { | |
| if (stencil[j][i] !== '1') continue; | |
| const x = -2.1 + i * .115, | |
| z = .74 - j * .155; | |
| g.quad(mark(x, z), mark(x + .116, z), mark(x + .116, z - .156), mark(x, z - .156), rgb('#514f40')); | |
| } | |
| } | |
| wing(5.35, 1.13, .55, 1.75, true); | |
| wing(4.97, -.42, .23, 1.55, false); | |
| const rings = [[-4.08, .08, .11, .02], [-3.7, .16, .22, .03], [-2.75, .32, .36, .03], [-1.55, .48, .48, .02], [-.4, .62, .57, .02], [.75, .68, .59, .01], [1.66, .66, .6, .01], [2.13, .57, .53, 0], [2.33, .42, .44, -.01]]; | |
| const ring = (r, k) => [r[1] * Math.cos(k * TAU / 16), r[3] + r[2] * Math.sin(k * TAU / 16), r[0]]; | |
| for (let j = 0; j < rings.length - 1; j++) for (let k = 0; k < 16; k++) { | |
| const light = Math.sin((k + .5) * TAU / 16), | |
| shade = .81 + .19 * light + .07 * Math.cos((k + .5) * TAU / 16); | |
| const c = j >= 6 ? metal : (k === 0 || k === 7) && j < 4 ? cream : light > .9 && j < 3 ? tint(red, 1.12) : red; | |
| g.quad(ring(rings[j], k), ring(rings[j], k + 1), ring(rings[j + 1], k + 1), ring(rings[j + 1], k), tint(c, shade)); | |
| } | |
| const trim = (r, next, t, width, color) => { | |
| for (let k = 0; k < 16; k++) { | |
| const at = (i, u) => { | |
| const p = blend(ring(r, i), ring(next, i), u); | |
| return [p[0] * 1.012, p[1] * 1.012, p[2]]; | |
| }; | |
| g.quad(at(k, t), at(k + 1, t), at(k + 1, t + width), at(k, t + width), tint(color, .88 + .11 * Math.sin((k + .5) * TAU / 16))); | |
| } | |
| }; | |
| trim(rings[1], rings[2], .69, .11, cream); | |
| trim(rings[1], rings[2], .86, .043, cream); | |
| trim(rings[5], rings[6], .91, .07, wood); | |
| for (const side of [-1, 1]) { | |
| const patch = (y, z) => [side * (.488 + (z + 1.55) * .122 - Math.abs(y) * .21), y + .025, z]; | |
| const decals = [navy, cream, bright]; | |
| for (let ring = 0; ring < 3; ring++) { | |
| const r = [.31, .215, .106][ring]; | |
| for (let k = 0; k < 22; k++) { | |
| const pt = a => { | |
| const v = patch(Math.sin(a) * r, -1.52 + Math.cos(a) * r); | |
| v[0] += side * (.022 + ring * .002); | |
| return v; | |
| }; | |
| const mid = patch(0, -1.52); | |
| mid[0] += side * (.022 + ring * .002); | |
| g.tri(mid, pt(k * TAU / 22), pt((k + 1) * TAU / 22), decals[ring]); | |
| } | |
| } | |
| } | |
| for (let k = 0; k < 16; k++) g.tri([0, 0, 2.34], ring(rings[8], k), ring(rings[8], k + 1), metal); | |
| function tailSurface(shape, y, color) { | |
| for (let i = 1; i < shape.length - 1; i++) g.tri([shape[0][0], y, shape[0][1]], [shape[i][0], y, shape[i][1]], [shape[i + 1][0], y, shape[i + 1][1]], color); | |
| } | |
| for (const s of [-1, 1]) { | |
| tailSurface([[0, -2.70], [s * .92, -2.9], [s * 1.65, -3.38], [s * 1.68, -3.65], [s * 1.46, -3.83], [0, -3.9]], .02, linen); | |
| tailSurface([[s * 1.18, -3.08], [s * 1.65, -3.38], [s * 1.68, -3.65], [s * 1.46, -3.83], [s * 1.18, -3.84]], .028, red); | |
| g.rod([s * .13, .043, -3.66], [s * 1.59, .044, -3.59], .012, wood, 4); | |
| } | |
| const rudder = [[-2.73, .15], [-3.02, .50], [-3.26, 1.05], [-3.49, 1.31], [-3.68, 1.37], [-3.90, 1.23], [-4.03, .9], [-4.09, .45], [-4.05, -.02], [-3.82, -.16], [-3.35, -.12]]; | |
| for (const s of [-1, 1]) { | |
| const p = (z, y) => [s * .045, y, z]; | |
| for (let i = 1; i < rudder.length - 1; i++) g.tri(p(...rudder[0]), p(...rudder[i]), p(...rudder[i + 1]), red); | |
| g.quad([s * .049, .04, -3.46], [s * .049, 1.27, -3.46], [s * .049, 1.35, -3.6], [s * .049, .02, -3.6], cream); | |
| g.quad([s * .05, .02, -3.34], [s * .05, 1.12, -3.34], [s * .05, 1.27, -3.46], [s * .05, .04, -3.46], navy); | |
| } | |
| for (let i = 0; i < rudder.length; i++) { | |
| const a = rudder[i], | |
| b = rudder[(i + 1) % rudder.length]; | |
| g.quad([-.045, a[1], a[0]], [.045, a[1], a[0]], [.045, b[1], b[0]], [-.045, b[1], b[0]], tint(red, .86)); | |
| } | |
| for (const s of [-1, 1]) { | |
| for (const x of [3.45, 3.63]) { | |
| const z = x === 3.45 ? -.38 : .75; | |
| g.rod([s * x, -.36, z - .25], [s * (x + .14), 1.12, z + .12], .046, wood); | |
| } | |
| g.rod([s * 3.45, -.35, -.65], [s * .64, 1.12, .93], .013, metal, 4); | |
| g.rod([s * .56, -.33, .86], [s * 3.59, 1.12, -.27], .013, metal, 4); | |
| g.rod([s * 3.45, -.35, -.66], [s * 3.78, 1.1, .91], .013, metal, 4); | |
| g.rod([s * .36, .44, -.12], [s * .84, 1.12, .75], .044, wood); | |
| g.rod([s * .45, .42, 1.37], [s * .82, 1.12, .04], .044, wood); | |
| g.rod([s * .48, -.35, 1.2], [s * .86, -1.38, .47], .054, metal); | |
| g.rod([s * .43, -.33, -.52], [s * .86, -1.38, .47], .05, metal); | |
| g.ellipsoid([s * .88, -1.36, .43], [.105, .36, .36], rgb('#31342f'), 12, 6); | |
| g.ellipsoid([s * .97, -1.36, .43], [.025, .19, .19], wood, 9, 5); | |
| } | |
| g.rod([-.88, -1.39, .43], [.88, -1.39, .43], .054, metal); | |
| g.rod([0, -.15, -3.43], [0, -.52, -3.8], .042, wood); | |
| g.ellipsoid([0, .50, -.65], [.39, .12, .52], rgb('#554738')); | |
| g.ellipsoid([0, .57, -.65], [.32, .09, .44], rgb('#2e332c')); | |
| g.ellipsoid([0, .66, -.77], [.238, .24, .24], rgb('#675843')); | |
| g.ellipsoid([0, .87, -.72], [.18, .22, .19], rgb('#685c47')); | |
| g.rod([-.28, .64, .7], [-.28, .65, 2.29], .058, metal); | |
| g.rod([.28, .64, .7], [.28, .65, 2.29], .058, metal); | |
| g.tri([-.13, .75, -.81], [-.12, .65, -.83], [-.31, .70, -1.34], cream); | |
| g.tri([-.12, .65, -.83], [-.28, .58, -1.51], [-.31, .70, -1.34], tint(cream, .83)); | |
| g.ellipsoid([0, .015, 2.43], [.17, .17, .22], wood); | |
| return mesh(g); | |
| } | |
| const playerMesh = airplane(false), | |
| banditMesh = airplane(true), | |
| propG = new Geometry(); | |
| for (const s of [-1, 1]) { | |
| const blade = tint(rgb('#96754b'), 1 + s * .10); | |
| propG.quad([-.055, 0, 0], [.12, s * .4, 0], [.095, s * 1.12, 0], [-.02, s * 1.2, 0], blade); | |
| propG.tri([-.055, 0, 0], [-.02, s * 1.2, 0], [-.13, s * .53, 0], blade); | |
| } | |
| const propMesh = mesh(propG); | |
| const stage = $('stage'), | |
| over = $('overlay'), | |
| oc = over.getContext('2d'), | |
| map = $('map'), | |
| mc = map.getContext('2d'), | |
| compass = $('compassDial'), | |
| cc = compass.getContext('2d'); | |
| let W = 1, | |
| H = 1, | |
| focal = 1, | |
| dpr = 1, | |
| cam = { | |
| pos: [0, 0, 0], | |
| right: [1, 0, 0], | |
| up: [0, 1, 0], | |
| forward: [0, 0, 1], | |
| yaw: 0, | |
| pitch: 0, | |
| roll: 0 | |
| }, | |
| chase = true; | |
| let player, | |
| enemies, | |
| shots = [], | |
| sparks = [], | |
| kills = 0, | |
| active = false, | |
| elapsed = 0, | |
| ambient = 0, | |
| modal = '', | |
| ended = '', | |
| reload = 0, | |
| fireClock = 0, | |
| hurt = 0, | |
| hit = 0, | |
| noticeTime = 0, | |
| hudClock = 0; | |
| const keys = new Set(), | |
| joy = { | |
| x: 0, | |
| y: 0 | |
| }; | |
| let lastTime = 0, | |
| waypoint = 0; | |
| const patrolRoute = [[245, 940], [395, 1660], [45, 2840], [-590, 3360], [-990, 2440], [-540, 1350], [-440, 300], [-490, -800], [20, -1370], [245, -670]]; | |
| function reset() { | |
| player = { | |
| pos: [245, 385, 0], | |
| yaw: 0, | |
| pitch: 0, | |
| roll: -.135, | |
| rollRate: 0, | |
| pitchRate: 0, | |
| path: 0, | |
| slip: 0, | |
| speed: 45.5, | |
| throttle: .72, | |
| hp: 100, | |
| ammo: 480 | |
| }; | |
| enemies = [[247, 388, 196, -.09], [94, 409, 366, .41], [399, 430, 548, -.42]].map((s, i) => ({ | |
| pos: s.slice(0, 3), | |
| yaw: s[3], | |
| pitch: 0, | |
| roll: (i - 1) * .16, | |
| speed: 38 + i, | |
| hp: 3, | |
| alive: true, | |
| fireIn: 3 + i * 1.9, | |
| id: i, | |
| stagger: 0 | |
| })); | |
| shots = []; | |
| sparks = []; | |
| keys.clear(); | |
| joy.x = joy.y = 0; | |
| kills = 0; | |
| elapsed = 0; | |
| ambient = 0; | |
| reload = fireClock = hit = hurt = 0; | |
| active = false; | |
| waypoint = 0; | |
| ended = ''; | |
| chase = true; | |
| hudClock = 0; | |
| lastTime = performance.now(); | |
| $('message').classList.remove('show'); | |
| $('message').textContent = ''; | |
| noticeTime = 0; | |
| setModal(''); | |
| updateHUD(); | |
| setCamera(0, true); | |
| draw(); | |
| } | |
| function project(p, limit = .38) { | |
| const d = sub(p, cam.pos), | |
| z = dot(d, cam.forward); | |
| return z < limit ? null : [W * .5 + dot(d, cam.right) * focal / z, H * .5 - dot(d, cam.up) * focal / z, z]; | |
| } | |
| function resize() { | |
| W = Math.max(stage.clientWidth, 1); | |
| H = Math.max(stage.clientHeight, 1); | |
| dpr = Math.min(window.devicePixelRatio || 1, 1.6); | |
| focal = H * .99; | |
| for (const c of [world, over, sky]) { | |
| c.width = Math.round(W * dpr); | |
| c.height = Math.round(H * dpr); | |
| } | |
| oc.setTransform(dpr, 0, 0, dpr, 0, 0); | |
| skyCtx.setTransform(dpr, 0, 0, dpr, 0, 0); | |
| for (const c of [map, compass]) { | |
| c.width = Math.round(c.clientWidth * dpr); | |
| c.height = Math.round(c.clientHeight * dpr); | |
| c.getContext('2d').setTransform(dpr, 0, 0, dpr, 0, 0); | |
| } | |
| if (gl) gl.viewport(0, 0, world.width, world.height);else softCtx.setTransform(dpr, 0, 0, dpr, 0, 0); | |
| if (player) { | |
| setCamera(0, true); | |
| draw(); | |
| } | |
| } | |
| function setCamera(dt, instant = false) { | |
| const p = player, | |
| adjust = clamp(1.45 / (W / H), 1, 2.15), | |
| distance = (chase ? 14.2 : 0) * adjust; | |
| const sideFactor = clamp(W / H, .5, 1); | |
| const yaw = p.yaw + (chase ? -.178 * sideFactor : 0), | |
| pitch = chase ? p.pitch * .76 - .094 : p.pitch + .006, | |
| roll = p.roll * (chase ? .19 : 1); | |
| const follow = chase ? axes(p.yaw, p.pitch * .7, p.roll * .16) : axes(p.yaw, p.pitch, p.roll); | |
| const offset = chase ? [2.96 * adjust * sideFactor, 4.05 * adjust, -distance] : [0, .94, -.50]; | |
| const target = add(p.pos, rotate(offset, follow)); | |
| let t = instant || !dt || !chase ? 1 : 1 - Math.exp(-dt * 10); | |
| const movement = sub(p.pos, cam.lastPlayerPos || p.pos); | |
| cam.pos = blend(add(cam.pos, movement), target, t); | |
| cam.lastPlayerPos = p.pos.slice(); | |
| cam.yaw += wrap(yaw - cam.yaw) * t; | |
| cam.pitch = mix(cam.pitch, pitch, t); | |
| cam.roll = mix(cam.roll, roll, t); | |
| const m = axes(cam.yaw, cam.pitch, cam.roll); | |
| cam.right = m.slice(0, 3); | |
| cam.up = m.slice(3, 6); | |
| cam.forward = m.slice(6, 9); | |
| } | |
| function drawSky() { | |
| const c = skyCtx, | |
| scale = focal * TAU / pano.width, | |
| sw = pano.width * scale, | |
| sh = pano.height * scale; | |
| const center = 2048 + cam.yaw * pano.width / TAU; | |
| c.save(); | |
| c.translate(W / 2, H / 2); | |
| c.rotate(cam.roll); | |
| const y = focal * Math.tan(clamp(cam.pitch, -1.24, 1.24)) - 540 * scale; | |
| c.fillStyle = '#5b97b8'; | |
| c.fillRect(-W - H, -W - H, (W + H) * 2, (W + H) * 2); | |
| c.fillStyle = '#e6d3b2'; | |
| c.fillRect(-W, y + sh - 1, W * 2, H * 3); | |
| const x = -(center * scale % sw + sw) % sw; | |
| for (let i = -1; i <= 1; i++) c.drawImage(pano, x + i * sw, y, sw, sh); | |
| c.restore(); | |
| } | |
| let faces = []; | |
| const fogColor = rgb('#b4c6c8'); | |
| function drawMesh(m, offset = origin, model = ID) { | |
| if (gl) { | |
| gl.uniform3fv(uo, offset); | |
| gl.uniformMatrix3fv(um, false, model); | |
| gl.bindBuffer(gl.ARRAY_BUFFER, m.buf); | |
| gl.vertexAttribPointer(attrPos, 3, gl.FLOAT, false, 24, 0); | |
| gl.vertexAttribPointer(attrCol, 3, gl.FLOAT, false, 24, 12); | |
| gl.drawArrays(gl.TRIANGLES, 0, m.count); | |
| return; | |
| } | |
| const D = m.data, | |
| staticMesh = model === ID && offset === origin; | |
| if (staticMesh && !m.chunks) { | |
| const cells = new Map(); | |
| for (let i = 0; i < D.length; i += 18) { | |
| const x = Math.floor(D[i] / 500), | |
| z = Math.floor(D[i + 2] / 500), | |
| k = x + ',' + z; | |
| if (!cells.has(k)) cells.set(k, { | |
| x: x * 500 + 250, | |
| z: z * 500 + 250, | |
| indices: [] | |
| }); | |
| cells.get(k).indices.push(i); | |
| } | |
| m.chunks = [...cells.values()]; | |
| } | |
| function triangle(i) { | |
| let coords = [], | |
| zsum = 0; | |
| for (let j = 0; j < 3; j++) { | |
| const k = i + j * 6; | |
| let p = [D[k], D[k + 1], D[k + 2]]; | |
| if (!staticMesh) p = add(rotate(p, model), offset); | |
| const delta = sub(p, cam.pos), | |
| z = dot(delta, cam.forward); | |
| coords.push([dot(delta, cam.right), dot(delta, cam.up), z]); | |
| zsum += z; | |
| } | |
| if (coords.every(p => p[2] < .42)) return; | |
| if (coords.some(p => p[2] < .42)) { | |
| const out = []; | |
| for (let j = 0; j < 3; j++) { | |
| const a = coords[j], | |
| b = coords[(j + 1) % 3]; | |
| if (a[2] >= .42) out.push(a); | |
| if (a[2] < .42 !== b[2] < .42) out.push(blend(a, b, (.42 - a[2]) / (b[2] - a[2]))); | |
| } | |
| coords = out; | |
| } | |
| const pts = coords.map(p => [W * .5 + focal * p[0] / p[2], H * .5 - focal * p[1] / p[2]]); | |
| if (pts.every(p => p[0] < 0) || pts.every(p => p[0] > W) || pts.every(p => p[1] < 0) || pts.every(p => p[1] > H)) return; | |
| const z = zsum / 3, | |
| fog = 1 - Math.exp(-Math.max(0, z - 90) / 4800), | |
| color = [0, 1, 2].map(j => Math.round(mix(D[i + j + 3], fogColor[j], fog) * 255)); | |
| faces.push([z, pts, 'rgb(' + color.join(',') + ')']); | |
| } | |
| if (staticMesh) { | |
| for (const c of m.chunks) { | |
| const dx = c.x - cam.pos[0], | |
| dz = c.z - cam.pos[2], | |
| forward = dx * Math.sin(cam.yaw) + dz * Math.cos(cam.yaw), | |
| lateral = dx * Math.cos(cam.yaw) - dz * Math.sin(cam.yaw); | |
| if (forward < -650 || Math.abs(lateral) > Math.max(0, forward) * (W * .55 / focal) + 800 || m === scenery && forward > 2600) continue; | |
| for (const i of c.indices) triangle(i); | |
| } | |
| } else for (let i = 0; i < D.length; i += 18) triangle(i); | |
| } | |
| function drawPlane(p, model, prop = true) { | |
| const a = axes(p.yaw, p.pitch, p.roll); | |
| drawMesh(model, p.pos, a); | |
| if (prop) { | |
| const b = axes(p.yaw, p.pitch, p.roll + ambient * (30 + 20 * player.throttle)); | |
| drawMesh(propMesh, add(p.pos, rotate([0, .015, 2.48], a)), b); | |
| } | |
| } | |
| function renderWorld() { | |
| drawSky(); | |
| if (gl) { | |
| gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
| gl.uniform3fv(uc, cam.pos); | |
| gl.uniform3fv(ur, cam.right); | |
| gl.uniform3fv(uu, cam.up); | |
| gl.uniform3fv(uf, cam.forward); | |
| gl.uniform2f(up, focal * 2 / W, focal * 2 / H); | |
| gl.uniform3fv(ufog, fogColor); | |
| } else { | |
| faces = []; | |
| softCtx.clearRect(0, 0, W, H); | |
| } | |
| drawMesh(mountains); | |
| drawMesh(terrain); | |
| drawMesh(water); | |
| drawMesh(scenery); | |
| for (const e of enemies) if (e.alive) drawPlane(e, banditMesh); | |
| drawPlane(player, playerMesh); | |
| if (!gl) { | |
| faces.sort((a, b) => b[0] - a[0]); | |
| const c = softCtx; | |
| for (const [, poly, color] of faces) { | |
| c.fillStyle = color; | |
| c.beginPath(); | |
| c.moveTo(...poly[0]); | |
| for (let i = 1; i < poly.length; i++) c.lineTo(...poly[i]); | |
| c.closePath(); | |
| c.fill(); | |
| if (poly.length === 3 && Math.abs((poly[1][0] - poly[0][0]) * (poly[2][1] - poly[0][1]) - (poly[2][0] - poly[0][0]) * (poly[1][1] - poly[0][1])) > 180) { | |
| c.strokeStyle = color; | |
| c.lineWidth = .55; | |
| c.stroke(); | |
| } | |
| } | |
| } | |
| } | |
| function toast(s, duration = 2) { | |
| $('message').textContent = s; | |
| $('message').classList.add('show'); | |
| noticeTime = duration; | |
| } | |
| function burst(pos, color, count) { | |
| for (let i = 0; i < count; i++) { | |
| const life = .35 + random() * .9; | |
| sparks.push({ | |
| pos: pos.slice(), | |
| vel: [(random() - .5) * 17, (random() - .15) * 13, (random() - .5) * 17], | |
| life, | |
| total: life, | |
| col: color, | |
| r: .4 + random() * 1.3 | |
| }); | |
| } | |
| } | |
| function damageEnemy(e) { | |
| e.hp--; | |
| hit = .22; | |
| e.stagger = .55; | |
| burst(e.pos, '#fcce77', 6); | |
| if (e.hp <= 0) { | |
| e.alive = false; | |
| kills++; | |
| burst(e.pos, '#dd9652', 25); | |
| burst(e.pos, '#55594d', 18); | |
| soundEffect('hit'); | |
| toast('BANDIT DOWN ' + kills + ' / 3'); | |
| if (kills === 3) finish('won'); | |
| } | |
| } | |
| function finish(state) { | |
| if (ended) return; | |
| ended = state; | |
| setModal(state); | |
| updateHUD(); | |
| } | |
| function damagePlayer(n) { | |
| player.hp = clamp(player.hp - n, 0, 100); | |
| hurt = .5; | |
| soundEffect('hit'); | |
| if (player.hp === 0) finish('shot'); | |
| } | |
| function shoot(p, isPlayer) { | |
| const rot = axes(p.yaw, p.pitch, p.roll); | |
| const dir = unit(rotate([(random() - .5) * .008, (random() - .5) * .006, 1], rot)); | |
| const pos = add(p.pos, rotate([isPlayer ? player.ammo % 2 ? .29 : -.29 : 0, .53, 2.6], rot)); | |
| shots.push({ | |
| pos, | |
| vel: mul(dir, 330 + p.speed), | |
| life: 2.7, | |
| player: isPlayer | |
| }); | |
| if (isPlayer) { | |
| player.ammo--; | |
| soundEffect('gun'); | |
| if (!player.ammo) startReload(); | |
| } | |
| } | |
| function fireGuns() { | |
| if (fireClock > 0 || reload > 0 || player.ammo === 0) return; | |
| shoot(player, true); | |
| fireClock = .095; | |
| } | |
| function startReload() { | |
| if (!active || ended || reload || player.ammo === 480) return; | |
| reload = 2.25; | |
| toast('RELOADING', 2.25); | |
| } | |
| function enemyStep(e, dt) { | |
| let rel = sub(player.pos, e.pos), | |
| dist = Math.hypot(...rel); | |
| const away = dist < 120 || e.stagger > 0, | |
| patrol = elapsed < 5 || dist < 300 && Math.sin(elapsed * .13 + e.id * 2.2) > .18; | |
| let wantYaw = patrol ? Math.sin(elapsed * .13 + e.id * 1.64) * .85 : Math.atan2(rel[0], rel[2]) + (away ? 1.45 : 0); | |
| const look = [e.pos[0] + Math.sin(e.yaw) * 170, e.pos[2] + Math.cos(e.yaw) * 170], | |
| floor = Math.max(ground(...look) + 83, ground(e.pos[0], e.pos[2]) + 50); | |
| const targetY = Math.max(floor, player.pos[1] + Math.sin(elapsed * .15 + e.id * 2.8) * 42 + (away ? 55 : 0)); | |
| const desiredPitch = clamp((targetY - e.pos[1]) / Math.max(115, dist * .55), -.33, .4), | |
| error = wrap(wantYaw - e.yaw); | |
| e.roll = mix(e.roll, clamp(-error * 1.35, -1.05, 1.05), 1 - Math.exp(-dt * 1.8)); | |
| e.yaw = wrap(e.yaw + clamp(error, -.24, .24) * dt); | |
| e.pitch = mix(e.pitch, desiredPitch, dt * .7); | |
| e.pos = add(e.pos, mul(axes(e.yaw, e.pitch, 0).slice(6), e.speed * dt)); | |
| e.stagger = Math.max(0, e.stagger - dt); | |
| e.fireIn -= dt; | |
| if (elapsed > 8 && dist < 620 && dist > 35 && e.fireIn <= 0) { | |
| const aim = unit(rel), | |
| forward = axes(e.yaw, e.pitch, 0).slice(6); | |
| if (dot(aim, forward) > .993) { | |
| shoot(e, false); | |
| e.fireIn = .36 + random() * .45; | |
| } | |
| } | |
| if (dist < 6.3) { | |
| damageEnemy(e); | |
| damagePlayer(35); | |
| e.pos = add(e.pos, mul(unit(sub(e.pos, player.pos)), 10)); | |
| } | |
| } | |
| function step(dt) { | |
| if (modal || ended) return; | |
| ambient += dt; | |
| if (noticeTime > 0 && (noticeTime -= dt) <= 0) $('message').classList.remove('show'); | |
| // An unengaged patrol follows the valley until the first flight input. | |
| if (!active) { | |
| const p = player, | |
| goal = patrolRoute[waypoint], | |
| dx = goal[0] - p.pos[0], | |
| dz = goal[1] - p.pos[2]; | |
| if (Math.hypot(dx, dz) < 200) waypoint = (waypoint + 1) % patrolRoute.length; | |
| const turn = clamp(wrap(Math.atan2(dx, dz) - p.yaw) * .62, -.14, .14); | |
| p.yaw = wrap(p.yaw + turn * dt); | |
| p.roll = mix(p.roll, clamp(-turn * 3.3 - .09 + Math.sin(ambient * .38) * .035, -.46, .46), 1 - Math.exp(-dt * .28)); | |
| const targetY = Math.max(385 + Math.sin(ambient * .12) * 5, ground(p.pos[0] + Math.sin(p.yaw) * 200, p.pos[2] + Math.cos(p.yaw) * 200) + 170); | |
| p.path = clamp((targetY - p.pos[1]) * .007, -.25, .25); | |
| p.pitch = p.path + Math.sin(ambient * .33) * .005; | |
| p.pos = add(p.pos, mul(axes(p.yaw, p.path, 0).slice(6), p.speed * dt)); | |
| const formation = axes(p.yaw, 0, 0); | |
| enemies.forEach((e, i) => { | |
| e.roll = p.roll + Math.sin(ambient * .28 + i * 1.4) * .22; | |
| e.yaw = wrap(p.yaw + [-.09, .41, -.42][i]); | |
| e.pos = add(p.pos, rotate([[2, -151, 154][i] + Math.sin(ambient * .16 + i) * 3, [3, 24, 45][i] + Math.sin(ambient * .27 + i) * 1.4, [196, 366, 548][i]], formation)); | |
| }); | |
| return; | |
| } | |
| elapsed += dt; | |
| const p = player; | |
| const axis = (positive, negative) => (keys.has(positive) ? 1 : 0) - (keys.has(negative) ? 1 : 0); | |
| p.throttle = clamp(p.throttle + axis('KeyW', 'KeyS') * dt * .31, 0, 1); | |
| const pitchInput = clamp(axis('ArrowDown', 'ArrowUp') + joy.y, -1, 1), | |
| rollInput = clamp(axis('ArrowLeft', 'ArrowRight') - joy.x, -1, 1), | |
| rudder = axis('KeyD', 'KeyA'); | |
| const authority = clamp(p.speed / 36, .32, 1.3); | |
| p.rollRate += ((rollInput * 1.44 * authority - p.rollRate) * 3.5 - (rollInput === 0 ? p.roll * .75 : 0)) * dt; | |
| p.roll = clamp(p.roll + p.rollRate * dt, -1.39, 1.39); | |
| p.pitchRate += ((pitchInput * .51 * authority - p.pitchRate) * 3.6 - (pitchInput === 0 ? p.pitch * .36 : 0)) * dt; | |
| p.pitch = clamp(p.pitch + p.pitchRate * dt, -1.04, .9); | |
| // Thrust, quadratic drag, gravity along the flight path, and bank-dependent lift. | |
| const acceleration = p.throttle * 9.3 + 1.0 - .00366 * p.speed * p.speed - 9.81 * Math.sin(p.path) - 1.3 * Math.abs(Math.sin(p.roll)); | |
| p.speed = clamp(p.speed + acceleration * dt, 17, 84); | |
| const stall = smooth(0, 1, (29 - p.speed) / 11); | |
| p.pitch -= stall * (.18 + Math.max(0, p.pitch) * .3) * dt; | |
| const targetPath = mix(p.pitch - (1 - Math.cos(p.roll)) * .14, -.51, stall); | |
| p.path = mix(p.path, targetPath, 1 - Math.exp(-dt * 1.5)); | |
| p.slip = mix(p.slip, rudder * .155, 1 - Math.exp(-dt * 2.5)); | |
| p.yaw = wrap(p.yaw + (-Math.sin(p.roll) * 13 / Math.max(22, p.speed) + p.slip) * dt); | |
| const velocity = mul(axes(p.yaw, p.path, 0).slice(6), p.speed); | |
| p.pos = add(p.pos, mul(velocity, dt)); | |
| if (p.pos[1] < ground(p.pos[0], p.pos[2]) + 1.3) { | |
| p.hp = 0; | |
| finish('crashed'); | |
| return; | |
| } | |
| if (Math.abs(p.pos[0]) > 6800 || Math.abs(p.pos[2]) > 7900) { | |
| finish('departed'); | |
| return; | |
| } | |
| if (stall > .5 && noticeTime <= 0) toast('STALL · LOWER THE NOSE', 1.3); | |
| fireClock = Math.max(0, fireClock - dt); | |
| if (reload > 0) { | |
| reload -= dt; | |
| if (reload <= 0) { | |
| reload = 0; | |
| p.ammo = 480; | |
| toast('GUNS READY', 1); | |
| } | |
| } | |
| if (keys.has('Space')) fireGuns(); | |
| for (const e of enemies) { | |
| if (e.alive) enemyStep(e, dt); | |
| if (ended) return; | |
| } | |
| for (const b of shots) { | |
| const prev = b.pos; | |
| b.pos = add(b.pos, mul(b.vel, dt)); | |
| b.life -= dt; | |
| const segment = sub(b.pos, prev), | |
| len2 = dot(segment, segment); | |
| const targets = b.player ? enemies.filter(e => e.alive) : [p]; | |
| for (const t of targets) { | |
| const v = sub(t.pos, prev), | |
| k = clamp(dot(segment, v) / (len2 || 1), 0, 1); | |
| if (Math.hypot(...sub(v, mul(segment, k))) < (b.player ? 8.6 : 4.3)) { | |
| if (b.player) damageEnemy(t);else damagePlayer(7); | |
| b.life = 0; | |
| break; | |
| } | |
| } | |
| if (b.life > 0 && b.pos[1] < ground(b.pos[0], b.pos[2])) b.life = 0; | |
| } | |
| shots = shots.filter(b => b.life > 0); | |
| for (const s of sparks) { | |
| s.life -= dt; | |
| s.vel[1] -= dt * 3; | |
| s.pos = add(s.pos, mul(s.vel, dt)); | |
| } | |
| sparks = sparks.filter(s => s.life > 0); | |
| hurt = Math.max(0, hurt - dt); | |
| hit = Math.max(0, hit - dt); | |
| } | |
| function drawOverlay() { | |
| const c = oc; | |
| c.clearRect(0, 0, W, H); | |
| c.save(); | |
| c.lineJoin = 'round'; | |
| for (const b of shots) { | |
| const a = project(b.pos), | |
| tail = project(sub(b.pos, mul(b.vel, .039))); | |
| if (a && tail) { | |
| c.strokeStyle = b.player ? '#ffe8ab' : '#e78c5e'; | |
| c.lineWidth = 2; | |
| c.shadowColor = '#f9ba55'; | |
| c.shadowBlur = 4; | |
| c.beginPath(); | |
| c.moveTo(a[0], a[1]); | |
| c.lineTo(tail[0], tail[1]); | |
| c.stroke(); | |
| } | |
| } | |
| c.shadowBlur = 0; | |
| for (const s of sparks) { | |
| const v = project(s.pos); | |
| if (!v) continue; | |
| c.globalAlpha = s.life / s.total; | |
| c.fillStyle = s.col; | |
| c.beginPath(); | |
| c.arc(v[0], v[1], clamp(s.r * focal / v[2], .6, 28), 0, TAU); | |
| c.fill(); | |
| } | |
| c.globalAlpha = 1; | |
| for (const e of enemies) { | |
| if (!e.alive) continue; | |
| const screen = project(e.pos), | |
| distance = Math.hypot(...sub(e.pos, player.pos)); | |
| if (!screen || screen[0] < 12 || screen[0] > W - 12 || screen[1] < 10 || screen[1] > H - 10 || distance > 2200) continue; | |
| const x = screen[0], | |
| y = screen[1] - clamp(focal * 1.8 / screen[2] + 8, 9, 25), | |
| s = 4.3; | |
| c.save(); | |
| c.translate(x, y); | |
| c.lineWidth = 1.45; | |
| c.shadowColor = '#f4edd48a'; | |
| c.shadowBlur = 2; | |
| c.strokeStyle = '#ad4e39'; | |
| c.beginPath(); | |
| c.moveTo(0, -s); | |
| c.lineTo(s, 0); | |
| c.lineTo(0, s); | |
| c.lineTo(-s, 0); | |
| c.closePath(); | |
| c.stroke(); | |
| c.shadowBlur = 0; | |
| if (e.id === 0) { | |
| c.font = '600 9px Consolas,monospace'; | |
| c.textAlign = 'center'; | |
| const val = Math.round(distance) + ' m'; | |
| c.fillStyle = '#37362dc4'; | |
| c.fillRect(-17, -20, 34, 12); | |
| c.fillStyle = '#f1d3ae'; | |
| c.fillText(val, 0, -11); | |
| } | |
| c.restore(); | |
| } | |
| const aim = project(add(player.pos, rotate([0, .54, 450], axes(player.yaw, player.pitch, player.roll)))); | |
| if (aim) { | |
| const x = aim[0], | |
| y = aim[1], | |
| r = chase ? 10 : 14; | |
| c.translate(x, y); | |
| c.strokeStyle = hit > 0 ? '#f6bc75' : 'rgba(255,253,230,.92)'; | |
| c.shadowColor = 'rgba(30,37,28,.7)'; | |
| c.shadowBlur = 2; | |
| c.lineWidth = 1.3; | |
| c.beginPath(); | |
| for (let i = 0; i < 4; i++) { | |
| const a = i * Math.PI / 2; | |
| c.moveTo(Math.cos(a + .22) * r, Math.sin(a + .22) * r); | |
| c.arc(0, 0, r, a + .22, a + Math.PI / 2 - .22); | |
| c.moveTo(Math.cos(a) * (r + 4), Math.sin(a) * (r + 4)); | |
| c.lineTo(Math.cos(a) * (r + 10), Math.sin(a) * (r + 10)); | |
| } | |
| c.stroke(); | |
| c.fillStyle = '#fff8df'; | |
| c.fillRect(-1, -1, 2, 2); | |
| if (hit > 0) { | |
| c.lineWidth = 2; | |
| c.beginPath(); | |
| for (let i = 0; i < 4; i++) { | |
| const a = Math.PI * .25 + i * Math.PI * .5; | |
| c.moveTo(Math.cos(a) * 6, Math.sin(a) * 6); | |
| c.lineTo(Math.cos(a) * 15, Math.sin(a) * 15); | |
| } | |
| c.stroke(); | |
| } | |
| } | |
| c.restore(); | |
| if (hurt > 0) { | |
| const g = c.createRadialGradient(W / 2, H / 2, H * .16, W / 2, H / 2, W * .62); | |
| g.addColorStop(0, '#9f362a00'); | |
| g.addColorStop(1, 'rgba(151,40,26,' + hurt * .64 + ')'); | |
| c.fillStyle = g; | |
| c.fillRect(0, 0, W, H); | |
| } | |
| } | |
| const atlas = document.createElement('canvas'), | |
| mapSize = 16000; | |
| atlas.width = atlas.height = 800; | |
| function makeAtlas() { | |
| const ctx = atlas.getContext('2d'), | |
| n = atlas.width, | |
| img = ctx.createImageData(n, n); | |
| for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) { | |
| const x = (i / n - .5) * mapSize, | |
| z = (.5 - j / n) * mapSize, | |
| h = ground(x, z); | |
| const topo = h / 31 + noise(x / 350, z / 320) * .13, | |
| line = Math.abs(topo - Math.round(topo)) < .059, | |
| v = 54 + clamp(h / 68, 0, 15) + noise(x / 310, z / 290) * 6 + (line ? 11 : 0), | |
| p = (j * n + i) * 4; | |
| img.data[p] = v - 2; | |
| img.data[p + 1] = v + 9; | |
| img.data[p + 2] = v - 2; | |
| img.data[p + 3] = 255; | |
| } | |
| ctx.putImageData(img, 0, 0); | |
| const px = x => (x / mapSize + .5) * n, | |
| py = z => (.5 - z / mapSize) * n; | |
| ctx.strokeStyle = '#758e82'; | |
| ctx.lineWidth = 2.5; | |
| ctx.beginPath(); | |
| for (let z = -8000; z <= 8000; z += 45) { | |
| if (z === -8000) ctx.moveTo(px(river(z)), py(z));else ctx.lineTo(px(river(z)), py(z)); | |
| } | |
| ctx.stroke(); | |
| ctx.lineWidth = .55; | |
| ctx.strokeStyle = '#82866c'; | |
| for (const sign of [-1, 1]) { | |
| ctx.beginPath(); | |
| for (let z = -7000; z <= 7000; z += 75) { | |
| if (z === -7000) ctx.moveTo(px(roadX(z, sign)), py(z));else ctx.lineTo(px(roadX(z, sign)), py(z)); | |
| } | |
| ctx.stroke(); | |
| } | |
| } | |
| makeAtlas(); | |
| function drawMap() { | |
| const c = mc, | |
| w = map.clientWidth, | |
| h = map.clientHeight, | |
| r = 1800, | |
| s = w / r, | |
| px = player.pos[0], | |
| pz = player.pos[2] + 230; | |
| c.clearRect(0, 0, w, h); | |
| const n = atlas.width; | |
| c.drawImage(atlas, (.5 + px / mapSize) * n - r * n / mapSize / 2, (.5 - pz / mapSize) * n - h / s * n / mapSize / 2, r * n / mapSize, h / s * n / mapSize, 0, 0, w, h); | |
| c.strokeStyle = '#d4dbc028'; | |
| c.lineWidth = .65; | |
| for (let x = w / 2 + -px * s % (w / 5) - w; x < w; x += w / 5) { | |
| c.beginPath(); | |
| c.moveTo(x, 0); | |
| c.lineTo(x, h); | |
| c.stroke(); | |
| } | |
| for (let y = h / 2 + pz * s % (w / 5) - w; y < h; y += w / 5) { | |
| c.beginPath(); | |
| c.moveTo(0, y); | |
| c.lineTo(w, y); | |
| c.stroke(); | |
| } | |
| function marker(p, isPlayer) { | |
| const x = w / 2 + (p.pos[0] - px) * s, | |
| y = h / 2 - (p.pos[2] - pz) * s; | |
| c.save(); | |
| c.translate(x, y); | |
| c.rotate(p.yaw); | |
| if (isPlayer) { | |
| c.strokeStyle = '#e8dbb855'; | |
| c.setLineDash([2, 3]); | |
| c.beginPath(); | |
| c.arc(0, 0, 15, 0, TAU); | |
| c.stroke(); | |
| c.setLineDash([]); | |
| c.fillStyle = '#f6e9bc'; | |
| c.strokeStyle = '#303a2e'; | |
| c.lineWidth = 1; | |
| c.beginPath(); | |
| c.moveTo(0, -6); | |
| c.lineTo(4.3, 5); | |
| c.lineTo(0, 3); | |
| c.lineTo(-4.3, 5); | |
| c.closePath(); | |
| c.fill(); | |
| c.stroke(); | |
| } else { | |
| c.fillStyle = '#df8064'; | |
| c.beginPath(); | |
| c.moveTo(0, -3.7); | |
| c.lineTo(3, 2.4); | |
| c.lineTo(-3, 2.4); | |
| c.closePath(); | |
| c.fill(); | |
| } | |
| c.restore(); | |
| } | |
| for (const e of enemies) if (e.alive) marker(e, false); | |
| marker(player, true); | |
| c.strokeStyle = '#c6caba'; | |
| c.lineWidth = 1; | |
| c.beginPath(); | |
| c.moveTo(8, h - 10); | |
| c.lineTo(8, h - 7); | |
| c.lineTo(8 + 200 * s, h - 7); | |
| c.lineTo(8 + 200 * s, h - 10); | |
| c.stroke(); | |
| c.fillStyle = '#d0d5c2'; | |
| c.font = '8px monospace'; | |
| c.fillText('200 m', 9, h - 13); | |
| } | |
| function drawCompass() { | |
| const c = cc, | |
| w = compass.clientWidth, | |
| h = compass.clientHeight, | |
| yaw = (player.yaw / rad + 360) % 360, | |
| sz = 3.1; | |
| c.clearRect(0, 0, w, h); | |
| c.textAlign = 'center'; | |
| c.font = '600 10px Consolas,monospace'; | |
| const labels = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; | |
| for (let deg = Math.floor((yaw - w / sz / 2) / 5) * 5; deg <= yaw + w / sz / 2; deg += 5) { | |
| const x = w / 2 + (deg - yaw) * sz, | |
| val = (deg + 720) % 360, | |
| major = val % 15 === 0; | |
| const alpha = Math.min(1, Math.max(.1, (1 - Math.abs(x - w / 2) / (w / 2)) * 2.2)); | |
| c.globalAlpha = alpha; | |
| c.strokeStyle = '#46554c'; | |
| c.lineWidth = 1; | |
| c.beginPath(); | |
| c.moveTo(x, 18); | |
| c.lineTo(x, major ? 24 : 21); | |
| c.stroke(); | |
| if (major) { | |
| c.fillStyle = '#35443c'; | |
| c.fillText(val % 45 === 0 ? labels[val / 45] : String(val).padStart(3, '0'), x, 13); | |
| } | |
| } | |
| c.globalAlpha = 1; | |
| c.fillStyle = '#a75239'; | |
| c.beginPath(); | |
| c.moveTo(w / 2 - 3, 31); | |
| c.lineTo(w / 2, 25); | |
| c.lineTo(w / 2 + 3, 31); | |
| c.closePath(); | |
| c.fill(); | |
| $('bearing').textContent = String(Math.round(yaw) % 360).padStart(3, '0') + '° ' + labels[Math.round(yaw / 45) % 8]; | |
| } | |
| function updateHUD() { | |
| if (!modal && !ended) $('statusText').textContent = active ? 'In flight' : 'Autopilot'; | |
| $('speed').textContent = Math.round(player.speed * 3.6); | |
| $('alt').textContent = Math.round(player.pos[1]); | |
| $('throttle').textContent = Math.round(player.throttle * 100) + '%'; | |
| $('throttleBar').style.width = $('throttle').textContent; | |
| $('hull').textContent = Math.round(player.hp) + '%'; | |
| $('hullBar').style.width = $('hull').textContent; | |
| $('ammo').textContent = reload ? '···' : player.ammo; | |
| $('kills').textContent = kills; | |
| document.querySelectorAll('.diamonds i').forEach((el, i) => el.classList.toggle('done', i < kills)); | |
| $('viewName').textContent = chase ? 'Chase cam' : 'Pilot cam'; | |
| drawMap(); | |
| drawCompass(); | |
| } | |
| function draw() { | |
| renderWorld(); | |
| drawOverlay(); | |
| } | |
| let audioOn = false, | |
| ac, | |
| engine, | |
| engineGain, | |
| filter; | |
| function setSound() { | |
| try { | |
| if (!ac) { | |
| ac = new (window.AudioContext || window.webkitAudioContext)(); | |
| engine = ac.createOscillator(); | |
| engine.type = 'sawtooth'; | |
| filter = ac.createBiquadFilter(); | |
| filter.type = 'lowpass'; | |
| filter.frequency.value = 170; | |
| engineGain = ac.createGain(); | |
| engineGain.gain.value = 0; | |
| engine.connect(filter).connect(engineGain).connect(ac.destination); | |
| engine.start(); | |
| } | |
| ac.resume(); | |
| audioOn = !audioOn; | |
| $('audioBtn').setAttribute('aria-pressed', String(audioOn)); | |
| $('audioBtn').setAttribute('aria-label', audioOn ? 'Mute sound' : 'Enable sound'); | |
| $('audioBtn').title = (audioOn ? 'Mute sound' : 'Enable sound') + ' (M)'; | |
| $('audioIcon').setAttribute('href', audioOn ? '#soundOn' : '#soundOff'); | |
| audioUpdate(); | |
| } catch { | |
| toast('AUDIO UNAVAILABLE'); | |
| } | |
| } | |
| function audioUpdate() { | |
| if (!ac) return; | |
| const t = ac.currentTime; | |
| engine.frequency.setTargetAtTime(28 + player.throttle * 29 + Math.sin(ambient * 15) * .7, t, .10); | |
| engineGain.gain.setTargetAtTime(audioOn && !modal && !ended ? .037 : 0, t, .065); | |
| } | |
| function soundEffect(kind) { | |
| if (!audioOn || !ac || modal) return; | |
| const t = ac.currentTime, | |
| o = ac.createOscillator(), | |
| g = ac.createGain(); | |
| o.type = kind === 'gun' ? 'sawtooth' : 'triangle'; | |
| o.frequency.setValueAtTime(kind === 'gun' ? 95 : 140, t); | |
| o.frequency.exponentialRampToValueAtTime(25, t + .1); | |
| g.gain.setValueAtTime(.075, t); | |
| g.gain.exponentialRampToValueAtTime(.001, t + .12); | |
| o.connect(g).connect(ac.destination); | |
| o.start(t); | |
| o.stop(t + .14); | |
| o.onended = () => { | |
| o.disconnect(); | |
| g.disconnect(); | |
| }; | |
| } | |
| const helpRows = [['Nose down / up', ['↑', '↓']], ['Roll left / right', ['←', '→']], ['Rudder left / right', ['A', 'D']], ['Throttle up / down', ['W', 'S']], ['Fire machine guns', ['SPACE']], ['Reload guns', ['R']], ['Switch camera', ['C']], ['Pause / resume', ['P', 'ESC']]]; | |
| for (const [label, buttons] of helpRows) { | |
| const row = document.createElement('div'); | |
| row.className = 'help-row'; | |
| const span = document.createElement('span'); | |
| span.textContent = label; | |
| const kb = document.createElement('span'); | |
| kb.className = 'keys'; | |
| buttons.forEach(k => { | |
| const el = document.createElement('kbd'); | |
| el.textContent = k; | |
| kb.append(el); | |
| }); | |
| row.append(span, kb); | |
| $('helpGrid').append(row); | |
| } | |
| const modalInfo = { | |
| pause: ['Flight paused', 'Your patrol is on hold.', 'Resume flight'], | |
| help: ['Flight controls', 'Use any flight control to take over. Bank to turn and use the rudder for fine aim.', 'Return to flight'], | |
| won: ['Mission complete', 'All three bandits are down. The valley is clear.', 'Fly again'], | |
| crashed: ['Aircraft lost', 'Your Kestrel struck the terrain.', 'Try again'], | |
| shot: ['Aircraft lost', 'Your airframe took too much damage.', 'Try again'], | |
| departed: ['Patrol ended', 'You flew beyond the patrol area.', 'Fly again'] | |
| }; | |
| let returnFocus = null; | |
| function setModal(next) { | |
| if (next && !modal) returnFocus = document.activeElement; | |
| modal = next; | |
| keys.clear(); | |
| joy.x = joy.y = 0; | |
| $('veil').hidden = !next; | |
| $('statusText').textContent = ended ? 'Sortie ended' : next ? 'Paused' : active ? 'In flight' : 'Autopilot'; | |
| $('pauseLabel').textContent = ended ? 'Debrief' : next ? 'Resume' : 'Pause'; | |
| $('pauseSymbol').setAttribute('href', next ? '#playIcon' : '#pauseIcon'); | |
| if (next) { | |
| const info = modalInfo[next]; | |
| $('dialogTitle').textContent = info[0]; | |
| $('dialogText').textContent = info[1]; | |
| $('primaryBtn').textContent = info[2]; | |
| $('secondaryBtn').hidden = !!ended || next === 'help'; | |
| $('helpGrid').hidden = next !== 'help'; | |
| $('closeDialog').hidden = !!ended; | |
| $('primaryBtn').focus({ | |
| preventScroll: true | |
| }); | |
| } else if (returnFocus) { | |
| stage.focus({ | |
| preventScroll: true | |
| }); | |
| returnFocus = null; | |
| } | |
| audioUpdate(); | |
| } | |
| function pause() { | |
| if (ended) setModal(ended);else setModal(modal ? '' : 'pause'); | |
| } | |
| function help() { | |
| if (ended) return; | |
| setModal(modal === 'help' ? '' : 'help'); | |
| } | |
| function cameraToggle() { | |
| if (modal || ended) return; | |
| chase = !chase; | |
| setCamera(0, true); | |
| updateHUD(); | |
| draw(); | |
| } | |
| $('pauseBtn').onclick = pause; | |
| $('helpBtn').onclick = help; | |
| $('audioBtn').onclick = () => { | |
| setSound(); | |
| if (!modal) stage.focus({ | |
| preventScroll: true | |
| }); | |
| }; | |
| $('viewBtn').onclick = () => { | |
| cameraToggle(); | |
| if (!modal) stage.focus({ | |
| preventScroll: true | |
| }); | |
| }; | |
| $('primaryBtn').onclick = () => ended ? reset() : setModal(''); | |
| $('secondaryBtn').onclick = reset; | |
| $('closeDialog').onclick = () => setModal(ended || ''); | |
| const flightKeys = new Set(['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'KeyA', 'KeyD', 'KeyW', 'KeyS', 'Space']); | |
| window.addEventListener('keydown', e => { | |
| if (e.metaKey || e.ctrlKey || e.altKey) return; | |
| if (modal && e.code === 'Tab') { | |
| const buttons = [...$('veil').querySelectorAll('button')].filter(b => !b.hidden); | |
| const index = buttons.indexOf(document.activeElement); | |
| e.preventDefault(); | |
| buttons[(index + (e.shiftKey ? -1 : 1) + buttons.length) % buttons.length].focus(); | |
| return; | |
| } | |
| if (e.code === 'Space' && document.activeElement instanceof HTMLButtonElement && (modal || document.activeElement.matches(':focus-visible'))) return; | |
| if (['KeyP', 'Escape', 'KeyH', 'KeyM', 'KeyC', 'KeyR'].includes(e.code)) { | |
| e.preventDefault(); | |
| if (e.repeat) return; | |
| if (e.code === 'KeyP' || e.code === 'Escape') pause(); | |
| if (e.code === 'KeyH') help(); | |
| if (e.code === 'KeyM') setSound(); | |
| if (e.code === 'KeyC') cameraToggle(); | |
| if (e.code === 'KeyR' && !modal) startReload(); | |
| return; | |
| } | |
| if (flightKeys.has(e.code) && !modal && !ended) { | |
| e.preventDefault(); | |
| stage.focus({ | |
| preventScroll: true | |
| }); | |
| active = true; | |
| keys.add(e.code); | |
| if (e.code === 'Space' && !e.repeat) fireGuns(); | |
| } | |
| }); | |
| window.addEventListener('keyup', e => keys.delete(e.code)); | |
| window.addEventListener('blur', () => { | |
| keys.clear(); | |
| joy.x = joy.y = 0; | |
| if (active && !modal && !ended) setModal('pause'); | |
| }); | |
| document.addEventListener('visibilitychange', () => { | |
| if (document.hidden && active && !modal && !ended) setModal('pause'); | |
| lastTime = performance.now(); | |
| }); | |
| const stick = $('stick'); | |
| let stickId = null; | |
| function moveStick(e) { | |
| if (stickId !== e.pointerId) return; | |
| const r = stick.getBoundingClientRect(); | |
| joy.x = clamp((e.clientX - r.left - r.width * .5) / (r.width * .40), -1, 1); | |
| joy.y = clamp((e.clientY - r.top - r.height * .5) / (r.height * .40), -1, 1); | |
| } | |
| stick.onpointerdown = e => { | |
| if (modal || ended) return; | |
| e.preventDefault(); | |
| active = true; | |
| stickId = e.pointerId; | |
| stick.setPointerCapture(e.pointerId); | |
| moveStick(e); | |
| }; | |
| stick.onpointermove = moveStick; | |
| stick.onlostpointercapture = () => { | |
| stickId = null; | |
| joy.x = joy.y = 0; | |
| }; | |
| for (const button of document.querySelectorAll('[data-hold]')) { | |
| button.onpointerdown = e => { | |
| if (modal || ended) return; | |
| e.preventDefault(); | |
| active = true; | |
| button.setPointerCapture(e.pointerId); | |
| keys.add(button.dataset.hold); | |
| if (button.dataset.hold === 'Space') fireGuns(); | |
| }; | |
| button.onlostpointercapture = () => keys.delete(button.dataset.hold); | |
| } | |
| function frame(now) { | |
| let dt = clamp((now - lastTime) / 1000, 0, .16); | |
| lastTime = now; | |
| if (!modal && !document.hidden) { | |
| const steps = Math.max(1, Math.ceil(dt / (1 / 60))); | |
| for (let i = 0; i < steps; i++) step(dt / steps); | |
| setCamera(dt); | |
| draw(); | |
| if ((hudClock -= dt) <= 0) { | |
| hudClock = .08; | |
| updateHUD(); | |
| audioUpdate(); | |
| } | |
| } | |
| requestAnimationFrame(frame); | |
| } | |
| resize(); | |
| reset(); | |
| window.addEventListener('resize', resize); | |
| requestAnimationFrame(frame); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment