Skip to content

Commit e616265

Browse files
obiotclaude
andauthored
Examples: Earth Defender, an arcade shooter on a globe (#1749)
* Examples: Earth Defender, an arcade shooter on a globe Fly a craft over a hexagonal glass dome, shooting the asteroids falling onto it. The dome is what is being defended: each pane cracks and finally shatters, and the run ends when the glass does. It exercises a lot of the 3D tier at once, which is why it is worth having: - `Camera3d` posed from the player's own surface point with `setBasis`, so the player orbits a fixed globe rather than the globe turning underneath them - ground shadows on a sphere via `shadowGroundPoint` and `shadowGroundNormal`, where "down" is radial rather than world down - `Sphere` collision shapes, `raycast3d`, mesh-hosted `ShaderEffect` for the shield bubble and the atmosphere, `Trail3d` for the exhaust - spatial audio with a listener following the craft, HDR with bloom and tone mapping, `ProgressBar` and `UIPanel` for the HUD and the pause menu - sprite-sheet particles for the debris All of the maths lives in `lib/sphereMath.ts`, which is spherical rather than planar: positions are unit vectors, distances are arcs in radians, and motion is rotation within a plane so a body can circle all day without drifting off the sphere. It has its own characterisation test, `sphereMath.test.ts`, run with `npx tsx` from `packages/examples`: 112 assertions, 32 of them golden values and the rest invariants that hold whatever the implementation is. Assets are credited in `packages/examples/LICENSE.md`. The Earth, the dome and the asteroids were modelled for this; the saucer, the bomb, the sound effects and the font come from elsewhere and are CC0 or CC BY-ND. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NGvtaUNATVCVxD2qcbiY4t * Examples: say what Earth Defender shows, in the gallery and the README The gallery card read "Fly a craft over a globe, shooting asteroids off a hexagonal shield dome", which says what the player does and nothing about why the example exists. Its neighbours name the engine features and the controls: AfterBurner lists `Camera3d`, `raycast3d` and `Box3d` with its keys, Jungle Rabbit lists `InstancedMesh` and the rigged boat. This one now does the same, and gives the controls, which no description without them can supply. Also adds it to the README's example list, which it was missing from, next to the other 3D entries. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NGvtaUNATVCVxD2qcbiY4t * Examples: the gallery card is about the tech, not the keys Earth Defender and AfterBurner both spent their last clause listing controls, which the example itself tells you and which is not why either one is in the gallery. Both now stop at what they demonstrate. Earth Defender also names what it is a tribute to, which places it faster than any feature list does. No em dashes in either description. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NGvtaUNATVCVxD2qcbiY4t * Examples: Stardust is already on a globe "A Stardust tribute on a globe" says the globe twice to anyone who knows the reference, and the reference is doing the work. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NGvtaUNATVCVxD2qcbiY4t * Examples: reunite twelve doc comments with what they document A doc comment followed by another doc comment documents nothing: the second one wins and the first is dropped. Twelve of them had drifted apart from their declarations here, including `deflect`'s, which I split from its own method earlier in this branch by inserting `shove` between the two. Nine moved back to the declaration they describe, all of which had no doc at all until now: `deflect`, `onShipHit`, `tickShield`, `placeWorld` and `drainHits` in the controller, `burst` in the blast pool, `nebulaField`, and `ringBasis` and `sightlineClearance2` in the sphere maths. Three were stale rather than misplaced, and are deleted: - a glTF descriptor helper that no longer exists in the controller, since `loader.getGLTF` is called directly now - a menu key-edge helper whose logic moved to `TitleScreen.pressed` and `seedHeld`, both of which carry the explanation already - an older signature of `burst`, from before it took `outward`, `speed`, `life` and `spread`; the fuller one directly below it is current The sphere maths file header is marked `@module`, which is what makes a leading comment the module's own rather than a comment that happens to sit above the first declaration. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NGvtaUNATVCVxD2qcbiY4t --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 82df72b commit e616265

64 files changed

Lines changed: 18633 additions & 2 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ Examples
192192
* [3D Mesh](https://melonjs.github.io/melonJS/examples/#/mesh-3d) ([source](https://github.com/melonjs/melonJS/tree/master/packages/examples/src/examples/mesh3d))
193193
* [3D Mesh Material](https://melonjs.github.io/melonJS/examples/#/mesh-3d-material) ([source](https://github.com/melonjs/melonJS/tree/master/packages/examples/src/examples/mesh3dMaterial))
194194
* [AfterBurner Clone](https://melonjs.github.io/melonJS/examples/#/after-burner) ([source](https://github.com/melonjs/melonJS/tree/master/packages/examples/src/examples/afterBurner)) — `Camera3d` + 3D Mesh arcade shooter
195+
* [Earth Defender](https://melonjs.github.io/melonJS/examples/#/earth-defender) ([source](https://github.com/melonjs/melonJS/tree/master/packages/examples/src/examples/earthDefender)) — a Stardust tribute: a `Camera3d` posed from the player's own surface point, blob shadows lying on a sphere through `shadowGroundPoint`, mesh-hosted `ShaderEffect` shields, spatial audio and HDR bloom
195196
* [Ground Shadows](https://melonjs.github.io/melonJS/examples/#/ground-shadows) ([source](https://github.com/melonjs/melonJS/tree/master/packages/examples/src/examples/groundShadows)) — every blob-shadow setting side by side under an orbiting sun, including blobs lying on a slope and a 70-instance scatter that costs one extra draw
196197
* [Jungle Rabbit](https://melonjs.github.io/melonJS/examples/#/jungle-rabbit) ([source](https://github.com/melonjs/melonJS/tree/master/packages/examples/src/examples/jungleRabbit)) — a low-poly river endless runner: Blender-modelled props through `InstancedMesh`, a rigged paddling boat, a procedural valley and shadows laid on its banks
197198
* [glTF Scene](https://melonjs.github.io/melonJS/examples/#/gltf) ([source](https://github.com/melonjs/melonJS/tree/master/packages/examples/src/examples/gltf)) — a Blender-authored, lit 3D scene loaded with `level.load`

‎packages/examples/LICENSE.md‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,72 @@ same folder are from UI packs published by **Kenney** (<https://www.kenney.nl>),
107107
released under **CC0 1.0 Universal (Public Domain Dedication)** — no attribution
108108
legally required, credited here as a courtesy.
109109

110+
### `earthDefender` example
111+
112+
The Earth, the hexagonal glass dome and the five asteroid shapes in
113+
`public/assets/earthDefender/` were modelled for this example and are covered
114+
by the MIT license above, as are the rock colour and normal maps, the nebula,
115+
and everything else the example generates at run time. The saucer, the bomb
116+
and the drone sound come from elsewhere and are credited below.
117+
118+
The flying saucer `ufo.glb` is derived from a model by **RayB2**, released
119+
into the public domain under **CC0 1.0**
120+
(<https://creativecommons.org/publicdomain/zero/1.0/>). It was re-exported for
121+
this example: the open edges filled, and its materials rebuilt as Principled
122+
BSDF so they survive the glTF round trip.
123+
124+
The bomb `bomb.glb` is derived from the **KayKit Mini-Game Variety Pack** by
125+
**Kay Lousberg** (<https://kaylousberg.com>), released under **CC0 1.0**. It was
126+
cut below the band and re-exported so that it stands flat where it lands.
127+
128+
The sound effects in `sfx/` are from the **Sci-Fi Sounds** pack by **Kenney**
129+
(<https://www.kenney.nl>), released under **CC0 1.0**: the saucer's engine note
130+
`earthDefenderUfoDrone.*` is `spaceEngine_003`, and the gun's five takes
131+
`earthDefenderLaser0-4.*` are `laserLarge_000` to `laserLarge_004`, played at
132+
random so the same shot is never heard twice running. Crediting Kenney is explicitly not mandatory and
133+
it is done anyway, as with the other CC0 work here.
134+
135+
It is not the published file: the saucer's drone loops for as long as it is in
136+
the sky, and the original is a one-shot with an attack at the front and a fade
137+
at the back, so looping it pumped. The sustained body was taken, its tail
138+
folded back over its head with an EQUAL-POWER crossfade, and the result
139+
normalised. Equal power rather than linear because the two ends are
140+
uncorrelated noise and a linear fade leaves an audible dip exactly at the loop
141+
point.
142+
143+
The title screen's music `bgm/earthDefenderMenu.*` is the "menu/industry"
144+
track from **"Atmospheric puzzles"** by **legoluft**, the music of the Krank
145+
game, submitted to OpenGameArt by qubodup and released under **CC0 1.0**:
146+
147+
<https://opengameart.org/content/atmospheric-puzzles>
148+
149+
CC0 asks for nothing and it is named anyway. Converted from the pack's OGG to
150+
an additional MP3 for the browsers without Vorbis; neither was otherwise
151+
edited.
152+
153+
The game's music `bgm/earthDefenderBattle.*` is **"Space Boss Battle Theme"**
154+
(Orbital Colossus) by **Matthew Pablo** (<https://www.matthewpablo.com>),
155+
licensed under **Creative Commons Attribution 3.0**
156+
(<https://creativecommons.org/licenses/by/3.0/>):
157+
158+
<https://opengameart.org/content/space-boss-battle-theme>
159+
160+
That license REQUIRES attribution, and the author asks to be credited as
161+
"Music by Matthew Pablo, www.matthewpablo.com", which is why he is named in
162+
the example's Credits panel as well as here. The source MP3 was re-encoded
163+
to a lower bit rate and transcoded to OGG; it was not otherwise edited. Note
164+
the author states the track does not loop seamlessly as published and offers
165+
a loopable version on request.
166+
167+
The display face `font/future-earth.ttf` is the FontStruction **"Future
168+
Earth"** by **V. Sarela**:
169+
170+
<https://fontstruct.com/fontstructions/show/477551>
171+
172+
licensed under **Creative Commons Attribution-NoDerivatives 3.0**
173+
(<http://creativecommons.org/licenses/by-nd/3.0/>). The archive's own
174+
`license.txt` and `readme.txt` ship alongside it, as that license requires.
175+
110176
### `jungleRabbit` example
111177

112178
The 3D models in `public/assets/jungleRabbit/` — boat, carrot, log, rock, palm,
64.3 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
28.2 KB
Binary file not shown.
130 KB
Binary file not shown.
517 KB
Binary file not shown.

0 commit comments

Comments
 (0)