The problem here is that there is only one circle whereas what I want is a number of circles emnating from the point of the click. What seems to be the Issue ?
Thanks in Advance
Here is the Code
Code: Select all
--[[
- Author :: Aswin Mohan
- Dated :: 23.July.2016
- @Description :
Draw Circles on the screen from last click Point
]]
-- Circle Description
local circles = {}
local circle = {}
-- Initialise Love
function love.load(arg)
-- Set up the Mouse
circle.posX = love.graphics.getWidth() / 2
circle.posY = love.graphics.getHeight() / 2
circle.radius = math.random(10,50)
circle.shouldDraw = false
circle.time = 0
-- Set the BackGround Color
love.graphics.setBackgroundColor(52 , 73 ,94 , 255)
end
-- Update before Each Frame
function love.update(dt)
circle.time = circle.time + dt
circle.shouldDraw = false
if circle.time > 1 then
-- Change Radius
circle.radius = math.random(10 , 100)
circle.shouldDraw = true
circle.speedX = 150 * math.random(-1 , 1)
circle.speedY = 150 * math.random(-1 , 1)
-- Create an Array of Circles
table.insert(circles,circle)
-- Update the Postion of the Circles Randomly
for i , v in pairs(circles) do
v.posX = v.posX + v.speedX * dt
v.posY = v.posY + v.speedY * dt
end
circle.time = 0
end
end
-- Draw each Frame
function love.draw()
for i , v in pairs(circles) do
love.graphics.circle("fill", v.posX, v.posY, v.radius, 20)
end
end
-- Handle Mouse Clicks
function love.mousepressed(x, y, button, isTouch)
if button == 1 or button == 2 then
circle.posX = x
circle.posY = y
end
end
-- Clean things up
function love.quit()
-- body...
end