building creation/replace/destroy
This commit is contained in:
30
choco.lua
30
choco.lua
@@ -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,29 @@ 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 =
|
||||||
|
{
|
||||||
|
fruits =
|
||||||
|
{
|
||||||
|
quantity = 5,
|
||||||
|
sprite = 33,
|
||||||
|
x = 70
|
||||||
|
},
|
||||||
|
money =
|
||||||
|
{
|
||||||
|
quantity = 100,
|
||||||
|
sprite = 35,
|
||||||
|
x = 0
|
||||||
|
},
|
||||||
|
jam =
|
||||||
|
{
|
||||||
|
quantity = 0,
|
||||||
|
sprite = 34,
|
||||||
|
x = 100
|
||||||
|
}
|
||||||
|
}
|
||||||
58
world.lua
58
world.lua
@@ -1,25 +1,20 @@
|
|||||||
|
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
|
||||||
|
|
||||||
ressources =
|
|
||||||
{
|
|
||||||
fruits =
|
|
||||||
{
|
|
||||||
quantity = 5,
|
|
||||||
sprite = 33,
|
|
||||||
x = 70
|
|
||||||
},
|
|
||||||
money =
|
|
||||||
{
|
|
||||||
quantity = 100,
|
|
||||||
sprite = 35,
|
|
||||||
x = 0
|
|
||||||
},
|
|
||||||
jam =
|
|
||||||
{
|
|
||||||
quantity = 0,
|
|
||||||
sprite = 34,
|
|
||||||
x = 100
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buildings = {
|
buildings = {
|
||||||
jam_workshop =
|
jam_workshop =
|
||||||
@@ -33,8 +28,8 @@ buildings = {
|
|||||||
city =
|
city =
|
||||||
{
|
{
|
||||||
sprite = 5,
|
sprite = 5,
|
||||||
inputs = {},
|
inputs = {jam = 1},
|
||||||
outputs = {}
|
outputs = {money = 1}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +67,7 @@ function new_worldtile(x, y, building)
|
|||||||
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)
|
||||||
for _,input in pairs(worldtile.building.inputs) do
|
for _,input in pairs(worldtile.building.inputs) do
|
||||||
@@ -81,3 +76,18 @@ function new_worldtile(x, y, building)
|
|||||||
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
|
||||||
Reference in New Issue
Block a user