flowers and sheep: ecology game, newbie needs 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.
Clödi
Prole
Posts: 7
Joined: Fri Sep 20, 2013 7:44 pm

flowers and sheep: ecology game, newbie needs help

Post by Clödi »

Hi,

i am a very inexperienced coder, so i guess i made an obvious mistake. Maybe someone could give me an easy way i can find out on which line my code crashes, in that way i might have to ask for help less often.

This is my code, i want it to grow flowers. Next step would be growing them in random directions. And then sheep eating them. But i only got them on the map, that was the best i could do.

Code: Select all

function love.load()

--debug variablen

koll = 0

-- map variables
   map_w = 40
   map_h = 80
   map_x = 0
   map_y = 0
   map_offset_x = -22
   map_offset_y = -22
   map_display_w = 20
   map_display_h = 20
   tile_w = 22
   tile_h = 22
   
-- blume

	flowergraphic = love.graphics.newImage("flower.png")
	
	flowers = {}
for i=0,4 do
	flower = {}
	flower.nutrition = 10
	flower.clone = 0
	flower.chlorophyll = 0
	flower.width = flowergraphic:getWidth()
	flower.height = flowergraphic:getHeight()
	flower.x = i * (flower.width + 30) + 30
	flower.y = flower.height + 20
	flowerx = 0
	flowery = 0
	table.insert(flowers, flower)
end

-- schaf

	sheepgraphic = love.graphics.newImage("sheep.png")
	
	sheeps = {}
for i=0,4 do
	sheep = {}
	sheep.nutrition = 10
	sheep.width = sheepgraphic:getWidth()
	sheep.height = sheepgraphic:getHeight()
	sheep.x = i * (sheep.width + 10) + 10
	sheep.y = sheep.height + 10
	table.insert(sheeps, sheep)
end

-- our tiles
   tile = {}
   for i=0,3 do -- change 3 to the number of tile images minus 1.
      tile[i] = love.graphics.newImage( "tile"..i..".bmp" )
   end
   
   love.graphics.setFont(12)
   
   
   map={
   --well, a lot of numbers making a map, edited this out.
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}
end

function love.update(dt)

mouse_x = love.mouse.getX()
mouse_y = love.mouse.getY()

-- sun for flowers

	for i,v in ipairs(flowers) do
	flower.chlorophyll = flower.chlorophyll + dt*10
		if v.chlorophyll > 100	then
	
		v.clone = 1
	
		end
	
	end

	
end

function growflower()


-- grow flower patches
	
	for ii,vv in ipairs(flowers) do
	
		if vv.clone = 1	then
		
		vv.clone = 0
		vv.chlorophyll = 0
		flowerx = vv.x
		flowery = vv.y
		
		local flower = {}
		vv.x = flowerx + 33
		vv.y = flowery
		table.insert(flowers, flower)
	
		
	
		end
	
	end


end

function draw_map()
   for y=1, map_display_h do
      for x=1, map_display_w do                                                        
         love.graphics.draw(
            tile[map[y+map_y][x+map_x]],
            (x*tile_w)+map_offset_x,
            (y*tile_h)+map_offset_y )
      end
   end
end

function love.draw()
draw_map()



for i,v in ipairs(flowers) do
	love.graphics.draw(flowergraphic, v.x, v.y)
end

for i,v in ipairs(sheeps) do
	love.graphics.draw(sheepgraphic, v.x, v.y)
end

end
Thanks in advance.
Last edited by Clödi on Mon Sep 23, 2013 3:47 pm, edited 2 times in total.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Newbie game crashing need some help to get me going

Post by Davidobot »

Interesting game, but I noticed one problem in your code, which is causing the problem, which is that LÖVE doesn't accept .bmp files.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Newbie game crashing need some help to get me going

Post by slime »

Davidobot wrote:LÖVE doesn't accept .bmp files.
That's not true, LÖVE can load all of the image formats on the left here: http://openil.sourceforge.net/features.php , although in the future that will probably change.
User avatar
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

Re: Newbie game crashing need some help to get me going

Post by ejmr »

Could you please post a '*.love' file with the images and everything else? That is a useful thing to do when asking for help, as it makes it easier for people to run your code, etc.
Davidobot wrote:Interesting game, but I noticed one problem in your code, which is causing the problem, which is that LÖVE doesn't accept .bmp files.
I thought it did.

https://www.love2d.org/wiki/ImageFormat
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經
Clödi
Prole
Posts: 7
Joined: Fri Sep 20, 2013 7:44 pm

Re: Newbie game crashing need some help to get me going

Post by Clödi »

Interesting game
Thank you, i want to add an avatar later that can do sandboxy stuff like placing fences, digging up flowers, killing sheep, maybe wolves... Playing with ecology, basically.

Oh, and if it didn't load *.bmp files, i would have run into problems way earlier, that is not the issue. But thank you, it would have been great if it was.

There's the file.
User avatar
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

Re: Newbie game crashing need some help to get me going

Post by ejmr »

Code: Select all

if vv.clone = 1 then
Common mistake, but you need to use '==' here for equality test. You are accidentally using the assignment operator.

Also this is an error:

Code: Select all

love.graphics.setFont(12)
LÖVE 0.8.0 no longer supports that form of the function.

http://love2d.org/wiki/love.graphics.setFont
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Newbie game crashing need some help to get me going

Post by davisdude »

But you can get the font at the beginning registering 'font' (or whatever) as love.graphics.setNewFont()

Code: Select all

local font = love.graphics.setNewFont()
love.graphics.setFont( font, 12 )
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Newbie game crashing need some help to get me going

Post by slime »

That list is for image formats LÖVE can save to, not necessarily load from. The list of formats LÖVE 0.8.0 can load from is on the left here: http://openil.sourceforge.net/features.php
User avatar
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

Re: Newbie game crashing need some help to get me going

Post by ejmr »

slime wrote:
That list is for image formats LÖVE can save to, not necessarily load from. The list of formats LÖVE 0.8.0 can load from is on the left here: http://openil.sourceforge.net/features.php
Ah ok. Thanks for the link and clarification.
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經
Clödi
Prole
Posts: 7
Joined: Fri Sep 20, 2013 7:44 pm

Re: Newbie game crashing need some help to get me going

Post by Clödi »

Yeah, totally forgot about that one. Now it works better.

The font isn't a problem right now, because i haven't updates in a while. Thanks though, because that would have caused me trouble when i get around doing that.

Now it crashes, it seems, when it tries to spawn the second flower.

By the way, where should i put that, is it right to have this in the love.update function?

Code: Select all

-- grow flower patches
	
	for ii,vv in ipairs(flowers) do
	
		if vv.clone == 1	then
		
		vv.clone = 0
		vv.chlorophyll = 0
		flowerx = vv.x
		flowery = vv.y
		
		local flower = {}
		flower.x = flowerx + 33
		flower.y = flowery
		table.insert(flowers, flower)
	
		
	
		end
	
	end
Attachments
Ecology.love
(5.88 KiB) Downloaded 85 times
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests