This is my first love thingy (not quite sure what to call it) that I am uploading
I made it while bored one night
hope you enjoy it
What happens:
Green and purple cubes spawn and fall
the mouse cursor pushes the cubes away
thats it...
thank you
Update
I have updated the file, now if you click it spawns 20 cubes
and thanks to rmcode, I have implemented your advise
justRandomStuffSpawning
justRandomStuffSpawning
- Attachments
-
- JustRandomStuffSpawning.love
- (7.33 KiB) Downloaded 149 times
Last edited by skyHights on Fri Sep 19, 2014 3:08 am, edited 1 time in total.
Learning to Löve.
Re: justRandomStuffSpawning
It's pretty
Just a small advice for future projects: You don't need to create a new image for every object you want to create. In general that's a bad idea because it is quite performance heavy. Instead, try to load the images at a place where multiple objects can access them. Here is an example of how you could improve your code:
Just a small advice for future projects: You don't need to create a new image for every object you want to create. In general that's a bad idea because it is quite performance heavy. Instead, try to load the images at a place where multiple objects can access them. Here is an example of how you could improve your code:
Code: Select all
local timer = 5;
-- Moved the images outside of the actual functions. Now the game only has to load two images in the beginning.
local green = love.graphics.newImage("graphics/greenSpawn.png");
local purple = love.graphics.newImage("graphics/exampleSpawn.png");
local function newSpawn(newX, newY)
local object = {}
object.x = newX
object.y = newY
object.Speed = 3
object.Width = 15
object.Hight = 15
object.Health = 1
object.LifeSpan = 1000
-- Randomly decide wether to pick the green or purple image and save a reference to the image to draw.
object.graphics = love.math.random(0, 1) == 0 and green or purple;
object.myMoveAmountX = love.math.random(1, 10) / 10
object.myMoveAmountY = love.math.random(1, 10) / 10
table.insert(TheStuff, object)
end
function theStuffUpdate()
timer = timer - 1;
if timer <= 0 then
timer = 5;
newSpawn(love.math.random(1, Screen.Width), love.math.random(1, Screen.Height))
end
end
Re: justRandomStuffSpawning
thank you, I have implemented that and updated the file and will keep that in mind with future projectsrmcode wrote: Just a small advice for future projects
Learning to Löve.
Who is online
Users browsing this forum: No registered users and 1 guest