Guest User

64x64 PICO-8 resolution with run-time zoom

a guest
Jul 26th, 2024
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | Software | 0 0
  1. -- interpolated value - [0.5, 1]
  2. local zoom = 1
  3. -- discrete value - either 0.5 or 1
  4. local zoom_target = 1
  5.  
  6. function _update()
  7.     -- write any game update logic here
  8.  
  9.     -- end game update logic
  10.  
  11.     if btnp(5) then
  12.         zoom_target = zoom_target == 1 and 0.5 or 1
  13.     end
  14.  
  15.     zoom = lerp(zoom, zoom_target, 0.2)
  16. end
  17.  
  18. function lerp(from, to, amount)
  19.     local dist = to - from
  20.     if abs(dist) <= 0.01 then return to end
  21.     return from + (dist * amount)
  22. end
  23.  
  24. function _draw()
  25.     -- set video mode to 128x128
  26.     poke(0x5f2c, 0)
  27.  
  28.     -- do your game draw operations here as normal
  29.  
  30.     -- end game draw operations
  31.  
  32.     -- set video mode to 64x64
  33.     poke(0x5f2c, 3)
  34.  
  35.     -- video remapping (screen is now treated as the spritesheet for draw operations)
  36.     poke(0x5f54, 0x60)
  37.  
  38.     -- draw screen to screen
  39.     -- (originx,originy) is the coordinate center of the zoom.
  40.     -- (-32,-32) will put the center of the 128x128 canvas on the center of the 64x64 screen.
  41.     local sx = originx * (zoom - 0.5) * 2
  42.     local sy = originy * (zoom - 0.5) * 2
  43.     local sw = 128 * zoom
  44.     local sh = 128 * zoom
  45.     -- treat the screen as a spritesheet when drawing to the screen (thanks video remapping)
  46.     sspr(0, 0, 128, 128, sx, sy, sw, sh)
  47.  
  48.     -- video remap back to defaults (screen is the screen, spritesheet is the spritesheet)
  49.     poke(0x5f54, 0x00)
  50. end
Tags: pico8
Advertisement
Add Comment
Please, Sign In to add comment