juice.module
This package holds more than this page lists. See all of its files in its world.
README.md
juice
twoDKit's game feel in one place. Every moment a player has comes through Juice.moment: it plays that moment's pixel effect and 8-bit sound on this peer, shakes the camera and holds a short hit stop for this peer's own player, and fires the moment on twoDKit.events.
twoDKit.Sprite2D calls it from the animation changes it draws (jump, wall jump, land, dash, death) and twoDKit.Player2D from its synced fields and Trapline's events (gem, goal, checkpoint, game over, restart). Both run on every peer, so every player sees and hears every other player's moments (others' sounds quieter, fading with distance) with no network traffic of their own.
| Moment | Effect | Sound | Own player only |
|---|---|---|---|
| jump | take-off dust, stretch | jump | |
| wallJump | wall-kick dust, stretch | wallJump | |
| land | landing dust and squash; a hard landing (a fall of HARD_LAND_DROP = 5 tiles or more) throws a wide cloud and squashes harder | land / landHard | small shake on a hard landing |
| dash | dash ring, speed lines, flashing after-images, stretch along the dash | dash | tiny shake |
| gem | crystal pop burst | gem | |
| checkpoint | gold star fountain at the flag | checkpoint | |
| death | white flash on the sprite, pixel burst at the body | death | camera shake, ~75 ms hit stop |
| goal | star fountain | levelClear | shake |
| gameOver / restart | gameOver / click | sound only for your own |
Sprite2D also kicks up dust when you start running or turn, and scrapes specks off the wall while you wall slide.
API
Juice.moment(name, payload) -> payload: play a moment and fire it.payload:player,x,y(feet),isLocal,face(1 / -1), plus the moment's own fields.Juice.squash(kind, t, strength?) -> dw, dh: squash and stretch in whole, even art pixels attseconds intojump,land,hardLand,wallJump,dashordashUp(Juice.SQUASHholds the shapes). Sprite2D draws it withSprites.setSquash, which resamples the frame at art-pixel resolution, so it stays crisp.Juice.landing(drop) -> kind, strength: "land" or "hardLand" for a fall ofdroptiles.Juice.shakeCamera(amount),Juice.freeze(seconds): this peer's camera shake (tiles) and hit stop (the engine's time scale, held briefly on this peer only).- Settings on this peer:
Juice.enabled,Juice.shake(multiplier),Juice.hitstop(seconds),Juice.HARD_LAND_DROP. Per sprite:Sprite2D.effects,Sprite2D.squash. Sounds:Player2D.sfxVolume,Player2D.sound, ortwoDKit.sfx.
local Juice = require("twoDKit.juice")
Juice.shake = 0.5 -- gentler screen shake
Juice.hitstop = 0 -- no freeze on death