justRandomStuffSpawning

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
skyHights
Citizen
Posts: 78
Joined: Mon Aug 25, 2014 12:14 pm

justRandomStuffSpawning

Post by skyHights »

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
Attachments
JustRandomStuffSpawning.love
(7.33 KiB) Downloaded 146 times
Last edited by skyHights on Fri Sep 19, 2014 3:08 am, edited 1 time in total.
Learning to Löve.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: justRandomStuffSpawning

Post by rmcode »

It's pretty :D

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
User avatar
skyHights
Citizen
Posts: 78
Joined: Mon Aug 25, 2014 12:14 pm

Re: justRandomStuffSpawning

Post by skyHights »

rmcode wrote: Just a small advice for future projects
thank you, I have implemented that and updated the file and will keep that in mind with future projects
Learning to Löve.
User avatar
skyHights
Citizen
Posts: 78
Joined: Mon Aug 25, 2014 12:14 pm

Re: justRandomStuffSpawning

Post by skyHights »

bump?
Learning to Löve.
Post Reply

Who is online

Users browsing this forum: No registered users and 82 guests