Advertisement
CrazedProgrammer

3 Game Pak

Jul 2nd, 2016 (edited)
1,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 37.47 KB | None | 0 0
  1. --[[
  2. 3 Game Pak by CrazedProgrammer
  3.  
  4. The MIT License (MIT)
  5.  
  6. Copyright (c) 2016 CrazedProgrammer
  7.  
  8. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  9.  
  10. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  11.  
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13. ]]
  14.  
  15. local screenwidth, screenheight = term.getSize()
  16. local screenoffset = 19 - screenheight
  17. if not (_HOST and screenwidth == 51 and (screenheight == 19 or screenheight == 18) and term.isColor()) then
  18.     if term.isColor() then
  19.         term.setTextColor(colors.red)
  20.     end
  21.     print("This program is not compatible with your current setup.\nRequirements:\n- ComputerCraft version 1.76 or newer\n- Must be ran on an Advanced Computer or a Command Computer\n- No more than 1 multishell instance")
  22.     return
  23. end
  24.  
  25. -- Assets
  26.  
  27. local img = {
  28.     crazed = "8888888888888888\n8f000f000fff00f7\n80ffff0ff0f0ff07\n80ffff000ff00007\n8f000f0ff0f0ff07\n8ffffffffffffff7\n80000f0000f000f7\n8ff0ff000ff0ff07\n8f0fff0ffff0ff07\n80000f0000f000f7\n8777777777777777\n       77\n      7777\n  888888888888\n  8777778778b8\n  888888888888"
  29. ,   madeby = "000 00                      00000\n0  0  0         0           0    0\n0  0  0         0           0    0\n0  0  0  000  000  000      00000  0   0\n0  0  0 0  0 0  0 00000     0    0  0 0\n0  0  0 0  0 0  0 0         0    0   0\n0     0  000  000  000      00000    0\n                                    0\n                                   0\n"
  30. ,   title1 = "1111111111\n1111111111\n       111\n     1111\n   1111\n 1111\n1111111111\n1111111111\n       111\n     1111\n    1111\n  1111\n 1111\n111\n11\n"
  31. ,   title2 = "  00000\n 0000000\n000    0\n00        00000   00 00 000    0000\n00  0000  000000  0000000000  000000\n00  0000      00  00  00  00  00  00\n00    00    0000  00  00  00  000000\n000   00  00  00  00  00  00  00\n 0000000  000000  00  00  00  000000\n  00000    00000  00  00  00   00000\n"
  32. ,   title3 = "000000           00\n0000000          00\n00   00          00\n00   00  00000   00   00\n00   00  000000  00  00\n0000000      00  00 00\n000000     0000  0000\n00       00  00  00 00\n00       000000  00  00\n00        00000  00   00\n"
  33. ,   help = "bbbbbbbbbbbbbbbbbb\nb0b0b000b0bbb00bbb\nb000b00bb0bbb0b0bb\nb0b0b0bbb0bbb00bbb\nb0b0b000b000b0bbbb\nbbbbbbbbbbbbbbbbbb\n"
  34. ,   exit = "eeeeeeeeeeeeeeeeee\ne000e0e0e000e000ee\ne00eee0eee0eee0eee\ne0eeee0eee0eee0eee\ne000e0e0e000ee0eee\neeeeeeeeeeeeeeeeee\n"
  35. ,   drdan = "333333333333333333333333333333\n3eeee33eee3333eeee33eee33eeee3\n33e33e3e33e3333e33e33e3e33e33e\n33e33e3e33e3333e33e33e3e33e33e\n33e33e3eee33333e33e3eeeee3e33e\n33e33e3e3e33333e33e3e333e3e33e\n3eeee33e33e333eeee43e33be3e33e\n33ee33333333e333ee4433bbee3333\n33ee3333333333333e43333be33333\n3b4333eebb3333bb333343343333ee\nbb44b3eebb3333bb333343343333ee\n3b433beebb3333bb333344443333ee\neeb7b734e333333e43bb47473b4333\nee7bbb44ee3333ee44bb4444bb4433\neeb77b34e333333e43bb47773b4333\nbbbbbbbb34b33333ee3343b4333333\nb3b33b3b44bb3333ee3344b4433333\n33bb3bb334b33333ee3333bb333333\n9be9999eb9ee999994b99999999944\nbbee99eebbee999944bb9999999944\n9be9999eb9ee999994b9cccccc9944\n9994b94499999eb9999c6666669999\n9944bb449999eebb999c6666669999\n9994b94499999eb9999c7777771119\n44e7e7ee9999999991167767761111\n44eeeeeb9999999111166666661111\n44e7eeeb9999991111166666661111\nbb9e77e994e9991111880000081111\nbb9e99e944ee911110008000800011\nbbee99ee94e9911110000888000011\nee999be99999911110000070000011\nee99bbee9999911110000700000011\nee999be99999991110000700000011\n"
  36. ,   font1 = "0000    0 0000 0000 0  0 0000 0000 0000 0000 0000\n0  0    0    0    0 0  0 0    0       0 0  0 0  0\n0  0    0 0000 0000 0000 0000 0000    0 0000 0000\n0  0    0 0       0    0    0 0  0    0 0  0    0\n0000    0 0000 0000    0 0000 0000    0 0000 0000\n"
  37. ,   font2 = " 00  000   000 000  0000 0000  000 0  0 0000 0000 0  0 0    0000 0  0  00  000   00  000   000 0000 0  0 0  0 0  0 0  0 0  0 0000\n0  0 0  0 0    0  0 0    0    0    0  0   0     0 0 0  0    0000 00 0 0  0 0  0 0  0 0  0 0      0  0  0 0  0 0 00 0  0 0  0    0\n0000 000  0    0  0 0000 0000 0 00 0000   0     0 00   0    0 00 0 00 0  0 0  0 0  0 000   00    0  0  0 0  0 0 00  00   000   0\n0  0 0  0 0    0  0 0    0    0  0 0  0   0     0 0 0  0    0 00 0  0 0  0 000  0 00 0 0     0   0  0  0  00  0000 0  0    0  0\n0  0 000   000 000  0000 0     000 0  0 0000 000  0  0 0000 0  0 0  0  00  0     000 0  0 000    0   00   00   0 0 0  0 000  0000\n"
  38. ,   leftsidepinkpipe = "f02\nf02\nf02"
  39. ,   rightsidepinkpipe = "20f\n20f\n20f"
  40. ,   bottomsidepinkpipe = "00\nff\nff"
  41. ,   topsidepinkpipe = "ff\nff\n00"
  42. ,   lefttoppinkpipe = "ff\nff\nf0"
  43. ,   righttoppinkpipe = "ff\nff\n0f"
  44. ,   leftbottompinkpipe = "f0\nff\nff"
  45. ,   rightbottompinkpipe = "0f\nff\nff"
  46. ,   decreasearrow = "  b\n bb\nbbb\n bb\n  b"
  47. ,   increasearrow = "b  \nbb \nbbb\nbb \nb  "
  48. ,   leftsidecyanpipe = "9079\n9079\n9079"
  49. ,   rightsidecyanpipe = "9709\n9709\n9709"
  50. ,   bottomsidecyanpipe = "99\n77\n99"
  51. ,   topsidecyanpipe = "99\n77\n99"
  52. ,   lefttopcyanpipe = "9999\n9077\n9079"
  53. ,   righttopcyanpipe = "9999\n7709\n9709"
  54. ,   leftbottomcyanpipe = "9079\n9077\n9999"
  55. ,   rightbottomcyanpipe = "9709\n7709\n9999"
  56. ,   drdanlevel = "f    ffff f  f ffff f\nf    f    f  f f    f\nf    ffff f  f ffff f\nf    f     ff  f    f\nffff ffff  ff  ffff ffff\n"
  57. ,   drdanspeed = " fff fff  ffff ffff fff\nf    f  f f    f    f  f\n ff  f  f ffff ffff f  f\n   f fff  f    f    f  f\nfff  f    ffff ffff fff\n"
  58. ,   drdanvirus = "f  f ffff fff  f  f  fff\nf  f   f  f  f f  f f\nf  f   f  fff  f  f  ff\n ff    f  f f  f  f    f\n ff  ffff f  f  ff  fff\n"
  59. ,   drdanvirus1 = "e \n e\ne "
  60. ,   drdanvirus2 = " e \ne \n e"
  61. ,   drdanblob = "ee\nee\nee"
  62. ,   drdanpillleft = " e\nee\n e"
  63. ,   drdanpillright = "e \nee\ne "
  64. ,   drdanpilltop = "  \nee\nee"
  65. ,   drdanpillbottom = "ee\nee\n  "
  66. ,   drdantop = "ffff  ff  fff\n  f  f  f f  f\n  f  f  f f  f\n  f  f  f fff\n  f   ff  f\n"
  67. ,   drdanscore = " fff  fff  ff  fff  ffff\nf    f    f  f f  f f\n ff  f    f  f fff  ffff\n   f f    f  f f f  f\nfff   fff  ff  f  f ffff"
  68. ,   drdandrdan = "   cccccc\n  c666666\n  c666666\n  c777777\n  6776776\n  6666666\n  6666666\n 88000008\n00080008000\n00008880000\n00000700000\n00007000000\n00007000000\n"
  69. ,   drdanbigpillleft = " eee\neeee\neeee\n eee"
  70. ,   drdanbigpillright = "eee \neeee\neeee\neee "
  71. ,   stackerdx = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nbb88b888bb8bbb88b8b8b888b88bbb\nb8bbbb8bb8b8b8bbb8b8b8bbb8b8bb\nbb8bbb8bb888b8bbb88bb888b88bbb\nbbb8bb8bb8b8b8bbb8b8b8bbb8b8bb\nb88bbb8bb8b8bb88b8b8b888b8b8bb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbb11111bbbb11bbb11b\nbbbbbbbbbbbbb111111bbb11bbb11b\nbbbbbbbbbbbbb11bb111bbb11b11bb\nbbbbbbbbbbbbb11bbb11bbbb111bbb\nbbbbbbbbbbbbb11bbb11bbbb111bbb\nbbbbbbbbbbbbb11bbb11bbbb111bbb\nbbbbbbbbbbbbb11bb111bbb11b11bb\nbbbbbbbbbbbbb111111bbb11bbb11b\nbbbbbbbbbbbbb11111bbbb11bbb11b\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nbb00000bbbbbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbb000000bbbbbbbbbbbb\nbbbbbbbbbbb0000000bbbbbbbbbbbb\nbbbbbbbbbb000000000bbbbbbbbbbb\nbbbbbbbbbb000000000bbbbbbbbbbb\nbbbbbbbbb0000000000bbbbbbbbbbb\nbbbbbbbbb000000000000bbbbbbbbb\nbbbbbbbb000000000000000bbbbbbb\nbbbbbbb0000000000000000bbbbbbb\n"
  72. ,   bhbird1 = "          dd\n         dddd\n         d00d\n         0ff0\n         ffff\n        ffffff\n       ffffffff\n      ffffffffff\n      ffffffffff\n     fffff00fffff\n    fff  1001 ffff\n    ff  11  11  ff\n        11  11\n"
  73. ,   bhbird2 = "          dd\n         dddd\n         d00d\n         0ff0\n         ffff\n   fff  ffffff  fff\n ffffffffffffffffffff\nffffffffffffffffffffff\nff    ffffffffff    ff\n        ff00ff\n         1001\n        11  11\n        11  11\n"
  74. ,   bhbird3 = "          dd\n  ff     dddd     ff\n fff     d00d     fff\n ffff    0ff0    ffff\n  fffff  ffff  fffff\n   ffffffffffffffff\n    ffffffffffffff\n     ffffffffffff\n       ffffffff\n        ff00ff\n         1001\n        11  11\n        11  11\n"
  75. ,   bhdead1 = "     ff      \n  110ff   fff\n1 110ff  ffff\n10000ff0fffff\n 000ff0fffff \n 000fffffff  \n  00ffffff   \n   0ffff     \n   ffff      \n   0000      \n 11dddd      \n111db0d      \n   dddd      \n"
  76. ,   bhdead2 = "      ff\nfff   ff011\nffff  ff011 1\nfffff0ff00001\n fffff0ff000\n  fffffff000\n   ffffff00\n     ffff0\n      ffff\n      0000\n      dddd11\n      d0bd111\n      dddd\n"
  77. ,   birdhunt = "eeeeee333ee33eeeeee333eeeeee33\neeeeeee33ee33eeeeeee33eeeeeee3\nee333ee33ee33ee333ee33ee333eee\nee333ee33ee33ee333ee33ee3333ee\neeeeee333ee33eeeeee333ee3333ee\neeeeeee33ee33eeeee3333ee3333ee\nee333ee33ee33ee33ee333ee3333ee\nee333ee33ee33ee33ee333ee333eee\neeeeeee33ee33ee333ee33eeeeeee3\neeeeee333ee33ee333ee33eeeeee33\n333333333333333333333333333333\n333333333333333333333333333333\nee33ee33ee33ee33ee333ee3eeeeee\nee33ee33ee33ee33eee33ee333ee33\nee33ee33ee33ee33eee33ee333ee33\neeeeee33ee33ee33ee3e3ee333ee33\nee33ee33ee33ee33ee3e3ee333ee33\nee33ee33ee33ee33ee33eee333ee33\nee33ee33ee33ee33ee33eee333ee33\nee33ee333eeee333ee333ee333ee33\n333333333333333333353333333333\n333333333333333553353333333355\n533333333333555553355333553355\n533533535533555553355333553555\n555533535535555555355335555555\nd5555553553555555555555555555d\nd555555555555d555555555555d55d\ndd5d55555d555dd555d555d555d5dd\ndd5ddddd5ddd5dd5ddddd5d5dddddd\ndd5ddddddddd5dddddddd5d5dddddd\ndd5ddddddddd5dddddddd5dddddddd\ndd5ddddddddddddddddddddddddddd\ndddddddddddddddddddddddddddddd\n"
  78. }
  79. -- Global variables
  80. local mode = 1
  81. local quit = false
  82.  
  83. -- Save data functions
  84.  
  85. local savedata = {drdantopscore = 0, stackerdxtopscore = 0, birdhunttopscore = 0}
  86. local savedatapath = fs.getDir(shell.getRunningProgram()).."/3gpsave.sav"
  87.  
  88. local function save()
  89.     local handle = fs.open(savedatapath, "w")
  90.     if not handle then return end
  91.     handle.write(textutils.serialize(savedata))
  92.     handle.close()
  93. end
  94.  
  95. local function loadSave()
  96.     local handle = fs.open(savedatapath, "r")
  97.     if not handle then
  98.         save()
  99.         return
  100.     end
  101.     local data = textutils.unserialize(handle.readAll())
  102.     handle.close()
  103.     local legit = true
  104.     if type(data) ~= "table" then
  105.         legit = false
  106.     end
  107.     if not legit then
  108.         fs.delete(savedatapath)
  109.         save()
  110.     else
  111.         savedata = data
  112.     end
  113. end
  114.  
  115. -- Graphics functions
  116.  
  117. local colorhex, smallchar = { }, { }
  118. local buffer = { }
  119.  
  120. local function clearScreen(color)
  121.     for i = 1, 102 * 57 do
  122.         buffer[i] = color
  123.     end
  124. end
  125.  
  126. local screenendline = 1, 19
  127.  
  128. local function renderScreen()
  129.     local commands, charline, mainline, subline, index, sub, char, c1, c2, c3, c4, c5, c6 = { }, { }, { }, { }, nil, 32768
  130.     for j = 0, 18 do       
  131.         for i = 0, 50 do
  132.             index = (j * 3) * 102 + (i * 2)
  133.             c1, c2, c3, c4, c5, c6 = buffer[index + 1], buffer[index + 2], buffer[index + 103], buffer[index + 104], buffer[index + 205], buffer[index + 206]
  134.             char = 0
  135.             if c1 ~= c6 then
  136.                 sub = c1
  137.                 char = 1
  138.             end
  139.             if c2 ~= c6 then
  140.                 sub = c2
  141.                 char = char + 2
  142.             end
  143.             if c3 ~= c6 then
  144.                 sub = c3
  145.                 char = char + 4
  146.             end
  147.             if c4 ~= c6 then
  148.                 sub = c4
  149.                 char = char + 8
  150.             end
  151.             if c5 ~= c6 then
  152.                 sub = c5
  153.                 char = char + 16
  154.             end
  155.             charline[i + 1] = smallchar[char + 1]
  156.             mainline[i + 1] = colorhex[c6]
  157.             subline[i + 1] = colorhex[sub]
  158.         end
  159.         commands[#commands + 1] = table.concat(charline)
  160.         commands[#commands + 1] = table.concat(subline)
  161.         commands[#commands + 1] = table.concat(mainline)
  162.     end
  163.     for i = 1 + screenoffset, screenendline do
  164.         term.setCursorPos(1, i - screenoffset)
  165.         term.blit(commands[i * 3 - 2], commands[i * 3 - 1], commands[i * 3])
  166.     end
  167. end
  168.  
  169. local function drawImage(image, x, y, color, sx, swidth)
  170.     sx, swidth = sx or 0, swidth or 9999
  171.     local ix, iy, c = 0, 0
  172.     for i = 1, #image do
  173.         c = image[i]
  174.         if c then
  175.             if c ~= 0 and ix >= sx and ix < sx + swidth and (x + ix - sx) >= 0 and (y + iy) >= 0 and (x + ix - sx) < 102 and (y + iy) < 57 then
  176.                 buffer[(y + iy) * 102 + x + ix - sx + 1] = color or c
  177.             end
  178.             ix = ix + 1
  179.         else
  180.             ix = 0
  181.             iy = iy + 1
  182.         end
  183.     end
  184. end
  185.  
  186. local function drawText(text, x, y, font, charwidth, offset, color)
  187.     for i = 1, #text do
  188.         local c = string.byte(text, i)
  189.         if c >= offset then
  190.             drawImage(font, x + (i - 1) * (charwidth + 1), y, color, (c - offset) * (charwidth + 1), charwidth)
  191.         end
  192.     end
  193. end
  194.  
  195. local function drawRect(color, x, y, width, height)
  196.     if x < 0 then
  197.         width = width + x
  198.         x = 0
  199.     end
  200.     if y < 0 then
  201.         height = height + y
  202.         y = 0
  203.     end
  204.     if x + width > 102 then
  205.         width = 102 - x
  206.     end
  207.     if y + height > 57 then
  208.         height = 57 - y
  209.     end
  210.     for j = 0, height - 1 do
  211.         for i = 0, width - 1 do
  212.             buffer[(j + y) * 102 + i + x + 1] = color
  213.         end
  214.     end
  215. end
  216.  
  217. -- Intro
  218.  
  219. local introstep = 0
  220.  
  221. local function updateIntro()
  222.     introstep = introstep + 1
  223.     local i = introstep
  224.     if i <= 106 then
  225.         clearScreen(colors.blue)
  226.         for j = 0, 101 do
  227.             local y = math.floor(math.sin(i / 7 + j / 17) * 7 + 0.5) + 43
  228.             if i > 60 then
  229.             y = y - (i - 60) * 3
  230.             end
  231.             if y < 0 then y = 0 end
  232.             for k = y, 56 do
  233.                 buffer[k * 102 + j + 1] = 512
  234.             end
  235.         end
  236.         drawImage(img.crazed, 43, 23)
  237.         drawImage(img.madeby, 31, 11)
  238.         if i >= 75 then
  239.             local gray = math.floor(56 - (i - 75) * 3.5)
  240.             local black = math.floor(56 - (i - 90) * 3.5)
  241.             if gray < 0 then gray = 0 end
  242.             if black < 0 then black = 0 end
  243.             for j = 0, 101 do
  244.                 for k = gray, 56 do
  245.                     buffer[k * 102 + j + 1] = 128
  246.                 end
  247.                 if black < 57 then
  248.                     for k = black, 56 do
  249.                         buffer[k * 102 + j + 1] = 32768
  250.                     end
  251.                 end
  252.             end
  253.         end
  254.        
  255.         if i <= 19 then
  256.             term.scroll(-1)
  257.             screenendline = i
  258.         end
  259.     elseif i >= 107 and i <= 112 then
  260.         local flash = {colors.gray, colors.white, colors.white, colors.lightGray, colors.gray, colors.gray}
  261.         clearScreen(flash[i - 106])
  262.     else
  263.         mode = 2
  264.     end
  265. end
  266.  
  267. local function keyIntro()
  268.     if mode == 1 then
  269.         mode = 2
  270.         screenendline = 19
  271.     end
  272. end
  273.  
  274. local function clickIntro()
  275.     keyIntro()
  276. end
  277.  
  278. -- Help
  279.  
  280. -- Dr Dan
  281.  
  282. local drdanmode, drdanplayfield, drdanvirus, drdanstep, drdanscore, drdanpill1, drdanpill2, drdannextpill1, drdannextpill2
  283. local drdanpillx1
  284. local drdanpillx2
  285. local drdanpilly1
  286. local drdanpilly2
  287. local drdankeyleft
  288. local drdankeyright
  289. local drdankeytapleft
  290. local drdankeytapright
  291. local drdankeydown
  292. local drdancombo
  293. local drdanviruslevel = 1
  294. local drdanspeed = 3
  295. local drdancolors = {colors.red, colors.yellow, colors.blue}
  296.  
  297. local function initDrDan()
  298.     drdanmode, drdankeyleft, drdankeyright, drdankeydown = false, false, false, false
  299.     drdanvirus = 0
  300.     drdanstep = 0
  301.     drdanscore = 0
  302.     drdanplayfield = { }
  303.     drdannextpill1 = math.floor(1 + math.random() * 3)
  304.     drdannextpill2 = math.floor(1 + math.random() * 3)
  305. end
  306.  
  307. local function updateInitLevelDrDan()
  308.     local totalvirus = math.floor(drdanviruslevel * 1.5) + 1
  309.     local miny = 12 - math.floor(drdanviruslevel / 20 * 5)
  310.     if drdanvirus < totalvirus then
  311.         while true do
  312.             local x, y = math.floor(math.random() * 8), math.floor(miny + math.random() * (16 - miny))
  313.             if drdanplayfield[(y * 8 + x) * 2 + 2] ~= 1 then
  314.                 drdanplayfield[(y * 8 + x) * 2 + 1] = math.floor(1 + math.random() * 3)
  315.                 drdanplayfield[(y * 8 + x) * 2 + 2] = 1
  316.                 drdanvirus = drdanvirus + 1
  317.                 break
  318.             end
  319.         end
  320.     else
  321.         drdankeydown = false
  322.         drdanmode = 2
  323.     end
  324. end
  325.  
  326. local function updateInitGameDrDan()
  327.     if drdanvirus == 0 then
  328.         drdanplayfield = { }
  329.         drdanscore = drdanscore + drdanviruslevel * 5 + drdanspeed
  330.         drdanviruslevel = drdanviruslevel + 1
  331.         drdanmode = 1
  332.         return
  333.     end
  334.     drdanpill1 = drdannextpill1
  335.     drdanpill2 = drdannextpill2
  336.     drdanori = 1
  337.     drdanpillx1 = 3
  338.     drdanpilly1 = 0
  339.     drdanpillx2 = 4
  340.     drdanpilly2 = 0
  341.     drdannextpill1 = math.floor(1 + math.random() * 3)
  342.     drdannextpill2 = math.floor(1 + math.random() * 3)
  343.     if not (drdanplayfield[7] or drdanplayfield[9]) then
  344.         drdanmode = 3
  345.     else
  346.         if drdanscore > savedata.drdantopscore then
  347.             savedata.drdantopscore = drdanscore
  348.         end
  349.         drdanmode = 5
  350.         if drdanplayfield[7] then
  351.             drdanplayfield[9] = drdanpill2
  352.             drdanplayfield[10] = 4
  353.         else
  354.             drdanplayfield[7] = drdanpill1
  355.             drdanplayfield[8] = 3
  356.         end
  357.     end
  358. end
  359.  
  360. local function checkRowsDrDan()
  361.     local color = drdanplayfield[1]
  362.     local ybegin = 0
  363.     local row = 0
  364.     local check = false
  365.     for i = 0, 7 do
  366.         for j = 0, 16 do
  367.             local c = drdanplayfield[(j * 8 + i) * 2 + 1]
  368.             if c ~= color then
  369.                 if color and row >= 4 then
  370.                     drdanscore = drdanscore + drdancombo * (1 + (row - 4) * 2)
  371.                     for k = ybegin, j - 1 do
  372.                         if drdanplayfield[(k * 8 + i) * 2 + 2] == 1 then
  373.                             drdanvirus = drdanvirus - 1
  374.                         elseif drdanplayfield[(k * 8 + i) * 2 + 2] == 3 then
  375.                             if drdanplayfield[(k * 8 + i) * 2 + 4] == 4 then
  376.                                 drdanplayfield[(k * 8 + i) * 2 + 4] = 2
  377.                             end
  378.                         elseif drdanplayfield[(k * 8 + i) * 2 + 2] == 4 then
  379.                             if drdanplayfield[(k * 8 + i) * 2] == 3 then
  380.                                 drdanplayfield[(k * 8 + i) * 2] = 2
  381.                             end
  382.                         end
  383.                         drdanplayfield[(k * 8 + i) * 2 + 1] = nil
  384.                         drdanplayfield[(k * 8 + i) * 2 + 2] = nil
  385.                     end
  386.                     check = true
  387.                     drdancombo = drdancombo + 1
  388.                 end
  389.                 ybegin = j
  390.                 row = 1
  391.                 color = c
  392.             else
  393.                 row = row + 1
  394.             end
  395.         end
  396.     end
  397.     return check
  398. end
  399.  
  400. local function updateGameDrDan()
  401.     if drdankeydown or (drdanstep % (20 - drdanspeed * 2) == 0) then
  402.         local newy1 = drdanpilly1 + 1
  403.         local newy2 = drdanpilly2 + 1
  404.         if not (drdanplayfield[(newy1 * 8 + drdanpillx1) * 2 + 1] or drdanplayfield[(newy2 * 8 + drdanpillx2) * 2 + 1]) then
  405.             drdanpilly1 = newy1
  406.             drdanpilly2 = newy2
  407.         end
  408.     end
  409.     if (drdankeyleft or drdankeytapleft) and (drdanstep % 2 == 0) then
  410.         drdankeytapleft = false
  411.         if drdanpillx1 > 0 and drdanpillx2 > 0 then
  412.             local newx1 = drdanpillx1 - 1
  413.             local newx2 = drdanpillx2 - 1
  414.             if not (drdanplayfield[(drdanpilly1 * 8 + newx1) * 2 + 1] or drdanplayfield[(drdanpilly2 * 8 + newx2) * 2 + 1]) then
  415.                 drdanpillx1 = newx1
  416.                 drdanpillx2 = newx2
  417.             end
  418.         end
  419.     end
  420.     if (drdankeyright or drdankeytapright) and (drdanstep % 2 == 0) then
  421.         drdankeytapright = false
  422.         if drdanpillx1 < 7 and drdanpillx2 < 7 then
  423.             local newx1 = drdanpillx1 + 1
  424.             local newx2 = drdanpillx2 + 1
  425.             if not (drdanplayfield[(drdanpilly1 * 8 + newx1) * 2 + 1] or drdanplayfield[(drdanpilly2 * 8 + newx2) * 2 + 1]) then
  426.                 drdanpillx1 = newx1
  427.                 drdanpillx2 = newx2
  428.             end
  429.         end
  430.     end
  431.     if drdanpilly1 == 15 or drdanpilly2 == 15 or drdanplayfield[((drdanpilly1 + 1) * 8 + drdanpillx1) * 2 + 1] or drdanplayfield[((drdanpilly2 + 1) * 8 + drdanpillx2) * 2 + 1] then
  432.         drdanplayfield[(drdanpilly1 * 8 + drdanpillx1) * 2 + 1] = drdanpill1
  433.         drdanplayfield[(drdanpilly1 * 8 + drdanpillx1) * 2 + 2] = 3
  434.         drdanplayfield[(drdanpilly2 * 8 + drdanpillx2) * 2 + 1] = drdanpill2
  435.         drdanplayfield[(drdanpilly2 * 8 + drdanpillx2) * 2 + 2] = 4
  436.         drdancombo = 1
  437.         if checkRowsDrDan() then
  438.             drdanmode = 4
  439.         else
  440.             drdanmode = 2
  441.         end
  442.     end
  443. end
  444.  
  445. local function fallDrDan()
  446.     if drdanstep % 4 == 0 then
  447.         local check = false
  448.         for i = 0, 7 do
  449.             for j = 14, 0, -1 do
  450.                 if drdanplayfield[(j * 8 + i) * 2 + 2] == 2 and not drdanplayfield[((j + 1) * 8 + i) * 2 + 2] then
  451.                     local color = drdanplayfield[(j * 8 + i) * 2 + 1]
  452.                     drdanplayfield[(j * 8 + i) * 2 + 1] = nil
  453.                     drdanplayfield[(j * 8 + i) * 2 + 2] = nil
  454.                     drdanplayfield[((j + 1) * 8 + i) * 2 + 1] = color
  455.                     drdanplayfield[((j + 1) * 8 + i) * 2 + 2] = 2
  456.                     check = true
  457.                 end
  458.             end
  459.         end
  460.         if not (check or checkRowsDrDan()) then
  461.             drdanmode = 2
  462.         end
  463.     end
  464. end
  465.  
  466. local function drawDrDanSetup()
  467.     for j = 0, 56 do
  468.         for i = 0, 101 do
  469.             buffer[j * 102 + i + 1] = ((i % 4 < 2) == not (j % 6 < 3)) and 16384 or 2
  470.         end
  471.     end
  472.     drawRect(colors.black, 21, 6, 60, 48)
  473.     for i = 0, 15 do
  474.         drawImage(img.leftsidepinkpipe, 18, 6 + i * 3)
  475.         drawImage(img.rightsidepinkpipe, 81, 6 + i * 3)
  476.     end
  477.     for i = 0, 30 do
  478.         drawImage(img.bottomsidepinkpipe, 20 + i * 2, 54)
  479.         drawImage(img.topsidepinkpipe, 20 + i * 2, 3)
  480.     end
  481.     drawImage(img.lefttoppinkpipe, 18, 3)
  482.     drawImage(img.righttoppinkpipe, 82, 3)
  483.     drawImage(img.leftbottompinkpipe, 18, 54)
  484.     drawImage(img.rightbottompinkpipe, 82, 54)
  485.     drawText("DR DAN", 36, 7, img.font2, 4, 65, colors.lightBlue)
  486.     drawText("VIRUS LEVEL", 24, 15, img.font2, 4, 65)
  487.     drawText(string.format("%02d", drdanviruslevel), 46, 22, img.font1, 4, 48, colors.red)
  488.     drawImage(img.decreasearrow, 41, 22)
  489.     drawImage(img.increasearrow, 57, 22)
  490.     drawText("SPEED", 39, 31, img.font2, 4, 65)
  491.     drawText(tostring(drdanspeed), 49, 38, img.font1, 4, 48, colors.red)
  492.     drawImage(img.decreasearrow, 44, 38)
  493.     drawImage(img.increasearrow, 55, 38)
  494.     drawRect(colors.white, 38, 45, 26, 7)
  495.     drawText("START", 39, 46, img.font2, 4, 65, colors.black)
  496. end
  497.  
  498. local function drawDrDanPlayfield()
  499.     for j = 0, 56 do
  500.         for i = 0, 101 do
  501.             buffer[j * 102 + i + 1] = ((i % 4 < 2) == not (j % 6 < 3)) and 128 or 256
  502.         end
  503.     end
  504.     drawRect(colors.black, 42, 6, 16, 48)
  505.     for i = 0, 15 do
  506.         drawImage(img.leftsidecyanpipe, 38, 6 + i * 3)
  507.         drawImage(img.rightsidecyanpipe, 58, 6 + i * 3)
  508.     end
  509.     for i = 0, 7 do
  510.         drawImage(img.bottomsidecyanpipe, 42 + i * 2, 54)
  511.         drawImage(img.topsidecyanpipe, 42 + i * 2, 3)
  512.     end
  513.     for j = 0, 15 do
  514.         for i = 0, 7 do
  515.             local v, t = drdanplayfield[(j * 8 + i) * 2 + 1], drdanplayfield[(j * 8 + i) * 2 + 2]
  516.             if v then
  517.                 if t == 1 then
  518.                     drawImage((math.floor(drdanstep / 8 + i + j) % 2 == 0) and img.drdanvirus1 or img.drdanvirus2, 42 + i * 2, 6 + j * 3, drdancolors[v])
  519.                 elseif t == 2 then
  520.                     drawImage(img.drdanblob, 42 + i * 2, 6 + j * 3, drdancolors[v])
  521.                 elseif t == 3 then
  522.                     drawImage(img.drdanpillleft, 42 + i * 2, 6 + j * 3, drdancolors[v])
  523.                 elseif t == 4 then
  524.                     drawImage(img.drdanpillright, 42 + i * 2, 6 + j * 3, drdancolors[v])
  525.                 end
  526.             end
  527.         end
  528.     end
  529.     if drdanmode == 3 and drdanpillx1 and drdanpilly1 then
  530.         drawImage(img.drdanpillleft, 42 + drdanpillx1 * 2, 6 + drdanpilly1 * 3, drdancolors[drdanpill1])
  531.         drawImage(img.drdanpillright, 42 + drdanpillx2 * 2, 6 + drdanpilly2 * 3, drdancolors[drdanpill2])
  532.     end
  533.     drawImage(img.lefttopcyanpipe, 38, 3)
  534.     drawImage(img.righttopcyanpipe, 58, 3)
  535.     drawImage(img.leftbottomcyanpipe, 38, 54)
  536.     drawImage(img.rightbottomcyanpipe, 58, 54)
  537.     drawRect(colors.orange, 4, 5, 32, 16)
  538.     drawRect(colors.black, 5, 6, 30, 15)
  539.     drawImage(img.drdandrdan, 7, 8)
  540.     drawImage(img.drdanbigpillleft, 22, 9, drdancolors[drdannextpill1])
  541.     drawImage(img.drdanbigpillright, 26, 9, drdancolors[drdannextpill2])
  542.     drawRect(colors.yellow, 4, 21, 32, 33)
  543.     drawRect(colors.lightBlue, 6, 22, 28, 31)
  544.     drawImage(img.drdantop, 7, 25)
  545.     drawText(string.format("%05d", savedata.drdantopscore), 9, 31, img.font1, 4, 48, colors.black)
  546.     drawImage(img.drdanscore, 7, 39)
  547.     drawText(string.format("%05d", drdanscore), 9, 45, img.font1, 4, 48, colors.black)
  548.     drawRect(colors.yellow, 64, 6, 32, 48)
  549.     drawRect(colors.lightBlue, 66, 7, 28, 46)
  550.     if drdanmode ~= 5 then
  551.         drawImage(img.drdanlevel, 67, 10)
  552.         drawText(string.format("%02d", drdanviruslevel), 84, 16, img.font1, 4, 48, colors.black)
  553.         drawImage(img.drdanspeed, 67, 24)
  554.         drawText(string.format("%01d", drdanspeed), 89, 30, img.font1, 4, 48, colors.black)
  555.         drawImage(img.drdanvirus, 67, 38)
  556.         drawText(string.format("%02d", drdanvirus), 84, 44, img.font1, 4, 48, colors.black)
  557.     else
  558.         drawText("GAME", 70, 22, img.font2, 4, 65, colors.black)
  559.         drawText("OVER", 70, 31, img.font2, 4, 65, colors.black)
  560.     end
  561. end
  562.  
  563. local function updateDrDan()
  564.     drdanstep = drdanstep + 1
  565.     if not drdanmode then
  566.         drawDrDanSetup()
  567.     else
  568.         if drdanmode == 1 then
  569.             updateInitLevelDrDan()
  570.         elseif drdanmode == 2 then
  571.             updateInitGameDrDan()
  572.         elseif drdanmode == 3 then
  573.             updateGameDrDan()
  574.         elseif drdanmode == 4 then
  575.             fallDrDan()
  576.         end
  577.         drawDrDanPlayfield()
  578.     end
  579. end
  580.  
  581. local function clickDrDan(x, y)
  582.     if not drdanmode then
  583.         if y == 8 or y == 9 then
  584.             if x == 21 or x == 22 then
  585.                 if drdanviruslevel > 1 then
  586.                     drdanviruslevel = drdanviruslevel - 1
  587.                 end
  588.             elseif x == 29 or x == 30 then
  589.                 if drdanviruslevel < 20 then
  590.                     drdanviruslevel = drdanviruslevel + 1
  591.                 end
  592.             end
  593.         elseif y >= 13 and y <= 15 then
  594.             if x == 23 or x == 24 then
  595.                 if drdanspeed > 1 then
  596.                     drdanspeed = drdanspeed - 1
  597.                 end
  598.             elseif x == 28 or x == 29 then
  599.                 if drdanspeed < 9 then
  600.                     drdanspeed = drdanspeed + 1
  601.                 end
  602.             end
  603.         elseif y >= 16 and y <= 18 and x >= 20 and x <= 32 then
  604.             drdanmode = 1
  605.         end
  606.     elseif drdanmode == 5 then
  607.         initDrDan()
  608.         drdanmode = false
  609.     end
  610. end
  611.  
  612. local function keyDrDan(key, hold)
  613.     if drdanmode == 5 then
  614.         initDrDan()
  615.         drdanmode = false
  616.     end
  617.     if key == 203 or key == 263 then
  618.         drdankeyleft = true
  619.         drdankeytapleft = true
  620.     elseif key == 205 or key == 262 then
  621.         drdankeyright = true
  622.         drdankeytapright = true
  623.     elseif key == 208 or key == 264 then
  624.         drdankeydown = true
  625.     elseif (key == 57 or key == 32) and not hold and drdanmode == 3 then
  626.         local temp = drdanpill1
  627.         drdanpill1 = drdanpill2
  628.         drdanpill2 = temp
  629.     end
  630. end
  631.  
  632. local function keyUpDrDan(key)
  633.     if key == 203 or key == 263 then
  634.         drdankeyleft = false
  635.     elseif key == 205 or key == 262 then
  636.         drdankeyright = false
  637.     elseif key == 208 or key == 264 then
  638.         drdankeydown = false
  639.     end
  640. end
  641.  
  642. -- Stacker DX
  643. local sdxmode
  644. local sdxstep
  645. local sdxcamera
  646. local sdxheight
  647. local sdxwidth
  648. local sdxpos
  649. local sdxleft, sdxright
  650. local sdxscore
  651.  
  652. local function initStackerDX()
  653.     sdxmode = 1
  654.     sdxstep = 0
  655.     sdxcamera = 47
  656.     sdxheight = 2
  657.     sdxleft = {35, 35}
  658.     sdxright = {66, 66}
  659.     sdxwidth = 32
  660.     sdxpos = 20
  661.     sdxscore = 0
  662. end
  663.  
  664. local function updateStackerDX()
  665.     sdxstep = sdxstep + 1
  666.     for j = 0, 56 do
  667.         local height = sdxcamera - j
  668.         local color
  669.         if height < 3 then
  670.             color = colors.green
  671.         elseif height < 9 then
  672.             color = colors.lime
  673.         elseif height < 57 then
  674.             color = colors.lightBlue
  675.         elseif height < 81 then
  676.             color = colors.cyan
  677.         elseif height < 111 then
  678.             color = colors.blue
  679.         elseif height < 150 then
  680.             color = colors.black
  681.         end
  682.         for i = 0, 101 do
  683.             buffer[j * 102 + i + 1] = color
  684.         end
  685.         if sdxleft[height + 1] then
  686.             for i = sdxleft[height + 1], sdxright[height + 1] do
  687.                 buffer[j * 102 + i + 1] = 1
  688.             end
  689.         end
  690.     end
  691.     drawImage(img.drdanscore, 9, 5, colors.lightGray)
  692.     drawText(string.format("%05d", sdxscore), 9, 12, img.font1, 4, 48)
  693.     drawImage(img.drdantop, 74, 5, colors.lightGray)
  694.     drawText(string.format("%05d", savedata.stackerdxtopscore), 69, 12, img.font1, 4, 48)
  695.     if sdxmode == 1 then
  696.         if math.floor(sdxstep % 1.5) == 0 then
  697.             sdxpos = sdxpos + 1
  698.         end
  699.         if sdxpos + sdxwidth > 100 then
  700.             sdxmode = 2
  701.             return
  702.         end
  703.        
  704.         local xmax = sdxpos + sdxwidth - 1
  705.         if xmax > 101 then xmax = 101 end
  706.         local height = sdxcamera - sdxheight
  707.         for i = sdxpos, xmax do
  708.             buffer[height * 102 + i + 1] = 1
  709.         end
  710.     else
  711.         if sdxscore > savedata.stackerdxtopscore then
  712.             savedata.stackerdxtopscore = sdxscore
  713.         end
  714.         drawText("GAME OVER", 30, 22, img.font2, 4, 65, (math.floor(sdxstep / 5) % 2 == 0) and colors.gray or colors.lightGray)
  715.     end
  716. end
  717.  
  718. local function keyStackerDX(key, hold)
  719.     if (key == 57 or key == 32) and not hold then
  720.         if sdxmode == 1 then
  721.             local x1 = sdxpos
  722.             local x2 = sdxpos + sdxwidth - 1
  723.             if x2 < sdxleft[sdxheight] or x1 > sdxright[sdxheight] then
  724.                 sdxmode = 2
  725.                 return
  726.             end
  727.             if x1 < sdxleft[sdxheight] then x1 = sdxleft[sdxheight] end
  728.             if x2 > sdxright[sdxheight] then x2 = sdxright[sdxheight] end
  729.             sdxscore = sdxscore + 5 + math.floor(sdxheight / 5)
  730.             sdxheight = sdxheight + 1
  731.             sdxleft[sdxheight] = x1
  732.             sdxright[sdxheight] = x2
  733.             sdxwidth = x2 - x1 + 1
  734.             sdxpos = x1 - 20
  735.             sdxcamera = math.floor((sdxheight + 30) / 3) * 3 + 2
  736.             if sdxcamera < 47 then
  737.                 sdxcamera = 47
  738.             end
  739.         else
  740.             initStackerDX()
  741.         end
  742.     end
  743. end
  744.  
  745. -- Bird Hunt
  746.  
  747. local bhlightgrassheights
  748. local bhdarkgrassheights
  749. local bhbirds
  750. local bhdeadbirds
  751. local bhmode
  752. local bhwave
  753. local bhscore
  754. local bhblackscreen
  755. local bhblackscreenboxx
  756. local bhblackscreenboxy
  757. local bhshots
  758. local bhlives
  759. local bhstep = 0
  760.  
  761. local function initBirdHunt()
  762.     bhlightgrassheights = { }
  763.     for i = 1, 102 do
  764.         bhlightgrassheights[i] = math.floor(40 + math.random() * 7)
  765.     end
  766.     bhdarkgrassheights = { }
  767.     for i = 1, 102 do
  768.         bhdarkgrassheights[i] = math.floor(45 + math.random() * 10)
  769.     end
  770.    
  771.     bhbirds = { }
  772.     bhdeadbirds = { }
  773.     bhmode = 1
  774.     bhwave = 0
  775.     bhscore = 0
  776.     bhlives = 4
  777. end
  778.  
  779. local function initWaveBirdHunt()
  780.     bhbirds = { }
  781.     bhwave = bhwave + 1
  782.     local birds = math.floor((bhwave - 1) / 3) + 1
  783.     for i = 1, birds do
  784.         local bird = { }
  785.         bird.x = math.floor(math.random() * 80)
  786.         bird.y = 70 + math.random() * 85 * birds
  787.         bird.speed = 2.5 + ((bhwave - 1) % 3) * 0.2 + math.random() * 0.2 + bhwave * 0.03
  788.         bird.frame = math.floor(math.random() * 3) + 1
  789.         bhbirds[i] = bird
  790.     end
  791.     bhmode = 2
  792.     bhshots = math.floor(bhwave / 3) + 2
  793. end
  794.  
  795. local function updateGameBirdHunt()
  796.     if #bhbirds == 0 and #bhdeadbirds == 0 then
  797.         bhmode = 1
  798.         return
  799.     end
  800.     local maxy = -100
  801.     for i = 1, #bhbirds do
  802.         local bird = bhbirds[i]
  803.         bird.y = bird.y - bird.speed
  804.         if bird.y > maxy then
  805.             maxy = bird.y
  806.         end
  807.         if math.floor(bhstep * 3) % 2 == 0 then
  808.             bird.frame = bird.frame % 3 + 1
  809.         end
  810.     end
  811.     if maxy < -20 and #bhdeadbirds == 0 then
  812.         bhmode = 3
  813.     end
  814.     local i = 1
  815.     while i <= #bhdeadbirds do
  816.         bhdeadbirds[i].y = bhdeadbirds[i].y + 2
  817.         bhdeadbirds[i].frame = bhdeadbirds[i].frame + 1
  818.         if bhdeadbirds[i].y > 80 then
  819.             table.remove(bhdeadbirds, i)
  820.             i = i - 1
  821.         end
  822.         i = i + 1
  823.     end
  824. end
  825.  
  826. local function updateDeadBirdHunt()
  827.     bhlives = bhlives - 1
  828.     if bhlives > 0 then
  829.         bhmode = 1
  830.     else
  831.         bhmode = 4
  832.     end
  833. end
  834.  
  835. local function updateGameOverBirdHunt()
  836.     if savedata.birdhunttopscore < bhscore then
  837.         savedata.birdhunttopscore = bhscore
  838.     end
  839. end
  840.  
  841. local function drawPlayfieldBirdHunt()
  842.     if bhblackscreen then
  843.         clearScreen(colors.black)
  844.         for i = 1, #bhbirds do
  845.             drawRect(colors.white, bhbirds[i].x, math.floor(bhbirds[i].y), 22, 13)
  846.         end
  847.         if bhblackscreenboxx then
  848.             drawRect(colors.red, bhblackscreenboxx, math.floor(bhblackscreenboxy), 22, 13)
  849.         end
  850.     else
  851.         clearScreen(colors.lightBlue)
  852.         for i = 1, #bhbirds do
  853.             local bird = bhbirds[i]
  854.             local birdimg = img.bhbird1
  855.             if bird.frame == 2 then
  856.                 birdimg = img.bhbird2
  857.             elseif bird.frame == 3 then
  858.                 birdimg = img.bhbird3
  859.             end
  860.             if bird.y < 57 then
  861.                 drawImage(birdimg, bird.x, math.floor(bird.y))
  862.             end
  863.         end
  864.         for i = 1, #bhdeadbirds do
  865.             drawImage((math.floor(bhdeadbirds[i].frame / 4) % 2 == 0) and img.bhdead1 or img.bhdead2, bhdeadbirds[i].x, math.floor(bhdeadbirds[i].y))
  866.         end
  867.         for i = 0, 101 do
  868.             for j = bhlightgrassheights[i + 1], bhdarkgrassheights[i + 1] - 1 do
  869.                 buffer[j * 102 + i + 1] = 32
  870.             end
  871.             for j = bhdarkgrassheights[i + 1], 56 do
  872.                 buffer[j * 102 + i + 1] = 8192
  873.             end
  874.         end
  875.     end
  876.     if bhmode == 2 then
  877.         drawText(string.format("%01d", bhshots), 90, 10, img.font1, 4, 48, colors.gray)
  878.         drawText(string.format("%01d", bhlives), 8, 10, img.font1, 4, 48, colors.blue)
  879.     elseif bhmode == 4 then
  880.         drawText("GAME OVER", 30, 8, img.font2, 4, 65, (math.floor(bhstep / 5) % 2 == 0) and colors.black or colors.white)
  881.         drawText("SHOT   TOP", 25, 16, img.font2, 4, 65, colors.gray)
  882.         drawText(string.format("%04d", bhscore), 25, 23, img.font1, 4, 48, colors.gray)
  883.         drawText(string.format("%04d", savedata.birdhunttopscore), 60, 23, img.font1, 4, 48, colors.gray)
  884.     end
  885.     bhblackscreen = false
  886.     bhblackscreenboxx = false
  887. end
  888.  
  889. local function updateBirdHunt()
  890.     bhstep = bhstep + 1
  891.     if bhmode == 1 then
  892.         initWaveBirdHunt()
  893.     elseif bhmode == 2 then
  894.         updateGameBirdHunt()
  895.     elseif bhmode == 3 then
  896.         updateDeadBirdHunt()
  897.     elseif bhmode == 4 then
  898.         updateGameOverBirdHunt()
  899.     end
  900.     drawPlayfieldBirdHunt()
  901. end
  902.  
  903. local function clickBirdHunt(x, y)
  904.     if bhmode == 2 and bhshots > 0 then
  905.         local sx, sy = (x - 1) * 2 + 1, (y - 1) * 3 + 1
  906.         local totalbirds = #bhbirds
  907.         for i = 1, #bhbirds do
  908.             local bird = bhbirds[i]
  909.             if sx >= bird.x - 1 and sy >= bird.y - 1 and sx < bird.x + 24 and sy < bird.y + 15 then
  910.                 bhbirds[i] = nil
  911.                 bhscore = bhscore + 1
  912.                 local dead = { }
  913.                 dead.x = bird.x + 3
  914.                 dead.y = bird.y
  915.                 dead.frame = 0
  916.                 bhdeadbirds[#bhdeadbirds + 1] = dead
  917.                 local tempbirds = bhbirds
  918.                 local newbirds = { }
  919.                 for j = 1, totalbirds do
  920.                     if tempbirds[j] then
  921.                         newbirds[#newbirds + 1] = tempbirds[j]
  922.                     end
  923.                 end
  924.                 bhbirds = newbirds
  925.                 bhblackscreenboxx = bird.x
  926.                 bhblackscreenboxy = bird.y
  927.                 break
  928.             end
  929.         end
  930.         bhshots = bhshots - 1
  931.         bhblackscreen = true
  932.     elseif bhmode == 4 then
  933.         initBirdHunt()
  934.         bhmode = 1
  935.     end
  936. end
  937.  
  938. -- Help
  939.  
  940. local helpscroll = 0
  941. local helplines = {
  942.     "THREE GAME PAK"
  943. ,   "BY CRAZEDPROGRAMMER"
  944. ,   ""
  945. ,   "USE THE SCROLL WHEEL"
  946. ,   "TO NAVIGATE"
  947. ,   ""
  948. ,   "CONTROLS"
  949. ,   ""
  950. ,   "GENERAL"
  951. ,   ""
  952. ,   " DELETE"
  953. ,   "  CLOSE THE PROGRAM"
  954. ,   " BACKSPACE"
  955. ,   "  RETURN TO MAIN"
  956. ,   "  MENU"
  957. ,   ""
  958. ,   "DR DAN"
  959. ,   ""
  960. ,   " LEFT OR RIGHT ARROW"
  961. ,   "  MOVE THE PILL LEFT"
  962. ,   "  OR RIGHT"
  963. ,   " SPACEBAR"
  964. ,   "  SWAP THE COLOURS"
  965. ,   "  OF THE PILL"
  966. ,   " ANY KEY"
  967. ,   "  WHEN YOU LOSE"
  968. ,   "  RESTART THE GAME"
  969. ,   ""
  970. ,   "STACKER DX"
  971. ,   ""
  972. ,   " SPACEBAR"
  973. ,   "  PLACE THE PLANE ON"
  974. ,   "  TOP OF THE TOWER"
  975. ,   " ANY KEY"
  976. ,   "  WHEN YOU LOSE"
  977. ,   "  RESTART THE GAME"
  978. ,   ""
  979. ,   "BIRD HUNT"
  980. ,   ""
  981. ,   " CLICK"
  982. ,   "  SHOOT AT THE MOUSE"
  983. ,   "  POSITION"
  984. ,   "  IF YOU HIT A DUCK"
  985. ,   "  YOU WILL SEE A"
  986. ,   "  RED BOX"
  987. ,   ""
  988. ,   " CLICK ANYWHERE"
  989. ,   "  WHEN YOU LOSE"
  990. ,   "  RESTART THE GAME"
  991. }
  992. local function updateHelp()
  993.     clearScreen(colors.gray)
  994.     for i = 0, 8 do
  995.         if helplines[i + helpscroll] then
  996.             drawText(helplines[i + helpscroll], 2, 1 + i * 6, img.font2, 4, 65, colors.white)
  997.         end
  998.     end
  999. end
  1000.  
  1001. local function keyHelp(key)
  1002.    
  1003. end
  1004.  
  1005. local function mouseScrollHelp(scroll)
  1006.     helpscroll = helpscroll + scroll
  1007. end
  1008.  
  1009. -- Main Menu
  1010.  
  1011. local function updateMainMenu()
  1012.     clearScreen(colors.black)
  1013.     drawImage(img.title1, 12, 3)
  1014.     drawImage(img.title2, 26, 7)
  1015.     drawImage(img.title3, 66, 7)
  1016.     drawImage(img.help, 32, 51)
  1017.     drawImage(img.exit, 52, 51)
  1018.     drawImage(img.drdan, 2, 21)
  1019.     drawImage(img.stackerdx, 36, 21)
  1020.     drawImage(img.birdhunt, 70, 21)
  1021. end
  1022.  
  1023. local function clickMainMenu(x, y)
  1024.     if y >= 18 and y <= 19 then
  1025.         if x >= 17 and x <= 25 then
  1026.             mode = 3
  1027.         elseif x >= 27 and x <= 35 then
  1028.             quit = true
  1029.         end
  1030.     end
  1031.     if y >= 8 and y <= 18 then
  1032.         if x >= 2 and x <= 16 then
  1033.             initDrDan()
  1034.             mode = 4
  1035.         elseif x >= 36 and x <= 50 then
  1036.             initBirdHunt()
  1037.             mode = 6
  1038.         end
  1039.     end
  1040.     if y >= 8 and y <= 16 and x >= 19 and x <= 33 then
  1041.         initStackerDX()
  1042.         mode = 5
  1043.     end
  1044. end
  1045.  
  1046. -- Event passers
  1047. local function passTimer()
  1048.     if mode == 1 then
  1049.         updateIntro()
  1050.     elseif mode == 2 then
  1051.         updateMainMenu()
  1052.     elseif mode == 3 then
  1053.         updateHelp()
  1054.     elseif mode == 4 then
  1055.         updateDrDan()
  1056.     elseif mode == 5 then
  1057.         updateStackerDX()
  1058.     elseif mode == 6 then
  1059.         updateBirdHunt()
  1060.     end
  1061. end
  1062.  
  1063. local function passKey(key, hold)
  1064.     if key == 211 or key == 261 then
  1065.         quit = true
  1066.     elseif key == 14 or key == 259 then
  1067.         mode = 2
  1068.     elseif mode == 1 then
  1069.         keyIntro()
  1070.     elseif mode == 3 then
  1071.         keyHelp(key, hold)
  1072.     elseif mode == 4 then
  1073.         keyDrDan(key, hold)
  1074.     elseif mode == 5 then
  1075.         keyStackerDX(key, hold)
  1076.     end
  1077. end
  1078.  
  1079. local function passKeyUp(key)
  1080.     if mode == 4 then
  1081.         keyUpDrDan(key)
  1082.     end
  1083. end
  1084.  
  1085. local function passClick(button, x, y)
  1086.     if mode == 1 then
  1087.         clickIntro()
  1088.     elseif mode == 2 then
  1089.         clickMainMenu(x, y)
  1090.     elseif mode == 4 then
  1091.         clickDrDan(x, y)
  1092.     elseif mode == 6 then
  1093.         clickBirdHunt(x, y)
  1094.     end
  1095. end
  1096.  
  1097. -- Main program functions
  1098.  
  1099. local function initProgram()
  1100.     for i = 0, 15 do
  1101.         colorhex[2 ^ i] = string.format("%01x", i)
  1102.     end
  1103.     for i = 1, 32 do
  1104.         smallchar[i] = string.char(127 + i)
  1105.     end
  1106.     local tempimg = { }
  1107.     for k, v in pairs(img) do
  1108.         local image = { }
  1109.         for i = 1, #v do
  1110.             local c = v:sub(i, i)
  1111.             if c == "\n" then
  1112.                 image[#image + 1] = false
  1113.             elseif c ~= "\r" then
  1114.                 local num = tonumber(c, 16)
  1115.                 if num then
  1116.                     image[#image + 1] = 2 ^ num
  1117.                 else
  1118.                     image[#image + 1] = 0
  1119.                 end
  1120.             end
  1121.         end
  1122.         tempimg[k] = image
  1123.     end
  1124.     img = tempimg
  1125.     loadSave()
  1126.     --[[local dx, dy = x, y
  1127.     for i = 1, #image do
  1128.         local c = image:sub(i, i)
  1129.         if c == "\n" then
  1130.             dy = dy + 1
  1131.             dx = x
  1132.         elseif c ~= "\r" then
  1133.             local number = tonumber(c, 16)
  1134.             if number and dx >= 0 and dx < 102 and dy >= 0 and dy < 57 then
  1135.                 buffer[dy * 102 + dx + 1] = 2 ^ number
  1136.             end
  1137.             dx = dx + 1
  1138.         end
  1139.     end]]
  1140. end
  1141.  
  1142. local function runProgram()
  1143.     local timer = os.startTimer(0)
  1144.     while not quit do
  1145.         local e = {os.pullEventRaw()}
  1146.         if e[1] == "timer" and e[2] == timer then
  1147.             timer = os.startTimer(0)
  1148.             passTimer()
  1149.             renderScreen()
  1150.         elseif e[1] == "key" then
  1151.             passKey(e[2], e[3])
  1152.         elseif e[1] == "key_up" then
  1153.             passKeyUp(e[2])
  1154.         elseif e[1] == "mouse_click" then
  1155.             passClick(e[2], e[3], e[4] + screenoffset)
  1156.         elseif e[1] == "mouse_scroll" and mode == 3 then
  1157.             mouseScrollHelp(e[2])
  1158.         elseif e[1] == "terminate" then
  1159.             quit = true
  1160.         end
  1161.     end
  1162. end
  1163.  
  1164. local function quitProgram()
  1165.     save()
  1166.     term.setBackgroundColor(colors.black)
  1167.     term.clear()
  1168.     term.setCursorPos(1, 1)
  1169. end
  1170.  
  1171.  
  1172.  
  1173.  
  1174. -------------------------------------
  1175. initProgram()
  1176. runProgram()
  1177. quitProgram()
  1178.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement