Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 21st, 2012  |  syntax: Lua  |  size: 19.13 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. a = 1
  2. level = 1
  3. levelreached = 1
  4. moves = 0
  5. totalmoves = 0
  6. game = false
  7. finished = false
  8. alpha = 216
  9. levelreached = 1
  10. scroll = 90
  11. leftscroll = false
  12. rightscroll = false
  13. up = true
  14. quit = false
  15. blockpos = {1,1,1,1}
  16. blockdir = 1
  17.  
  18. --tile = {0,4,5,10,20,6,14,0}
  19. tile = {0,84,6,94,21,92,15,82}
  20. tilesel = {0,42,3,47,10,46,7,41}
  21. tc = {0,84,6,94,21,92,15,82}
  22. tcs = {0,42,3,47,10,46,7,41}
  23.  
  24. local floormap = {
  25.         --level 1
  26.         {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  27.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  28.         {1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
  29.         {1,1,1,1,1,1,0,0,0,0,0,0,0,0,0},
  30.         {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
  31.         {0,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
  32.         {0,0,0,0,0,1,1,2,1,1,0,0,0,0,0},
  33.         {0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},
  34.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  35.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  36.         {8,7},1,{1,1,1,1,1,1,1},{2,4,2,4}},
  37.         --level 2
  38.         {{0,0,0,0,0,0,1,1,1,1,0,0,1,1,1},
  39.         {1,1,1,1,0,0,1,1,4,1,0,0,1,2,1},
  40.         {1,1,3,1,0,0,1,1,1,1,0,0,1,1,1},
  41.         {1,1,1,1,0,0,1,1,1,1,0,0,1,1,1},
  42.         {1,1,1,1,0,0,1,1,1,1,0,0,1,1,1},
  43.         {1,1,1,1,0,0,1,1,1,1,0,0,0,0,0},
  44.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  45.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  46.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  47.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  48.         {14,2},2,{3,3,2,5,5,5,6,1},{9,2,2,5,11,5,12,1},{2,5,2,5}},
  49.         --level 3
  50.         {{0,0,0,0,0,0,1,1,1,1,1,1,1,0,0},
  51.         {1,1,1,1,0,0,1,1,1,0,0,1,1,0,0},
  52.         {1,1,1,1,1,1,1,1,1,0,0,1,1,1,1},
  53.         {1,1,1,1,0,0,0,0,0,0,0,1,1,2,1},
  54.         {1,1,1,1,0,0,0,0,0,0,0,1,1,1,1},
  55.         {0,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
  56.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  57.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  58.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  59.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  60.         {14,4},1,{1,1,1,1,1,1,1,1},{2,4,2,4}},
  61.         --level 4
  62.         {{0,0,0,5,5,5,5,5,5,5,0,0,0,0,0},
  63.         {0,0,0,5,5,5,5,5,5,5,0,0,0,0,0},
  64.         {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0},
  65.         {1,1,1,0,0,0,0,0,0,0,1,1,0,0,0},
  66.         {1,1,1,0,0,0,0,0,0,0,1,1,0,0,0},
  67.         {1,1,1,0,0,1,1,1,1,5,5,5,5,5,0},
  68.         {1,1,1,0,0,1,1,1,1,5,5,5,5,5,0},
  69.         {0,0,0,0,0,1,2,1,0,0,5,5,1,5,0},
  70.         {0,0,0,0,0,1,1,1,0,0,5,5,5,5,0},
  71.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  72.         {7,8},1,{1,1,1,1,1,1,1,1},{2,6,2,6}},
  73.         --level 5
  74.         {{0,0,0,0,0,0,0,0,0,0,0,1,1,1,1},
  75.         {0,1,1,1,1,1,1,1,3,1,1,1,1,1,1},
  76.         {0,1,1,1,1,0,0,0,0,0,0,0,1,1,1},
  77.         {0,1,1,3,1,0,0,0,0,0,0,0,0,0,0},
  78.         {0,1,1,1,1,0,0,0,0,0,0,0,0,0,0},
  79.         {0,0,0,1,1,1,3,1,1,1,1,1,1,0,0},
  80.         {0,0,0,0,0,0,0,0,0,0,1,1,1,1,3},
  81.         {1,1,1,0,0,0,0,0,0,0,1,1,1,1,1},
  82.         {1,2,1,1,1,1,1,1,1,1,1,1,1,0,0},
  83.         {1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
  84.         {2,9},4,{9,2,2,2,6,2,7,2},{4,4,2,9,6,9,7,1},{7,6,2,9,6,9,7,0},{15,7,2,9,6,9,7,2},{14,2,14,2}},
  85.         --level 6
  86.         {{0,0,0,0,0,1,1,1,1,1,1,0,0,0,0},
  87.         {0,0,0,0,0,1,0,0,1,1,1,0,0,0,0},
  88.         {0,0,0,0,0,1,0,0,1,1,1,1,1,0,0},
  89.         {1,1,1,1,1,1,0,0,0,0,0,1,1,1,1},
  90.         {0,0,0,0,1,1,1,0,0,0,0,1,1,2,1},
  91.         {0,0,0,0,1,1,1,0,0,0,0,0,1,1,1},
  92.         {0,0,0,0,0,0,1,0,0,1,1,0,0,0,0},
  93.         {0,0,0,0,0,0,1,1,1,1,1,0,0,0,0},
  94.         {0,0,0,0,0,0,1,1,1,1,1,0,0,0,0},
  95.         {0,0,0,0,0,0,0,1,1,1,0,0,0,0,0},
  96.         {14,5},1,{1,1,1,1,1,1,1,1},{1,4,1,4}},
  97.         --level 7
  98.         {{0,0,0,0,0,0,0,0,1,1,1,1,0,0,0},
  99.         {0,0,0,0,0,0,0,0,1,1,1,1,0,0,0},
  100.         {1,1,1,0,0,0,0,0,1,0,0,1,1,1,1},
  101.         {1,1,1,1,1,1,1,1,1,0,0,0,1,2,1},
  102.         {1,1,1,0,0,0,0,1,1,4,0,0,1,1,1},
  103.         {1,1,1,0,0,0,0,1,1,1,0,0,1,1,1},
  104.         {0,1,1,0,0,0,0,1,0,0,0,0,0,0,0},
  105.         {0,0,1,1,1,1,1,1,0,0,0,0,0,0,0},
  106.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  107.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  108.         {14,4},1,{10,5,1,7,4,1},{2,4,2,4}},
  109.         --level 8
  110.         {{0,0,1,1,1,1,0,0,0,0,0,0,0,0,0},
  111.         {0,0,1,2,1,1,0,0,0,0,0,0,0,0,0},
  112.         {0,0,1,1,1,0,0,0,0,0,0,0,0,0,0},
  113.         {0,0,1,0,0,0,1,1,1,1,1,1,0,0,0},
  114.         {0,0,1,0,0,0,1,1,0,0,1,1,0,0,0},
  115.         {0,1,1,1,1,1,1,1,0,0,1,1,1,0,0},
  116.         {0,0,0,0,0,0,1,3,0,0,0,0,1,0,0},
  117.         {0,0,0,0,0,0,1,1,1,1,0,0,1,0,0},
  118.         {0,0,0,0,0,0,1,1,1,1,1,1,1,0,0},
  119.         {0,0,0,0,0,0,0,0,0,1,1,1,0,0,0},
  120.         {4,2},1,{8,7,2,1,6,2,6,0},{2,6,2,6}},
  121.         --level 9
  122.         {{0,0,0,0,0,0,0,0,0,0,0,0,0,4,0},
  123.         {0,0,0,0,0,0,1,1,1,0,0,1,1,1,0},
  124.         {0,0,0,0,0,0,1,4,1,1,1,1,1,0,0},
  125.         {0,0,0,0,1,1,1,1,1,0,0,1,1,0,0},
  126.         {0,0,0,0,1,2,1,0,0,0,0,1,1,0,0},
  127.         {0,1,1,1,1,1,1,0,0,0,1,1,1,1,0},
  128.         {0,1,1,1,1,0,0,0,0,0,1,1,1,1,0},
  129.         {0,1,1,1,1,0,0,1,1,1,1,1,0,0,0},
  130.         {0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},
  131.         {0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},
  132.         {6,5},2,{14,1,1,5,8,1,2},{8,3,1,3,14,1,2},{4,7,4,7}},
  133.         --level 10
  134.         {{1,1,1,5,1,1,1,1,5,1,1,1,1,0,0},
  135.         {1,1,0,0,0,0,0,0,0,0,1,1,1,0,0},
  136.         {1,1,0,0,0,0,0,0,0,0,0,1,1,1,0},
  137.         {1,1,1,0,0,0,1,1,1,0,0,1,1,1,0},
  138.         {1,1,1,5,5,5,1,2,1,0,0,1,1,1,0},
  139.         {1,1,1,0,0,5,1,1,1,0,0,1,1,1,0},
  140.         {0,0,1,0,0,5,5,5,5,5,1,1,0,0,0},
  141.         {0,0,1,1,1,5,5,1,5,5,5,0,0,0,0},
  142.         {0,0,0,1,1,5,5,5,5,5,5,0,0,0,0},
  143.         {0,0,0,1,1,1,0,0,1,1,0,0,0,0,0},
  144.         {8,5},1,{1,1,1,1,1,1},{13,4,13,4}},
  145.         --level 11
  146.         {{0,0,0,0,0,0,0,0,1,1,1,0,0,0,0},
  147.         {0,0,0,1,1,1,0,0,1,1,1,0,0,0,0},
  148.         {1,0,0,1,1,1,1,1,1,1,1,1,1,1,0},
  149.         {1,0,0,1,1,1,0,0,0,0,0,0,4,1,0},
  150.         {1,0,0,0,0,0,0,0,0,0,0,0,1,1,0},
  151.         {1,0,0,0,0,0,0,0,0,0,0,0,1,1,0},
  152.         {1,0,0,0,0,0,0,0,1,1,1,1,1,1,0},
  153.         {1,1,1,1,1,0,0,0,1,1,1,0,0,0,0},
  154.         {0,1,1,2,1,0,0,0,1,1,1,0,0,0,0},
  155.         {0,0,1,1,1,0,0,0,1,1,1,1,1,4,0},
  156.         {4,9},2,{13,4,2,3,2,3,3,2},{14,10,2,4,2,4,3,2},{5,3,5,3}},
  157.         --level 12
  158.         {{1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
  159.         {1,1,1,1,1,1,1,1,1,0,0,0,1,1,1},
  160.         {1,1,1,0,0,0,0,0,1,1,1,1,1,2,1},
  161.         {1,1,1,0,0,0,0,0,0,0,0,0,4,4,1},
  162.         {1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
  163.         {1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
  164.         {1,1,1,0,0,0,0,1,1,1,1,1,4,0,0},
  165.         {1,1,1,1,1,1,1,1,0,0,0,1,1,0,0},
  166.         {1,3,1,0,0,0,0,0,0,0,0,1,1,0,0},
  167.         {1,1,1,0,0,0,0,0,0,0,0,1,4,0,0},
  168.         {14,3},5,{13,4,1,7,7,0},{14,4,1,7,7,1},{13,7,1,3,8,1},{2,9,1,8,9,2},{13,10,2,2,10,8,10,2},{2,2,2,2}},
  169.         --level 13
  170.         {{0,0,0,0,0,0,0,3,0,0,0,0,0,0,0},
  171.         {1,1,3,1,0,0,0,1,0,0,0,0,0,0,0},
  172.         {1,1,1,1,1,0,0,1,0,0,0,0,0,0,0},
  173.         {1,3,1,1,1,1,1,1,0,0,1,1,0,0,1},
  174.         {1,1,1,1,1,0,0,0,1,0,0,0,1,0,0},
  175.         {1,1,3,1,0,0,0,0,1,0,0,0,1,0,0},
  176.         {1,0,0,0,0,0,0,0,3,0,0,1,1,1,0},
  177.         {1,0,0,0,0,0,0,0,0,0,1,1,2,1,0},
  178.         {1,0,0,4,0,0,0,0,0,0,1,1,1,1,0},
  179.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  180.         {13,8},6,{2,4,2,4,9,4,10,0},{3,6,4,9,2,9,3,4,13,4,14,0},{3,2,4,9,2,9,3,4,13,4,14,0},{8,1,2,4,9,4,10,1},{9,7,4,9,2,9,3,4,13,4,14,1},{4,9,1,5,6,2},{3,4,3,4}},
  181.         --level 14
  182.         {{0,1,1,1,1,1,1,1,1,1,3,1,1,1,1},
  183.         {0,0,0,0,0,1,1,0,0,0,0,0,0,1,1},
  184.         {0,0,0,0,0,1,1,0,0,0,0,0,0,1,1},
  185.         {0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  186.         {0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  187.         {1,1,1,0,0,1,1,0,0,1,3,1,1,1,1},
  188.         {1,2,1,0,0,1,1,0,0,0,0,0,0,0,0},
  189.         {1,1,1,0,0,1,1,0,0,0,0,0,0,0,0},
  190.         {0,1,1,0,0,1,1,0,0,0,0,0,0,0,0},
  191.         {0,1,1,1,1,1,1,1,1,1,3,1,1,1,0},
  192.         {2,7},3,{11,1,2,6,8,6,9,2},{11,6,2,10,3,10,4,0},{11,10,2,10,3,10,4,1},{2,1,2,1}},
  193.         --level 15
  194.         {{0,0,0,0,0,0,0,0,1,1,0,0,0,0,0},
  195.         {0,0,0,0,0,0,0,1,1,1,0,0,0,0,0},
  196.         {1,1,0,0,1,1,1,1,1,1,0,0,0,0,0},
  197.         {1,1,1,1,1,1,0,0,1,0,0,0,0,0,0},
  198.         {1,1,1,1,0,0,0,0,1,0,0,0,1,1,1},
  199.         {0,1,1,0,0,0,0,0,4,1,1,1,1,2,1},
  200.         {0,0,1,0,0,0,0,0,4,1,0,0,1,1,1},
  201.         {0,0,1,1,1,0,0,0,1,1,0,0,0,0,0},
  202.         {0,0,0,1,1,1,0,0,1,1,0,0,0,0,0},
  203.         {0,0,0,0,1,1,1,1,1,1,0,0,0,0,0},
  204.         {14,6},2,{9,6,1,10,4,2},{9,7,1,8,6,2},{2,4,2,4}},
  205.         --level 16
  206.         {{0,0,0,0,0,1,1,0,0,0,0,1,1,1,0},
  207.         {0,0,0,1,1,1,1,1,1,0,0,1,2,1,0},
  208.         {1,1,1,1,1,1,3,1,1,1,1,1,1,1,0},
  209.         {1,1,1,1,3,0,0,1,1,1,1,1,0,0,0},
  210.         {1,1,1,0,0,0,0,0,0,1,1,1,0,0,0},
  211.         {0,1,0,0,0,0,0,0,0,0,1,0,0,0,0},
  212.         {0,1,0,0,0,0,0,0,0,0,1,0,0,0,0},
  213.         {0,1,0,0,0,0,0,0,0,1,1,0,0,0,0},
  214.         {0,1,1,0,0,0,0,0,0,1,1,0,0,0,0},
  215.         {0,0,4,0,0,0,0,0,0,4,0,0,0,0,0},
  216.         {13,2},4,{5,4,2,8,3,4,13,0},{7,3,2,8,3,4,13,0},{3,10,1,4,13,2},{10,10,1,8,3,2},{2,4,2,4}}
  217. }
  218.  
  219.         colormap = {{170,170,170},{194,41,0},{100,100,100},{50,50,50},{194,141,0}}
  220.         for i=1,5 do
  221.                 colormap[i] = zmg.makeColor(colormap[i][1],colormap[i][2],colormap[i][3])
  222.         end
  223.  
  224.         --1=tile, 2=finish, 3=button, 4=hard button, 5=orange (weight)
  225.         --button:x,y hardbutton:y,x orange:x,y finish:x,y
  226.         --floormap{{tiles},{finish},nrofbridges,{button1coord,nroftilestobridge,bridge1coord,bridge2coord},{butto...},{startcoord,startcoord}}
  227. function onNewLevel()
  228.         for i=1,4 do
  229.                 blockpos[i] = floormap[level][13+floormap[level][12]][i]
  230.         end
  231.         blockdir = 1
  232.         --blockdir 1=hor, 2=vert
  233.         up = true
  234.         done = false
  235.         win = false
  236.         falling = false
  237.         button = false
  238.         totalmoves = totalmoves + moves
  239.         moves = 0
  240.         alpha = 216
  241.         m=0
  242. end
  243.  
  244. function onarrowKey(key)
  245.  
  246.         if game then
  247.                 if not done then
  248.                 if key==27 then
  249.                         blockpos[1] = blockpos[1] + 1
  250.                         blockpos[3] = blockpos[3] + 1
  251.                         moves = moves+1
  252.                         if up then
  253.                                 up = false
  254.                                 blockdir=1
  255.                                 blockpos[3]=blockpos[1]+1
  256.                                 blockpos[4]=blockpos[2]
  257.                         elseif blockdir==1 then
  258.                                 up = true
  259.                                 blockpos[1] = blockpos[1] + 1
  260.                                 blockpos[3]=blockpos[1]
  261.                                 blockpos[4]=blockpos[2]
  262.                         end
  263.                         if floormap[level][blockpos[2]][blockpos[1]]==0 or floormap[level][blockpos[4]][blockpos[3]]==0 or not floormap[level][blockpos[4]][blockpos[3]] or not floormap[level][blockpos[2]][blockpos[1]]then
  264.                                 done = true
  265.                                 win = false
  266.                         end
  267.                 elseif key==38 then
  268.                         blockpos[1] = blockpos[1] - 1
  269.                         blockpos[3]=blockpos[3] - 1
  270.                         moves = moves+1
  271.                         if up then
  272.                                 up = false
  273.                                 blockdir=1
  274.                                 blockpos[1]=blockpos[1] - 1
  275.                                 blockpos[3]=blockpos[1] + 1
  276.                                 blockpos[4]=blockpos[2]
  277.                         elseif blockdir==1 then
  278.                                 up = true
  279.                                 blockpos[3]=blockpos[1]
  280.                                 blockpos[4]=blockpos[2]
  281.                         end
  282.                         if floormap[level][blockpos[2]][blockpos[1]]==0 or floormap[level][blockpos[4]][blockpos[3]]==0 or not floormap[level][blockpos[4]][blockpos[3]] or not floormap[level][blockpos[2]][blockpos[1]] then
  283.                                 done = true
  284.                                 win = false
  285.                         end
  286.                 elseif key==28 then
  287.                         blockpos[2]=blockpos[2]-1
  288.                         blockpos[4]=blockpos[4]-1
  289.                         moves = moves+1
  290.                         if up then
  291.                                 up = false
  292.                                 blockdir=2
  293.                                 blockpos[2]=blockpos[2]-1
  294.                                 blockpos[3]=blockpos[1]
  295.                                 blockpos[4]=blockpos[2]+1
  296.                         elseif blockdir==2 then
  297.                                 up = true
  298.                                 blockpos[3]=blockpos[1]
  299.                                 blockpos[4]=blockpos[2]
  300.                         end
  301.                         if blockpos[1]<16 and blockpos[1]>0 and blockpos[2]<11 and blockpos[2]>0 then
  302.                         if floormap[level][blockpos[2]][blockpos[1]]==0 or floormap[level][blockpos[4]][blockpos[3]]==0 or not floormap[level][blockpos[4]][blockpos[3]] or not floormap[level][blockpos[2]][blockpos[1]] then
  303.                                 done = true
  304.                                 win = false
  305.                         end
  306.                         else
  307.                                 done = true
  308.                                 win=false
  309.                         end
  310.                 elseif key==37 then
  311.                         blockpos[2]=blockpos[2] + 1
  312.                         blockpos[4]=blockpos[4] + 1
  313.                         moves = moves+1
  314.                         if up then
  315.                                 up = false
  316.                                 blockdir=2
  317.                                 blockpos[3]=blockpos[1]
  318.                                 blockpos[4]=blockpos[2]+1
  319.                         elseif blockdir==2 then
  320.                                 up = true
  321.                                 blockpos[2]=blockpos[2] + 1
  322.                                 blockpos[3]=blockpos[1]
  323.                                 blockpos[4]=blockpos[2]
  324.                         end
  325.                         if blockpos[2]>10 or blockpos[4]>10 then
  326.                                 gmeover = true
  327.                         else
  328.                         if floormap[level][blockpos[2]][blockpos[1]]==0 or floormap[level][blockpos[4]][blockpos[3]]==0 or not floormap[level][blockpos[4]][blockpos[3]] or not floormap[level][blockpos[2]][blockpos[1]] then
  329.                                 done = true
  330.                                 win = false
  331.                                 falling = true
  332.                         end
  333.                         end
  334.                 end
  335.                 if blockpos[1]<16 and blockpos[1]>0 and blockpos[2]<11 and blockpos[2]>0 then
  336.                 for m=0,floormap[level][12]-1 do
  337.                         if floormap[level][floormap[level][13+m][2]][floormap[level][13+m][1]]==3 then
  338.                                 if blockpos[1]==floormap[level][13+m][1] and blockpos[2]==floormap[level][13+m][2] or blockpos[3]==floormap[level][13+m][1] and blockpos[4]==floormap[level][13+m][2] then
  339.                                         button = true
  340.                                         for l=1,floormap[level][13+m][3] do
  341.                                                 if         floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]==0 and floormap[level][13+m][4+2*floormap[level][13+m][3]]==1 then
  342.                                                         floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]=1
  343.                                                 elseif floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]==0 and floormap[level][13+m][4+2*floormap[level][13+m][3]]==0 then
  344.                                                         floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]=0
  345.                                                 elseif floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]==0 and floormap[level][13+m][4+2*floormap[level][13+m][3]]==2 then
  346.                                                         floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]=1
  347.                                                 elseif floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]==1 and floormap[level][13+m][4+2*floormap[level][13+m][3]]==2 then
  348.                                                         floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]=0
  349.                                                 elseif floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]==1 and floormap[level][13+m][4+2*floormap[level][13+m][3]]==0 then
  350.                                                         floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]=0
  351.                                                 elseif floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]==1 and floormap[level][13+m][4+2*floormap[level][13+m][3]]==1 then
  352.                                                         floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]=1
  353.                                                 elseif floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]==0 and floormap[level][13+m][4+2*floormap[level][13+m][3]]==1 then
  354.                                                         floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]=1
  355.                                                 end
  356.                                                 --veld = 1, knop = 0 ==> veld = 0 OK
  357.                                                 --veld = 1, knop = 1 ==> veld = 1 OK
  358.                                                 --veld = 1, knop = 2 ==> veld = 0 OK
  359.                                                 --veld = 0, knop = 0 ==> veld = 0 OK
  360.                                                 --veld = 0, knop = 1 ==> veld = 1 OK
  361.                                                 --veld = 0, knop = 2 ==> veld = 1 OK
  362.                                         end
  363.                                 end
  364.                         elseif floormap[level][floormap[level][13+m][2]][floormap[level][13+m][1]]==4 then
  365.                                 if blockpos[1]==floormap[level][13+m][1] and blockpos[2]==floormap[level][13+m][2] and blockpos[3]==floormap[level][13+m][1] and blockpos[4]==floormap[level][13+m][2] then
  366.                                         for l=1,floormap[level][13+m][3] do
  367.                                                 if floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]==0 then
  368.                                                         floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]=1
  369.                                                 else
  370.                                                         floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]=0
  371.                                                 end
  372.                                         end
  373.                                 end
  374.                         end
  375.                         if floormap[level][blockpos[2]][blockpos[1]]==5 and floormap[level][blockpos[4]][blockpos[3]]==5 and blockpos[1]==blockpos[3] and blockpos[2]==blockpos[4] then
  376.                                 done=true
  377.                                 win=false
  378.                                 falling=true
  379.                         end
  380.                 end
  381.                 if blockpos[1]==floormap[level][11][1] and blockpos[2]==floormap[level][11][2] and up then
  382.                         done=true
  383.                         win=true
  384.                 end
  385.                 else
  386.                         done = true
  387.                         win = false
  388.                
  389.                 moves = moves + 1
  390.                 end
  391.         else
  392.                 if key==38 then
  393.                         if not leftscroll then
  394.                                 leftscroll = true
  395.                         elseif level>2 and leftscroll then
  396.                                 leftscroll = false
  397.                         end
  398.                 end
  399.                 if key==27 then
  400.                         if not rightscroll then
  401.                                 rightscroll = true
  402.                         elseif level<=14 and rightscroll then
  403.                                 rightscroll = false
  404.                         end
  405.                 end
  406.         end
  407. end
  408. end
  409. function ontabKey()
  410. zmg.clear()
  411.         if game then
  412.                 game = false
  413.                 zmg.fastCopy()
  414.         else
  415.                 level = levelreached
  416.                 zmg.fastCopy()
  417.         end
  418. end
  419. function onenterKey()
  420.         if game then
  421.                 if done and win then
  422.                         level=level+1
  423.                         if level>levelreached then
  424.                                 levelreached = level
  425.                         end
  426.                         onNewLevel()
  427.                         --var.store("levelreached",levelreached)
  428.                 end
  429.                 if done and not win then
  430.                         --var.store("levelreached",levelreached)
  431.                 end
  432.                 zmg.fastCopy()
  433.         else
  434.                 game = true
  435.                 zmg.fastCopy()
  436.         end
  437. end
  438.  
  439. function drawTile(x1, x2, xoff, y1, y2, yoff, tcreset)
  440.         for i=1,10 do
  441.                 for j=1,15 do
  442.                         --tcs = {0,42,3,47,10,46,8,41}
  443.                         --tc = {0,84,6,94,21,92,15,82}
  444.        
  445.                         for k=1,7,2 do
  446.                                 --tc[k]=0,84,6,94,21,92,15,82[k]+i*7+j*8-18
  447.                                 --tc[k+1]=0,84,6,94,21,92,15,82[k+1]+i*5-j*1+5
  448.                                 tcs[k]=tcreset[k]+i*x1+j*x2+xoff
  449.                                 tcs[k+1]=tcreset[k+1]+i*y1-j*y2+yoff
  450.                         end
  451.                         if floormap[level][i][j] > 0 then
  452.                                 color = colormap[floormap[level][i][j]]
  453.                                 zmg.drawLine(tcs[1],tcs[2],tcs[3],tcs[4],color)
  454.                                 zmg.drawLine(tcs[3],tcs[4],tcs[5],tcs[6],color)
  455.                                 zmg.drawLine(tcs[5],tcs[6],tcs[7],tcs[8],color)
  456.                                 zmg.drawLine(tcs[7],tcs[8],tcs[1],tcs[2],color)
  457.                         end
  458.  
  459.                 end
  460.         end
  461. end
  462.  
  463. function drawselector()
  464.         zmg.clear()
  465.         -- zmg.drawText(0,0,"levelreached = "..levelreached,0x0000, 0xFFFF)
  466.         zmg.drawText(130,5,"Level "..level,0x0000, 0xFFFF)
  467.         drawTile(3,8,scroll,6,1,40,{0,42,3,47,10,46,8,41})
  468.         zmg.fastCopy()
  469.         key = zmg.keyMenu()
  470.         if levelreached > 1 then
  471.          if level < levelreached then
  472.           if key==27 then
  473.            level = level+1
  474.           end
  475.          end
  476.          if level > 1 then
  477.           if key==38 then
  478.            level = level-1
  479.           end
  480.          end
  481.         end
  482.         if key == 47 then quit = true end
  483. end
  484.  
  485. function drawgame()
  486.         zmg.clear()
  487.         if finished then
  488.                 zmg.drawText(60,25,"Game finished (last level reached)",0x0000, 0xFFFF)
  489.         end
  490.         zmg.drawText(130,5,"Level "..level,0x0000, 0xFFFF)
  491.         -- zmg.drawText(0,0,"levelreached = "..levelreached,0x0000, 0xFFFF)
  492.         drawTile(7,16,-18,11,2,5,{0,84,6,94,21,92,15,82});
  493.         if up then
  494.                 blocktop = {5,74,11,84,26,82,20,72}
  495.                 blockfront = {11,84,11,108,26,106,26,82}
  496.                 blockleft = {5,74,5,98,11,108,11,84}
  497.         elseif blockdir==1 then
  498.                 blocktop = {5,84,11,94,42,90,36,80}
  499.                 blockfront = {11,84,11,108,42,104,42,90}
  500.                 blockleft = {5,84,5,98,11,108,11,84}
  501.         elseif blockdir==2 then
  502.                 blocktop = {5,84,18,105,33,103,20,82}
  503.                 blockfront = {18,105,18,119,33,117,33,103}
  504.                 blockleft = {5,84,5,98,18,119,18,105}
  505.         end
  506.  
  507.         -- HERE
  508.         if done and not win then
  509.                 alpha = alpha - 24
  510.                 if alpha >= 0 then
  511.                         zmg.drawRectFill(0,alpha,384,216-alpha,zmg.makeColor("crimson"))
  512.                         zmg.fastCopy()
  513.                 else
  514.                         onNewLevel()
  515.                         drawgame()
  516.                 end
  517.                 return
  518.         end
  519.  
  520.         for k=1,7,2 do
  521.                 blocktop[k] = blocktop[k]+(blockpos[2]-1)*7+(blockpos[1]-1)*16
  522.                 blocktop[k+1] = blocktop[k+1]+(blockpos[2]-1)*11-(blockpos[1]-1)*2
  523.                 blockfront[k] = blockfront[k]+(blockpos[2]-1)*7+(blockpos[1]-1)*16
  524.                 blockfront[k+1] = blockfront[k+1]+(blockpos[2]-1)*11-(blockpos[1]-1)*2
  525.                 blockleft[k] = blockleft[k]+(blockpos[2]-1)*7+(blockpos[1]-1)*16
  526.                 blockleft[k+1] = blockleft[k+1]+(blockpos[2]-1)*11-(blockpos[1]-1)*2
  527.         end
  528.         if done and win then
  529.                 level = level + 1
  530.                 if level>16 then
  531.                         level = 16
  532.                         finished = true
  533.                 end
  534.                 if level>levelreached then
  535.                         levelreached = level
  536.                 end
  537.                 --var.store("levelreached",levelreached)
  538.                 onNewLevel()
  539.         end
  540.         zmg.drawLine(blocktop[1],blocktop[2],blocktop[3],blocktop[4],zmg.makeColor(80,80,80))
  541.         zmg.drawLine(blocktop[3],blocktop[4],blocktop[5],blocktop[6],zmg.makeColor(80,80,80))
  542.         zmg.drawLine(blocktop[5],blocktop[6],blocktop[7],blocktop[8],zmg.makeColor(80,80,80))
  543.         zmg.drawLine(blocktop[7],blocktop[8],blocktop[1],blocktop[2],zmg.makeColor(80,80,80))
  544.         zmg.drawLine(blockfront[1],blockfront[2],blockfront[3],blockfront[4],zmg.makeColor(0,0,0))
  545.         zmg.drawLine(blockfront[3],blockfront[4],blockfront[5],blockfront[6],zmg.makeColor(0,0,0))
  546.         zmg.drawLine(blockfront[5],blockfront[6],blockfront[7],blockfront[8],zmg.makeColor(0,0,0))
  547.         zmg.drawLine(blockfront[7],blockfront[8],blockfront[1],blockfront[2],zmg.makeColor(0,0,0))
  548.         zmg.drawLine(blockleft[1],blockleft[2],blockleft[3],blockleft[4],zmg.makeColor(40,40,40))
  549.         zmg.drawLine(blockleft[3],blockleft[4],blockleft[5],blockleft[6],zmg.makeColor(40,40,40))
  550.         zmg.drawLine(blockleft[5],blockleft[6],blockleft[7],blockleft[8],zmg.makeColor(40,40,40))
  551.         zmg.drawLine(blockleft[7],blockleft[8],blockleft[1],blockleft[2],zmg.makeColor(40,40,40))
  552.         zmg.drawText(0,5,"Moves: "..moves,0x0000, 0xFFFF)
  553.         zmg.fastCopy()
  554. end
  555.  
  556. function onpaint()
  557.         if game then
  558.                 drawgame()
  559.         else
  560.                 drawselector()
  561.         end
  562.         local key = zmg.keyMenuFast()
  563.         if key==31 then
  564.                 onenterKey()
  565.         elseif key==68 then
  566.                 ontabKey()
  567.         elseif key==38 or key==37 or key==28 or key==27 then
  568.                 onarrowKey(key)
  569.         end
  570. end
  571.  
  572. --Actual start is here
  573. onNewLevel()
  574. zmg.clear()
  575.  
  576. repeat
  577.         if levelreached<16 then
  578.                 finished = false
  579.         else
  580.                 finished = true
  581.         end
  582. if a==1 then
  583.         onpaint()
  584. end
  585.  
  586. zmg.fastCopy()
  587. until zmg.keyMenuFast() == 47 or quit == true