This works, but, now my spin function doesn't work
Sure, the code I provided is just for what you ask for. Everything else is on you.
Also, this is probably expected but, whenever you open up the game again, it stays the same colour and doesn't re-randomise it.
That is wrong. when using the code as I provided above the colour get selected properly (tested). Make sure to use love.math.random instead of math.random. if you prefer to use math.random you need to create a random seed as well using math.randomseed(os.time()). the love.math module do that automatically.
Now to add additional functionality you just have to expend the code. if you're not sure how to do that, then you should take a deeper look into lua and löve itself. Here are some good resources to learn lua and LÖVE. :
Programming in Lua (Online Book)
LÖVE Tutorials
Here is an example for the wheel movement (but its not exactly what you need and its not perfect, its just an example):
Code: Select all
local screen_width, screen_height = love.graphics.getDimensions()
local wheel_velocity = 300
local boxes ={}
function pickAColour()
reds = { 255, 0, 0 }
blues = { 0, 0, 255 }
Colours = { reds, blues }
return Colours[ love.math.random(#Colours)]
end
function newBox(x, y)
local box = {x = x, y = y, colour = pickAColour(), width = 60, height = 60}
table.insert(boxes, box)
end
function updateBoxes(dt)
for k, box in ipairs(boxes) do
-- Move the box --
box.x = box.x + wheel_velocity * dt
-- Reset position if the box is outside of the screen --
if box.x > screen_width then box.x = -box.width end
end
end
function drawBoxes()
for k, box in ipairs(boxes) do
love.graphics.setColor(box.colour)
love.graphics.rectangle("fill", box.x, box.y, box.width, box.height)
love.graphics.setColor(255, 255, 255, 255)
end
end
function love.load()
for i = 1, 10 do
newBox(-100 + 85 * i, 200)
end
end
function love.update(dt)
updateBoxes(dt)
end
function love.draw()
drawBoxes()
end
function love.keypressed(key) if key == "escape" then love.event.quit() end end