Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function on.create()
- timer.start(0.1)
- x, y, a, b = 0, 0, 280, 170
- pause, alive =false, true
- end
- function on.timer()
- if x<a then
- a=a-2
- elseif x>a then
- a=a+2
- end
- if y<b then
- b=b-2
- elseif y>b then
- b=b+2
- end
- if math.abs(x-a)<=30 and math.abs(y-b)<=30 then
- alive=false
- end
- platform.window:invalidate()
- end
- function on.paint(gc)
- gc:setColorRGB(0,0,0)
- if alive and not pause then
- gc:setColorRGB(math.random(0,255),math.random(0,255),math.random(0,255))
- gc:drawRect(x,y,30,30)
- gc:fillRect(a,b,30,30)
- elseif alive then
- gc:drawString("Paused",0,0,"top")
- elseif not alive then
- gc:drawString("You died!",0,0,"top")
- end
- end
- function on.enterKey()
- pause = not pause
- platform.window:invalidate()
- end
- function on.arrowKey(arrow)
- if arrow=='up' and y>9 then
- y = y - 8
- elseif arrow=='down' and y<170 then
- y = y + 8
- elseif arrow=='left' and x>9 then
- x = x - 8
- elseif arrow=='right' and x<280 then
- x = x + 8
- end
- platform.window:invalidate()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement