math.randomseed(sys.Datetime().milliseconds) --random ile sayı üretirken bizi tekrar yapmaktan korur
local ui= require "ui"
local direction= ""
local win= ui.Window("My Win",1200,800)
win:show()
local bottonLeft= ui.Button(win,"Left", 10, 50, 60, 25)
local bottonRight= ui.Button(win,"Right", 110, 50, 60, 25)
local bottonUp= ui.Button(win,"Up", 60, 15, 60, 25)
local bottonDown= ui.Button(win,"Down", 60, 85, 60, 25)
local shape= ui.Picture(win,"F_16_60x60.png",600,400)
local barrierNumber= 15
function numberRandom(_x, _y)
return math.random(_x,_y)
end
function barrier()
local x = numberRandom(100,1100)
local y = numberRandom(100,700)
local width = numberRandom(60,300)
local height = numberRandom(60,300)
local var= numberRandom(1,2)
if var==1 then
direction= "horizontal"
height= 29
else
direction= "vertical"
width= 29
end
return x, y, height, width
end
for i=1, barrierNumber do -- Barrier create
local x, y, height, width
x, y, height, width= barrier()
_G["groupbox"..i] = ui.Groupbox(win, "", x, y, height, width)
end
function calculate(o_X, o_Y) --calculate
for i=1, barrierNumber do
local p1_X= _G["groupbox"..i].x
local p1_Y= _G["groupbox"..i].y
local p2_X= _G["groupbox"..i].x + _G["groupbox"..i].width
local p3_X= _G["groupbox"..i].x + _G["groupbox"..i].width
local p3_Y= _G["groupbox"..i].y + _G["groupbox"..i].height
for j=0, 50 , 10 do
if ( o_X +j > p1_X and o_X + j < p2_X and o_Y+15 > p1_Y and o_Y+15< p3_Y ) then
ui.msg("don't crash !!")
shape.x= 600
shape.y= 600
break
end
end
end
end
function bottonLeft:onHover()
shape.x= shape.x-1
calculate(shape.x, shape.y)
end
function bottonRight:onHover()
shape.x= shape.x+1
calculate(shape.x, shape.y)
end
function bottonUp:onHover()
shape.y= shape.y-1
calculate(shape.x, shape.y)
end
function bottonDown:onHover()
shape.y= shape.y+1
calculate(shape.x, shape.y)
end
while (win.visible) do
ui.update()
end