Advertisement
Guest User

epic7

a guest
Dec 28th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. function on.create()
  2.     timer.start(0.1)
  3.     x, y, a, b = 0, 0, 280, 170
  4.     pause, alive =false, true
  5. end
  6.  
  7. function on.timer()
  8.     if x<a then
  9.         a=a-2
  10.     elseif x>a then
  11.         a=a+2
  12.     end
  13.     if y<b then
  14.         b=b-2
  15.     elseif y>b then
  16.         b=b+2
  17.     end
  18.     if math.abs(x-a)<=30 and math.abs(y-b)<=30 then
  19.         alive=false
  20.     end
  21.     platform.window:invalidate()
  22. end
  23.  
  24. function on.paint(gc)
  25.     gc:setColorRGB(0,0,0)
  26.     if alive and not pause then
  27.         gc:setColorRGB(math.random(0,255),math.random(0,255),math.random(0,255))
  28.         gc:drawRect(x,y,30,30)
  29.         gc:fillRect(a,b,30,30)
  30.     elseif alive then
  31.         gc:drawString("Paused",0,0,"top")  
  32.     elseif not alive then
  33.         gc:drawString("You died!",0,0,"top")
  34.     end
  35. end
  36.  
  37. function on.enterKey()
  38.     pause = not pause
  39.     platform.window:invalidate()
  40. end
  41.  
  42. function on.arrowKey(arrow)
  43.     if arrow=='up' and y>9 then
  44.         y = y - 8
  45.     elseif arrow=='down' and y<170 then
  46.         y = y + 8
  47.     elseif arrow=='left' and x>9 then
  48.         x = x - 8
  49.     elseif arrow=='right' and x<280 then
  50.         x = x + 8
  51.     end
  52.     platform.window:invalidate()
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement