Can you make the helicopter control more easily like : Space (flight up), Ctrl (flight down), W (forward), S(backward), A/D(rudder), Q/E(lean) ? what do you think ?
Raidez
9
Posts
3
Topics
2
Following
A member registered Jan 25, 2017 · View creator page →
Creator of
Recent community posts
I have a passion to create useless code snippets for me, so I decide to share the most useful for others (or not ;) ).
-- script: moon
export width=240
export height=136
export tilesize=8
export fontsize=6
btnAxis=(a,b)->
if btn(a) and btn(b)
return 0
elseif btn(a)
return -1
elseif btn(b)
return 1
else
return 0
class Menu
new:(x=0,y=0,index=1)=>
@x=x
@y=y
@index=index
@items={}
add:(text)=>
table.insert(@items,text)
prev:=>
i=@index-1
if i<1
@index=#@items
else
@index=i
next:=>
i=@index+1
if i>#@items
@index=1
else
@index=i
draw:(sel="> ",usel=" ",spc=10,col=15)=>
for k,v in ipairs(@items)
dy=@y+(k-1)*spc
if @index==k
print(sel..v,@x,dy,col)
else
print(usel..v,@x,dy,col)
class Spr
new:(id=0,x=0,y=0,alpha=-1,scale=1,flip=0,rotate=0)=>
@id=id
@x=x
@y=y
@alpha=alpha
@scale=scale
@flip=flip
@rotate=rotate
draw:=>
spr(@id,@x,@y,@alpha,@scale,@flip,@rotate)
class RectCollider
new:(x=0,y=0,w=1,h=1)=>
@x=x
@y=y
@w=w
@h=h
draw:(col=8)=>
rectb(@x,@y,@w,@h,col)
collide:(B)=>
if @x>(B.x+B.w) or (@x+@w-1)<B.x or @y>(B.y+B.h) or (@y+@h-1)<B.y
return false
else
return true
class CircCollider
new:(x=0,y=0,r=1)=>
@x=x
@y=y
@r=r
draw:(col=8)=>
circb(@x,@y,@r,col)
collide:(B)=>
d=(@x-B.x)^2+(@y-B.y)^2
r=(@r+B.r)^2
if @x>=(B.x-B.r) and @y>=(B.y-B.r)
r=(@r+B.r+1)^2
if d>r
return false
else
return true
--------------------
cls!
t=Spr(1,104,24,2,4)
export TIC=->
--update
t.y+=btnAxis(0,1)
t.x+=btnAxis(2,3)
t.id=time()%1000//500+1
--draw
cls(12)
t\draw!
print("HELLO WORLD!",84,64)
I test that code :
function TIC() if btn(0) then sfx(0,34,2,5) elseif btn(1) then sfx(0,34,2,15) else sfx(-1,0,0) end end
But the sound don't stop and there aren't difference with volume parameter.
Why ? (I use 0.15.0 dev version/same problem on 0.16.0)
Others problems detect on 0.16.0:
shortcuts Alt+1..5 don't work (but F1...5 work fine ;) )
Sorry for my bad language, I'm french !
I don't see function for drawing circle, so I made it:
function _360(x,y,r,color,fill)
if not fill then
for a=1,360,1 do --draw outline only
dx=math.cos(a)*r+x
dy=math.sin(a)*r+y
pix(dx,dy,color)
end
else
for r=r,1,-1 do --draw circle for each radius (for fill circle)
for a=1,360,1 do
dx=math.cos(a)*r+x
dy=math.sin(a)*r+y
pix(dx,dy,color)
end
end
end
end
function _bresenham(x,y,r,color)
--see <a href="<a href=" https:="" fr.wikipedia.org="" wiki="" algorithme_de_trac%c3%a9_d%27arc_de_cercle_de_bresenham"=""></a><a href="<a href=" https:="" fr.wikipedia.org="" wiki="" algorithme_de_trac%c.."="">https://fr.wikipedia.org/wiki/Algorithme_de_trac%C...</a>">https://fr.wikipedia.org/wiki/Algorithme_de_trac%C....">https://fr.wikipedia.org/wiki/Algorithme_de_trac%C...
px=0
py=r
m=5-4*r
while(px<=py) do
pix((px+x),(py+y),color)
pix((py+x),(px+y),color)
pix((-px+x),(py+y),color)
pix((-py+x),(px+y),color)
pix((px+x),(-py+y),color)
pix((py+x),(-px+y),color)
pix((-px+x),(-py+y),color)
pix((-py+x),(-px+y),color)
if m>0 then
py=py-1
m=m-8*py
end
px=px+1
m=m+8*px+4
end
end
function _andres(x,y,r,color,fill)
--see <a href="<a href=" https:="" fr.wikipedia.org="" wiki="" algorithme_de_trac%c3%a9_de_cercle_d%27andres"="">https://fr.wikipedia.org/wiki/Algorithme_de_trac%C...</a>">https://fr.wikipedia.org/wiki/Algorithme_de_trac%C...
px=x
py=y
d=r-1
a=r
--a=r-1
b=0
while(a>=b) do
if not fill then
pix((px+b),(py+a),color)
pix((px+a),(py+b),color)
pix((px-b),(py+a),color)
pix((px-a),(py+b),color)
pix((px+b),(py-a),color)
pix((px+a),(py-b),color)
pix((px-b),(py-a),color)
pix((px-a),(py-b),color)
else
line((px+b),(py-a),(px+b),(py+a),color)
line((px+a),(py-b),(px+a),(py+b),color)
line((px-b),(py-a),(px-b),(py+a),color)
line((px-a),(py-b),(px-a),(py+b),color)
end
if d>=2*b then
d=d-2*b-1
b=b+1
elseif d<2*(r-a) then
d=d+2*a-1
a=a-1
else
d=d+2*(a-b-1)
a=a-1
b=b+1
end
end
end
function _axis(cx,cy,r,color,fill)
if not fill then
for y=-r,r,1 do --outline
for x=-r,r,1 do
if (x*x+y*y)<=(r*r) then
pix(cx+x,cy+y,color)
end
end
end
r=r-1
for y=-r,r,1 do --unfill
for x=-r,r,1 do
if (x*x+y*y)<=(r*r) then
pix(cx+x,cy+y,-1)
end
end
end
else
for y=-r,r,1 do
for x=-r,r,1 do
if (x*x+y*y)<=(r*r) then
pix(cx+x,cy+y,color)
end
end
end
end
end
function circ(x,y,r,color,algo)
if algo=="360" then
--don't use it, it's false/incomplete
--_360(x,y,r,color,true)
elseif algo=="bresenham" then
_bresenham(x,y,r,color)
_andres(x,y,(r),color,true)
elseif algo=="andres" then
_andres(x,y,r,color,true)
elseif algo=="axis" then
_axis(x,y,r,color,true)
end
end
function circb(x,y,r,color,algo)
if algo=="360" then
--don't use it, it's false/incomplete
--_360(x,y,r,color,false)
elseif algo=="bresenham" then
_bresenham(x,y,r,color)
elseif algo=="andres" then
_andres(x,y,r,color,false)
elseif algo=="axis" then
_axis(x,y,r,color,false)
end
end
There are a lot of algorithm to drawing circle, but after comparison, I suggest to use Andres's method:
function _andres(x,y,r,color,fill) --see https://fr.wikipedia.org/wiki/Algorithme_de_trac%C.... px=x py=y d=r-1 a=r --a=r-1 b=0 while(a>=b) do if not fill then pix((px+b),(py+a),color) pix((px+a),(py+b),color) pix((px-b),(py+a),color) pix((px-a),(py+b),color) pix((px+b),(py-a),color) pix((px+a),(py-b),color) pix((px-b),(py-a),color) pix((px-a),(py-b),color) else line((px+b),(py-a),(px+b),(py+a),color) line((px+a),(py-b),(px+a),(py+b),color) line((px-b),(py-a),(px-b),(py+a),color) line((px-a),(py-b),(px-a),(py+b),color) end if d>=2*b then d=d-2*b-1 b=b+1 elseif d<2*(r-a) then d=d+2*a-1 a=a-1 else d=d+2*(a-b-1) a=a-1 b=b+1 end end end function circ(x,y,r,color) _andres(x,y,r,color,true) end function circb(x,y,r,color) _andres(x,y,r,color,false) end

