24

Cart [#17463#] | Code | 2015-12-03 | No License
24

Controls:

• right/left to increase/decrease amplitude
• up/down to increase/decrease wavelength
• Z/X to increase/decrease animation speed
• Q to change background
• W to change effect type

I've been toying around with my Pico-8 for the last few days and after a good amount of bashing my head against a wall I finally have something cool and somewhat presentable. It translates horizontal lines on the screen either horizontally or vertically in a sine-wave-like pattern, just like the battle backgrounds in Earthbound and Mother 3.

Thinking of making a short vertical slice of some sort of RPG with a basic battle system that makes use of it.

Here are the relevant code snippets if you'd like to use the effects in your own game:

 ```-- horizontal distortion effect -- by qbicfeet -- -- t: time -- a: amplitude (in pixels) -- l: wavelength (in pixels) -- s: speed -- y1: first horizontal line -- y2: last horizontal line -- mode: interlaced y/n function sine_xshift(t,a,l,s,y1,y2,mode) for y=y1,y2 do local off = a * sin((y + flr(t*s + 0.5) + 0.5) / l) if mode and y%2 < 1 then off *= -1 end local x = flr(off/2 + 0.5) % 64 local addr = 0x6000+64*y memcpy(0x4300,addr,64) memcpy(addr+x,0x4300,64-x) memcpy(addr,0x4340-x,x) end end ```
 ```-- vertical distortion effect -- by qbicfeet -- -- t: time -- a: amplitude (in pixels) -- l: wavelength (in pixels) -- s: speed -- y1: first horizontal line -- y2: last horizontal line -- -- note: the difference between -- y2 and y1 can not be greater -- than 111 or it will corrupt -- the draw state ram! function sine_yshift(t,a,l,s,y1,y2) local dy = y2-y1+1 memcpy(0x4300,0x6000+64*y1,64*dy) for y=y1,y2 do local yy = (y + flr(a * sin((y + flr(t*s + 0.5) + 0.5) / l) + 0.5)) % dy memcpy(0x6000+64*y,0x4300+64*yy,64) end end ```

Some things worth noting:

• y1 and y2 values lower than 0 and higher than 127 will likely corrupt data in the RAM and/or crash the game
• if the wavelength is set to 0 a division by zero happens, but it seems like Pico-8 handles division by zero implicitly
• you could technically get around the "max height 112" problem with sine_yshift if you copy the screen data to 0x3f00 instead of 0x4300, which will overwrite part of the sound region of the RAM but give you another 16 horizontal lines to work with

Not sure what else to say... If you have any questions or comments I'll happily answer them!

Old version:

Cart [#17387#] | Code | 2015-12-02 | No License
24

P#17390 2015-12-02 12:49 ( Edited 2017-01-24 21:43)

I love it! I'm impressed by how many effects you can get by fiddling with these settings.

P#17394 2015-12-02 14:41 ( Edited 2015-12-02 19:41)

Wow this is VERY nice! Thank you very much for the code snippets!!

P#17397 2015-12-02 15:09 ( Edited 2015-12-02 20:09)
:: Pizza

Damn, this is great.

P#17398 2015-12-02 15:17 ( Edited 2015-12-02 20:17)

Whoaaaaa this is cool.

P#17407 2015-12-02 18:17 ( Edited 2015-12-02 23:17)

Discovered a slight bug with sine_yshift and fixed it - the very last line would grab incorrect values. Updated the code snippets with the corrected code (dy = y2-y1+1).

Also fixed the positioning of the text at the bottom.

P#17464 2015-12-03 18:00 ( Edited 2015-12-03 23:00)
:: JTE

It's beautiful...

P#17479 2015-12-04 15:24 ( Edited 2015-12-04 20:24)

Niiice, makes me think of my C version for a calculator! Now you need to implement plaette cycling! :D

P#17928 2015-12-19 14:13 ( Edited 2015-12-19 19:13)

Thank you so much, I can't wait to try those snippets out !

P#36608 2017-01-24 16:43 ( Edited 2017-01-24 21:43)