building setup
This commit is contained in:
14
choco.lua
14
choco.lua
@@ -19,9 +19,9 @@ end
|
|||||||
|
|
||||||
ressources =
|
ressources =
|
||||||
{
|
{
|
||||||
fruits =
|
fruit =
|
||||||
{
|
{
|
||||||
quantity = 5,
|
quantity = 55,
|
||||||
sprite = 33,
|
sprite = 33,
|
||||||
x = 70
|
x = 70
|
||||||
},
|
},
|
||||||
@@ -33,8 +33,16 @@ ressources =
|
|||||||
},
|
},
|
||||||
jam =
|
jam =
|
||||||
{
|
{
|
||||||
quantity = 0,
|
quantity = 100,
|
||||||
sprite = 34,
|
sprite = 34,
|
||||||
x = 100
|
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
|
||||||
71
world.lua
71
world.lua
@@ -8,6 +8,7 @@ function world_init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function world_update()
|
function world_update()
|
||||||
|
if (btnp(4)) build(3,2,buildings.jam_workshop)
|
||||||
if (btnp(5)) compute_effect_array(worldtiles)
|
if (btnp(5)) compute_effect_array(worldtiles)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -16,37 +17,46 @@ function world_draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
buildings = {
|
buildings =
|
||||||
|
{
|
||||||
jam_workshop =
|
jam_workshop =
|
||||||
{
|
{
|
||||||
sprite = 1,
|
sprite = 1,
|
||||||
inputs = {
|
inputs =
|
||||||
{fruit = 2}
|
{
|
||||||
|
{
|
||||||
|
type = "fruit",
|
||||||
|
quantity = 2
|
||||||
|
}
|
||||||
},
|
},
|
||||||
outputs = {jam = 3}
|
outputs =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
type = "jam",
|
||||||
|
quantity = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
city =
|
city =
|
||||||
{
|
{
|
||||||
sprite = 5,
|
sprite = 5,
|
||||||
inputs = {jam = 1},
|
inputs =
|
||||||
outputs = {money = 1}
|
{
|
||||||
|
{
|
||||||
|
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)
|
function compute_effect_array(array)
|
||||||
for obj in all(array) do
|
for obj in all(array) do
|
||||||
obj.compute_effet(obj)
|
obj.compute_effet(obj)
|
||||||
@@ -59,8 +69,6 @@ function draw_array(array)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function new_worldtile(x, y, building)
|
function new_worldtile(x, y, building)
|
||||||
local worldtile = {}
|
local worldtile = {}
|
||||||
worldtile.x = x
|
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)
|
spr(worldtile.building.sprite,worldtile.x*2*8,8+worldtile.y*2*8, 2, 2)
|
||||||
end
|
end
|
||||||
worldtile.compute_effet = function(this)
|
worldtile.compute_effet = function(this)
|
||||||
|
has_ressource = true
|
||||||
for _,input in pairs(worldtile.building.inputs) do
|
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
|
||||||
end
|
end
|
||||||
return worldtile
|
return worldtile
|
||||||
@@ -91,3 +108,11 @@ function replace(worldtile, building)
|
|||||||
destroy(worldtile)
|
destroy(worldtile)
|
||||||
return build(worldtile.x, worldtile.y, building)
|
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