Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. Hexagon = {}
  2.  
  3. function Hexagon:new(...)
  4. local object = setmetatable({}, {__index = self})
  5. if object.construct then
  6. object:construct(...)
  7. end
  8. return object
  9. end
  10.  
  11. function Hexagon:construct(...)
  12. self.screen = Vector2( guiGetScreenSize( ) )
  13. end
  14.  
  15. function Hexagon:isTriangleMouse(x1, y1, x2, y2, x3, y3, px, py)
  16. local areaOrig = math.abs( (x2-x1)*(y3-y1) - (x3-x1)*(y2-y1) )
  17. local area1 = math.abs( (x1-px)*(y2-py) - (x2-px)*(y1-py) );
  18. local area2 = math.abs( (x2-px)*(y3-py) - (x3-px)*(y2-py) );
  19. local area3 = math.abs( (x3-px)*(y1-py) - (x1-px)*(y3-py) );
  20. if (area1 + area2 + area3 == areaOrig) then
  21. return true
  22. else
  23. return false
  24. end
  25. end
  26.  
  27. function Hexagon:colission(posX, posY, Size, Angel)
  28. local sx, sy = guiGetScreenSize ( )
  29. local cx, cy = getCursorPosition ( )
  30. local cx, cy = ( cx * sx ), ( cy * sy )
  31. local lastX = nil
  32. local lastY = nil
  33. local points = {}
  34. for i=0,6 do
  35. local angle = Angel+(2 * math.pi / 6 * (i + 0.5) )
  36. local x = posX + Size * math.cos(angle)
  37. local y = posY + Size * math.sin(angle)
  38. points[i+1] = { Vector2(lastX, lastY), Vector2(x, y) }
  39. lastX = x
  40. lastY = y
  41. end
  42. local sx, sy = guiGetScreenSize ( )
  43. local cx, cy = getCursorPosition ( )
  44. local cursor = Vector2(cx * sx, cy * sy)
  45. local toggle = false
  46. if self:isTriangleMouse(points[6][2].x, points[6][2].y, points[2][2].x, points[2][2].y, points[3][2].x, points[3][2].y, cursor.x, cursor.y) or self:isTriangleMouse(points[3][2].x, points[3][2].y, points[4][2].x, points[4][2].y, points[5][2].x, points[5][2].y, cursor.x, cursor.y) or self:isTriangleMouse(points[2][2].x, points[2][2].y, points[6][2].x, points[6][2].y, points[1][2].x, points[1][2].y, cursor.x, cursor.y) or self:isTriangleMouse(points[6][2].x, points[6][2].y, points[3][2].x, points[3][2].y, points[5][2].x, points[5][2].y, cursor.x, cursor.y) then
  47. toggle = true
  48. end
  49. return toggle
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement