2 |
-- (c) 2002 Petr Machata/ant_39 |
-- (c) 2002 Petr Machata/ant_39 |
3 |
-- Licensed under GPL v2.0 or above |
-- Licensed under GPL v2.0 or above |
4 |
|
|
5 |
floortile = "fl-sand" |
dofile(enigma.FindDataFile("levels/ant.lua")) |
|
bordertile = "st-rock1" |
|
|
walltile = bordertile |
|
|
|
|
|
levelw = 20 |
|
|
levelh = 13 |
|
|
|
|
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
|
|
|
|
|
create_world(levelw, levelh) |
|
|
fill_floor(floortile, 0, 0, level_width, level_height) |
|
|
|
|
|
draw_border(bordertile) |
|
6 |
|
|
7 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
|
--constants and preparations |
|
|
x1 = 6 |
|
|
y1 = 0 |
|
|
|
|
8 |
--turtle state |
--turtle state |
9 |
ingame = nil |
ingame = nil |
10 |
|
|
15 |
command_west = enigma.WEST |
command_west = enigma.WEST |
16 |
command_east = enigma.EAST |
command_east = enigma.EAST |
17 |
|
|
18 |
--default command value |
--work |
19 |
command=command_clean |
command=command_clean |
20 |
|
|
21 |
|
--pad center |
22 |
|
cent = {}; function set_pad_center(x, y) cent.x, cent.y = x, y end |
23 |
|
|
24 |
|
--magic stone position |
25 |
|
mags = {}; function set_magic_stone(x, y) mags.x, mags.y = x, y end |
26 |
|
|
27 |
--table to translate current command to stone properties |
--table to translate current command to stone properties |
28 |
|
--x, y is current direction indicator position - floor |
29 |
|
--face is face of stone in buffer |
30 |
|
--params are parameters of buffer stone |
31 |
function new_command(flx0, fly0, face0, params0) |
function new_command(flx0, fly0, face0, params0) |
32 |
ret = {} |
ret = {} |
33 |
ret.face = face0 |
ret.face = face0 |
38 |
end |
end |
39 |
|
|
40 |
buftable = {} |
buftable = {} |
|
buftable [command_clean] = new_command(nil, nil, "st-grate1", {}) |
|
|
buftable [command_north] = new_command(x1-3, y1+4, "st-bolder", {direction=NORTH}) |
|
|
buftable [command_south] = new_command(x1-3, y1+8, "st-bolder", {direction=SOUTH}) |
|
|
buftable [command_east] = new_command(x1-1, y1+6, "st-bolder", {direction=EAST }) |
|
|
buftable [command_west] = new_command(x1-5, y1+6, "st-bolder", {direction=WEST }) |
|
|
|
|
|
--buffer to remember commands |
|
|
commandbuffer={n=20} |
|
41 |
|
|
42 |
--command selection via the trigger "gamepad" |
--command selection via the trigger "gamepad" |
43 |
function setcommand(newcmd) |
function setcommand(newcmd) |
45 |
local clx0, cly0 = buftable[command].x, buftable[command].y |
local clx0, cly0 = buftable[command].x, buftable[command].y |
46 |
|
|
47 |
if (not(ingame)) then |
if (not(ingame)) then |
48 |
if ((clx0 or cly0) ~= nil) then set_floor(floortile, clx0, cly0); end |
if ((clx0 or cly0) ~= nil) then set_floor("fl-sand", clx0, cly0); end |
49 |
if ((flx0 or fly0) ~= nil) then set_floor("fl-normal", flx0, fly0); end |
if ((flx0 or fly0) ~= nil) then set_floor("fl-normal", flx0, fly0); end |
50 |
command = newcmd |
command = newcmd |
51 |
end |
end |
58 |
function commandclean() setcommand(command_clean); end |
function commandclean() setcommand(command_clean); end |
59 |
|
|
60 |
--magic stones eyecandy |
--magic stones eyecandy |
61 |
function draw_magic() |
function magic_stone(face) |
62 |
enigma.KillStone(x1, y1+12) |
enigma.KillStone(mags.x, mags.y) |
63 |
set_stone("st-magic", x1, y1+12) |
set_stone(face, mags.x, mags.y) |
|
end |
|
|
|
|
|
function erase_magic() |
|
|
enigma.KillStone(x1, y1+12) |
|
|
set_stone(bordertile, x1, y1+12) |
|
64 |
end |
end |
65 |
|
|
66 |
function invalid_magic() |
function draw_magic() magic_stone("st-magic") end |
67 |
enigma.KillStone(x1, y1+12) |
function erase_magic() magic_stone("st-rock1") end |
68 |
set_stone("st-death", x1, y1+12) |
function invalid_magic() magic_stone("st-death") end |
|
end |
|
69 |
|
|
70 |
--bufferworks |
--bufferworks |
71 |
first_free_element = function (buf,i) return buf[i] ~= command_clean end |
first_free_element = function (buf,i) return buf[i].command ~= command_clean end |
72 |
first_command = function (buf,i) return buf[i] == command_clean end |
first_command = function (buf,i) return buf[i].command == command_clean end |
73 |
|
|
74 |
|
function buffer_create(buf) |
75 |
|
local ret = {} |
76 |
|
ret.n = 0 |
77 |
|
return ret |
78 |
|
end |
79 |
|
|
80 |
function draw_buffer() |
function buffer_add_item(buf, x,y) |
81 |
for i=1,commandbuffer.n do |
buf.n = buf.n+1 |
82 |
local x,y = i,1 |
buf[buf.n] = {} |
83 |
while (x>5) do x = x-5; y = y+1; end |
buf[buf.n].x = x |
84 |
if (y>2) then y = y+7; end |
buf[buf.n].y = y |
85 |
x,y = x1-6+x, y1+y |
buf[buf.n].command = command_clean |
86 |
|
end |
87 |
|
|
88 |
local tab = buftable[commandbuffer[i]] |
function draw_buffer(buf, tab) |
89 |
|
for i=1,buffer_items.n do |
90 |
|
local x, y, cmd = buf[i].x, buf[i].y, buf[i].command |
91 |
|
local tab = tab[cmd] |
92 |
|
|
93 |
enigma.KillStone(x, y) |
enigma.KillStone(x, y) |
94 |
set_stone(tab.face, x, y, tab.par) |
set_stone(tab.face, x, y, tab.par) |
95 |
end |
end |
96 |
end |
end |
97 |
|
|
98 |
function generic_buf_test(buf,test) |
function buffer_generic_test(buf,test) |
99 |
local i=1 |
local i=1 |
100 |
while test(buf,i) do --(commandbuffer[i] ~= command_clean) do |
while test(buf,i) do |
101 |
i=i+1 |
i=i+1 |
102 |
if (not(buf[i])) then |
if (not(buf[i])) then |
103 |
return nil |
return nil |
106 |
return i |
return i |
107 |
end |
end |
108 |
|
|
109 |
|
function buffer_push_command(buf) |
110 |
|
local i = buffer_generic_test(buf, first_free_element) |
111 |
|
|
112 |
|
if (i) then |
113 |
|
buf[i].command = command |
114 |
|
end |
115 |
|
end |
116 |
|
|
117 |
|
function buffer_pop_command(buf) |
118 |
|
local i = buffer_generic_test(buf, first_command) |
119 |
|
|
120 |
|
if (i) then |
121 |
|
local ret = buf[i].command |
122 |
|
buf[i].command = command_clean |
123 |
|
return ret |
124 |
|
else |
125 |
|
return nil |
126 |
|
end |
127 |
|
end |
128 |
|
|
129 |
|
function buffer_clear_commands(buf) |
130 |
|
for i=1,buf.n do |
131 |
|
buf[i].command = command_clean |
132 |
|
end |
133 |
|
end |
134 |
|
|
135 |
|
-- wrappers to be called by enigma and map drawing function |
136 |
|
function additem(x,y) |
137 |
|
buffer_add_item(buffer_items, x, y) |
138 |
|
end |
139 |
|
|
140 |
|
buffer_items = buffer_create() |
141 |
|
|
142 |
function addcommand() |
function addcommand() |
143 |
if (not(ingame)) then |
if (not(ingame)) then |
144 |
local i = generic_buf_test(commandbuffer, first_free_element) |
buffer_push_command(buffer_items) |
145 |
|
draw_buffer(buffer_items, buftable) |
146 |
if (i) then |
commandclean() |
|
commandbuffer[i] = command |
|
|
draw_buffer() |
|
|
commandclean() |
|
|
end |
|
147 |
end |
end |
148 |
end |
end |
149 |
|
|
150 |
function clearbuffer() |
function clearbuffer() |
151 |
ingame = nil |
ingame = nil |
152 |
for i=1,commandbuffer.n do |
buffer_clear_commands(buffer_items) |
153 |
commandbuffer[i] = command_clean |
draw_buffer(buffer_items, buftable) |
|
end |
|
|
draw_buffer() |
|
154 |
erase_magic() |
erase_magic() |
155 |
end |
end |
156 |
|
|
157 |
counter = 0 |
counter = 0 |
|
|
|
158 |
function boldercommand(startcommand) |
function boldercommand(startcommand) |
159 |
if (startcommand==1) then |
if (startcommand==1) then |
160 |
counter = 0 |
counter = 0 |
161 |
end |
end |
162 |
|
|
163 |
if (mod(counter,2) == 0) then --trigger works twice: upon enter and upon leave |
if (mod(counter,2) == 0) then --trigger works twice: upon enter and upon leave |
164 |
local i = generic_buf_test(commandbuffer, first_command) |
local cmd = buffer_pop_command(buffer_items) |
165 |
|
|
166 |
if (i) then |
if (cmd) then |
167 |
set_attribs(enigma.GetNamedObject("bolder1"), buftable[commandbuffer[i]].par) |
set_attribs(enigma.GetNamedObject("bolder1"), buftable[cmd].par) |
168 |
commandbuffer[i] = command_clean |
draw_buffer(buffer_items, buftable) |
|
draw_buffer() |
|
169 |
draw_magic() |
draw_magic() |
170 |
else |
else |
171 |
invalid_magic() |
invalid_magic() |
178 |
function startbolder() |
function startbolder() |
179 |
if (not(ingame)) then |
if (not(ingame)) then |
180 |
ingame = 1 |
ingame = 1 |
181 |
boldercommand(1) |
boldercommand(1) |
182 |
end |
end |
183 |
end |
end |
184 |
|
|
185 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
186 |
-- and finally, the map itself |
-- and finally, the map itself |
187 |
|
cells={} |
188 |
-- arena |
cells[" "]=cell{floor={face="fl-sand"}} |
189 |
draw_stones(walltile, {x1,y1+1},{0,1},5) |
cells["#"]=cell{parent={cells[" "]},stone={face="st-rock1"}} |
190 |
draw_stones(walltile, {x1,y1+7},{0,1},5) |
cells["x"]=cell{parent={cells[" "]},stone={face="st-grate1"}} |
191 |
draw_stones(walltile, {x1+10,y1+5}, {0,-1}, 3) |
cells["!"]=cell{parent={cells["x"], additem}} |
192 |
draw_stones(walltile, {x1+10,y1+7}, {0,1}, 3) |
cells["a"]=cell{parent={cells[" "]},stone={face="st-switch", attr={action="callback", target="addcommand"}}} |
193 |
set_stone("st-bolder", x1+3, y1+6, {name="bolder1", direction=WEST}) |
cells["b"]=cell{parent={cells[" "]},stone={face="st-switch", attr={action="callback", target="startbolder"}}} |
194 |
draw_stones(walltile, {x1+1,y1+5}, {1,0}, 2) |
cells["c"]=cell{parent={cells[" "]},stone={face="st-switch", attr={action="callback", target="clearbuffer"}}} |
195 |
draw_stones(walltile, {x1+1,y1+7}, {1,0}, 2) |
cells["d"]=cell{parent={cells[" "]},item={face="it-trigger", attr={action="callback", target="commandwest"}}} |
196 |
|
cells["e"]=cell{parent={cells[" "]},item={face="it-trigger", attr={action="callback", target="commandnorth"}}} |
197 |
-- triggers |
cells["f"]=cell{parent={cells[" "]},item={face="it-trigger", attr={action="callback", target="commandeast"}}} |
198 |
triggers = { |
cells["g"]=cell{parent={cells[" "]},item={face="it-trigger", attr={action="callback", target="commandsouth"}}} |
199 |
{ 1, 1}, { 8, 1}, {12, 1}, |
cells["+"]=cell{parent={cells[" "]},item={face="it-document", attr={text="Welcome to the control room. Use the triggers and switches to plan the movement of the turtle. The switches are, clockwise: Add, Run and Restart."}}} |
200 |
{ 2, 2}, { 9, 2}, {11, 2}, {12, 2}, |
cells["*"]=cell{parent={cells[" "], set_pad_center},item={face="ac-blackball", attr={player=0}, actor=1}} |
201 |
{ 1, 3}, { 4, 3}, { 7, 3}, |
cells["~"]=cell{parent={cells["#"], set_magic_stone}} |
202 |
{ 5, 4}, { 2, 4}, |
cells["<"]=cell{parent={cells[" "]},stone={face="st-bolder", attr={name="bolder1", direction=enigma.WEST}}} |
203 |
{ 3, 5}, { 8, 5}, |
cells["1"]=cell{parent={cells[" "]},stone={face="st-oxyd", attr={flavor="a", color="0"}}} |
204 |
{ 7, 6}, {12, 6}, |
cells["2"]=cell{parent={cells[" "]},stone={face="st-oxyd", attr={flavor="a", color="1"}}} |
205 |
{ 3, 7}, { 6, 7}, |
cells["t"]=cell{parent={cells[" "]},item={face="it-trigger", attr={action="callback", target="boldercommand"}}} |
206 |
{ 1, 8}, { 5, 8}, |
|
207 |
{ 2, 9}, { 7, 9}, |
level = { |
208 |
{ 1,10}, { 9,10}, {11,10}, {12,10}, |
"########1########2##", |
209 |
{ 1,11}, { 8,11}, {12,11} |
"#!!!!!#t t t#", |
210 |
|
"#!!!!!# t t tt#", |
211 |
|
"#####a#t t t # #", |
212 |
|
"# +# t t # #", |
213 |
|
"# e ###t t # #", |
214 |
|
"# d*f b< t t#", |
215 |
|
"# g ###t t # #", |
216 |
|
"# #t t # #", |
217 |
|
"#####c# t t # #", |
218 |
|
"#!!!!!#t t tt#", |
219 |
|
"#!!!!!#t t t#", |
220 |
|
"######~#1########2##", |
221 |
} |
} |
222 |
|
|
|
for key, coord in triggers do |
|
|
set_item("it-trigger", x1+coord[1], y1+coord[2], {action="callback", target="boldercommand"}) |
|
|
end |
|
|
|
|
|
-- control room |
|
|
draw_stones(walltile, {x1-1,y1+3}, {-1,0}, 5) |
|
|
draw_stones(walltile, {x1-1,y1+9}, {-1,0}, 5) |
|
|
set_stone("st-switch", x1-1, y1+3, {action="callback", target="addcommand"}) |
|
|
set_stone("st-switch", x1+2, y1+6, {action="callback", target="startbolder"}) |
|
|
set_stone("st-switch", x1-1, y1+9, {action="callback", target="clearbuffer"}) |
|
|
set_item("it-trigger", x1-4, y1+6, {action="callback", target="commandwest"}) |
|
|
set_item("it-trigger", x1-2, y1+6, {action="callback", target="commandeast"}) |
|
|
set_item("it-trigger", x1-3, y1+5, {action="callback", target="commandnorth"}) |
|
|
set_item("it-trigger", x1-3, y1+7, {action="callback", target="commandsouth"}) |
|
|
|
|
|
document(x1-1, y1+4, "Welcome to the control room. Use the triggers and switches to plan the movement of the turtle. The switches are, clockwise: Add, Run and Restart.") |
|
223 |
|
|
224 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
225 |
-- oxyd, marble, init |
-- init |
226 |
|
|
227 |
clearbuffer() |
levelw = 20 |
228 |
|
levelh = 13 |
229 |
|
create_world(levelw, levelh) |
230 |
|
|
231 |
set_actor("ac-blackball", x1-2.5, y1+6.5, {player=0}) |
draw_map(0, 0, level) |
232 |
|
|
233 |
oxyd_default_flavor="a" |
buftable [command_clean] = new_command(nil, nil, "st-grate1", {}) |
234 |
oxyd (x1+2,y1) |
buftable [command_north] = new_command(cent.x, cent.y-2, "st-bolder", {direction=NORTH}) |
235 |
oxyd (x1+2,y1+12) |
buftable [command_south] = new_command(cent.x, cent.y+2, "st-bolder", {direction=SOUTH}) |
236 |
oxyd (x1+11,y1) |
buftable [command_east] = new_command(cent.x+2, cent.y, "st-bolder", {direction=EAST }) |
237 |
oxyd (x1+11,y1+12) |
buftable [command_west] = new_command(cent.x-2, cent.y, "st-bolder", {direction=WEST }) |
238 |
|
|
239 |
|
clearbuffer() |
240 |
oxyd_shuffle() |
oxyd_shuffle() |
241 |
|
|
242 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |