Planet Spawning, Please Help

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Puzzelism
Prole
Posts: 16
Joined: Wed Mar 06, 2013 2:00 am

Planet Spawning, Please Help

Post by Puzzelism »

Okay, so i'm trying to make some pretty basic code to spawn some planets (also known as circles), I don't know what I'm doing that makes the drawing function not work. here is the code:

Code: Select all

math.randomseed(os.time())

planet = {}

numPlanetsMax = math.random(3, 5)
numPlanets = 0

function planet_generate(dt)
	for i=1, numPlanetsMax do
		if numPlanets < numPlanetsMax then
			planet_load(12, 32, 54)
			numPlanets = numPlanets + 1
		end
	end
end

function planet_load(x, y, size)
	table.insert(planet, {x = x, y = y, size = size})
end


function planet_draw()
	for i,v in ipairs(planet) do
		love.graphics.setColor(255,255,255)
		love.graphics.circle("fill", planet.x, planet.y, planet.size, planet.size)
	end
end
Also here is the .love:
planets.love
(557 Bytes) Downloaded 161 times
One cannot simply code love.. Oh wait with LÖVE you can..
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: Planet Spawning, Please Help

Post by HugoBDesigner »

It MAY be because you're making the 4th argument of love.graphics.circle as the same value as the 3rd.
In LÖVE, circles don't have different widths and heights: it's all a single variable (the 3rd argument). The 4th argument is for number of sizes of the circle (since it's not a circle properly, but a polygon with a bunch of sides - I often set it to 32).

So you'd maybe do this:
love.graphics.circle("fill", planet.x, planet.y, planet.size, 32)
@HugoBDesigner - Twitter
HugoBDesigner - Blog
Puzzelism
Prole
Posts: 16
Joined: Wed Mar 06, 2013 2:00 am

Re: Planet Spawning, Please Help

Post by Puzzelism »

Thanks for the reply, tried your solution and it didn't work. I believe the problem is with argument 2 of the circle drawing. However thank you for that information, I hadn\t properly researched love.graphics.circle before hand, and i kinda understood it, thanks for the clarification :megagrin:
One cannot simply code love.. Oh wait with LÖVE you can..
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: Planet Spawning, Please Help

Post by HugoBDesigner »

I downloaded it, took a look at your code again and realized:

You're doing a for loop through each item in the planet table: for i, v in pairs(planet) do
But you're drawing it as planet.something, even though the planet table contains all the planets. So, in the drawing function, replace all "planet" by "v" and it should work :)
@HugoBDesigner - Twitter
HugoBDesigner - Blog
Puzzelism
Prole
Posts: 16
Joined: Wed Mar 06, 2013 2:00 am

Re: Planet Spawning, Please Help

Post by Puzzelism »

Thanks, figured that out like three seconds before reading this post and I felt so dumb :P Anyways thanks for the help. Happy LÖVING :awesome:.
One cannot simply code love.. Oh wait with LÖVE you can..
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Planet Spawning, Please Help

Post by s-ol »

Also a quick hint: your planet_generate method doesn't need the dt argument! First it just doesn't fit there and second the argument isn't used anyway

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Puzzelism
Prole
Posts: 16
Joined: Wed Mar 06, 2013 2:00 am

Re: Planet Spawning, Please Help

Post by Puzzelism »

Thanks for all the replies, however I ran into another problem that ive been trying to solve all night. The problem here is that im trying to spawn forests, really for no reason other than for future uses, im trying to spawn them individually onto planets, however i will work on that later, as of now however im trying to just focus on variety in the forests, different colors etc. Run the .love and you will find out the new problem. Please feel free to clean up my code and judge it as much as you want, im still pretty new to this. :P

Love it:
planets.love
(2.64 KiB) Downloaded 155 times
One cannot simply code love.. Oh wait with LÖVE you can..
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests