Last active
December 20, 2018 17:48
-
-
Save revdan/5774e57c97b5aefd8a7227dd3eab4795 to your computer and use it in GitHub Desktop.
This file contains 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
debug=false | |
pause=debug | |
skip_speed=50 | |
start_time=0 | |
t_offset=-5000 | |
x_offset=-5 | |
y_offset=-3 | |
z_offset=-600 | |
pan=0.075 | |
zoom=0.025 | |
function _init() | |
t=(start_time or 0) | |
mult=8.0 | |
star_plane=0 | |
cam={x=0,y=0,z=z_offset} | |
if (not debug)music(0) | |
t=step(t) | |
end | |
function _update60() | |
if btn(5) then | |
if btn(2) then | |
cam.z-=cam.z*zoom | |
elseif btn(3) then | |
cam.z+=cam.z*zoom | |
end | |
if pause then | |
if btnp(0) then | |
t=step(-1) | |
elseif btnp(1) then | |
t=step() | |
end | |
else | |
if btnp(0) then | |
t=step(-skip_speed) | |
elseif btnp(1) then | |
t=step(skip_speed) | |
end | |
end | |
else | |
if btn(0) then | |
cam.x+=cam.z*pan | |
elseif btn(1) then | |
cam.x-=cam.z*pan | |
elseif btn(2) then | |
cam.y+=cam.z*pan | |
elseif btn(3) then | |
cam.y-=cam.z*pan | |
end | |
if not pause then | |
t=step() | |
end | |
end | |
if (btnp(4)) then | |
pause=not pause | |
end | |
if (btn(0))btnl="⬅️" else btnl="" | |
if (btn(1))btnr="➡️" else btnr="" | |
if (btn(2))btnu="⬆️" else btnu="" | |
if (btn(3))btnd="⬇️" else btnd="" | |
if (btn(4))btnz="🅾️" else btnz="" | |
if (btn(5))btnx="❎" else btnx="" | |
end | |
function _draw() | |
cls() | |
for s in all(stars) do | |
draw_point(s) | |
end | |
color(11) | |
rect(0, 0, 127, 127) | |
print('t: '..t+t_offset,4,4) | |
print('x: '..flr(cam.x),4, 12) | |
print('y: '..-flr(cam.y),4,20) | |
print('z: '..(flr(cam.z)),4,28) | |
print(btnz,48,116) | |
print(btnx,48,116) | |
print(btnl,56,116) | |
print(btnr,70.5,116) | |
print(btnu,63.5,112) | |
print(btnd,63.5,120) | |
end | |
function step(m) | |
for s in all(stars) do | |
s.x+=s.vx*(m or 1) | |
s.y+=s.vy*(m or 1) | |
end | |
return increment(t,m) | |
end | |
function increment(n, amount) | |
n+=(amount or 1) | |
return n | |
end | |
function draw_point(p) | |
local x,y=project(p) | |
if cam.z>=-1 then | |
spr(star_sprite_color(),x,y) | |
else | |
pset(x,y,star_color()) | |
end | |
end | |
function project(p) | |
local x=(p.x-cam.x+x_offset)*mult/(star_plane-cam.z)+127/2 | |
local y=(p.y-cam.y+y_offset)*mult/(star_plane-cam.z)+127/2 | |
return x, y | |
end | |
function star_color() | |
return shuffle_colors({7,7,7,7,7,0,1}) | |
end | |
function star_sprite_color() | |
return shuffle_colors({2,2,2,2,3,3,4}) | |
end | |
function shuffle_colors(colors) | |
local i=ceil(rnd(#colors)) | |
return colors[i] | |
end | |
stars={ | |
{x=9,y=-9999,vx= 0,vy= 2},{x=5007,y=0,vx=-1,vy= 0},{x=5003,y=-5002,vx=-1,vy= 1},{x=10006,y=5010,vx=-2,vy=-1},{x=-9998,y=-10004,vx= 2,vy= 2},{x=-10006,y=10010,vx= 2,vy=-2},{x=-4999,y=5008,vx= 1,vy=-1},{x=-4999,y=7,vx= 1,vy= 0},{x=-5003,y=10011,vx= 1,vy=-2},{x=5007,y=5006,vx=-1,vy=-1},{x=-5002,y=3,vx= 1,vy= 0},{x=-10004,y=3,vx= 2,vy= 0},{x=5010,y=-5003,vx=-1,vy= 1},{x=-4995,y=10011,vx= 1,vy=-2},{x=4,y=5007,vx= 0,vy=-1},{x=8,y=-5002,vx= 0,vy= 1},{x=10015,y=0,vx=-2,vy= 0},{x=-4999,y=6,vx= 1,vy= 0},{x=8,y=5009,vx= 0,vy=-1},{x=5003,y=-4997,vx=-1,vy= 1},{x=0,y=5005,vx= 0,vy=-1},{x=-10002,y=2,vx= 2,vy= 0},{x=-4995,y=-10002,vx= 1,vy= 2},{x=-9999,y=-4996,vx= 2,vy= 1},{x=-10002,y=10007,vx= 2,vy=-2},{x=5003,y=5006,vx=-1,vy=-1},{x=-4995,y=0,vx= 1,vy= 0},{x=-10006,y=0,vx= 2,vy= 0},{x=-4995,y=10009,vx= 1,vy=-2},{x=10014,y=7,vx=-2,vy= 0},{x=-10003,y=5006,vx= 2,vy=-1} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment