Post by leon26leon26 on Jul 5, 2016 9:31:45 GMT
Just a simple scrolling example, here a scoreboard.
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
scoreboard={
{score=2900,name="leon26leon26"},
{score=2800,name="leon26leon26"},
{score=2700,name="leon26leon26"},
{score=2600,name="leon26leon26"},
{score=2500,name="leon26leon26"},
{score=2400,name="leon26leon26"},
{score=2300,name="leon26leon26"},
{score=2200,name="leon26leon26"},
{score=2100,name="leon26leon26"},
{score=2000,name="leon26leon26"},
{score=1900,name="leon26leon26"},
{score=1800,name="leon26leon26"},
{score=1700,name="leon26leon26"},
{score=1600,name="leon26leon26"},
{score=1500,name="leon26leon26"},
{score=1400,name="leon26leon26"},
{score=1300,name="leon26leon26"},
{score=1200,name="leon26leon26"},
{score=1100,name="leon26leon26"},
{score=1000,name="leon26leon26"},
}
TouchMoved={0,0,0,0,0}
function TB(x,y)
touchbegan=y
origoffset=offset
speed=0
end
function TM(x,y)
table.insert(TouchMoved,y)
table.remove(TouchMoved,1)
touchmoved=y
offset=origoffset+touchmoved-touchbegan
if offset>0 then offset=0 end
end
function TE(x,y)
touchended=y
speed=(touchended-touchmoved+TouchMoved[5]-TouchMoved[4]+TouchMoved[4]-TouchMoved[3]+TouchMoved[3]-TouchMoved[2]+TouchMoved[2]-TouchMoved[1])/5
end
draw.tracktouches(TB,TM,TE)
function hiscores()
if offset>0 then
offset=0
speed=0
elseif offset<-910 then
offset=-910
speed=0
end
if speed>0 then
if speed<0.5 then speed=0 end
if speed>0.5 then
speed=speed-0.4
end
elseif speed<0 then
if speed>-0.5 then speed=0 end
if speed<-0.5 then
speed=speed+0.4
end
end
offset=offset+speed
for i=1,#scoreboard do
draw.fillroundedrect(20,i*75+offset,355,i*75+70+offset,10,draw.darkgray)
draw.fillroundedrect(20,i*75+offset,95,i*75+70+offset,10,draw.gray)
draw.setlinestyle(2,"round")
draw.roundedrect(20,i*75+offset,355,i*75+70+offset,10,draw.black)
draw.setfont("Helvetica",60)
draw.string(i,(75-draw.stringsize(i))/2+20,i*75+offset,draw.black)
draw.setfont("Menlo",40)
draw.string(scoreboard[i].score,100,i*75+offset+5,draw.black)
draw.setfont("Menlo",20)
draw.string(scoreboard[i].name,105,i*75+offset+45,draw.black)
end
end
offset=0
speed=0
draw.setscreen(2)
draw.settitle("Highscores")
active=true
while active do
sleep(1)
draw.beginframe()
draw.clear(draw.gray)
hiscores()
draw.endframe()
draw.doevents()
print(speed)
end