Compare commits
7 Commits
18776cbb68
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab3107b5d9 | ||
|
|
42dec882fa | ||
| c4d08543e3 | |||
| f28a65d1f8 | |||
|
|
0f79131bd9 | ||
|
|
35b8ce3ef5 | ||
|
|
34d70d8be9 |
91
choco.lua
91
choco.lua
@@ -1,9 +1,27 @@
|
|||||||
|
function _init()
|
||||||
|
world_init()
|
||||||
|
playercontroler_init()
|
||||||
|
end
|
||||||
|
|
||||||
|
function _update()
|
||||||
|
world_update()
|
||||||
|
playercontroler_update()
|
||||||
|
end
|
||||||
|
|
||||||
|
function _draw()
|
||||||
|
cls(0)
|
||||||
|
map(0, 0, 0, 8, 64, 64)
|
||||||
|
camera(0,0)
|
||||||
|
draw_ressource_bar()
|
||||||
|
world_draw()
|
||||||
|
playercontroler_draw()
|
||||||
|
end
|
||||||
|
|
||||||
ressources =
|
ressources =
|
||||||
{
|
{
|
||||||
fruits =
|
fruit =
|
||||||
{
|
{
|
||||||
quantity = 5,
|
quantity = 55,
|
||||||
sprite = 33,
|
sprite = 33,
|
||||||
x = 70
|
x = 70
|
||||||
},
|
},
|
||||||
@@ -15,34 +33,12 @@ ressources =
|
|||||||
},
|
},
|
||||||
jam =
|
jam =
|
||||||
{
|
{
|
||||||
quantity = 0,
|
quantity = 100,
|
||||||
sprite = 34,
|
sprite = 34,
|
||||||
x = 100
|
x = 100
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function _init()
|
|
||||||
-- always start on white
|
|
||||||
col = 7
|
|
||||||
worldtiles = {}
|
|
||||||
init_worldtiles()
|
|
||||||
end
|
|
||||||
|
|
||||||
function _update()
|
|
||||||
-- press x for a random colour
|
|
||||||
if (btnp(5)) compute_effect_array(worldtiles)
|
|
||||||
end
|
|
||||||
|
|
||||||
function _draw()
|
|
||||||
cls(0)
|
|
||||||
map(0, 0, 0, 8, 64, 64)
|
|
||||||
camera(0,0)
|
|
||||||
draw_array(worldtiles)
|
|
||||||
draw_ressource_bar()
|
|
||||||
end
|
|
||||||
|
|
||||||
function draw_ressource_bar()
|
function draw_ressource_bar()
|
||||||
rectfill(0, 0, 127, 7, 1)
|
rectfill(0, 0, 127, 7, 1)
|
||||||
for _,res in pairs(ressources) do
|
for _,res in pairs(ressources) do
|
||||||
@@ -50,48 +46,3 @@ function draw_ressource_bar()
|
|||||||
print(res.quantity, res.x + 8, 1, 6)
|
print(res.quantity, res.x + 8, 1, 6)
|
||||||
end
|
end
|
||||||
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, sprite)
|
|
||||||
local worldtile = {}
|
|
||||||
worldtile.x = x
|
|
||||||
worldtile.y = y
|
|
||||||
worldtile.spr = sprite
|
|
||||||
worldtile.draw = function(this)
|
|
||||||
spr(worldtile.spr,worldtile.x*2*8,8+worldtile.y*2*8, 2, 2)
|
|
||||||
end
|
|
||||||
worldtile.compute_effet = function(this)
|
|
||||||
worldtile.spr = 4
|
|
||||||
end
|
|
||||||
return worldtile
|
|
||||||
end
|
|
||||||
|
|
||||||
function init_worldtiles()
|
|
||||||
for x=0,8 do
|
|
||||||
for y=0,8 do
|
|
||||||
sprite = mget(x*2, y*2)
|
|
||||||
flag = fget(sprite, 0)
|
|
||||||
if (flag) then
|
|
||||||
add(worldtiles, new_worldtile(x,y,sprite))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
45
choco.p8
45
choco.p8
@@ -1,6 +1,9 @@
|
|||||||
pico-8 cartridge // http://www.pico-8.com
|
pico-8 cartridge // http://www.pico-8.com
|
||||||
version 43
|
version 43
|
||||||
__lua__
|
__lua__
|
||||||
|
|
||||||
|
#include world.lua
|
||||||
|
#include playercontroler.lua
|
||||||
#include choco.lua
|
#include choco.lua
|
||||||
|
|
||||||
__gfx__
|
__gfx__
|
||||||
@@ -14,27 +17,37 @@ __gfx__
|
|||||||
00000000f2e88f52e828882f4fff3bff3ffbfff5f4ff556667655665fff51111216665ffffffffffffffffffccccccccfdccccccfdccccccfdd1ffffff1fffdd
|
00000000f2e88f52e828882f4fff3bff3ffbfff5f4ff556667655665fff51111216665ffffffffffffffffffccccccccfdccccccfdccccccfdd1ffffff1fffdd
|
||||||
00000000f2e88f528828882f5fff3bf3bffbff54f4f55555fff56665ff5221122165511ffffbfffffdcccccc00000000f5ffffff000000000000000000000000
|
00000000f2e88f528828882f5fff3bf3bffbff54f4f55555fff56665ff5221122165511ffffbfffffdcccccc00000000f5ffffff000000000000000000000000
|
||||||
00000000f2e88f542228882f5ff33ff3fffbfff57755666557756565ff1224232445111ffffb3fffffdccccc000000001cdfff1d000000000000000000000000
|
00000000f2e88f542228882f5ff33ff3fffbfff57755666557756565ff1224232445111ffffb3fffffdccccc000000001cdfff1d000000000000000000000000
|
||||||
00000000f2888f54444222ff4ff3bff33ff3fff5d556666657d56665ff2244433344115ff3fb3b3fff51515c00000000cccdddcc000000000000000000000000
|
00100100f2888f54444222ff4ff3bff33ff3fff5d556666657d56665ff2244433344115ff3fb3b3fff51515c00000000cccdddcc000000000000000000000000
|
||||||
00000000f28e8f444545ffff5ff3ffff3ffb3ff5d56676565dd56765ff2411113311155ffbfbbbffff41414c00000000cccccccc000000000000000000000000
|
000cc000f28e8f444545ffff5ff3ffff3ffb3ff5d56676565dd56765ff2411113311155ffbfbbbffff41414c00000000cccccccc000000000000000000000000
|
||||||
00000000f28881111145ffff5ffffffffffffff5f56666665ff51715ff551155551155fffbbb3ffff15555cc00000000cccccccc000000000000000000000000
|
000cc000f28881111145ffff5ffffffffffffff5f56666665ff51715ff551155551155fffbbb3ffff15555cc00000000cccccccc000000000000000000000000
|
||||||
00000000ff222f54411111ff5ff545f4ffffff54f56766765fffffffffff5555f551ffffffbb3ffff5cccccc00000000cccccccc000000000000000000000000
|
00100100ff222f54411111ff5ff545f4ffffff54f56766765fffffffffff5555f551ffffffbb3ffff5cccccc00000000cccccccc000000000000000000000000
|
||||||
00000000ff55ff74441828ff54544f545545f5f4f56756665ffffffffffffffffffffffffffb3fffdccccccc00000000cccccccc000000000000000000000000
|
00000000ff55ff74441828ff54544f545545f5f4f56756665ffffffffffffffffffffffffffb3fffdccccccc00000000cccccccc000000000000000000000000
|
||||||
00000000ff5fff64451111fff4ff4ff4ff4f44f4f51751115ffffffffffffffffffffffffffbbffffdcccccc00000000cccccccc000000000000000000000000
|
00000000ff5fff64451111fff4ff4ff4ff4f44f4f51751115ffffffffffffffffffffffffffbbffffdcccccc00000000cccccccc000000000000000000000000
|
||||||
00000000000000000222222000444400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
01100110000000000222222000444400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
000000000003bb000122221004aaaa40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
1c0000c10003bb000122221004aaaa40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000883b000188881049a9aaa4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
1000000100883b000188881049a9aaa4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000008888bb00186677049aa9aa4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0000000008888bb00186677049aa9aa4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000008e883b001e7771049aaa9a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0000000008e883b001e7771049aaa9a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
000000000888883001888810499aaaa4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
100000010888883001888810499aaaa4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
000000000888e8000188e81004999940000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
1c0000c10888e8000188e81004999940000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
00000000000000000111111000444400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
01100110000000000111111000444400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
__gff__
|
||||||
|
0001010202040408080000000000000000010102020404080800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
__map__
|
__map__
|
||||||
0909090909090909090903040909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0909090909090909090903040909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
091909090909090a0909131409090a0900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
091909090909090a0909131409090a0900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
09090a0909090909090909090909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0909070809090909090909090909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
09090909090901020909090909090c1c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
09091718090909090909090909090c1c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
09070809090911120909190909091a0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
09090909090901020909190909091a0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0917180909090909090909090a090f0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0909090a09091112090909090a090f0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0909090909090909090909090909090e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0909090909090909090909090909090e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
090909090a090506090909190909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0919090909090909090909090909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0909090909091516090909090909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0a09090905060909090919090909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
090909091516090a090909090909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0909091909090909090909090708090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0909090909090a09090909091718090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0909090909090909090909090909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0909090909090909090909090909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0909090909090909090909090909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0909090909090909090909090909090900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
|||||||
29
playercontroler.lua
Normal file
29
playercontroler.lua
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
function playercontroler_init()
|
||||||
|
mposx=0
|
||||||
|
mposy=0
|
||||||
|
poke(0x5F2D,1)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function playercontroler_update()
|
||||||
|
mposx=stat(32)
|
||||||
|
mposy=stat(33)
|
||||||
|
cposx=mposx-4
|
||||||
|
cposy=mposy-4
|
||||||
|
ccellx=flr(mposx/16)
|
||||||
|
ccelly=flr((mposy-8)/16)
|
||||||
|
|
||||||
|
sprite = mget(ccellx*2, ccelly*2)
|
||||||
|
flag = fget(sprite)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function playercontroler_draw()
|
||||||
|
spr(16, cposx, cposy)
|
||||||
|
rect(ccellx*16,(ccelly*16)+8,(ccellx+1)*16, ((ccelly+1)*16)+8,7)
|
||||||
|
|
||||||
|
print("mouse pos:"..mposx..", "..mposy,5,100,0)
|
||||||
|
print("cell pos:"..ccellx..", "..ccelly,5,110,0)
|
||||||
|
print("flag:"..flag,5,120,0)
|
||||||
|
|
||||||
|
end
|
||||||
119
world.lua
Normal file
119
world.lua
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
function world_init()
|
||||||
|
worldtiles = {}
|
||||||
|
--test start
|
||||||
|
bob = build(3,2,buildings.jam_workshop)
|
||||||
|
bob = replace(bob, buildings.city)
|
||||||
|
--destroy(get_worldtile(3,2))
|
||||||
|
--test end
|
||||||
|
end
|
||||||
|
|
||||||
|
function world_update()
|
||||||
|
if (btnp(4)) build(3,2,buildings.jam_workshop)
|
||||||
|
if (btnp(5)) compute_effect_array(worldtiles)
|
||||||
|
if (time()%1 == 0) compute_effect_array(worldtiles)
|
||||||
|
end
|
||||||
|
|
||||||
|
function world_draw()
|
||||||
|
draw_array(worldtiles)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
buildings =
|
||||||
|
{
|
||||||
|
jam_workshop =
|
||||||
|
{
|
||||||
|
sprite = 1,
|
||||||
|
inputs =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
type = "fruit",
|
||||||
|
quantity = 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
outputs =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
type = "jam",
|
||||||
|
quantity = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
city =
|
||||||
|
{
|
||||||
|
sprite = 5,
|
||||||
|
inputs =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
type = "jam",
|
||||||
|
quantity = 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
outputs =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
type = "money",
|
||||||
|
quantity = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
has_ressource = true
|
||||||
|
for _,input in pairs(worldtile.building.inputs) do
|
||||||
|
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
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user