RoboCatz.com
About FLL | Navigation | Playbook | Strategy | Models | Techniques | RobotC | Programming | Robot News |

-- Script for making a castle

--Workspace.startingScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local s = require(ReplicatedStorage.genericShapes)

-- Perfectly good castle with 4 interior rooms
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local s = require(ReplicatedStorage.genericShapes)

local wallHeight = 8
local wallThickness = 1
local archWidth = 8
local archHeight = 8

local material = Enum.Material.Brick
local wallColor = Color3.fromRGB(210, 200, 190)

--========================================================--
--  HELPER: Create a wall
--========================================================--
local function makeWall(x1, z1, x2, z2)
	return s.wall({
		x1 = x1, y1 = 0, z1 = z1,
		x2 = x2, y2 = wallHeight, z2 = z2,
		thickness = wallThickness,
		material = material,
		color = wallColor
	})
end

--========================================================--
--  OUTER WALLS
--========================================================--

makeWall(-20, 20, 20, 20)   -- North
makeWall(-20, -20, 20, -20) -- South
makeWall(-20, -20, -20, 20) -- West
makeWall(20, -20, 20, 20)   -- East

--========================================================--
--  INNER WALLS (Room Dividers)
--========================================================--

local verticalDivider   = makeWall(0, -20, 0, 20)
local horizontalDivider = makeWall(-20, 0, 20, 0)

--========================================================--
--  FUNCTION: Cut opening + add archway
--========================================================--
local function addArchway(wall, x, z, orientation)
	-- Create cutter cube
	local cutter = s.cube({
		x = x,
		y = archHeight / 2,
		z = z,
		width = archWidth,
		height = archHeight + 2,
		size = archWidth,
		thickness = wallThickness + 2,
		color = Color3.new(1, 0, 0)
	})

	-- Perform the subtraction
	wall = wall:subtract(cutter, true)

	-- Add the visible archway frame
	s.archway({
		x = x,
		z = z,
		width = archWidth,
		height = archHeight,
		thickness = wallThickness,
		material = material,
		color = wallColor,
		orientation = orientation
	})

	-- Return the modified wall
	return wall
end


--========================================================--
--  FUNCTION: Cut opening for windows
--========================================================--
local function addWindow(wall, x, z, width, height)
	local wallHeight = wall.part.Size.Y

	-- Create cutter block
	local cutter = s.cube({
		x = x,
		y = wallHeight / 2,      -- center vertically
		z = z,
		width = width,
		height = height,
		size = width,
		thickness = wallThickness + 2,
		color = Color3.new(0, 1, 1)  -- cyan for debugging
	})

	-- Perform subtraction
	wall = wall:subtract(cutter, true)

	-- Optional: add a decorative frame
	-- s.windowFrame({ ... })

	return wall
end

local function randomWindowPosition(x1, z1, x2, z2)
	-- Determine if wall is vertical or horizontal
	local isVertical = (x1 == x2)

	-- Random offset along the wall
	local t = math.random() * 0.6 + 0.2   -- keeps windows away from edges

	local x = x1 + (x2 - x1) * t
	local z = z1 + (z2 - z1) * t

	return x, z
end

--========================================================--
--  ARCHWAYS BETWEEN ROOMS
--========================================================--

-- Between Room 1 & Room 2 (vertical wall)
verticalDivider = addArchway(verticalDivider, 0, 10, Vector3.new(0, 90, 0))

-- Between Room 3 & Room 4 (vertical wall)
verticalDivider = addArchway(verticalDivider, 0, -10, Vector3.new(0, 90, 0))

-- Between Room 1 & Room 3 (horizontal wall)
horizontalDivider = addArchway(horizontalDivider, -10, 0, Vector3.new(0, 0, 0))

-- Between Room 2 & Room 4 (horizontal wall)
horizontalDivider = addArchway(horizontalDivider, 10, 0, Vector3.new(0, 0, 0))


--========================================================--
--  NOW ADD WINDOWS ON THE WALLS
--========================================================--

-- Window dimensions
local windowWidth = 2
local windowHeight = 2

-- Add windows to vertical divider
for i = 1, 2 do
	local x, z = randomWindowPosition(0, -20, 0, 20)
	verticalDivider = addWindow(verticalDivider, x, z, windowWidth, windowHeight)
end

-- Add windows to horizontal divider
for i = 1, 2 do
	local x, z = randomWindowPosition(-20, 0, 20, 0)
	horizontalDivider = addWindow(horizontalDivider, x, z, windowWidth, windowHeight)
end