Skip to content

Instantly share code, notes, and snippets.

@Powersaurus
Created April 19, 2020 13:39
Show Gist options
  • Save Powersaurus/1cb58afc30de5aaa75e25e8eaf9151f7 to your computer and use it in GitHub Desktop.
Save Powersaurus/1cb58afc30de5aaa75e25e8eaf9151f7 to your computer and use it in GitHub Desktop.
Pico-8 tline rotated map demo
pico-8 cartridge // http://www.pico-8.com
version 19
__lua__
-- basic tline demo by @powersaurus
-- player rotation
a=270/360
-- player screen pos
px=64
py=64
-- toggle map/map-rotated-with-tline
rotated=true
function _update()
if btn(⬅️) then
a-=3/360
elseif btn(➡️) then
a+=3/360
end
if btnp(❎) then
rotated=not rotated
end
if(a<0)a+=1.0
if(a>=1.0)a-=1.0
end
function _draw()
cls(6)
if rotated then
draw_rotated()
else
draw_map_view()
end
print("⬅️ ➡️ rotate view",2,112,7)
print("❎ toggle rotated view",2,120,7)
end
function draw_rotated()
-- player direction
local stx=sin(a)
local sty=cos(a)
-- perpendicular to player dir
-- used to define the start of
-- each line in map space
local msx=sin(a+90/360)
local msy=cos(a+90/360)
-- map delta x and y values
local mdx=stx/8
local mdy=sty/8
-- map position
local mx=5
local my=5
-- how long the
-- textured line is
local xl=40
-- render a square of the map
-- from players pov
for y=-16,15 do
tline(
-- horizontal line on screen
px,py+y,px+xl,py+y,
-- map space line start
mx+y*msx/8,my+y*msy/8,
-- map deltas for line
mdx,mdy)
end
-- point in direction of players view
line(px,py,px+8,py,7)
end
function draw_map_view()
map(0,0,24,24,10,10)
draw_player()
end
function draw_player()
local stx=sin(a)
local sty=cos(a)
local psx=sin(a+90/360)
local psy=cos(a+90/360)
-- player location
circfill(px,py,1,7)
-- player view direction
line(px,py,px+stx*8,py+sty*8,7)
end
__gfx__
5ee55eeeeeeeee55ddbbbbbd23b3b33b9922999900000000000000005ee55eeeeeeeee5500000000000000000000000000000000000000000000000000000000
eeeeee55eeeeeeeeddbbdbbb53525235992299220000000000000000eeeeee55eeeeeeee00000000000000000000000000000000000000000000000000000000
eeeee555eeeeeeeebbbbbbbb533b3335999999220000000000000000eeeee555eeeeeeee00000000000000000000000000000000000000000000000000000000
eeee55555ee555eedbbbbbdd43353b21999229990000000000000000eeee55555ee555ee00000000000000000000000000000000000000000000000000000000
eeeee555eee555eedbbddbdd33b22532229229920000000000000000eeeee555eee555ee00000000000000000000000000000000000000000000000000000000
55eeeeeeeeee5eeebbbddbbbb353353329999922000000000000000055eeeeeeeeee5eee00000000000000000000000000000000000000000000000000000000
55eeeeeeeeeeeeeeddbddbbb5213414399999999000000000000000055eeeeeeeeeeeeee00000000000000000000000000000000000000000000000000000000
eeeeeeeeeeeeeeeeddbbbbbd13233533992299990000000000000000eeeeeeeeeeeeeeee00000000000000000000000000000000000000000000000000000000
eeeee55eee55eeee0000000011ddddd1888888220000000000000000eeeee55eee55eeee00000000000000000000000000000000000000000000000000000000
eeeee55ee555eeee00000000ddd111dd822888220000000000000000eeeee55ee555eeee00000000000000000000000000000000000000000000000000000000
e55eeeeee5555eee000000001dd111d1888888880000000000000000e55eeeeee5555eee00000000000000000000000000000000000000000000000000000000
e555eeeee5555eee000000001d111dd1288822820000000000000000e555eeeee5555eee00000000000000000000000000000000000000000000000000000000
e555eeee5555eeee000000001dd11dd1288888820000000000000000e555eeee5555eeee00000000000000000000000000000000000000000000000000000000
eeeeeeeee5555eee00000000d1dddddd822228880000000000000000eeeeeeeee5555eee00000000000000000000000000000000000000000000000000000000
5eeeeeeeeeeeee5500000000111d1d118222288800000000000000005eeeeeeeeeeeee5500000000000000000000000000000000000000000000000000000000
5ee55eeeeeeeee5500000000111d1d118222282200000000000000005ee55eeeeeeeee5500000000000000000000000000000000000000000000000000000000
__map__
070807080708080313130000000d0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
171817181718180313130000000d0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
070114040708080313130000000d0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
101102030418180313130000000d0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
070814081408030313130000000d0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
171817181718031313130000000d0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
030303030303031313130000000d0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1313131313131313131300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1313131313131313131300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0404040404040404040400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment