Roblox Forsaken Generator Simulator
Game Description
Connect numbered dots on a 6x6 grid to progress through levels. Use your mouse to create lines between matching numbered dots. Lines cannot intersect with other lines, grid boundaries, or starting dots.
Game Implementation
Here's a basic implementation of the game using Lua and Roblox's built-in UI and input handling.
-- Services
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
-- Grid properties
local gridSize = 6
local cellSize = 50
-- Game state
local grid = {}
local lines = {}
local dots = {}
local currentLevel = 1
local isDrawing = false
local startDot = nil
-- Create grid
for i = 1, gridSize do
grid[i] = {}
for j = 1, gridSize do
local cell = Instance.new("Frame")
cell.Size = UDim2.new(1/gridSize, 0, 1/gridSize, 0)
cell.Position = UDim2.new((i-1)/gridSize, 0, (j-1)/gridSize, 0)
cell.BackgroundColor3 = Color3.new(1, 1, 1)
cell.BorderSizePixel = 1
cell.Parent = script.Parent
grid[i][j] = cell
end
end
-- Create dots
for i = 1, 8 do
local dot1 = Instance.new("ImageLabel")
dot1.Image = "rbxassetid://148840371"
dot1.Size = UDim2.new(0.1, 0, 0.1, 0)
dot1.Position = UDim2.new(math.random()/gridSize, 0, math.random()/gridSize, 0)
dot1.Parent = script.Parent
table.insert(dots, {dot1, i})
local dot2 = Instance.new("ImageLabel")
dot2.Image = "rbxassetid://148840371"
dot2.Size = UDim2.new(0.1, 0, 0.1, 0)
dot2.Position = UDim2.new(math.random()/gridSize, 0, math.random()/gridSize, 0)
dot2.Parent = script.Parent
table.insert(dots, {dot2, i})
end
-- User input handling
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isDrawing = true
for _, dot in pairs(dots) do
local dotPosition = dot[1].Position
local mousePosition = UserInputService:GetMousePositionInViewport()
local distance = (dotPosition.X.Offset - mousePosition.X)^2 + (dotPosition.Y.Offset - mousePosition.Y)^2
if distance < 100 then
startDot = dot
break
end
end
end
end)
UserInputService.InputChanged:Connect(function(input)
if isDrawing and startDot then
local mousePosition = UserInputService:GetMousePositionInViewport()
local line = Instance.new("Line")
line.From = startDot[1].Position
line.To = UDim2.new(mousePosition.X, 0, mousePosition.Y, 0)
line.Parent = script.Parent
table.insert(lines, line)
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isDrawing = false
if startDot then
for _, dot in pairs(dots) do
if dot[2] == startDot[2] and dot ~= startDot then
local dotPosition = dot[1].Position
local mousePosition = UserInputService:GetMousePositionInViewport()
local distance = (dotPosition.X.Offset - mousePosition.X)^2 + (dotPosition.Y.Offset - mousePosition.Y)^2
if distance < 100 then
-- Check if line intersects with other lines or grid boundaries
local intersects = false
for _, line in pairs(lines) do
if line ~= lines[#lines] then
if doLinesIntersect(line.From, line.To, startDot[1].Position, dotPosition) then
intersects = true
break
end
end
end
if not intersects then
-- Update line to connect dots
lines[#lines].To = dotPosition
-- Check if all dots are connected
if areAllDotsConnected() then
-- Progress to next level
currentLevel = currentLevel + 1
resetGame()
end
else
-- Remove line if it intersects
lines[#lines]:Destroy()
table.remove(lines)
end
break
end
end
end
startDot = nil
end
end
end)
-- Helper functions
local function doLinesIntersect(p1, p2, p3, p4)
local denom = (p1.X.Offset - p2.X.Offset) * (p3.Y.Offset - p4.Y.Offset) - (p1.Y.Offset - p2.Y.Offset) * (p3.X.Offset - p4.X.Offset)
if denom == 0 then
return false
end
local t = ((p1.X.Offset - p3.X.Offset) * (p3.Y.Offset - p4.Y.Offset) - (p1.Y.Offset - p3.Y.Offset) * (p3.X.Offset - p4.X.Offset)) / denom
local u = -((p1.X.Offset - p2.X.Offset) * (p1.Y.Offset - p3.Y.Offset) - (p1.Y.Offset - p2.Y.Offset) * (p1.X.Offset - p3.X.Offset)) / denom
return t > 0 and t < 1 and u > 0 and u < 1
end
local function areAllDotsConnected()
for i = 1, #dots, 2 do
if dots[i][1].Position ~= dots[i+1][1].Position then
return false
end
end
return true
end
local function resetGame()
-- Reset dots and lines
for _, dot in pairs(dots) do
dot[1].Position = UDim2.new(math.random()/gridSize, 0, math.random()/gridSize, 0)
end
for _, line in pairs(lines) do
line:Destroy()
end
lines = {}
end
Notes
- The code above assumes that you have a
LocalScript or Script in your Roblox game with the necessary permissions to create and manipulate UI elements.
- The grid and dots are created using Roblox's UI system, and lines are represented as simple line instances.
- The game logic is implemented using Lua, and user input is handled using Roblox's built-in input handling services.
- The
doLinesIntersect function checks if two lines intersect, and the areAllDotsConnected function checks if all dots are connected.
- The game resets when all dots are connected, and a new level begins.
Future Improvements
- Improve the game's UI and visuals.
- Add sound effects and music.
- Implement a scoring system and leaderboards.
- Add more levels and challenges.
- Optimize the game's performance and responsiveness.