xerpi

Take the ball by xerpi

Jun 4th, 2011
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. ang=0
  2. vel=1
  3. basket = {x=210,y=20,w=60,h=40}
  4.  
  5. ball = {img=image.load("SYSTEM/resources/balls/usedball/ball.png"),x=240,y=136}
  6. ball.w= ball.img:width()
  7. ball.h= ball.img:height()
  8.  
  9. radius=20
  10. score=0
  11.  
  12. function colision(obj1,obj2)
  13. if obj1.x>= obj2.x and
  14.     obj1.x+obj1.w <= obj2.x+obj2.w and
  15.     obj1.y >= obj2.y and
  16.     obj1.y+obj1.h <= obj2.y+obj2.h  then
  17.     return true else return false
  18. end
  19. end
  20.  
  21. while true do
  22. ball.x=240+math.cos(math.rad(ang))*radius
  23. ball.y=136+math.sin(math.rad(ang))*radius
  24. ang=ang+vel
  25. controls.read()
  26. draw.rect(basket.x,basket.y,basket.w,basket.h,color.new(255,0,0))
  27.  
  28. ball.img:blit(ball.x,ball.y)
  29.  
  30. if controls.up() then radius=radius+0.5 end
  31. if controls.down() then radius=radius-0.5 end
  32. if controls.r() then vel=vel+0.1 end
  33. if controls.l() then vel=vel-0.1 end
  34. if controls.analogx()  >100 then vel=vel+0.5 end
  35. if controls.analogx()  <-100 then vel=vel-0.5 end
  36.  
  37. if controls.press("cross") then
  38.     if colision(ball,basket) then
  39.         score=score+10
  40.     end
  41. end
  42. screen.print(5,5,"Score: "..score.."   Rad: "..radius.."   Vel: "..vel)
  43. screen.print(5,25,"Up-Down radius")
  44. screen.print(5,45,"L-R velocity")
  45.  
  46. if controls.select() then a() end
  47. screen.flip()
  48. end
Add Comment
Please, Sign In to add comment