building setup
This commit is contained in:
16
choco.lua
16
choco.lua
@@ -19,9 +19,9 @@ end
|
||||
|
||||
ressources =
|
||||
{
|
||||
fruits =
|
||||
fruit =
|
||||
{
|
||||
quantity = 5,
|
||||
quantity = 55,
|
||||
sprite = 33,
|
||||
x = 70
|
||||
},
|
||||
@@ -33,8 +33,16 @@ ressources =
|
||||
},
|
||||
jam =
|
||||
{
|
||||
quantity = 0,
|
||||
quantity = 100,
|
||||
sprite = 34,
|
||||
x = 100
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
75
world.lua
75
world.lua
@@ -8,7 +8,8 @@ function world_init()
|
||||
end
|
||||
|
||||
function world_update()
|
||||
if (btnp(5)) compute_effect_array(worldtiles)
|
||||
if (btnp(4)) build(3,2,buildings.jam_workshop)
|
||||
if (btnp(5)) compute_effect_array(worldtiles)
|
||||
end
|
||||
|
||||
function world_draw()
|
||||
@@ -16,37 +17,46 @@ function world_draw()
|
||||
end
|
||||
|
||||
|
||||
buildings = {
|
||||
buildings =
|
||||
{
|
||||
jam_workshop =
|
||||
{
|
||||
sprite = 1,
|
||||
inputs = {
|
||||
{fruit = 2}
|
||||
inputs =
|
||||
{
|
||||
{
|
||||
type = "fruit",
|
||||
quantity = 2
|
||||
}
|
||||
},
|
||||
outputs = {jam = 3}
|
||||
outputs =
|
||||
{
|
||||
{
|
||||
type = "jam",
|
||||
quantity = 3
|
||||
}
|
||||
}
|
||||
},
|
||||
city =
|
||||
{
|
||||
sprite = 5,
|
||||
inputs = {jam = 1},
|
||||
outputs = {money = 1}
|
||||
inputs =
|
||||
{
|
||||
{
|
||||
type = "jam",
|
||||
quantity = 1
|
||||
}
|
||||
},
|
||||
outputs =
|
||||
{
|
||||
{
|
||||
type = "money",
|
||||
quantity = 2
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
@@ -59,8 +69,6 @@ function draw_array(array)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function new_worldtile(x, y, building)
|
||||
local worldtile = {}
|
||||
worldtile.x = x
|
||||
@@ -70,8 +78,17 @@ function new_worldtile(x, y, building)
|
||||
spr(worldtile.building.sprite,worldtile.x*2*8,8+worldtile.y*2*8, 2, 2)
|
||||
end
|
||||
worldtile.compute_effet = function(this)
|
||||
has_ressource = true
|
||||
for _,input in pairs(worldtile.building.inputs) do
|
||||
--input.
|
||||
if (ressources[input.type].quantity < input.quantity) has_ressource = false
|
||||
end
|
||||
if (has_ressource) then
|
||||
for _,input in pairs(worldtile.building.inputs) do
|
||||
ressources[input.type].quantity-=input.quantity
|
||||
end
|
||||
for _,output in pairs(worldtile.building.outputs) do
|
||||
ressources[output.type].quantity+=output.quantity
|
||||
end
|
||||
end
|
||||
end
|
||||
return worldtile
|
||||
@@ -90,4 +107,12 @@ end
|
||||
function replace(worldtile, building)
|
||||
destroy(worldtile)
|
||||
return build(worldtile.x, worldtile.y, building)
|
||||
end
|
||||
end
|
||||
|
||||
function get_worldtile(x,y)
|
||||
for _,tile in pairs(worldtiles) do
|
||||
if (tile.x == x and tile.y == y) then
|
||||
return tile
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user