feat: rampage mode (the hedgehog can now knock your website over) - #43
Open
Colin-Moran wants to merge 1 commit into
Open
feat: rampage mode (the hedgehog can now knock your website over)#43Colin-Moran wants to merge 1 commit into
Colin-Moran wants to merge 1 commit into
Conversation
Adds two easter egg keywords that turn the host page into furniture. `rampage` sends him on a tear for 20 seconds: anything he lands on gets knocked off the page, tumbles under physics, and springs back into place. `earthquake` does the whole visible page at once. The page's elements were already physics bodies, since that's how he walks on your buttons, but nothing ever pushed back. ShovedElement gives a DOM element a dynamic Matter body and writes that body's position onto the real element as a CSS transform each frame. Deliberately transform-only, so this can never damage a host page: - nothing is added to or removed from the DOM, so the page never reflows - the element restores in beforeUnload(), which means it goes home whether it settles on its own, the game is torn down, or the host re-renders it out from under us - inline transform/transition/will-change are saved and put back exactly as they were found - it's opt in, capped at 40 elements at a time, and skips anything bigger than 40% of the viewport, since watching a layout wrapper cartwheel just reads as broken The offset is measured against the element's nearest scrolling ancestor rather than the window, so shoved elements stay glued to their bodies in apps that scroll a panel instead of the document. Rampage opens with the headband animation, which has been sitting in the spritesheet unused since it was drawn. update() reasserts walk/fall every frame, so the flourish also needs the AI paused and the pose held, or it is gone before anyone sees it.
|
@Colin-Moran is attempting to deploy a commit to the PostHog Team on Vercel. A member of the Team first needs to authorize it. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I wanted the hedgehog to be able to knock stuff over!
what this adds
two easter egg keywords, in the existing
secretMapstyle:rampageputs a headband on him for 20 seconds. anything he lands on getsknocked off the page, tumbles under physics, and springs back into place.
earthquakedoes the whole visible page at once, which is exactly asproductive as it sounds.
both are listed in the
cheatcodessheet.GIF (the low fps doesn't do it justice)
how it works
your page elements were already rigid bodies. that's how he stands on your nav
bar. they just never pushed back.
ShovedElementgives one of them a dynamicMatter body and writes that body's position onto the real element as a CSS
transform every frame, so the thing tumbling across the screen is your actual
button, not a picture of it.
why this can't hurt a host page
this is a library that runs on top of real products, including yours, so the
whole thing is built to be un-break-able:
beforeUnload(), so it goes home on settle, on game destroy, and on host re-render alikeworth stating plainly: after everything settles,
document.querySelectorAllfindszero elements carrying a transform and zero carrying a leftover inline style.
i checked, because "it probably cleans up" is not a thing to say about a library
that ships to customers.
a note on the headband
skins/default/actionhas been sitting in the spritesheet since someone drew itand no code has ever played it. rampage opens with it. it needed the AI paused
and the pose held, because
update()reasserts walk/fall every frame and wouldotherwise bin the animation on the very next tick, which is presumably why it
never got used.
that leaves
phone,inspect,signandflagstill unplayed, if anyone wantsthem.
how it was tested
unit tests on the offset maths, including the scroll compensation, which is the
part that is easy to get subtly wrong and invisible in a screenshot.
then in the playground, measured rather than eyeballed:
earthquaketranslate(-142px, -45px) rotate(-2.73rad), then home againthe offset is measured against the element's nearest scrolling ancestor rather
than the window, because this project's own playground scrolls a panel rather
than the document, and so does the app this library actually lives in.
pnpm test,pnpm lintandpnpm buildall pass.what it doesn't do
no new art, no new dependencies, no public API changes, nothing exported. the
engine gets one new item and one new hedgehog trick, and every existing keyword
behaves exactly as before.