This commit is contained in:
2025-12-28 20:29:09 +01:00
2 changed files with 113 additions and 48 deletions

View File

@@ -1,10 +1,10 @@
function _init() function _init()
world_init()
playercontroler_init() playercontroler_init()
worldtiles = {}
end end
function _update() function _update()
if (btnp(5)) compute_effect_array(worldtiles) world_update()
playercontroler_update() playercontroler_update()
end end
@@ -12,7 +12,37 @@ function _draw()
cls(0) cls(0)
map(0, 0, 0, 8, 64, 64) map(0, 0, 0, 8, 64, 64)
camera(0,0) camera(0,0)
draw_array(worldtiles)
draw_ressource_bar() draw_ressource_bar()
world_draw()
playercontroler_draw() playercontroler_draw()
end end
ressources =
{
fruit =
{
quantity = 55,
sprite = 33,
x = 70
},
money =
{
quantity = 100,
sprite = 35,
x = 0
},
jam =
{
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

125
world.lua
View File

@@ -1,57 +1,62 @@
function world_init()
worldtiles = {}
--test start
bob = build(3,2,buildings.jam_workshop)
bob = replace(bob, buildings.city)
destroy(bob)
--test end
end
ressources = function world_update()
{ if (btnp(4)) build(3,2,buildings.jam_workshop)
fruits = if (btnp(5)) compute_effect_array(worldtiles)
{ end
quantity = 5,
sprite = 33,
x = 70
},
money =
{
quantity = 100,
sprite = 35,
x = 0
},
jam =
{
quantity = 0,
sprite = 34,
x = 100
}
}
buildings = { function world_draw()
draw_array(worldtiles)
end
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 = {}, inputs =
outputs = {} {
{
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)
@@ -64,20 +69,50 @@ 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
worldtile.y = y worldtile.y = y
worldtile.building = building worldtile.building = building
worldtile.draw = function(this) worldtile.draw = function(this)
spr(worldtile.bulding.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
end 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
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