Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. local openBox = {
  2. x1 = 1,
  3. y1 = 1,
  4. x2 = 26,
  5. y2 = 10,
  6. color = colors.green
  7. }
  8. local closeBox = {
  9. x1 = 1,
  10. y1 = 11,
  11. x2 = 26,
  12. y2 = 18,
  13. color = colors.red
  14. }
  15. local exitBox = {
  16. x1 = 10,
  17. y1 = 18,
  18. x2 = 16,
  19. y2 = 20,
  20. color = colors.gray
  21. }
  22. function drawBox(boxObj)
  23. paintutils.drawFilledBox(boxObj.x1,boxObj.y1,boxObj.x2,boxObj.y2,boxObj.color)
  24. end
  25. function boxClicked(boxObj, x, y)
  26. if(x <= boxObj.x2 && x >= boxObj.x1 && y <= boxObj.y2 && y >= boxObj.y1) then
  27. return true
  28. else
  29. return false
  30. end
  31. end
  32.  
  33. drawBox(openBox)
  34. drawBox(closeBox)
  35. drawBox(exitBox)
  36. term.setCursorPos(12,19)
  37. print("EXIT")
  38. local loop = true
  39. while loop do
  40. local e, b, x, y = os.pullEvent("mouse_click")
  41. if boxClicked(openBox, x, y) then
  42. --open door
  43. elseif boxClicked(closeBox, x, y) then
  44. --close door
  45. elseif boxClicked(exitBox, x, y) then
  46. loop = false
  47. end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement