Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 20th, 2012  |  syntax: Lua  |  size: 1.67 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Button = {
  2. X = 350,
  3. Y = 200,
  4. W = 150,
  5. H = 50,
  6. Colour = {
  7. R = 255,
  8. G = 255,
  9. B = 255
  10. }
  11. }
  12. Mouse = {
  13. X = 0,
  14. Y = 0,
  15. W = 5,
  16. H = 5,
  17. Hover_X = 0,
  18. Hover_Y = 0,
  19. Click_X = 0,
  20. Click_Y = 0,
  21. Click_Sent = false,
  22. Click_Recv = false,
  23. }
  24.  
  25.  
  26. function love.draw()
  27.         if Mouse.Click_Sent == true and Mouse.Click_Recv == false then
  28.                 Mouse.X = Mouse.Click_X
  29.                 Mouse.Y = Mouse.Click_Y
  30.                 if CheckCollision() == true then
  31.                         Button.Colour.R = 255
  32.                         Button.Colour.G = 100
  33.                         Button.Colour.B = 100
  34.                 else
  35.                         Button.Colour.R = 100
  36.                         Button.Colour.G = 255
  37.                         Button.Colour.B = 100
  38.                 end
  39.                 Mouse.Click_Recv = true
  40.         else
  41.                 Mouse.X = Mouse.Hover_X
  42.                 Mouse.Y = Mouse.Hover_Y
  43.                 if CheckCollision() == true then
  44.                         Button.Colour.R = 100
  45.                         Button.Colour.G = 100
  46.                         Button.Colour.B = 255
  47.                 else
  48.                         Button.Colour.R = 255
  49.                         Button.Colour.G = 255
  50.                         Button.Colour.B = 255
  51.                 end
  52.         end
  53.         love.graphics.setColor (Button.Colour.R, Button.Colour.G, Button.Colour.B)
  54.         love.graphics.rectangle("fill", Button.X, Button.Y, Button.W, Button.H)
  55. end
  56.  
  57. function CheckCollision (ButtonX,ButtonY,ButtonW,ButtonH,MouseX,MouseY,MouseW,MouseH)  
  58.         local MouseTop, MouseBottom, ButtonTop, ButtonBottom = Mouse.X + Mouse.W, Mouse.Y + Mouse.H, Button.X + Button.W, Button.Y + Button.H
  59.         return Mouse.X < ButtonTop and MouseTop > Button.X and Mouse.Y < ButtonBottom and MouseBottom > Button.Y
  60. end
  61.  
  62. function love.update(dt)
  63.         Mouse.Hover_X, Mouse.Hover_Y = love.mouse.getPosition()
  64.         if love.mouse.isDown("l") then
  65.                 if Mouse.Click_Sent == false then
  66.                         Mouse.Click_X, Mouse.Click_Y = love.mouse.getPosition()
  67.                         Mouse.Click_Sent = true
  68.                         Mouse.Click_Recv = false
  69.                 end
  70.         else
  71.                 Mouse.Click_Sent = false;
  72.         end
  73. end