Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hexagon = {}
- function Hexagon:new(...)
- local object = setmetatable({}, {__index = self})
- if object.construct then
- object:construct(...)
- end
- return object
- end
- function Hexagon:construct(...)
- self.screen = Vector2( guiGetScreenSize( ) )
- end
- function Hexagon:isTriangleMouse(x1, y1, x2, y2, x3, y3, px, py)
- local areaOrig = math.abs( (x2-x1)*(y3-y1) - (x3-x1)*(y2-y1) )
- local area1 = math.abs( (x1-px)*(y2-py) - (x2-px)*(y1-py) );
- local area2 = math.abs( (x2-px)*(y3-py) - (x3-px)*(y2-py) );
- local area3 = math.abs( (x3-px)*(y1-py) - (x1-px)*(y3-py) );
- if (area1 + area2 + area3 == areaOrig) then
- return true
- else
- return false
- end
- end
- function Hexagon:colission(posX, posY, Size, Angel)
- local sx, sy = guiGetScreenSize ( )
- local cx, cy = getCursorPosition ( )
- local cx, cy = ( cx * sx ), ( cy * sy )
- local lastX = nil
- local lastY = nil
- local points = {}
- for i=0,6 do
- local angle = Angel+(2 * math.pi / 6 * (i + 0.5) )
- local x = posX + Size * math.cos(angle)
- local y = posY + Size * math.sin(angle)
- points[i+1] = { Vector2(lastX, lastY), Vector2(x, y) }
- lastX = x
- lastY = y
- end
- local sx, sy = guiGetScreenSize ( )
- local cx, cy = getCursorPosition ( )
- local cursor = Vector2(cx * sx, cy * sy)
- local toggle = false
- 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
- toggle = true
- end
- return toggle
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement