Created
March 5, 2016 11:27
-
-
Save Powersaurus/7b6e61fe69b55f7b8493 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
leveltime=0 | |
width=256 | |
sealevel=20 | |
screenshake=0 | |
--slug | |
px=64 | |
py=20 | |
pdx=0 | |
pdy=0 | |
pflip=false | |
shootangle=180 | |
--bullet | |
bx=-10 | |
by=-10 | |
bdx=0 | |
bdy=0 | |
bh=0 | |
expt=0 | |
--wind | |
wind=0 | |
landscape2d={} | |
function _init() | |
landscape = {} | |
for i=1,width do | |
landscape[i]=50 | |
end | |
--landscape[1]=50 | |
--landscape[width]=50 | |
pos=0 | |
var=50 | |
left=1 | |
right=width | |
step=flr(width/2) | |
while(step>=1) do | |
t=1 | |
while(t<=width) do | |
left=t | |
right=t+step | |
if right>width then right-=width end | |
pos=flr(t+step/2) | |
landscape[pos]= | |
((landscape[left]+ | |
landscape[right])/2) | |
+(rnd(var)-(var/2)) | |
t+=step | |
end | |
var/=2 | |
step/=2 | |
end | |
-- generate terrain | |
local c=1 | |
for x=1,width do | |
landscape2d[x]={} | |
for y=1,landscape[x] do | |
if y>=landscape[x]-2 then | |
c=11 | |
elseif y>=landscape[x]-4 then | |
c=3 | |
elseif flr(rnd(2))==0 then | |
c=4 | |
else | |
c=2 | |
end | |
landscape2d[x][y]=c | |
end | |
end | |
end | |
function updateplayer() | |
-- can't climb cliffs | |
if py<4+120-landscape[flr(px+pdx)] then | |
px+=pdx | |
pdx*=0.1 | |
else | |
pdx=0 | |
end | |
if pdy<4 then pdy+=0.4 end | |
py+=pdy | |
if py>120-landscape[flr(px)] then | |
pdy=0 | |
py=120-landscape[flr(px)] | |
end | |
end | |
function updatebullet() | |
expt-=1 | |
if bh==1 and by>120-landscape[flr(bx)] then | |
bh=0 | |
bdx=0 | |
bdy=0 | |
--a2 + b2 = c2 | |
--x*x + ? = 25 | |
--25-x*x = ? | |
r=15 | |
expt=7 | |
screenshake=4 | |
-- bounce slugs | |
if (px-bx)*(px-bx)+(py-by)*(py-by)<r*r then | |
pdy-=6 | |
end | |
-- destroy landscape | |
for x=-r,r do | |
dy=sqrt(r*r-x*x) | |
landscape[flr(bx)+x]= | |
min(landscape[flr(bx)+x], | |
(120-by)-dy) | |
end | |
elseif bh==1 then | |
bdy+=0.4 | |
bdx+=wind | |
bx+=bdx | |
by+=bdy | |
if bx<1 or bx>width then | |
bdx=-bdx | |
bx+=bdx | |
end | |
end | |
end | |
function updateinput() | |
if btn(0) then | |
if shootangle>270 then | |
shootangle-=180 | |
end | |
pflip=true | |
pdx-=1 | |
end | |
if btn(1) then | |
if shootangle<90 then | |
shootangle+=180 | |
end | |
pflip=false | |
pdx+=1 | |
end | |
if btn(2) then shootangle+=2 end | |
if btn(3) then shootangle-=2 end | |
if btn(5) and pdy==0 then | |
pdy-=3 | |
end | |
if btn(4) then | |
bx=px | |
by=py | |
bdy=-sin(shootangle/360)*6 | |
bdx=-cos(shootangle/360)*4 | |
bh=1 | |
end | |
end | |
function _update() | |
leveltime+=1 | |
updateplayer() | |
updatebullet() | |
updateinput() | |
if (screenshake>0) screenshake-=1 | |
end | |
function _draw() | |
local cx=flr(px-64) | |
if screenshake>0 then | |
camera(cx+rnd(3),rnd(3)) | |
else | |
camera(cx, 0) | |
end | |
rectfill(cx,0,cx+128,128,12) | |
--for i=max(1,cx),min(cx+128,width) do | |
-- line(i-1,128,i-1,128-(landscape[i]-4),4) | |
-- line(i-1,128-(landscape[i]-4),i-1,128-(landscape[i]-2),3) | |
-- line(i-1,128-(landscape[i]-2),i-1,128-landscape[i],11) | |
--end | |
for x=max(1,cx),min(cx+128,width) do | |
for y=1,landscape[x] do | |
pset( | |
x-1, | |
127-y, | |
landscape2d[x][y]) | |
--landscape2d[x % width + flr(y / width)]) | |
end | |
end | |
spr(000,px-4,py,1,1,pflip,false) | |
-- | |
-- xy\ 10 | |
-- \ \ | |
-- \--xy | |
local tx=px+3-cos(shootangle/360)*10 | |
local ty=py+3-sin(shootangle/360)*10 | |
rectfill(tx-1,ty-1,tx+1,ty+1,7) | |
if bh>0 then | |
spr(001,bx,by) | |
end | |
if expt>0 then | |
local br=-sin((expt/7)/2)*15 | |
circfill(bx,by,br,8) | |
circfill(bx,by,br-1,9) | |
circfill(bx,by,br-2,7) | |
end | |
sealevel+=sin(leveltime%60/60)/4 | |
rectfill(cx,128-sealevel,cx+128,128,1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment