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