93 lines
1.6 KiB
Lua
93 lines
1.6 KiB
Lua
function world_init()
|
|
worldtiles = {}
|
|
--test start
|
|
bob = build(3,2,buildings.jam_workshop)
|
|
bob = replace(bob, buildings.city)
|
|
destroy(bob)
|
|
--test end
|
|
end
|
|
|
|
function world_update()
|
|
if (btnp(5)) compute_effect_array(worldtiles)
|
|
end
|
|
|
|
function world_draw()
|
|
draw_array(worldtiles)
|
|
end
|
|
|
|
|
|
buildings = {
|
|
jam_workshop =
|
|
{
|
|
sprite = 1,
|
|
inputs = {
|
|
{fruit = 2}
|
|
},
|
|
outputs = {jam = 3}
|
|
},
|
|
city =
|
|
{
|
|
sprite = 5,
|
|
inputs = {jam = 1},
|
|
outputs = {money = 1}
|
|
},
|
|
}
|
|
|
|
|
|
function draw_ressource_bar()
|
|
rectfill(0, 0, 127, 7, 1)
|
|
for _,res in pairs(ressources) do
|
|
spr(res.sprite, res.x, 0)
|
|
print(res.quantity, res.x + 8, 1, 6)
|
|
end
|
|
end
|
|
|
|
|
|
function updatecycle()
|
|
|
|
end
|
|
|
|
function compute_effect_array(array)
|
|
for obj in all(array) do
|
|
obj.compute_effet(obj)
|
|
end
|
|
end
|
|
|
|
function draw_array(array)
|
|
for obj in all(array) do
|
|
obj.draw(obj)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
function new_worldtile(x, y, building)
|
|
local worldtile = {}
|
|
worldtile.x = x
|
|
worldtile.y = y
|
|
worldtile.building = building
|
|
worldtile.draw = function(this)
|
|
spr(worldtile.building.sprite,worldtile.x*2*8,8+worldtile.y*2*8, 2, 2)
|
|
end
|
|
worldtile.compute_effet = function(this)
|
|
for _,input in pairs(worldtile.building.inputs) do
|
|
--input.
|
|
end
|
|
end
|
|
return worldtile
|
|
end
|
|
|
|
function build(x, y, building)
|
|
newtile = new_worldtile(x,y,building)
|
|
add(worldtiles, newtile)
|
|
return newtile
|
|
end
|
|
|
|
function destroy(worldtile)
|
|
del(worldtiles, worldtile)
|
|
end
|
|
|
|
function replace(worldtile, building)
|
|
destroy(worldtile)
|
|
return build(worldtile.x, worldtile.y, building)
|
|
end |