ÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÀ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÌ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌ̬ÀÀÀ¬ÀÀÀ¬ÀÀ¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî € !! í6ÀÀÀÀÀÀÀÀÀÀÌÌ ÌÌ ÌÌ ÌÌ ÌÌ ÀÀÀÀÀÀÀÀÀÀÌÌ ÌÌ ÌÌ ÌÌ ÌÌ ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÌÌ ÌÌ ÀÀÀÀÌÌ ÌÌÌÌÌ ÀÀÌÌÌÀÀÀÀÌ ÀÀÀÀÀÀÀÀÌÌ Ì ÌÌ ÌÌ ÌÌ ÌÌ ÀÀÌÌ ÀÀÀÀÀÀÀÀÌÌ ÌÌ ÌÌÌ ÌÌ ÌÌ ÌÌ ÀÀÌÌ ÌÀÀÀÀÀÀÀÀÀÀÀÀÌ ÀÀÌÌ ÌÌ Ì ÌÌ ÀÀÀÀÌÌ ÀÀÌÌ ÌÌÌ ÌÌÌ ÌÌÌ ÀÀÌÀÀÌÌÌ ÌÀÀÀÀÀÀÀÀÌ ÀÀÌÌ ÌÌ ÌÌ Ì ÌÌ ÀÀÀÀÀÀÌÌ ÀÀÌÌ ÌÌÌÌ ÌÌ Ì ÌÌÌ ÀÀÌÌÀÀÀÀÌ ÌÀÀÀÀÌ ÀÌÀÀÌÌ Ì ÌÌ ÀÀÌÌ Ì ÀÀÌÌ ÌÌ Ì ÌÌÌÌ ÀÀÌÌ ÌÀÌÌÌÀÀÀÀÀÀÀÀÀÀÀÀÀÀÌÌ ÌÌ ÌÌ ÌÌ ÌÌ ÌÌ ÀÀÀÀÀÀÀÀÀÀÀÀÌÌ ÌÌ ÌÌ ÌÌÌÌ ÌÌ ÌÌ ÀÀÀÀÀÀÌÌÀÀÀÀÀÀÀÀÀÀÀÀÀÀÌÌ ÌÌ ÌÌ ÌÌ ÀÀÀÀÀÀÀÀÌÌ ÌÌ ÌÌ ÌÌ ÀÀÀÀÀÀÀÀàîîîààîîàîîîîîàîàîàîàîîàîîîàîîààîîàîîàîîîàîîàîîàîîààîîîàîàîîàîîàîîîîîîîààîàîàîàîîîàîîîàîîààîîîîîîîîîîàîààîîàîîàîîîîîîîàîàîàîàîîîààîîîîîîîàîîàîîàîîîàîààîàîàîàîîîàîàîîàîîàîîàîîàîàîîàîàîîàîàîàîàîàî•:-- title: H+H=H2 -- author: Feishiko -- desc: Tiny puzzle -- site: website link -- license: MIT License (change this to your license of choice) -- version: 0.1 -- script: lua levelTree = {}; --levelTree["st"] = {}; currentLevel = "st"; insNum = {}; idNumber = 1; local obj = {}; function obj:new(_x, _y) local o = {}; o.x = _x; o.y = _y; o.id = idNumber; self.__index = self; idNumber = idNumber + 1; return setmetatable(o, self); end function createObj(_x, _y, _level) local ob = obj:new(_x, _y); ob.level = _level; levelTree[_level] = {}; levelTree[_level][ob.id] = ob; return ob; end function Add2Level(_obj) levelTree[_obj.level][_obj.id] = _obj; insNum[_obj.level] = idNumber; end -- Title local title = createObj(0, 0, "st"); --String, x, y, color, scale, smallfont function printCenter(_str, _x, _y, _col) local length = string.len(_str); print(_str, _x - length*5/2, _y - 3, _col); end function title:draw() cls(15); printCenter("H + H = H2", 240/2, 30, 10); printCenter("PRESS ARROW KEYS TO CONTINUE", 240/2, 136/2, 12); printCenter("Game By Feishiko", 240/2, 126, 12); if btnp(0) or btnp(1) or btnp(2) or btnp(3) then currentLevel = "level1"; if pmem(0) ~= 0 then currentLevel = "level"..pmem(0); end end end --levelTree[title.level][title.id] = title; Add2Level(title); -- Level1 idNumber = 1; local level1 = createObj(0, 0, "level1"); asciiMap = {}; asciiMap[1] =[[ ####### #.H..H# #.##### #.# #.##### #....@# ####### ]]; function gridMapCreate(_weight, _height, _map) gridMap = {}; for iter = 1, _weight do gridMap[iter] = {}; end n = 1; j = 1; repeat for i = 1, _weight do gridMap[i][j] = string.sub(_map, n, n); if i == _weight then j = j + 1; n = n + 2; break; end n = n + 1; end until j > _height return gridMap; end level1Map = gridMapCreate(7, 7, asciiMap[1]); function PlayerData(_width, _height, _map) for i = 1,_width do for j = 1,_height do if _map[i][j] == "@" then local posPlayer = {}; posPlayer.x = i; posPlayer.y = j; return posPlayer; end end end end function PlayerMovement(_map, _width, _height) local player = PlayerData(_width, _height, _map); -- Controls if(_map[player.x][player.y - 1] ~= "#" and btnp(0)) then if(_map[player.x][player.y - 1] == ".") then _map[player.x][player.y] = "."; player.y = player.y - 1; _map[player.x][player.y] = "@"; elseif(_map[player.x][player.y - 2] == "H") and _map[player.x][player.y - 1] == "H" then _map[player.x][player.y] = "."; player.y = player.y - 1; _map[player.x][player.y] = "@"; _map[player.x][player.y - 1] = "H2"; elseif(_map[player.x][player.y - 2] == "." and _map[player.x][player.y - 1] == "H") then _map[player.x][player.y] = "."; player.y = player.y - 1; _map[player.x][player.y] = "@"; _map[player.x][player.y - 1] = "H"; elseif(_map[player.x][player.y - 1] == "H2" and _map[player.x][player.y - 2] == ".") then _map[player.x][player.y] = "."; player.y = player.y - 1; _map[player.x][player.y] = "@"; _map[player.x][player.y - 1] = "H2"; elseif(_map[player.x][player.y - 1] == "H2" and _map[player.x][player.y - 2] == "H") then _map[player.x][player.y] = "."; player.y = player.y - 1; _map[player.x][player.y] = "@" _map[player.x][player.y - 1] = "H3"; elseif(_map[player.x][player.y - 1] == "H" and _map[player.x][player.y - 2] == "H2") then _map[player.x][player.y] = "."; player.y = player.y - 1; _map[player.x][player.y] = "@"; _map[player.x][player.y - 1] = "H3"; end end if(_map[player.x][player.y + 1] ~= "#" and btnp(1)) then if(_map[player.x][player.y + 1] == ".") then _map[player.x][player.y] = "."; player.y = player.y + 1; _map[player.x][player.y] = "@"; elseif(_map[player.x][player.y + 2] == "H" and _map[player.x][player.y + 1] == "H") then _map[player.x][player.y] = "."; player.y = player.y + 1; _map[player.x][player.y] = "@"; _map[player.x][player.y + 1] = "H2"; elseif(_map[player.x][player.y + 2] == "." and _map[player.x][player.y + 1] == "H") then _map[player.x][player.y] = "."; player.y = player.y + 1; _map[player.x][player.y] = "@"; _map[player.x][player.y + 1] = "H"; elseif(_map[player.x][player.y + 1] == "H2" and _map[player.x][player.y + 2] == ".") then _map[player.x][player.y] = "."; player.y = player.y + 1; _map[player.x][player.y] = "@"; _map[player.x][player.y + 1] = "H2"; elseif(_map[player.x][player.y + 1] == "H2" and _map[player.x][player.y + 2] == "H") then _map[player.x][player.y] = "."; player.y = player.y + 1; _map[player.x][player.y] = "@" _map[player.x][player.y + 1] = "H3"; elseif(_map[player.x][player.y + 1] == "H" and _map[player.x][player.y + 2] == "H2") then _map[player.x][player.y] = "."; player.y = player.y + 1; _map[player.x][player.y] = "@"; _map[player.x][player.y + 1] = "H3"; end end if(_map[player.x - 1][player.y] ~= "#" and btnp(2)) then if(_map[player.x - 1][player.y] == ".") then _map[player.x][player.y] = "."; player.x = player.x - 1; _map[player.x][player.y] = "@"; elseif(_map[player.x - 2][player.y] == "H" and _map[player.x - 1][player.y] == "H") then _map[player.x][player.y] = "."; player.x = player.x - 1; _map[player.x][player.y] = "@"; _map[player.x - 1][player.y] = "H2"; elseif(_map[player.x - 2][player.y] == "." and _map[player.x - 1][player.y] == "H") then _map[player.x][player.y] = "."; player.x = player.x - 1; _map[player.x][player.y] = "@"; _map[player.x - 1][player.y] = "H"; elseif(_map[player.x - 1][player.y] == "H2" and _map[player.x - 2][player.y] == ".") then _map[player.x][player.y] = "."; player.x = player.x - 1; _map[player.x][player.y] = "@"; _map[player.x - 1][player.y] = "H2"; elseif(_map[player.x - 1][player.y] == "H2" and _map[player.x - 2][player.y] == "H") then _map[player.x][player.y] = "."; player.x = player.x - 1; _map[player.x][player.y] = "@" _map[player.x - 1][player.y] = "H3"; elseif(_map[player.x - 1][player.y] == "H" and _map[player.x - 2][player.y] == "H2") then _map[player.x][player.y] = "."; player.x = player.x - 1; _map[player.x][player.y] = "@"; _map[player.x - 1][player.y] = "H3"; end end if(_map[player.x + 1][player.y] ~= "#" and btnp(3)) then if(_map[player.x + 1][player.y] == ".") then _map[player.x][player.y] = "."; player.x = player.x + 1; _map[player.x][player.y] = "@"; elseif(_map[player.x + 2][player.y] == "H" and _map[player.x + 1][player.y] == "H") then _map[player.x][player.y] = "."; player.x = player.x + 1; _map[player.x][player.y] = "@"; _map[player.x + 1][player.y] = "H2"; elseif(_map[player.x + 2][player.y] == "." and _map[player.x + 1][player.y] == "H") then _map[player.x][player.y] = "."; player.x = player.x + 1; _map[player.x][player.y] = "@"; _map[player.x + 1][player.y] = "H"; elseif(_map[player.x + 1][player.y] == "H2" and _map[player.x + 2][player.y] == ".") then _map[player.x][player.y] = "."; player.x = player.x + 1; _map[player.x][player.y] = "@"; _map[player.x + 1][player.y] = "H2"; elseif(_map[player.x + 1][player.y] == "H2" and _map[player.x + 2][player.y] == "H") then _map[player.x][player.y] = "."; player.x = player.x + 1; _map[player.x][player.y] = "@" _map[player.x + 1][player.y] = "H3"; elseif(_map[player.x + 1][player.y] == "H" and _map[player.x + 2][player.y] == "H2") then _map[player.x][player.y] = "."; player.x = player.x + 1; _map[player.x][player.y] = "@"; _map[player.x + 1][player.y] = "H3"; end end end function MapPrint(_map, _width, _height, _tip) for i = 1,_width do for j = 1, _height do if(_map[i][j] ~= "H2" and _map[i][j] ~= "H3") then print(_map[i][j], 240/2 +i*6 - (6*_width)/2, 136/2 + j*6 - (6*_height)/2, 12); elseif(_map[i][j] == "H3") then print("H", 240/2 +i*6 - (6*_width)/2, 136/2 + j*6 - (6*_height)/2, 8); else print("H", 240/2 +i*6 - (6*_width)/2, 136/2 + j*6 - (6*_height)/2, 10); end end end print(_tip, 20, 110, 14); end function AsciiExist(_ascii, _map, _width, _height) local times = 0; for i = 1, _width do for j = 1, _height do if _map[i][j] == _ascii then times = times + 1; end end end return times; end function level1:draw() cls(16); MapPrint(level1Map, 7, 7, "Arrow keys can move\nPush atom into molecule"); PlayerMovement(level1Map, 7, 7); if(AsciiExist("H", level1Map, 7, 7) == 0) then print("Welcome to H + H = H2, my friend!\nLives and drink!\n(When messages like this pop up,\nyou can press Key X to continue)"); if btnp(5) then pmem(0, 2); currentLevel = "level2"; end elseif(btnp(4)) then level1Map = gridMapCreate(7, 7, asciiMap[1]); end end Add2Level(level1); -- Level2 idNumber = 1; asciiMap[2] =[[ ##### #...# #...# #...# ##H## ##@## ##H## ##### ]]; local level2 = createObj(0, 0, "level2"); level2Map = gridMapCreate(5, 8, asciiMap[2]); function level2:draw() cls(16); MapPrint(level2Map, 5, 8, "You can restart this level\nby press Z(Key A)\nif you did something wrong"); PlayerMovement(level2Map, 5, 8); if(AsciiExist("H", level2Map, 5, 8) == 0) then print("Nice work!"); if btnp(5) then currentLevel = "level3"; pmem(0, 3); end elseif(btnp(4)) then level2Map = gridMapCreate(5, 8, asciiMap[2]); end end Add2Level(level2); -- Level3 idNumber = 1; asciiMap[3] = [[ ####### #@.H..# #.###.## #..#...# #..H...# #..##### #### ]]; local level3 = createObj(0, 0, "level3"); level3Map = gridMapCreate(8, 7, asciiMap[3]); function level3:draw() cls(16); MapPrint(level3Map, 8, 7, "Your progress will be autosaved\nDon't worry~"); PlayerMovement(level3Map, 8, 7); if(AsciiExist("H", level3Map, 8, 7) == 0) then print("Not bad~ Let's try something new!"); if btnp(5) then pmem(0, 4); currentLevel = "level4"; end elseif(btnp(4)) then level3Map = gridMapCreate(8, 7, asciiMap[3]); end end Add2Level(level3); --Level4 idNumber = 1; asciiMap[4] = [[ ##### #...# #.H.#### #.#..H.# #..##H.# #.H.@..# ###..### #### ]]; local level4 = createObj(0, 0, "level4"); level4Map = gridMapCreate(8, 8, asciiMap[4]); function level4:draw() cls(16); MapPrint(level4Map, 8, 8, "The goal is to make H atom no more exists"); PlayerMovement(level4Map, 8, 8); if(AsciiExist("H", level4Map, 8, 8) == 0) then print("Excellent."); if btnp(5) then pmem(0, 5); currentLevel = "level5"; end elseif(btnp(4)) then level4Map = gridMapCreate(8, 8, asciiMap[4]); end end Add2Level(level4); -- Level5 idNumber = 1; asciiMap[5] = [[ ####### #H....# #.H...# ##.#H## #H#H# ###@# ### ]]; local level5 = createObj(0, 0, "level5"); level5Map = gridMapCreate(7, 7, asciiMap[5]); function level5:draw() cls(16); MapPrint(level5Map, 7, 7, "H + H2 = H3"); PlayerMovement(level5Map, 7, 7); if(AsciiExist("H", level5Map, 7, 7) == 0) then print("Good, and we have H2 and H3 now"); if btnp(5) then pmem(0, 6); currentLevel = "level6"; end elseif(btnp(4)) then level5Map = gridMapCreate(7, 7, asciiMap[5]); end end Add2Level(level5); -- Level 6 idNumber = 1; asciiMap[6] = [[ #### #..##### #.H....# #.##H..# #..#H### #.HH@H# ####### ]]; local level6 = createObj(0, 0, "level6"); level6Map = gridMapCreate(8, 7, asciiMap[6]); function level6:draw() cls(16); MapPrint(level6Map, 8, 7, "Double & Solid"); PlayerMovement(level6Map, 8, 7); if(AsciiExist("H", level6Map, 8, 7) == 0) then print("Finally..."); if btnp(5) then pmem(0, 7); currentLevel = "level7"; end elseif(btnp(4)) then level6Map = gridMapCreate(8, 7, asciiMap[6]); end end Add2Level(level6); -- Level 7 idNumber = 1; asciiMap[7] = [[ ####### #.....# #.HHH.# #.H@H.# #.HHH.# #.....# ####### ]]; local level7 = createObj(0, 0, "level7"); level7Map = gridMapCreate(7, 7, asciiMap[7]); function level7:draw() cls(16); MapPrint(level7Map, 7, 7, "Dungeon"); PlayerMovement(level7Map, 7, 7); if(AsciiExist("H", level7Map, 7, 7) == 0) then print("You're so awesome!"); if btnp(5) then pmem(0, 8); currentLevel = "level8"; end elseif(btnp(4)) then level7Map = gridMapCreate(7, 7, asciiMap[7]); end end Add2Level(level7); -- End idNumber = 1; asciiMap[8] = [[ ##### #.H.# #.@H# #...# ##### ]]; local level8 = createObj(0, 0, "level8"); level8Map = gridMapCreate(5, 5, asciiMap[8]); function level8:draw() cls(16); MapPrint(level8Map, 5, 5, "THE END\nSolve this puzzle if you wanna restart"); PlayerMovement(level8Map, 5, 5); if(AsciiExist("H", level8Map, 5, 5) == 0) then print("Thanks for your playing!"); if btnp(5) then pmem(0, 1); currentLevel = "level1"; end elseif(btnp(4)) then level8Map = gridMapCreate(5, 5, asciiMap[8]); end end Add2Level(level8); function draw() for iter = 1,insNum[currentLevel] - 1 do levelTree[currentLevel][iter]:draw(); end end function TIC() draw(); --print(currentLevel); end