1maps = {
2	{
3		title = "first:Cats cant swim";
4		map = {
5'                                        ';
6'                                        ';
7'                                        ';
8'                                        ';
9'                                        ';
10'                                        ';
11'                                        ';
12'                                        ';
13'                                        ';
14'                                        ';
15'                                        ';
16'                                        ';
17'                                        ';
18'                                        ';
19'                                        ';
20'                                        ';
21'                                        ';
22'                                        ';
23'                                        ';
24'                                        ';
25'                                        ';
26'                                        ';
27'                                        ';
28'>                                       ';
29'#############            ###############';
30'            #            #              ';
31'            #            #              ';
32'            #            #              ';
33'            #            #              ';
34'            #~~~~~~~~~~~~#              ';
35};
36},
37	{
38		title = "2dots:Be careful!",
39		map = {
40'                                        ';
41'                                        ';
42'                                        ';
43'                                        ';
44'                                        ';
45'                                        ';
46'                                        ';
47'                                        ';
48'                                        ';
49'                                        ';
50'                                        ';
51'                                        ';
52'                                        ';
53'                                        ';
54'                                        ';
55'                                        ';
56'                                        ';
57'                                        ';
58'                                        ';
59'                                        ';
60'                                        ';
61'                                        ';
62'                                        ';
63'>             *         *               ';
64'########################################';
65'                                        ';
66'                                        ';
67'                                        ';
68'                                        ';
69'                                        ';
70		};
71	},
72	{
73		title = "tramp:Tramboline",
74		map = {
75'                                        ';
76'                                        ';
77'                                        ';
78'                                        ';
79'                                        ';
80'                                        ';
81'                                        ';
82'                                        ';
83'                                        ';
84'                                        ';
85'                                        ';
86'                                        ';
87'                                        ';
88'                                        ';
89'                                        ';
90'                        %%%%%%          ';
91'                                        ';
92'                                        ';
93'                %%%%%%                  ';
94'                                        ';
95'                                        ';
96'        %%%%%%                          ';
97'                                        ';
98'>                                       ';
99'########                        ########';
100'       #                        #       ';
101'       #                        #       ';
102'       #                        #       ';
103'       #                        #       ';
104'       #~~~~~~~~~~~~~~~~~~~~~~~~#       ';
105};
106},
107	{
108		title = "ladder:Ladder";
109		map = {
110'                                        ';
111'                                        ';
112'                                        ';
113'                                        ';
114'                                        ';
115'                                        ';
116'                                        ';
117'                                        ';
118'                                        ';
119'                                        ';
120'                                        ';
121'                                        ';
122'                                        ';
123'                                        ';
124'                                        ';
125'                                        ';
126'                                        ';
127'                                        ';
128'                                        ';
129'                                        ';
130'                                ########';
131'                        *########       ';
132'                *########               ';
133'>       #########                       ';
134'#########                               ';
135'                                        ';
136'                                        ';
137'                                        ';
138'                                        ';
139'                                        ';
140};
141
142},
143	{
144		title = "laser:Laser";
145		map = {
146'                                        ';
147'                                        ';
148'                                        ';
149'                                        ';
150'                                        ';
151'                                        ';
152'                                        ';
153'                                        ';
154'                                        ';
155'                                        ';
156'                                        ';
157'                                        ';
158'                                        ';
159'                                        ';
160'                                        ';
161'                                        ';
162'                                        ';
163'                                        ';
164'                                        ';
165'>                  *                    ';
166'########################################';
167'                                        ';
168'                                        ';
169'                                        ';
170'                                        ';
171'                                        ';
172'                                        ';
173'                                        ';
174'                                        ';
175'                                        ';
176};
177life = function(s)
178	if hero.x < 10 * BW then
179		s.laser = false
180	end
181	if hero.x > 10 * BW and hero:state() == WALK then
182		s.laser = true
183	end
184	if s.laser then
185		laser.on(19, 0, 19);
186	else
187		laser.off()
188	end
189end
190},
191	{
192		title = "trap:Dont be so fast";
193		map = {
194'                                        ';
195'                                        ';
196'                                        ';
197'                                        ';
198'                                        ';
199'                                        ';
200'                                        ';
201'                                        ';
202'                                        ';
203'                                        ';
204'                                        ';
205'                                        ';
206'                                        ';
207'                                        ';
208'                                        ';
209'                                        ';
210'                                        ';
211'                                        ';
212'                                        ';
213'>                                       ';
214'#########        ######        #########';
215'#                                       ';
216'#                                       ';
217'#                                       ';
218'#                                       ';
219'#                                       ';
220'#                                       ';
221'#                                       ';
222'#                                       ';
223'#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
224};
225life = function(s)
226	if not s.step then
227		s.step = 0
228	end
229	s.step = s.step + 1
230	local y, x
231	y = 20
232	for x = 16, 23 do
233		local c = map:cell(x, y)
234		if math.floor(s.step / 50) % 2 == 0 then
235			c[1] = BLOCK
236		else
237			c[1] = 0
238		end
239	end
240end
241},
242
243	{
244		title = "panic:Dont stop!";
245		map = {
246'         #####   #####   #####          ';
247'          ###     ###     ###           ';
248'           *       *       *            ';
249'                                        ';
250'          # #     # #     # #           ';
251'          # #     # #     # #           ';
252'########### ####### ####### ############';
253'                                        ';
254'                                        ';
255'                                        ';
256'                                        ';
257'                                        ';
258'                                        ';
259'                                        ';
260'                                        ';
261'                                        ';
262'                                        ';
263'                                        ';
264'                                        ';
265'>                                       ';
266'########### ############### ############';
267'                                        ';
268'                                        ';
269'                                        ';
270'                                        ';
271'                                        ';
272'                                        ';
273'                                        ';
274'                                        ';
275'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
276};
277life = function(s)
278	if not s.y then
279		s.y = 3
280	end
281	local c = map:cell(11, s.y)
282	c[1] = 0
283	c = map:cell(27, s.y)
284	c[1] = 0
285
286	c = map:cell(19, s.y)
287	c[1] = 0
288
289	s.y = s.y + 1
290
291	if s.y >= 29 then
292		s.y = 3
293	end
294	c = map:cell(11, s.y)
295	c[1] = EMERGENCY
296
297	c = map:cell(19, s.y)
298	c[1] = EMERGENCY
299
300	c = map:cell(27, s.y)
301	c[1] = EMERGENCY
302end
303},
304
305	{
306		title = "walk:Walk";
307		map = {
308'                                        ';
309'                                        ';
310'                                        ';
311'                                        ';
312'                                        ';
313'                                        ';
314'                                        ';
315'                                        ';
316'                                        ';
317'                                        ';
318'                                        ';
319'                                        ';
320'                                        ';
321'                                        ';
322'                                        ';
323'  ###########^^^^^^^^^^^^^###########   ';
324'                                        ';
325'                                        ';
326'                                        ';
327'>                                       ';
328'#########                      #########';
329'        #                      #        ';
330'        #                      #        ';
331'        #                      #        ';
332'        #                      #        ';
333'        #                      #        ';
334'        #                      #        ';
335'        #                      #        ';
336'        #                      #        ';
337'~~~~~~~~#                      #        ';
338};
339life = function(s)
340	local c
341	if not s.x then
342		s.x = 9
343	end
344	local x
345	for x = 9, 9 + 21 do
346		c = map:cell(x, 20)
347		c[1] = 0
348	end
349	local sx = math.floor(s.x)
350	x = sx - 4
351	for x = sx - 3, sx do
352		if x >= 9 and x < 32 then
353			c = map:cell(x, 20)
354			c[1] = BLOCK
355		end
356	end
357	s.x = s.x + 0.2
358	if s.x > 38 then
359		s.x = 9
360	end
361end
362},
363
364	{
365		title = "jump:Jump!";
366		map = {
367'                                        ';
368'                                        ';
369'                                        ';
370'                                        ';
371'                                        ';
372'                                        ';
373'                                        ';
374'                                        ';
375'                                        ';
376'                                        ';
377'                                        ';
378'                                        ';
379'                                        ';
380'                                        ';
381'                                        ';
382'###############^^^^^^^^^^^##############';
383'                                        ';
384'                                        ';
385'                                        ';
386'>                                       ';
387'#########                      #########';
388'        #*                    *#        ';
389'        ########################        ';
390'                                        ';
391'                                        ';
392'                                        ';
393'                                        ';
394'                                        ';
395'                                        ';
396'                                        ';
397};
398life = function(s)
399	local c
400	if not s.laser then
401		s.laser = 50
402	end
403	s.laser = s.laser + 1
404	if math.floor(s.laser / 80) % 2 == 1 then
405		laser.on(10, 21, -20);
406	else
407		laser.off()
408	end
409end
410},
411
412	{
413		title = "monolit:Monolith";
414		map = {
415'                                        ';
416'                                        ';
417'                                        ';
418'                                        ';
419'                                        ';
420'                                        ';
421'              #############             ';
422'              #############             ';
423'              #############             ';
424'              #############             ';
425'              #############             ';
426'              #############             ';
427'              #############             ';
428'              #############             ';
429'              #############             ';
430'              #############             ';
431'              #############             ';
432'              #############             ';
433'              #############             ';
434'>             #############             ';
435'########################################';
436'                                        ';
437'                                        ';
438'                                        ';
439'                                        ';
440'                                        ';
441'                                        ';
442'                                        ';
443'                                        ';
444'                                        ';
445};
446life = function(s)
447	if hero:state() == WALK and hero.speed_x == 0 then
448		if not s.trig then
449			s.trig = 0
450		end
451	else
452		s.trig = false
453	end
454	if s.trig and not s.fall then
455		s.trig = s.trig + 1
456		if s.trig > 150 then s.fall = 6 end
457	end
458	if s.fall and s.fall < 18 then
459		local y = math.floor(s.fall)
460		local x
461		for x = 14, 26 do
462			local c = map:cell(x, y)
463			c[1] = 0
464		end
465		s.fall = s.fall + 0.1
466	end
467end
468},
469	   	{
470		title = "moving:Moving";
471		map = {
472'                                        ';
473'                                        ';
474'                                        ';
475'                                        ';
476'                                        ';
477'                                        ';
478'                                        ';
479'                                        ';
480'                                        ';
481'                                        ';
482'                                        ';
483'                                        ';
484'                                        ';
485'                                        ';
486'                                        ';
487'                                        ';
488'                                        ';
489'                                        ';
490'                                        ';
491'>                                       ';
492'######                            ######';
493'     ##############################     ';
494'                                        ';
495'                                        ';
496'                                        ';
497'                                        ';
498'                                        ';
499'                                        ';
500'                                        ';
501'                                        ';
502};
503life = function (s)
504   local i
505   if not s.x then
506      s.x = {}
507      s.x[1] = 6 * BW
508      s.x[2] = 15 * BW
509      s.x[3] = 24 * BW
510      s.speed = 1
511   end
512   for i = 1, 3 do
513      sprite.fill (sprite.screen(), s.x[i], 20 * BW, BW, BW, 'red')
514      if hero:collision(s.x[i], 20 * BW, BW, BW) and hero:alive() then
515	 hero:state(FLY)
516      end
517      s.x[i] = s.x[i] + s.speed
518   end
519   if s.x[1] == 15 * BW or s.x[1] == 6 * BW then
520      s.speed = s.speed * -1
521   end
522end
523},
524
525	{
526		title = "rope:Rope";
527		map = {
528'             +                        * ';
529'                                        ';
530'                                        ';
531'                                        ';
532' ====-----------------------------------';
533'                                        ';
534'                                        ';
535'                                        ';
536'     ====                               ';
537'                                        ';
538'                                        ';
539'                                        ';
540' ====                                   ';
541'                                        ';
542'                                        ';
543'                                        ';
544'     ====                               ';
545'                                        ';
546'                                        ';
547'>                                       ';
548'#######                          #######';
549'    #                              #    ';
550'    #                              #    ';
551'    #                              #    ';
552'    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#    ';
553'    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#    ';
554'    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#    ';
555'    ################################    ';
556'                                        ';
557'                                        ';
558};
559},
560	{
561		title = "teleports:Teleports";
562		map = {
563'                                        ';
564'                                        ';
565'                                        ';
566'                                        ';
567'                                        ';
568'                                        ';
569'                                        ';
570'                                        ';
571'                                        ';
572'                                        ';
573'                                        ';
574'                                        ';
575'                                        ';
576'                                        ';
577'        ###                  ###        ';
578'                                        ';
579'                                        ';
580'                                        ';
581'                                        ';
582'>       xxx                             ';
583'###########                  ###########';
584'                                        ';
585'                                        ';
586'              +                         ';
587'             #####                      ';
588'                                        ';
589'                                        ';
590'                                        ';
591'                                        ';
592'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
593};
594life = function(s)
595	local x = 8
596	local y = 16
597	local c = 'blue'
598	if not tel_trigger then c = 'white' end
599	tel_trigger = not tel_trigger
600	sprite.fill(sprite.screen(), x * BW, y * BH - BH, 3 * BW, 5 * BH, c);
601
602	if hero:collision((x + 1) * BW, (y + 2)* BH, BW, 1 * BH) then
603		hero.x = 30*BW + BW/2 - hero.dir * (3*BW) - hero.w/2
604		hero.speed_x = - hero.speed_x
605		hero.dir = -1
606		sound.play(teleport_snd)
607	end
608	x = 29
609	sprite.fill(sprite.screen(), x * BW, y * BH - BH, 3 * BW, 5 * BH, c);
610	if hero:collision((x + 1) * BW, (y + 2)* BH, BW, 1 * BH) then
611		hero.x = 9*BW + BW/2 - hero.dir * (3*BW) - hero.w/2
612		hero.speed_x = - hero.speed_x
613		hero.dir = -1
614		sound.play(teleport_snd)
615	end
616end
617},
618
619	{
620		title = "black:Dont afraid";
621		color = 'black';
622		map = {
623'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
624'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
625'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
626'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
627'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
628'                                        ';
629'                                        ';
630'                                        ';
631'                                 #######';
632'                                 #     #';
633'                                 #     #';
634'                                 #     #';
635'                                 #     #';
636'                                 #     #';
637'                                 #     #';
638'                                 #     #';
639'                                 #     #';
640'                                 #     #';
641'                                 #     #';
642'>                                #     #';
643'#######     #####     #####      #     #';
644'                                 #######';
645'                                        ';
646'                                        ';
647'                                        ';
648'      ------####-------###              ';
649'             ###       ###              ';
650'             ###       ###  ###         ';
651'+        *   ###   *   ###  #*#         ';
652'########################################';
653};
654},
655	{
656		title = "lift:Lift";
657		color = 'white';
658		map = {
659'                                        ';
660'                                        ';
661'                                        ';
662'                                        ';
663'                                        ';
664'                                        ';
665'                                        ';
666'                                        ';
667'                                        ';
668'                                        ';
669'                                        ';
670'                                        ';
671'                                        ';
672'                                        ';
673'                                        ';
674'                            ====########';
675'                                *       ';
676'                                        ';
677'                                        ';
678'                                        ';
679'                                        ';
680'                                        ';
681'                                        ';
682'                                        ';
683'                                        ';
684'                                        ';
685'                                        ';
686'                                        ';
687'>                               *       ';
688'########################################';
689};
690life = function(s)
691	local y = 29 * BH
692	local x = 28 * BW
693	local draw_lift = function(s)
694		sprite.fill(sprite.screen(), x, s.y, 64, 4, 'black')
695	end
696
697	if hero.x >= 29 * BW then
698		laser.on(32, 17, 11);
699	else
700		laser.off()
701	end
702
703	if not s.y then s.y = y end
704	if s.y == 15 * BH then return end
705	if (hero.y + hero.h) - BH <= s.y and hero.x >= x and (hero.x + hero.w) <= x + 64 then
706		if not s.lift and hero:state() ~= WALK or math.abs(hero.speed_x) > 0 then
707			return
708		end
709		s.lift = true
710		if s.y ~= 15 * BH then
711			hero.y = s.y - hero.h - 1
712			hero:state(WALK)
713			hero.speed_x = 0
714		end
715	end
716	if s.lift then
717		s.y = s.y - 1
718		if s.y <= 15 * BH then s.y = 15 * BH end
719		draw_lift(s)
720	end
721end
722
723},
724
725	{
726		title = "snake:Snake";
727		map = {
728'                                        ';
729'                                        ';
730'                                        ';
731'                                        ';
732'                                        ';
733'                                        ';
734'                                        ';
735'                                        ';
736'########################################';
737'                                       #';
738'                                       #';
739'                                       #';
740'                                       #';
741'                                       #';
742'>                                      #';
743'#################################      #';
744'                                       #';
745'                                       #';
746'                                       #';
747'                                       #';
748'                                       #';
749'                                       #';
750'      ##################################';
751'                                        ';
752'                                        ';
753'                                        ';
754'                                        ';
755'                                        ';
756'  +                                     ';
757'########################################';
758--[[
759 0123456789012345678901234567890123456789
760           1         2         3
761]]--
762};
763life = function(s)
764	local path = { { 32, 8 }, { 32, 22},
765			{24, 22}, {24, 8},
766			{16, 8}, {16, 22},
767			{8, 22}, {8, 8},
768			{0, 8}, {0, 22},
769			{8, 22}, {8, 8},
770			{16, 8}, {16, 22},
771			{24, 22}, {24, 8},
772			{32, 8}, {32, 22},
773			{40, 22}, {40, 8} };
774	if not s.path then
775		s.path = path
776	end
777	if not s.snake then
778		s.snake = {}
779		local k
780		for k=1, 40 do
781			table.insert(s.snake, {k + 50, 8})
782		end
783	end
784	snake.step(s)
785	snake.draw(s)
786end
787
788},
789
790	{
791		title = "rain:Rain";
792		map = {
793'                                        ';
794'                                        ';
795'                                        ';
796'                                        ';
797'                                        ';
798'                                        ';
799'                                        ';
800'                                        ';
801'                                        ';
802'                                        ';
803'                                        ';
804'                                        ';
805'                                        ';
806'                                        ';
807'                                        ';
808'                                        ';
809'                                        ';
810'                                        ';
811'                                        ';
812'                                        ';
813'                                        ';
814'                                        ';
815'                                        ';
816'                                        ';
817'                                        ';
818'                                        ';
819'                                        ';
820'                                        ';
821'>                                       ';
822'########################################';
823--[[
824 0123456789012345678901234567890123456789
825           1         2         3
826]]--
827	},
828life = function(s)
829	rain_play()
830	if hero:state() == JUMP or hero:state() == FALL then
831		hero.speed_x = hero.speed_x - GX*0.70
832		if hero.speed_x < -MAX_SPEEDX then
833			hero.speed_x = -MAX_SPEEDX
834		end
835	end
836	local k, v
837	if not s.move then
838		s.move = 0
839		s.r = 2
840	end
841	s.move = s.move + 0.1
842	if s.move > 20 then
843		s.move = 0
844		s.r = 1
845	end
846	local c = map:cell(0, 28)
847	c[1] = 0
848	for k=s.r, 2 do
849		v = math.ceil(s.move)
850		local c = map:cell(k * 20 - v, 28)
851		if c then
852			c[1] = EMERGENCY
853		end
854		c = map:cell(k * 20 - v + 1, 28)
855		if c then
856			c[1] = 0
857		end
858		if hero:collision((k * 20 - v) * BW, 28 * BH, BW, BH) then
859			hero:state(FLY)
860		end
861	end
862end;
863after = function(s)
864	local x, y, i
865	if not s.rain then
866		s.rain = {}
867		for i = 1, 80 do
868			table.insert(s.rain, {rnd(640), rnd(480), rnd(8) + 8 })
869		end
870	end
871	for i=1, 80 do
872		x = s.rain[i][1]
873		y = s.rain[i][2]
874		sprite.fill(sprite.screen(), x, y, 2, 12, 'blue');
875		s.rain[i][2] = s.rain[i][2] + s.rain[i][3]
876		s.rain[i][1] = s.rain[i][1] - 3
877		if s.rain[i][2] > 480 - BH - 8 or s.rain[i][1] < 0 or hero:collision(x, y + 12, 2, 2) then
878			s.rain[i][1] = rnd(740)
879			s.rain[i][2] = 0
880			s.rain[i][3] = rnd(8) + 8
881		end
882	end
883end
884},
885 {
886      title = "spacehere:Dont panic!";
887      map = {
888'                                        ';
889'                                        ';
890'                                        ';
891'                                        ';
892'                                        ';
893'########################################';
894'#                                      #';
895'                                        ';
896'                                        ';
897'                                        ';
898'                                        ';
899'                                        ';
900'                                        ';
901'                                        ';
902'                                        ';
903'                                        ';
904'                                        ';
905'                                        ';
906'                                        ';
907'                                        ';
908'                                        ';
909'                                        ';
910'                                        ';
911'                              #####     ';
912'                         ######   ##    ';
913'                    ######         ##   ';
914'               ######               ##  ';
915'          ######                     ## ';
916'>    ######                           ##';
917'######                                 #';
918};
919life = function(s)
920   local position, index
921   if not s.x then
922      s.x = 38 * BW
923      s.speed = -2
924      s.length = {22, 22, 22, 22, 22, 21, 21, 21, 21, 21, 20, 20, 20, 20, 20, 19, 19, 19, 19, 19, 18, 18, 18, 18, 18, 17, 17, 17, 17, 17, 16, 16, 16, 16, 16, 17, 18, 19, 20, 21 }
925      s.laser = false
926   end
927   if (rnd(100) > 50) then
928	   sprite.fill (sprite.screen(), s.x, 6 * BW, BW, BW, "yellow")
929    else
930	sprite.fill (sprite.screen(), s.x, 6 * BW, BW, BW, "gold")
931    end
932   if s.laser then
933	laser_play()
934      if s.speed < 0 then
935	 index = math.floor ((s.x + 6) / BW) + 1
936	 sprite.fill (sprite.screen(), s.x + 6, 7 * BW, 3, s.length[index] * BW, 'red')
937	 if hero:collision(s.x + 6, 7 * BW, 3, s.length[index] * BW) and hero:alive() then
938	    hero:state(FLY)
939	 end
940      else
941	 index = math.floor ((s.x + 7) / BW) + 1
942	 sprite.fill (sprite.screen(), s.x + 7, 7 * BW, 3, s.length[index] * BW, 'red')
943	 if hero:collision(s.x + 7, 7 * BW, 3, s.length[index] * BW) and hero:alive() then
944	    hero:state(FLY)
945	 end
946      end
947   else
948	laser_mute()
949   end
950   s.x = s.x + s.speed
951   if s.x == BW or s.x == 38 * BW then
952      s.speed = s.speed * -1
953   end
954   position = hero.x + hero.w
955   if (position > 9 * BW and position < 10 * BW
956	  or position > 14 * BW and position < 15 * BW
957	  or position > 19 * BW and position < 20 * BW
958	  or position > 24 * BW and position < 25 * BW
959	  or position > 29 * BW and position < 30 * BW)
960   and hero:state() == WALK then
961      s.laser = true
962   end
963end
964},
965
966	{
967		title = "lasers:Lasers";
968		map = {
969'          #########################     ';
970'           *          *          *      ';
971'                                        ';
972'                                        ';
973'                                        ';
974'                                        ';
975'                                        ';
976'                                        ';
977'                                        ';
978'                                        ';
979'                                        ';
980'                                        ';
981'                                        ';
982'                                        ';
983'                                        ';
984'                                        ';
985'                                        ';
986'                                        ';
987'                                        ';
988'                                        ';
989'                                        ';
990'                                        ';
991'                                        ';
992'                                        ';
993'                                     ###';
994'                                     #  ';
995'                                     #  ';
996'                                     #  ';
997'>          *          *          *   #  ';
998'######################################  ';
999--[[
1000 0123456789012345678901234567890123456789
1001           1         2         3
1002]]--
1003},
1004life = function(s)
1005	if not s.state then
1006		s.state = 1
1007	end
1008	local k = math.ceil(s.state / 25) % 3
1009	if k == 1 then k = 2 elseif k == 2 then k = 0 else k = 1 end
1010	s.state = s.state + 1
1011	laser.on(11 + 11 * k, 2, 26);
1012end
1013},
1014{
1015	title = "press:Press",
1016	map = {
1017'                                        ';
1018'                                        ';
1019'                                        ';
1020'                                        ';
1021'                                        ';
1022'                                        ';
1023'                                        ';
1024'                                        ';
1025'                                        ';
1026'########################################';
1027'                                        ';
1028'                                        ';
1029'                                        ';
1030'                                        ';
1031'                                        ';
1032'                                        ';
1033'                                        ';
1034'                                        ';
1035'                                        ';
1036'                                        ';
1037'                                        ';
1038'                                        ';
1039'                                        ';
1040'>                                       ';
1041'########################################';
1042'                                        ';
1043'                                        ';
1044'                                        ';
1045'                                        ';
1046'                                        ';
1047};
1048		life =  function(s)
1049			if not s.water then
1050				s.water = 0
1051			end
1052			if s.water then
1053				sprite.fill(sprite.screen(), 0, 30 * BH - math.ceil(s.water), 640, math.ceil(s.water), 'blue');
1054				s.water = s.water + 0.2
1055				if 30 * BH - s.water < hero.y + hero.h and hero:alive()then
1056					hero:state(DROWN)
1057				end
1058			end
1059		   if not s.sq then
1060		      s.sq = true
1061		      s.squeezer = {}
1062		      s.squeezer_speed = {}
1063		      for a = 1, 3 do
1064			 s.squeezer[a] = 64
1065			 s.squeezer_speed[a] = a + 1
1066		      end
1067		   end
1068		   for a = 1, 3 do
1069		      s.squeezer[a] = s.squeezer[a] + s.squeezer_speed[a]
1070		      if s.squeezer[a] >= 13 * 16 or s.squeezer[a] < 64 then
1071			 s.squeezer_speed[a] = s.squeezer_speed[a] *-1
1072		      end
1073		      sprite.fill(sprite.screen(), a * 9 * 16 , 160, 21, s.squeezer[a], '#888888')
1074		      sprite.fill(sprite.screen(), a * 9 * 16 + 21 , 160, 22, s.squeezer[a], '#AAAAAA')
1075		      sprite.fill(sprite.screen(), a * 9 * 16 + 43 , 160, 21, s.squeezer[a], '#DDDDDD')
1076		      if hero:collision(a * 9 * 16 , 160, 64, s.squeezer[a]) then
1077			 hero:state(FLY)
1078		      end
1079		   end
1080		end;
1081
1082},
1083{
1084	title = "run:Run",
1085	map = {
1086'                                        ';
1087'                                        ';
1088'                                        ';
1089'                                   #    ';
1090'                                   #~~~~';
1091'                                   #~~~~';
1092'                                   #~~~~';
1093'                                   #~~~~';
1094'                                   #~~~~';
1095'                                   #~~~~';
1096'                                   #####';
1097'                                        ';
1098'                                        ';
1099'                                        ';
1100'                                        ';
1101'                                        ';
1102'                          %%%%%%        ';
1103'                                        ';
1104'                                        ';
1105'                                        ';
1106'                 %%%%%%            #####';
1107'                                   #    ';
1108'                                   #~~~~';
1109'>                                  #~~~~';
1110'%%%%%%%%%%%%%%                     #~~~~';
1111'                                   #~~~~';
1112'                                   #~~~~';
1113'                                   #~~~~';
1114'                                   #~~~~';
1115'                                   #~~~~';
1116};
1117},
1118{
1119		title = "flow:Flow";
1120		map = {
1121'                                        ';
1122'                                        ';
1123'                                        ';
1124'                                        ';
1125'                                        ';
1126'                                        ';
1127'                                        ';
1128'                                        ';
1129'                                        ';
1130'                                        ';
1131'########################################';
1132'                        #  #            ';
1133'                                        ';
1134'                                        ';
1135'                                        ';
1136'                                        ';
1137'                                        ';
1138'                                        ';
1139'                                        ';
1140'>                                       ';
1141'##########%%%%%%%%######################';
1142'                                        ';
1143'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
1144'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
1145'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
1146'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
1147'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
1148'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
1149'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
1150'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
1151};
1152life = function(s)
1153   local i
1154   if not s.w1 then
1155      s.switched = false
1156      s.w1 = 6 * BW
1157      s.w2 = 0
1158      s.flow = 0
1159   end
1160   sprite.fill (sprite.screen(), 0, 10 * BW - s.w1 + 1, 41 * BW, s.w1, "blue")
1161   sprite.fill (sprite.screen(), 0, 22 * BW - s.w2 + 1, 41 * BW, s.w2, "blue")
1162   if hero.x > 7 * BW and hero.x < 18 * BW and hero:state() == WALK and not s.switched then
1163      s.switched = true
1164      for i = 25, 26 do
1165	 c = map:cell(i, 10)
1166	 c[1] = 0
1167      end
1168   end
1169   if s.switched then
1170      sprite.fill (sprite.screen(), 25 * BW, 10 * BW, 2 * BW, s.flow, "blue")
1171      if s.flow <= 12 * BW then
1172	 s.flow = s.flow + 4
1173      end
1174      s.w1 = s.w1 - 0.1
1175      if s.flow > 12 * BW then
1176	 s.w2 = s.w2 + 0.1
1177      end
1178   end
1179   if hero:collision(25 * BW, 10 * BW, 2 * BW, s.flow) and hero:alive() then
1180      hero:state(FLY)
1181   elseif 22 * BH - s.w2 < hero.y + hero.h and hero:alive()then
1182      hero:state(DROWN)
1183   end
1184end
1185},
1186{
1187		title = "propeller:Propeller",
1188		map = {
1189'                                        ';
1190'                                        ';
1191'                                        ';
1192'                                        ';
1193'                                        ';
1194'                                        ';
1195'                                        ';
1196'       ##*##*##*##*##*##*##*##*##       ';
1197'       #                        #       ';
1198'       #                        #       ';
1199'########                        ########';
1200'                                        ';
1201'                                        ';
1202'                                        ';
1203'                                        ';
1204'                                        ';
1205'                                        ';
1206'                   +                    ';
1207'                                        ';
1208'>                                       ';
1209'########                        ########';
1210'       #                        #       ';
1211'       #                        #       ';
1212'       #                        #       ';
1213'       #                        #       ';
1214'       #                        #       ';
1215'       #                        #       ';
1216'       #                        #       ';
1217'       #    xxxxxxxXXxxxxxxx    #       ';
1218'       ##########################       ';
1219};
1220life = function(s)
1221	local max = 1
1222	if not s.vent then
1223		s.vent = 1
1224		s.speed = 0.001
1225	end
1226	s.speed = s.speed + 0.002
1227	if s.speed > max then s.speed = max end
1228	if hero.x > 7 * BW and hero.x + hero.w <= 32 * BW then
1229		local h = 29 - (hero.y + hero.h)/ BH
1230		h = (38 - h)/38 -- 1..0
1231		if hero:alive() then
1232			G = origG - (s.speed * s.speed * h * 2 * origG)
1233		else
1234			G = origG
1235		end
1236		if math.abs(G) < 0.05 then G = G * 0.1 end
1237		if G < 0 then hero.y = hero.y + G end
1238	else
1239		G = origG
1240	end
1241	local v = { 7, 6, 4, 2, 0, 1, 2, 4, 6, 7 }
1242	s.vent = s.vent + s.speed * 2
1243	local n = math.floor(s.vent)
1244	if n >#v then s.vent = 1;n = 1; end
1245	local c
1246	local x, y, xx
1247	x = 19
1248	y = 28
1249	xx = x - v[n]
1250	sprite.fill(sprite.screen(), xx * BW, y * BH + 4, (v[n] * 2 + 2) * BW, 4, 'black')
1251	sprite.fill(sprite.screen(), x * BW, y * BH, 2 * BW, BH, '#333333')
1252	if hero:collision(xx * BW, y * BH, (v[n] * 2 + 2) * BW, 4) then
1253		hero:state(FLY)
1254	end
1255end
1256},
1257
1258{
1259		title = "stairs:Stairs";
1260		map = {
1261'                                        ';
1262'                                        ';
1263'                                        ';
1264'                                        ';
1265'                                        ';
1266'                                        ';
1267'                                        ';
1268'                                        ';
1269'                                        ';
1270'                                        ';
1271'                                        ';
1272'                                        ';
1273'                                        ';
1274'                                        ';
1275'                                        ';
1276'                                        ';
1277'                                        ';
1278'                                        ';
1279'                                        ';
1280'>                                       ';
1281'#######*                                ';
1282'       #######*                         ';
1283'              #######*                  ';
1284'                     #######*         + ';
1285'                            ############';
1286'                                       #';
1287'                                       #';
1288'                                       #';
1289'                                       #';
1290'                                       #';
1291};
1292},
1293{
1294	title = "figure:Figure out",
1295	map = {
1296'                                        ';
1297'                                        ';
1298'                                        ';
1299'                                        ';
1300'                                        ';
1301'                                        ';
1302'                                        ';
1303'                                        ';
1304'                                        ';
1305'                                        ';
1306'                                        ';
1307'                                        ';
1308'                                        ';
1309'                                        ';
1310'                                        ';
1311'                                        ';
1312'                                        ';
1313'                                        ';
1314'                                        ';
1315'                                        ';
1316'                                        ';
1317'                                        ';
1318'                                        ';
1319'>                                       ';
1320'########                        ########';
1321'########                        ^^^^^^^^';
1322'########                        ^^^^^^^^';
1323'########                        ^^^^^^^^';
1324'########                        ^^^^^^^^';
1325'########                        ########';
1326};
1327--[[
1328 0123456789012345678901234567890123456789
1329           1         2         3
1330]]--
1331
1332		life =  function(s)
1333			if (hero:state() == JUMP or hero:state() == FALL) and hero.x > 4 * BW and hero.y + hero.h < 24 * BH then
1334				if not s.pos then
1335					s.pos = 0
1336				end
1337				local x, y, c
1338				for x = 4 + math.ceil(s.pos), 8 + math.ceil(s.pos) do
1339					for y = 24, 29 do
1340						c = map:cell(x, y)
1341						c[1] = 0
1342					end
1343				end
1344
1345				s.pos = s.pos + 0.1
1346				if s.pos >= 23 then s.pos = 23 end
1347				for x = 4 + math.ceil(s.pos),8 + math.ceil(s.pos) do
1348					for y = 24, 29 do
1349						c = map:cell(x, y)
1350						c[1] = BLOCK
1351					end
1352				end
1353			end
1354		end;
1355},
1356{
1357	title = "easy:Easy?",
1358	map = {
1359'                                        ';
1360'                                        ';
1361'                                        ';
1362'                                        ';
1363'                                        ';
1364'                                        ';
1365'                                        ';
1366'                                        ';
1367'                                        ';
1368'                                        ';
1369'                                        ';
1370'                                        ';
1371'                                        ';
1372'                                        ';
1373'                                        ';
1374'                                        ';
1375'                                        ';
1376'                                        ';
1377'                                        ';
1378'                                        ';
1379'                        *       ########';
1380'                *       #########       ';
1381'        +       #########               ';
1382'>       #########                       ';
1383'#########                               ';
1384'                                        ';
1385'                                        ';
1386'                                        ';
1387'                +        +              ';
1388'########################################';
1389};
1390--[[
1391 0123456789012345678901234567890123456789
1392           1         2         3
1393]]--
1394},
1395{
1396	title = "impossible:Impossible?",
1397	map = {
1398'                                       #';
1399'                                       #';
1400'                                       #';
1401'                                       #';
1402'                                       #';
1403'                                       #';
1404'                                       #';
1405'                  +                    #';
1406'          ======                       #';
1407'                 # #                   #';
1408'                  *                   *#';
1409'                 # #                   #';
1410'                  *                   *#';
1411'  ======         # #                   #';
1412'                  *                   *#';
1413'                 # #                   #';
1414'                  *                   *#';
1415'                 # #                   #';
1416'           %%%%%  *                   *#';
1417'>                # #                   #';
1418'#####                                  #';
1419'                                       #';
1420'                                       #';
1421'                                       #';
1422'                                       #';
1423'                                        ';
1424'                                        ';
1425'                                        ';
1426'                                        ';
1427'#------------------------------#########';
1428};
1429--[[
1430 0123456789012345678901234567890123456789
1431           1         2         3
1432]]--
1433life = function(s)
1434	if not s.laser then
1435		s.laser = 0
1436	end
1437	if s.laser <= 5 then
1438		laser.on(19, 10 + 2 * math.floor(s.laser), -19);
1439	else
1440		laser.off()
1441	end
1442	s.laser = s.laser + 0.1
1443	if s.laser > 5 then s.laser = 0 end
1444end
1445},
1446	{
1447		title = "mars:Mars",
1448		map = {
1449'                                        ';
1450'                                        ';
1451'                                        ';
1452'                                        ';
1453'                                        ';
1454'                                        ';
1455'                                        ';
1456'                                        ';
1457'                                        ';
1458'                                        ';
1459'                                        ';
1460'                                        ';
1461'                 #########              ';
1462'                  *  *  *               ';
1463'                                        ';
1464'                                        ';
1465'                                        ';
1466'                                        ';
1467'                                        ';
1468'                                        ';
1469'                 #########              ';
1470'                 #       #              ';
1471'                 #       #              ';
1472'                 #       #              ';
1473'                 #       ###############';
1474'                 #                      ';
1475'                 #                      ';
1476'                 #                      ';
1477'>                #                      ';
1478'##################                      ';
1479};
1480life = function(s)
1481	if hero:state() == JUMP or hero:state() == FALL then
1482		G = 0.2
1483	else
1484		G = origG
1485	end
1486end;
1487},
1488	{
1489		title = "meteors:Meteors",
1490		map = {
1491'                                        ';
1492'                                        ';
1493'                                        ';
1494'                                        ';
1495'                                        ';
1496'                                        ';
1497'                                        ';
1498'                                        ';
1499'                                        ';
1500'                                        ';
1501'                                        ';
1502'                                        ';
1503'                                        ';
1504'                                       #';
1505'                                      ##';
1506'                                     ###';
1507'                                     ###';
1508'                                     ###';
1509'                                     ###';
1510'                                     ###';
1511'                                    ####';
1512'                      #######       ####';
1513'                     #########   + #####';
1514'>                   ###########  #######';
1515'###              #######################';
1516'########################################';
1517'########################################';
1518'########################################';
1519'########################################';
1520'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
1521};
1522life = function(s)
1523	local x, y, i, xx, yy
1524	if not s.meteo then
1525		s.r = 0
1526		s.meteo = {}
1527		for i = 1, 3 do
1528			table.insert(s.meteo, {rnd(640) - BW * 4, rnd(480) - 480, rnd(2) + 1 })
1529		end
1530	end
1531	local exp
1532	for i=1, #s.meteo do
1533		exp = false
1534		x = s.meteo[i][1]
1535		y = s.meteo[i][2]
1536		if rnd(50) > 25 then
1537			sprite.fill(sprite.screen(), x, y, BW, BH, 'white');
1538		else
1539			sprite.fill(sprite.screen(), x, y, BW, BH, 'red');
1540		end
1541		s.meteo[i][2] = s.meteo[i][2] + s.meteo[i][3]
1542		xx, yy = map:pos2block(x + BW / 2, y + BH / 2)
1543		if xx >= 0 and yy >= 0 then
1544			local c = map:cell(xx, yy)
1545			if c and c[1] ~= 0 and c[1] ~= HEART then
1546				explode.add(s, xx, yy)
1547				exp = true
1548			end
1549		end
1550		if hero:collision(x, y, BW, BH) then
1551			exp = true
1552			explode.add(s, xx, yy)
1553			hero:state(FLY)
1554		end
1555		if s.meteo[i][1] < 0 or s.meteo[i][2] > 480 - BH or exp then
1556			if i == s.right then
1557				s.right = false
1558			end
1559			s.meteo[i][1] = rnd(640) - BW * 4
1560			s.meteo[i][2] = -BH
1561			s.meteo[i][3] = rnd(2) + 1
1562			if not s.right and s.r <= 4 then
1563				s.meteo[i][1] = 640 - BW * ((s.r % 3)) - BW
1564				s.r = s.r + 1
1565				s.meteo[i][3] = 3
1566				s.right = i
1567			end
1568		end
1569	end
1570end;
1571},
1572	{
1573		title = "valley:Valley",
1574		map = {
1575'                                        ';
1576'                                        ';
1577'                                        ';
1578'                                        ';
1579'                                        ';
1580'                                        ';
1581'                                        ';
1582'                                        ';
1583'                                        ';
1584'                                        ';
1585'                                        ';
1586'                                        ';
1587'>                                       ';
1588'@@                                      ';
1589'@@@                                     ';
1590'@@@                                     ';
1591'@@@@                                    ';
1592'#@#@                                    ';
1593'###@                                    ';
1594'#####                                   ';
1595'#####                                   ';
1596'######                                  ';
1597'######                                  ';
1598'########                                ';
1599'##############        +           ######';
1600'             #~~~~~~#####~~~~~~~~~#     ';
1601'             ######################     ';
1602'                                        ';
1603'                                        ';
1604'                                        ';
1605};
1606after = function(s)
1607	sprite.fill(sprite.screen(), 35 * BW, 2 * BH, 4 * BW, BH*4, 'yellow');
1608	sprite.fill(sprite.screen(), 0 * BW, 24 * BH, 40 * BW, BH*3, 'green');
1609	sprite.fill(sprite.screen(), 0 * BW, 27 * BH, 40 * BW, BH*3, '#444444');
1610	sprite.fill(sprite.screen(), 14 * BW, 24 * BH, 20 * BW, BH*2, 'blue');
1611end
1612},
1613
1614	{
1615		title = "faster:Faster, higher, stronger!",
1616		map = {
1617'                                        ';
1618'                                        ';
1619'                                        ';
1620'                                        ';
1621'                                        ';
1622'                                        ';
1623'                                        ';
1624'                                        ';
1625'                                        ';
1626'                                        ';
1627'                                        ';
1628'                                        ';
1629'                              %%%%      ';
1630'                                        ';
1631'                                        ';
1632'                                        ';
1633'                                        ';
1634'                  %%%%                  ';
1635'                                        ';
1636'                                        ';
1637'                                        ';
1638'      +                                 ';
1639'      %%%%                              ';
1640'>                                       ';
1641'####                                ####';
1642'   #                               *#   ';
1643'   #                               ##   ';
1644'   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#    ';
1645'   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#    ';
1646'   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#    ';
1647};
1648		life =  function(s)
1649			if not s.laser then
1650				s.laser = 60
1651			end
1652			s.laser = s.laser - 1
1653			if s.laser <= 0 then
1654				s.laser = 60
1655			end
1656			if s.laser <= 20 then
1657				laser.on(35, 0, 25);
1658			else
1659				laser.off()
1660			end
1661		end;
1662
1663},
1664      	{
1665		title = "careful:Be careful!",
1666		map = {
1667'                                        ';
1668'                                        ';
1669'                                        ';
1670'                                        ';
1671'                                        ';
1672'#####                                   ';
1673'    #                                   ';
1674'    #    ###############################';
1675'    #    #*                           *#';
1676'    #    #                             #';
1677'    #    #                          ####';
1678'    ######                          #   ';
1679'                                    #   ';
1680'                                    #   ';
1681'                                    #   ';
1682'                ####        ####    #   ';
1683'       ====     #  #        #  #    #   ';
1684'                #  #        #  #    #   ';
1685'                #  #        #  #    #   ';
1686'       ====     #  #        #  #    ####';
1687'                #  #        #  #        ';
1688'                #  #        #  #        ';
1689'       ####     #  #        #  #        ';
1690'>      #  #     #  #        #  #        ';
1691'########  #     #  #        #  #%%%%%%%%';
1692'          #~~~~~#  #~~~~~~~~#  #        ';
1693'          #~~~~~#  #~~~~~~~~#  #        ';
1694'          #~~~~~#  #~~~~~~~~#  #        ';
1695'          #~~~~~#  #~~~~~~~~#  #        ';
1696'          #~~~~~#  #~~~~~~~~#  #        ';
1697};
1698		life =  function(s)
1699			if not s.laser then
1700				s.laser = 60
1701			end
1702			s.laser = s.laser - 1
1703			if s.laser <= 0 then
1704				s.laser = 60
1705			end
1706			if s.laser <= 30 then
1707				laser.on(11, 8, -27);
1708			else
1709				laser.off()
1710			end
1711		end;
1712
1713},
1714      	{
1715		title = "winter:Winter",
1716		map = {
1717'                                        ';
1718'                                        ';
1719'                                        ';
1720'                                        ';
1721'                                        ';
1722'                                        ';
1723'                                        ';
1724'                                        ';
1725'                                        ';
1726'                                        ';
1727'                                        ';
1728'                                        ';
1729'                                        ';
1730'                                        ';
1731'                                        ';
1732'                                  @@@@@@';
1733'                                  @@@@@@';
1734'                                  @@@@@@';
1735'                  *        *      @@@@@@';
1736'            @@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1737'            @@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1738'            @@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1739'            @@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1740'>           @@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1741'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1742'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1743'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1744'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1745'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1746'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1747};
1748		life =  function(s)
1749			if hero:state() == WALK then
1750				RGX = 0.1
1751			else
1752				RGX = origRGX
1753			end
1754		end;
1755
1756after = function(s)
1757	local x, y, i
1758	if not s.snow then
1759		s.snow = {}
1760		for i = 1, 80 do
1761			table.insert(s.snow, {rnd(640), rnd(480), (rnd(2) + 1)/2 })
1762		end
1763	end
1764	for i=1, 80 do
1765		x = s.snow[i][1]
1766		y = s.snow[i][2]
1767		sprite.fill(sprite.screen(), x, y, 2, 2, 'white');
1768		s.snow[i][2] = s.snow[i][2] + s.snow[i][3]
1769		s.snow[i][1] = s.snow[i][1] + 2 -  rnd(3)
1770		if s.snow[i][1] < 0 or s.snow[i][2] > 480 or hero:collision(x, y, 2, 2) then
1771			s.snow[i][1] = rnd(640)
1772			s.snow[i][2] = 0
1773			s.snow[i][3] = (rnd(2) + 1)/2
1774		end
1775	end
1776end
1777
1778},
1779
1780	{
1781		title = "tired:Tired?",
1782		map = {
1783'                                        ';
1784'                                        ';
1785'                                        ';
1786'                                        ';
1787'                                        ';
1788'                                        ';
1789'                                        ';
1790'                                        ';
1791'                                        ';
1792'                                        ';
1793'                                        ';
1794'                                        ';
1795'                                        ';
1796'                                        ';
1797'>                                       ';
1798'########################################';
1799'########################################';
1800'########################################';
1801'########################################';
1802'########################################';
1803'########################################';
1804'########################################';
1805'########################################';
1806'                                        ';
1807'                                        ';
1808'                                        ';
1809'                                        ';
1810'                                        ';
1811'                                        ';
1812'                                        ';
1813};
1814},
1815
1816	{
1817		title = "danger:Danger",
1818		map = {
1819'                ########                ';
1820'                ########                ';
1821'                ########                ';
1822'                ########                ';
1823'                ########                ';
1824'                ########                ';
1825'                ########                ';
1826'                ########                ';
1827'                                        ';
1828'                                        ';
1829'                                        ';
1830'                                        ';
1831'                                        ';
1832'                                        ';
1833'>                                       ';
1834'################========################';
1835'################        ################';
1836'################        ################';
1837'################        ################';
1838'################        ################';
1839'################        ################';
1840'################        ################';
1841'################        ################';
1842'                                        ';
1843'                                        ';
1844'                                        ';
1845'                                        ';
1846'                                        ';
1847'                                        ';
1848'                                        ';
1849};
1850life = function(s)
1851	if not s.fall and hero.x > 16 * BW and hero.speed_x >= SPEED_RUN * 0.65 and hero.x < 22 * BW then
1852		s.fall = 0
1853	end
1854	if s.fall and s.fall * BH < 480 then
1855		local yy = math.floor(s.fall)
1856		local xx = 0
1857		local x, y
1858		for x = 0, 7 do
1859			for y = yy, yy + 7 do
1860				local c = map:cell(16 + x, y)
1861				if c then
1862					c[1] = 0
1863				end
1864			end
1865		end
1866		s.fall = s.fall + G;
1867		if hero.y > (s.fall * BH) then
1868			if s.fall and hero.y <= (s.fall + 8) * BH and hero.x < 24 * BW - hero.w and hero.x > 16 * BW then
1869				hero.y = (s.fall + 8) * BH + hero.yoff
1870			end
1871		end
1872		yy = math.floor(s.fall)
1873		for x = 0, 7 do
1874			for y = yy, yy + 7 do
1875				local c = map:cell(16 + x, y)
1876				if c then
1877					c[1] = BLOCK
1878				end
1879			end
1880		end
1881	end
1882end
1883},
1884
1885
1886
1887	{
1888		title = "?",
1889		map = {
1890'                                        ';
1891'                                        ';
1892'                                        ';
1893'                                        ';
1894'                                        ';
1895'                                        ';
1896'                                        ';
1897'                                        ';
1898'                                        ';
1899'                                        ';
1900'                                        ';
1901'                                        ';
1902'                                        ';
1903'                                        ';
1904'>                                       ';
1905'#####                                   ';
1906'####                                    ';
1907'###                                     ';
1908'##                                      ';
1909'#                                       ';
1910'                                        ';
1911'                                        ';
1912'                                        ';
1913'                                        ';
1914'                                        ';
1915'                                        ';
1916'                                        ';
1917'                                        ';
1918'                                        ';
1919'                        ........      ..';
1920};
1921},
1922
1923	{
1924		title = "mines:Mines",
1925		map = {
1926'                                        ';
1927'                                        ';
1928'                                        ';
1929'                                        ';
1930'                                        ';
1931'                                        ';
1932'                                        ';
1933'                                        ';
1934'                                        ';
1935'                                        ';
1936'                                        ';
1937'                                        ';
1938'                                        ';
1939'                                        ';
1940'                                        ';
1941'                                        ';
1942'                                        ';
1943'                                        ';
1944'                                        ';
1945'                                        ';
1946'                                        ';
1947'                                        ';
1948'                                        ';
1949'                                        ';
1950'                                        ';
1951'                                        ';
1952'                                        ';
1953'          m          +          m       ';
1954'>         ##############################';
1955'###########                             ';
1956};
1957},
1958   	{
1959		title = "wait:Wait";
1960		map = {
1961'                             #          ';
1962'                             #          ';
1963'                             #          ';
1964'                             #          ';
1965'                             #          ';
1966'                             #          ';
1967'                             #          ';
1968'                             #          ';
1969'                             #          ';
1970'                             #          ';
1971'                             #          ';
1972'                             #          ';
1973'                             #          ';
1974'                             #          ';
1975'                             #          ';
1976'                             #          ';
1977'                             ##         ';
1978'        %%%%                  ##        ';
1979'                               ##       ';
1980'                                ##      ';
1981'%%%%               #####         ##     ';
1982'%%%%               #   #          ##    ';
1983'                   #   #           #####';
1984'    %%%%          *#   #                ';
1985'                   #   #                ';
1986'                   #   #                ';
1987'                   #   #                ';
1988'>                  #   #           xm   ';
1989'####################   #     ###########';
1990'                       #~~~~~#          ';
1991};
1992},
1993{
1994		title = "mines2:Мины II";
1995		map = {
1996'                                        ';
1997'                                        ';
1998'                                        ';
1999'                                        ';
2000'                                        ';
2001'                                        ';
2002'                                        ';
2003'                                        ';
2004'                                        ';
2005'                                        ';
2006'                                        ';
2007'                 #####                  ';
2008'             #####mmm#####              ';
2009'         #####mmmm   mmmm#####          ';
2010'     #####mmmm           mmmm#####      ';
2011'######mmmm                   mmmm#######';
2012'                                        ';
2013'                                        ';
2014'                                        ';
2015'                                        ';
2016'                                        ';
2017'                                        ';
2018'                                        ';
2019'                                        ';
2020'                 #####                  ';
2021'             #####   #####              ';
2022'         #####           #####          ';
2023'>    #####                   #####      ';
2024'######                           #####  ';
2025'                                     ###';
2026},
2027},
2028
2029	{
2030		title = "power:Power",
2031		map = {
2032'                                        ';
2033'                                        ';
2034'                                        ';
2035'                                        ';
2036'                                        ';
2037'                                        ';
2038'                                        ';
2039'                                        ';
2040'                                        ';
2041'                                        ';
2042'                                        ';
2043'                                        ';
2044'                                        ';
2045'                                        ';
2046'                                        ';
2047'                                        ';
2048'                                        ';
2049'                                        ';
2050'                                        ';
2051'                                        ';
2052'                           %%%%%########';
2053'                               *########';
2054'                                ########';
2055'                                ########';
2056'                                ########';
2057'            ####                ########';
2058'            ####                ########';
2059'            ####                ########';
2060'>           ####      m         ########';
2061'########################################';
2062};
2063life = function(s)
2064	if not s.pos then s.pos = 12 end
2065	local c, y, x
2066
2067	for x = 0, 3 do
2068		for y = 1, 4 do
2069			c = map:cell(math.floor(s.pos) + x, 24 + y)
2070			c[1] = 0
2071		end
2072	end
2073	if hero.y >= 25 * BH and hero.speed_x <= GX and hero:state() == WALK and key_right
2074		    and hero.x + hero.w >= math.floor(s.pos) * BW and hero.x + hero.w < (math.floor(s.pos) + 4) * BW then
2075		s.pos = s.pos + 0.1
2076	end
2077	if s.pos >= 18 then s.pos = 18 end
2078	for x = 0, 3 do
2079		for y = 1, 4 do
2080			c = map:cell(math.floor(s.pos) + x, 24 + y)
2081			c[1] = BLOCK
2082		end
2083	end
2084
2085end
2086},
2087
2088	{
2089		title = "darkness:Darkness",
2090		map = {
2091'                                        ';
2092'                                        ';
2093'                                        ';
2094'                                        ';
2095'                                        ';
2096'                                        ';
2097'                                        ';
2098'                                        ';
2099'                                        ';
2100'                                        ';
2101'                                        ';
2102'                                        ';
2103'                                        ';
2104'                                        ';
2105'                                        ';
2106'                                        ';
2107'                                        ';
2108'                                        ';
2109'                                        ';
2110'>                                       ';
2111'##############             #############';
2112'                                        ';
2113'                                        ';
2114'                                        ';
2115'                                        ';
2116'                                        ';
2117'                                        ';
2118'                                        ';
2119'                                        ';
2120'                                        ';
2121};
2122after = function(s)
2123	local y = 0
2124	for y = 0, 30 * BW - 1 do
2125		sprite.fill(sprite.screen(), 10 * BW + rnd(3) - 2, y, 20 * BW - 1 + rnd(3) - 2, 1, 'black');
2126	end
2127end
2128},
2129	{
2130		title = "bunker:Bunker",
2131		map = {
2132'                                        ';-- 0
2133'                                        ';-- 1
2134'                                        ';-- 2
2135'                                        ';-- 3
2136'                                        ';-- 4
2137'                                        ';-- 5
2138'                                        ';--
2139'                                        ';-- 7
2140'                                        ';-- 8
2141'                                        ';-- 9
2142'                                        ';-- 10
2143'                                        ';-- 11
2144'                                        ';-- 12
2145'                                        ';-- 13
2146'########################################';-- 14
2147'#m#####   m   ###   m   ###   m   #m####';-- 15
2148'                                        ';-- 16
2149'                                        ';-- 17
2150'                                        ';-- 18
2151'>   +                                  m';-- 19
2152'########################################';-- 20
2153'########################################';-- 21
2154'                                        ';-- 22
2155'                                        ';-- 23
2156'                                        ';-- 24
2157'                                        ';-- 25
2158'                                        ';-- 26
2159'                                        ';-- 27
2160'                                        ';-- 28
2161'                                        ';-- 29
2162};
2163--[[
2164 0123456789012345678901234567890123456789
2165           1         2         3
2166]]--
2167},
2168
2169	{
2170		title = "platforms:Platforms",
2171		map = {
2172'           m   m   m   m   m   m        ';-- 0
2173'                                        ';-- 1
2174'                                        ';-- 2
2175'                                        ';-- 3
2176'                                        ';-- 4
2177'                                    ####';-- 5
2178'                                    ####';--
2179'                                       #';-- 7
2180'                                       #';-- 8
2181'                                       #';-- 9
2182'                                       #';-- 10
2183'                                       #';-- 11
2184'                                       #';-- 12
2185'                                       #';-- 13
2186'                                       #';-- 14
2187'                                       #';-- 15
2188'                                       #';-- 16
2189'                                       #';-- 17
2190'                                       #';-- 18
2191'>                                      #';-- 19
2192'####                                   #';-- 20
2193'####                                   #';-- 21
2194'#                                      #';-- 22
2195'#                                      #';-- 23
2196'#                                      #';-- 24
2197'#                                      #';-- 25
2198'#                                      #';-- 26
2199'#                                      #';-- 27
2200'#                                      #';-- 28
2201'#                                      #';-- 29
2202};
2203--[[
2204 0123456789012345678901234567890123456789
2205           1         2         3
2206]]--
2207before = function(s)
2208	if not s.lifts then
2209		s.lifts = {{}, {}, {}, {}}
2210--		lift.activate(s.lifts[1], 5, 1, 4, 0.25, 1, 28)
2211		lift.activate(s.lifts[2], 14, 28, 4, -0.3, 1, 28)
2212		lift.activate(s.lifts[3], 23, 1, 4, 0.3, 1, 28)
2213		lift.activate(s.lifts[4], 32, 28, 4, -0.3, 1, 28)
2214	end
2215--	lift.draw(s.lifts[1])
2216	lift.draw(s.lifts[2])
2217	lift.draw(s.lifts[3])
2218	lift.draw(s.lifts[4])
2219end
2220},
2221
2222	{
2223		title = "entrance:Entrance",
2224		map = {
2225'......                           ......m';-- 0
2226'                                       m';-- 1
2227'                                       m';-- 2
2228'                                       m';-- 3
2229'>                                      m';-- 4
2230'==================================######';-- 5
2231'                                  ######';--
2232'                                        ';-- 7
2233'                                        ';-- 8
2234'                                        ';-- 9
2235'                                        ';-- 10
2236'                                        ';-- 11
2237'                                        ';-- 12
2238'                                        ';-- 13
2239'                                        ';-- 14
2240'                                        ';-- 15
2241'                                        ';-- 16
2242'                                        ';-- 17
2243'                                        ';-- 18
2244'                                        ';-- 19
2245'                                        ';-- 20
2246'                                        ';-- 21
2247'                                        ';-- 22
2248'                                        ';-- 23
2249'                                        ';-- 24
2250'                                        ';-- 25
2251'                                        ';-- 26
2252'                                        ';-- 27
2253'                                        ';-- 28
2254'                                        ';-- 29
2255};
2256--[[
2257 0123456789012345678901234567890123456789
2258           1         2         3
2259]]--
2260},
2261
2262	{
2263		title = "well:Well",
2264		map = {
2265'                                        ';-- 0
2266'                                        ';-- 1
2267'                                        ';-- 2
2268'                                        ';-- 3
2269'>                                       ';-- 4
2270'########     #                         #';-- 5
2271'       #     #~~~~~~~~~~~~~~~~~~~~~~~~~#';--
2272'       #     #~~~~~~~~~~~~~~~~~~~~~~~~~#';-- 7
2273'       #     #~~~~~~~~~~~~~~~~~~~~~~~~~#';-- 8
2274'       #     #~~~~~~~~~~~~~~~~~~~~~~~~~#';-- 9
2275'       #     #~~~~~~~~~~~~~~~~~~~~~~~~~#';-- 10
2276'       #     ###########################';-- 11
2277'       #     #                          ';-- 12
2278'       #     #                          ';-- 13
2279'       #     #                          ';-- 14
2280'       #     #                          ';-- 15
2281'       #     #                          ';-- 16
2282'       #     #                          ';-- 17
2283'       #     #                          ';-- 18
2284'       #     #                          ';-- 19
2285'       #                              ##';-- 20
2286'       #                         ###### ';-- 21
2287'       #                    ######      ';-- 22
2288'       #               ######           ';-- 23
2289'       #          ######                ';-- 24
2290'       #     ######                     ';-- 25
2291'       #     #                          ';-- 26
2292'       #     #                          ';-- 27
2293'       #     #                          ';-- 28
2294'       #  *  #                          ';-- 29
2295};
2296--[[
2297 0123456789012345678901234567890123456789
2298           1         2         3
2299]]--
2300life = function(s)
2301	local x, y
2302	x = 8
2303	y = 25
2304
2305	if not s.step then
2306		s.step = 0
2307	end
2308	s.step = s.step +1
2309	if s.step < 100 then
2310		for x = 8, 8 + 4 do
2311			local c = map:cell(x, y)
2312			c[1] = 0
2313		end
2314	elseif s.step >= 100 and s.step <= 115 then
2315		for x = 8, 8 + 4 do
2316			local c = map:cell(x, y)
2317			c[1] = BRIDGE
2318		end
2319	else
2320		s.step = 0
2321	end
2322end
2323},
2324
2325
2326
2327	{
2328		title = "snake2:Snake II",
2329		map = {
2330'                                        ';-- 0
2331'                                        ';-- 1
2332'                                        ';-- 2
2333'                                        ';-- 3
2334'                                        ';-- 4
2335'                                        ';-- 5
2336'                                        ';-- 6
2337'                                        ';-- 7
2338'                                        ';-- 8
2339'                                        ';-- 9
2340'                                        ';-- 1
2341'                                        ';-- 11
2342'                                        ';-- 12
2343'                                        ';-- 13
2344'                                        ';-- 14
2345'                                        ';-- 15
2346'                                        ';-- 16
2347'                                        ';-- 17
2348'                                        ';-- 18
2349'>                  +                    ';-- 19
2350'########################################';-- 20
2351'                                        ';-- 21
2352'                                        ';-- 22
2353'                                        ';-- 23
2354'                                        ';-- 24
2355'                                        ';-- 25
2356'                                        ';-- 26
2357'                                        ';-- 27
2358'                                        ';-- 28
2359'                                        ';-- 29
2360};
2361--[[
2362 0123456789012345678901234567890123456789
2363           1         2         3
2364]]--
2365life = function(s)
2366	local path = { { 12, 6 }, { 12, 19},
2367			{27, 19}, {27, 6} };
2368	if not s.path then
2369		s.path = path
2370		s.step = 0
2371	end
2372	if not s.snake then
2373		s.snake = {}
2374		local k
2375		for k=1, 47 do
2376			table.insert(s.snake, {k + 12, 6})
2377		end
2378	end
2379	if s.step > 3 then
2380		snake.step(s)
2381		s.step = 0
2382	end
2383	snake.draw(s)
2384	s.step = s.step + 1
2385end
2386
2387},
2388	{
2389		mirror = true,
2390		title = "strange:Strange place",
2391		map = {
2392'                                        ';-- 0
2393'                                        ';-- 1
2394'         #######################        ';-- 2
2395'          m                   m         ';-- 3
2396'                                        ';-- 4
2397'                                        ';-- 5
2398'                                        ';-- 6
2399'                                        ';-- 7
2400'                                        ';-- 8
2401'                                        ';-- 9
2402'                                        ';-- 1
2403'                                        ';-- 11
2404'                                        ';-- 12
2405'                                        ';-- 13
2406'                                        ';-- 14
2407'                                        ';-- 15
2408'                                        ';-- 16
2409'                                        ';-- 17
2410'                                        ';-- 18
2411'>         m                   m         ';-- 19
2412'########################################';-- 20
2413'                                        ';-- 21
2414'                                        ';-- 22
2415'                                        ';-- 23
2416'                                        ';-- 24
2417'                                        ';-- 25
2418'                                        ';-- 26
2419'                                        ';-- 27
2420'                                        ';-- 28
2421'                                        ';-- 29
2422};
2423--[[
2424 0123456789012345678901234567890123456789
2425           1         2         3
2426]]--
2427life = function(s)
2428	local st, m
2429	st, m = game:state()
2430	if st == CHANGE_LEVEL and m >= 16 and hero.x > 600 and not s.skip then
2431		map.nr = map.nr - 1
2432	elseif hero.x < - (hero.w * 3) and s ~= CHANGE_LEVEL then
2433		hero.x = 700
2434		hero.y = 0
2435		hero.speed_x = 0
2436		game:state(CHANGE_LEVEL)
2437		hero:state(WALK)
2438		s.skip = true
2439	end
2440	map:dist(0)
2441end
2442},
2443	{
2444		title = "gate:Gate",
2445		map = {
2446'>                    ###################';
2447'                     #                 #';
2448'                     #                 #';
2449'                     #                 #';
2450'                     #                 #';
2451'                     #                 #';
2452'%%%                  #                 #';
2453'%%%                  #                 #';
2454'                     #                 #';
2455'                     #                 #';
2456'       %%%%          #                 #';
2457'       %%%%          #                 #';
2458'                     #                 #';
2459'                     #                 #';
2460'%%%                  #                 #';
2461'%%%                  #                 #';
2462'                     #                 #';
2463'                     #                 #';
2464'                     #                 #';
2465'                     #                  ';
2466'                    *#                  ';
2467'                     #                  ';
2468'                     #                  ';
2469'       m             #                  ';
2470'###############      #                ##';
2471'              #                     ####';
2472'              #                   ####  ';
2473'              #                 ####    ';
2474'              #               ####      ';
2475'              ##################        ';
2476};
2477		life =  function(s)
2478			if not s.timer then
2479				s.timer = 0
2480			end
2481			s.timer = s.timer + 1
2482			if s.timer < 250 then
2483				laser.on(0, 20, -20)
2484				s.l1on = true
2485			else
2486				s.l1on = false
2487				laser.off()
2488			end
2489			if not s.x then
2490				s.x = 0
2491				s.dx = 0.5
2492
2493			end
2494			if rnd(50) > 25 then
2495				sprite.fill(sprite.screen(), 22 * BW + s.x, BH * 2, 16, 16, 'gold')
2496			else
2497				sprite.fill(sprite.screen(), 22 * BW + s.x, BH * 2, 16, 16, 'red')
2498			end
2499			s.x = s.x + s.dx
2500			if s.x >= 16 * BW then s.dx = -0.5 end
2501			if s.x <= 0 then s.dx = 0.5 end
2502			local h = 26
2503			if s.x > 7 * BW + 8 then h = h - 1 end
2504			if s.x > 9 * BW + 8 then h = h - 1 end
2505			if s.x > 11 * BW + 8  then h = h - 1 end
2506			if s.x > 13 * BW + 8 then h = h - 1 end
2507			if s.x > 15 * BW + 8 then h = h - 1 end
2508			if not s.pos then s.pos = 0 end
2509			if s.pos > 30 then
2510				local c = 'red'
2511				if not phaser_step then
2512					c = 'yellow'
2513				end
2514				phaser_step = not phaser_step
2515				sprite.fill(sprite.screen(), 22 * BW + s.x + BW / 2 - 3, BH * 2 + BH, 4, BH * h, c)
2516				laser_play()
2517				if hero:collision(22 * BW + s.x + BW / 2 - 3, BH * 2 + BH, 4, BH * h) then
2518					hero:state(FLY)
2519				end
2520			elseif not s.l1on then
2521				laser_mute()
2522			end
2523			if s.pos > 60 then s.pos = 0 end
2524			s.pos = s.pos + 1
2525		end;
2526
2527},
2528
2529	{
2530		title = "exit:Exit",
2531		color = "blue",
2532		map = {
2533'                                       #';
2534'                                      ##';
2535'                                        ';
2536'                                        ';
2537'                                        ';
2538'                                        ';
2539'                                        ';
2540'                                        ';
2541'                                        ';
2542'                                        ';
2543'                                        ';
2544'                                        ';
2545'                                        ';
2546'                                        ';
2547'                                        ';
2548'                                       *';
2549'                                      ##';
2550'                                       #';
2551'                                       #';
2552'                                       #';
2553'                                       #';
2554'                                       #';
2555'                                       #';
2556'>                                      #';
2557'########################################';
2558'                                       #';
2559'                                       #';
2560'                                       #';
2561'                                       #';
2562'                                       #';
2563},
2564life = function(s)
2565	if not s.door then
2566		s.door = 0
2567	end
2568	if math.floor(s.door) < 7 then
2569		s.door = s.door + 0.004
2570	end
2571	local x, y, i, xx, yy
2572	x = math.floor(s.door)
2573	local c = map:cell(39, 24 - x)
2574	if x ~= 0 then
2575		c[1] = 0
2576	end
2577	if not s.robots then
2578		s.robots = {}
2579		for i = 1, 3 do
2580			table.insert(s.robots, {rnd(640) + 640, rnd(160) +BH+BH, i, rnd(60) })
2581		end
2582	end
2583	local exp
2584	local laser_on = false
2585	for i=1, #s.robots do
2586		x = s.robots[i][1]
2587		y = s.robots[i][2]
2588		if rnd(50) > 25 then
2589			sprite.fill(sprite.screen(), x, y, BW, BH, 'white');
2590		else
2591			sprite.fill(sprite.screen(), x, y, BW, BH, 'red');
2592		end
2593		s.robots[i][4] = s.robots[i][4] + 1
2594		if s.robots[i][4] > 60 then
2595			if s.robots[i][4] > 80 then
2596				s.robots[i][4] = 0
2597			end
2598			if x < 640 - BW - BW then
2599				local c = 'red'
2600				if not phaser_step then
2601					c = 'yellow'
2602				end
2603				phaser_step = not phaser_step
2604				laser_on = true
2605				sprite.fill(sprite.screen(), x + BW / 2 - 3, y + BH, 4, 22 * BH - y + BH, c)
2606				laser_play()
2607				if hero:collision(x + BW / 2 - 3, y + BH, 4, 22 * BH - y + BH) then
2608					hero:state(FLY)
2609				end
2610			end
2611		end
2612		s.robots[i][1] = x - s.robots[i][3]
2613		if s.robots[i][1] <= 0 then
2614			s.robots[i][3] = - (rnd(2) + 1)
2615			s.robots[i][4] = rnd(60)
2616		elseif s.robots[i][1] >= 640 - BW and s.robots[i][3] < 0 then
2617			s.robots[i][3] = (rnd(2) + 1)
2618			s.robots[i][4] = rnd(60)
2619		end
2620	end
2621	if not laser_on then laser_mute() end
2622end;
2623},
2624
2625}
2626