--# Levels -- Content: -- LevelList (Init: Level Blocks Positions, and Data) -- LevelBackground (Init: Draws the Map, Buildings, Trees, and the entire Background) -- Classes: LevelList = {} -- Overworld -- Use: {vec2(x, y), bossLevel} LevelList.OverWorld = { {vec2(100, 100), 0, "Tutorial", function() currentPage = Game(8, 8, 5, 80, function() alert("Beta Tests work well.", "Beta") end) end}, {vec2(100, 200), 0, "Robber's Glade"}, {vec2(230, 195), 0, "Lost-Treasure Saga"}, {vec2(270, 275), 0, "Dried Lake"}, {vec2(200, 320), 0, "The Enemies Defense"}, {vec2(115, 330), 1, "Alvin's Observatory"}, {vec2(105, 430), 0, "Illegal Shop"}, {vec2(270, 550), 0, "Welcome to the City"}, {vec2(450, 590), 0, "Alvin's Home"}, } -- Level Backgrounds LevelBackground = {} LevelBackground.OverWorld = function() -- Entire Background fill(39, 127, 31, 255) strokeWidth(0) rect(-5, -5, WIDTH+10, HEIGHT+10) -- Sprites -- First Forest sprite("Small World:Tree Round", 50, 125) sprite("Small World:Tree Round", 175, 40) sprite("Small World:Tree Round", 250, 85) sprite("Small World:Tree Round", 180, 175) sprite("Small World:Tree Round", 200, 290) sprite("Small World:Tree Round", 250, 170) sprite("Small World:Tree Round", 50, 260) sprite("Small World:Rock", 115, 250) -- First Creations sprite("Small World:Observatory", 80, 340) sprite("Small World:House", 320, 60) sprite("Small World:Store Extra Large", 75, 530) -- Treasure sprite("Small World:Treasure", 325, 175) sprite("Small World:Treasure", 380, 225) sprite("Small World:Treasure", 315, 205) sprite("Small World:Treasure", 345, 170) sprite("Small World:Chest", 360, 205) -- More Creations sprite("Small World:Watch Tower", 250, 465) sprite("Small World:Watch Tower", 285, 415) sprite("Small World:Watch Tower", 245, 400) -- No water sprite("Small World:Dirt Patch", 295, 290, 200, 175) -- Second Forest sprite("Small World:Grass Patch", 215, 585) sprite("Small World:Tree 3", 125, 625) sprite("Small World:Tree Round Dark", 160, 545) sprite("Small World:Mine", 215, 650) -- City sprite("Small World:House White", 300, 530) sprite("Small World:House", 325, 630) sprite("Small World:Store Large", 450, 545) sprite("Small World:House", 380, 515) sprite("Small World:Mine Large", 470, 675) sprite("Small World:Windmill", 400, 675) -- Small Info fill(255, 255, 255, 255) strokeWidth(0) rect(350, 350, WIDTH-700, HEIGHT-700) fill(0, 0, 0, 255) font("ArialMT") fontSize(35) text("Beta only.", WIDTH/2, HEIGHT/2+15) fontSize(15) text("These will work only next updates.", WIDTH/2, HEIGHT/2-20) end --# Game Game = class() function Game:init(x, y, Bombs, size, funcOnWin) self.x, self.y = x, y self.size = size self.maxBombs = Bombs if funcOnWin then self.func = function() funcOnWin() saveCurrentData() end else self.func = function() print("Normal Game Won.") --[[self:draw() saveCurrentData()]] end end self.firstMove = true self.firstFunctionCall = true self.gameOver = false self.gameWon = false self.justFlagged = false self.freeBlocks = {} self.flaggingNow = vec2() self.loseWheel = 100 self.powerUpsY = 0 self.startedTime = 0 self.touchingBottomTheMiddleLine = nil self.time = {} --self.time.ms = 0-- Not used anymore self.time.seconds = 0 self.time.minutes = 0 self.val = {} self.val.money = 0 self.val.xp = 0 self.translate = vec2(-size+5, -size+5) self.touching = {} self.touching.placeBomb = false self.touching.placeFlag = false self.touching.placeFlagCountDown = nil self.count = {} self.count.bombs = 0 -- Field self.field = {} -- TRUE = Hidden Block self.bomb = {} -- TRUE = Bomb here self.bombsAround = {} -- INTEGER OF BOMBS AROUND self.flag = {} -- TRUE: Safe against accidental bomb touching self.line3Tab = {} for x = -1, self.x+2 do self.field[x] = {} self.bomb[x] = {} self.bombsAround[x] = {} self.flag[x] = {} self.line3Tab[x] = {} for y = -1, self.y+2 do self.field[x][y] = true self.bomb[x][y] = false self.bombsAround[x][y] = 0 self.flag[x][y] = false self.line3Tab[x][y] = false end end --!! The Field above is a bit longer, for secure reasons. -- Buttons self.winButton = Button("Continue", function() -- Activate new Data and go to Lobby currentPage = Lobby() money = money + self.val.money levelXP = levelXP + self.val.xp magicScore = magicScore + self.val.magic if level >= 5 then achievment[1] = achievment[1] + 1 end -- Save score saveCurrentData() end, vec2(WIDTH/2-80, 165)) self.loseButton = Button("Go To Lobby", function() currentPage = Lobby() end, vec2(WIDTH/2-100, 215)) -- Power Ups self.powerUps1 = { -- PowerUps Game.PowerUp1(1, "Project:Second Chance", powerups[2]), Game.PowerUp1(2, "Project:3 Lines", powerups[3]), Game.PowerUp1(3, nil, powerups[1]), --Game.PowerUp1(4), -- Buttons Button("Exit", function() currentPage = Lobby() end, vec2(25, HEIGHT-75)) -- On Start } self.inGame = { Button("Exit", function() currentPage = Lobby() end, vec2(WIDTH - 250, 25)), Button("Restart", function() self:init(self.x, self.y, self.maxBombs, self.size) end, vec2(WIDTH-150, 25)) } -- In Game Power Ups -- START self.doubleLife = false self.line3 = false self.open10Bombs = false -- INGAME end function Game:draw() -- Field translate(self.translate.x, self.translate.y) for x = 1, self.x do for y = 1, self.y do -- Background fill(215, 213, 198, 100) if self.bomb[x][y] then fill(202, 105, 105, 87) end rect(x * self.size, y * self.size, self.size, self.size) -- "Decoration" if self.bomb[x][y] then rect(x * self.size, y * self.size, self.size, self.size) sprite("Tyrian Remastered:Mine Spiked Huge", (x + 0.5) * self.size, (y + 0.5) * self.size, self.size, self.size) elseif self.bombsAround[x][y] ~= 0 then if self.bombsAround[x][y] > 5 then -- 6, 7, 8 fill(150, 0, 0, 255) elseif self.bombsAround[x][y] > 4 then -- 5 fill(255, 100, 100, 255) elseif self.bombsAround[x][y] > 3 then -- 4 fill(210, 115, 35, 255) elseif self.bombsAround[x][y] > 2 then -- 3 fill(200, 200, 0, 255) elseif self.bombsAround[x][y] <= 2 then -- 1, 2 fill(15, 255, 0, 255) end fontSize(self.size-5) text(self.bombsAround[x][y], (x+0.5) * self.size, (y+0.5) * self.size) end -- Hidden Fields if self.field[x][y] then fill(127, 127, 127, 255) rect(x * self.size, y * self.size, self.size, self.size) if self.flag[x][y] then fill(255, 255, 255, 255) fontSize(self.size - 5/self.size) text("šŸš©", (x+0.5) * self.size, (y+0.5) * self.size) end end -- Line 3 Power Up if self.line3Tab[x][y] then fill(0, 0, 255, 100) rect(x * self.size, y * self.size, self.size, self.size) end end end translate(-self.translate.x, -self.translate.y) -- Menu fill(75, 255) rect(WIDTH-275, 0, 275, HEIGHT) if self.firstMove and not (self.gameWon and self.gameOver) then for a, b in ipairs(self.powerUps1) do b:draw() end elseif not (self.gameWon and self.gameOver) then fill(255, 255, 255, 255) fontSize(30) font("Marion-Regular") --local d = self.time.ms .. "" local f = self.time.seconds .. "" -- First format our number. if #f == 3 then f = string.sub(f, 1, 1) elseif #f == 4 then f = string.sub(f, 1, 2) end --[[if #d == 1 then d = "0" .. d end]] if #f == 1 then f = "0" .. f end text("Time: " .. self.time.minutes ..":".. f--[[ ..".".. d]], WIDTH-135, HEIGHT-50) -- Bombs left local n = 0 for x = 1, self.x do for y = 1, self.y do if self.flag[x][y] then n = n + 1 end end end local l = self.maxBombs - n if l > 0 then text("Bombs left: " .. l, WIDTH-135, HEIGHT-100) else if self.gameWon then text("All Bombs marked.", WIDTH-135, HEIGHT-100) else text("Too many flags.", WIDTH-135, HEIGHT-100) -- Too many flags (or ==) then Bombs. end end for a, b in ipairs(self.inGame) do b:draw() end end if self.justFlagged and not self.firstMove then fill(255, 255, 255, 255) strokeWidth(0) if self.touchingBottomTheMiddleLine then rect(WIDTH/4 - 50, HEIGHT - HEIGHT/3, WIDTH/3 + 30, 100) fill(0, 0, 0, 255) fontSize(35) font("Marion-Bold") if self.flag[self.flaggingNow.x][self.flaggingNow.y] then text("Release to place flag", WIDTH/3+50, HEIGHT - HEIGHT/3 + 50) else text("Release to remove flag", WIDTH/3+50, HEIGHT - HEIGHT/3 + 50) end else rect(WIDTH/4 - 50, HEIGHT/3 - 100, WIDTH/3 + 30, 100) fill(0, 0, 0, 255) fontSize(35) font("Marion-Bold") if self.flag[self.flaggingNow.x][self.flaggingNow.y] then text("Release to place flag", WIDTH/3+50, HEIGHT/3 - 50) else text("Release to remove flag", WIDTH/3+50, HEIGHT/3 - 50) end end end -- Game Won Alert if self.gameWon then fill(255, 255, 255, 200) rect(150, 150, WIDTH-300, HEIGHT-300) fill(0, 0, 0, 255) -- Heading fontSize(35) font("HelveticaNeue-Bold") text("Level Completed!", WIDTH/2, HEIGHT-180) -- Sub-Heading fontSize(30) text("Score", WIDTH/2, HEIGHT-220) text("Receiving", WIDTH/2, HEIGHT-315) -- Text font("HelveticaNeue") fontSize(25) text("Bombs Unlocked: " .. self.maxBombs, WIDTH/2, HEIGHT-250) local t = self.time.seconds .. "" if #t == 1 then t = "0" .. t end text("Time: " .. self.time.minutes .. ":" .. t, WIDTH/2, HEIGHT-275) -- local m = math.floor(self.maxBombs * 1.25) - self.time.minutes - math.ceil(self.time.seconds/150) if vip.enabled then if vip.level == 1 then m = math.floor(m * 1.5) elseif vip.level == 2 then m = math.floor(m * 1.75) end end if m <= 5 then text("Money: 5", WIDTH/2, HEIGHT-345) self.val.money = 5 else text("Money: " .. m, WIDTH/2, HEIGHT-345) self.val.money = m end -- local s = math.floor(self.maxBombs * 9.75 - (self.time.minutes * 60 + math.tointeger(self.time.seconds) * 100) * 0.0075) if s <= 10 then text("Experience: 10", WIDTH/2, HEIGHT-370) self.val.xp = 10 else text("Experience: " .. s, WIDTH/2, HEIGHT-370) self.val.xp = s end -- local d = -math.ceil(math.floor((self.x * self.y - self.maxBombs) / 15) - (self.x * self.y) / 15 - self.time.minutes/10) if d <= 0 then text("Magic Points: 0", WIDTH/2, HEIGHT-395) self.val.magic = 0 else text("Magic Points: " .. d, WIDTH/2, HEIGHT-395) self.val.magic = d end -- Button self.winButton:draw() elseif self.gameOver then fill(255, 255, 255, 200) rect(200, 200, WIDTH-400, HEIGHT-400) -- Heading fill(0, 0, 0, 255) fontSize(50) font("Baskerville-SemiBold") text("You lost!", WIDTH/2, HEIGHT-250) translate(WIDTH/2, HEIGHT/2) local deg = 0.3 rotate(-self.loseWheel * deg * ElapsedTime) fontSize(25) text("But you tried!") fill(255, 255, 255, 255) text("šŸ˜€", 0, 25) text("šŸ˜¬", 0, -25) rotate(self.loseWheel * deg * ElapsedTime) self.loseWheel = self.loseWheel + 1 translate(-WIDTH/2, -HEIGHT/2) self.loseButton:draw() end self:update() end function Game:touched(t) if self.firstMove then for a, b in ipairs(self.powerUps1) do b:touched(t) end end if t.x < WIDTH-275 then -- Specify touchingBottomTheMiddleLine Input if t.y > HEIGHT/2 then self.touchingBottomTheMiddleLine = false else self.touchingBottomTheMiddleLine = true end -- Specify others if t.state == BEGAN then self.touching.placeBomb = true self.touching.placeFlag = true for x = 1, self.x do for y = 1, self.y do if t.x > self.translate.x + x * self.size and t.x < self.translate.x + (x + 1) * self.size and t.y > self.translate.y + y * self.size and t.y < self.translate.y + (y + 1) * self.size then -- Flag Count Down self.flaggingNow = vec2(x, y) end end end elseif t.state == ENDED then for x = 1, self.x do for y = 1, self.y do if t.x > self.translate.x + x * self.size and t.x < self.translate.x + (x + 1) * self.size and t.y > self.translate.y + y * self.size and t.y < self.translate.y + (y + 1) * self.size and not self.gameOver and not self.justFlagged then if self.firstMove then -- Power Ups if self.powerUps1[1]:active() then powerups[2] = powerups[2] - 1 self.doubleLife = true end if self.powerUps1[2]:active() then powerups[3] = powerups[3] - 1 self.line3 = true end if self.powerUps1[3]:active() then powerups[1] = powerups[1] - 1 self.open10Bombs = true end end -- Unlock block if self.flag[x][y] then --self.flag[x][y] = false else -- Remove Hidden Block if self.touching.placeBomb then self.field[x][y] = false end -- Check Bombs if self.bomb[x][y] and self.touching.placeBomb then if self.doubleLife then self.doubleLife = false else self.gameOver = true for a = 1, self.x do for b = 1, self.y do if self.bomb[a][b] then self.field[a][b] = false end end end end end -- Randomize Bombs if self.firstMove and self.touching.placeBomb then -- Generate Random Field while self.count.bombs < self.maxBombs do local X = math.random(1, self.x) local Y = math.random(1, self.y) if not self.bomb[X][Y] and not (y == Y and x == X) then self.count.bombs = self.count.bombs + 1 self.bomb[X][Y] = true end end self:getFieldNumber() --Generate Random "3 Lines" Effect if self.line3 then local tb = {} local n = 1 -- Generate Random Blocks while n < 3 do local a = math.random(1, self.x) local b = math.random(1, self.y) if #tb == 0 then table.insert(tb, 1, vec2(a, b)) else n = n + 1 table.insert(tb, 1, vec2(a, b)) end end -- for o, p in ipairs(tb) do for g = 1, self.x do for k = 1, self.y do -- horizontal if self.bomb[g][p.y] then self.flag[g][p.y] = true else self.field[g][p.y] = false if self.bombsAround[g][p.y] == 0 then self:filler(g, p.y) end end -- vertical if self.bomb[p.x][k] then self.flag[p.x][k] = true else self.field[p.x][k] = false if self.bombsAround[p.x][k] == 0 then self:filler(p.x, k) end end -- Show lines self.line3Tab[g][p.y] = true self.line3Tab[p.x][k] = true end end end end -- Time Set self.startedTime = os.time() -- Bombs Unlocking local bombList = {} local bombsCount = self.maxBombs if self.open10Bombs then -- Find all Bombs for h = 1, self.x do for m = 1, self.y do if self.bomb[h][m] and not self.flag[h][m] then table.insert(bombList, 1, vec2(h, m)) --print("Use Bombs: ", h, m) end end end -- Calculate 10% of all Bombs bombsCount = math.ceil( bombsCount * 0.1 ) --print(self.maxBombs - bombsCount, #bombList) -- Remove 10% Bombs while self.maxBombs - bombsCount < #bombList do local v = math.random(1, #bombList) self.flag[bombList[v].x][bombList[v].y] = true self.line3Tab[bombList[v].x][bombList[v].y] = true table.remove(bombList, v) end end -- end -- Filler Method if self.bombsAround[x][y] == 0 and self.touching.placeBomb then self:filler(x, y) end -- Post Tags if self.touching.placeBomb then -- Only if the placeBomb method is valid. self.firstMove = false -- ALWAYS set to false end -- end end -- End For Cycle: end end self.touching.placeBomb = false self.touching.placeFlag = false self.touching.placeFlagCountDown = nil self.justFlagged = false else -- Moving self.translate.x = self.translate.x + t.deltaX self.translate.y = self.translate.y + t.deltaY if t.deltaY > -5 and t.deltaY < 5 and t.deltaX > -5 and t.deltaX < 5 then else self.touching.placeBomb = false self.touching.placeFlag = false self.touching.placeFlagCountDown = nil self.justFlagged = false end end else self.touching.placeBomb = false self.touching.placeFlag = false self.touching.placeFlagCountDown = nil self.justFlagged = false -- if self.firstMove then self.powerUpsY = self.powerUpsY + t.deltaY if self.powerUpsY <= 0 then self.powerUpsY = 0 end end end -- Random Library Tools if self.gameWon then self.winButton:touched(t) elseif self.gameOver then self.loseButton:touched(t) else if not self.firstMove then for a, b in ipairs(self.inGame) do b:touched(t) end end end if t.state == ENDED then self.touchingBottomTheMiddleLine = nil end end function Game:getFieldNumber() for x = 1, self.x do for y = 1, self.y do local n = 0 if x > 0 and x <= self.x and y > 0 and y <= self.y then if self.bomb[x-1][y-1] then n = n + 1 end if self.bomb[x-1][y] then n = n + 1 end if self.bomb[x-1][y+1] then n = n + 1 end if self.bomb[x][y+1] then n = n + 1 end if self.bomb[x+1][y+1] then n = n + 1 end if self.bomb[x+1][y] then n = n + 1 end if self.bomb[x+1][y-1] then n = n + 1 end if self.bomb[x][y-1] then n = n + 1 end end if self.bomb[x][y] then n = n + 1 end self.bombsAround[x][y] = n if n == 0 then table.insert(self.freeBlocks, 1, vec2(x, y)) end end end end function Game:filler(x, y) if x > 0 and y > 0 and x <= self.x and y <= self.y then self.field[x][y] = false if self.bombsAround[x-1][y] == 0 and self.field[x-1][y] then self:filler(x-1, y) end if self.bombsAround[x][y-1] == 0 and self.field[x][y-1] then self:filler(x, y-1) end if self.bombsAround[x][y+1] == 0 and self.field[x][y+1] then self:filler(x, y+1) end if self.bombsAround[x+1][y] == 0 and self.field[x+1][y] then self:filler(x+1, y) end if self.bombsAround[x-1][y-1] == 0 and self.field[x-1][y-1] then self:filler(x-1, y-1) end if self.bombsAround[x-1][y+1] == 0 and self.field[x-1][y+1] then self:filler(x-1, y+1) end if self.bombsAround[x+1][y-1] == 0 and self.field[x+1][y-1] then self:filler(x+1, y-1) end if self.bombsAround[x+1][y+1] == 0 and self.field[x+1][y+1] then self:filler(x+1, y+1) end --[[for a = -1, 1 do for b = -1, 1 do if self.bombsAround[x+a][y+b] and self.field[x+a][y+b] and not (a == 0 and b == 0) then self:filler(x+a, y+b) end end end]] for a = -1, 1 do for b = -1, 1 do self.field[x+a][y+b] = false end end end end function Game:update() -- Flag --[[if self.touching.placeFlag then if self.touching.placeFlagCountDown == nil then self.touching.placeFlagCountDown = 15 end self.touching.placeFlagCountDown = self.touching.placeFlagCountDown - 1 if self.touching.placeFlagCountDown <= 0 then self.touching.placeFlagCountDown = nil if self.flag[self.flaggingNow.x][self.flaggingNow.y] then self.flag[self.flaggingNow.x][self.flaggingNow.y] = false else self.flag[self.flaggingNow.x][self.flaggingNow.y] = true end self.justFlagged = true end end]] if self.touching.placeFlag then if self.touching.placeFlagCountDown == nil then self.touching.placeFlagCountDown = os.time() end if os.difftime(os.time(), self.touching.placeFlagCountDown) >= 1 then self.touching.placeFlagCountDown = nil if self.flag[self.flaggingNow.x][self.flaggingNow.y] then self.flag[self.flaggingNow.x][self.flaggingNow.y] = false else if not self.firstMove then self.flag[self.flaggingNow.x][self.flaggingNow.y] = true end end self.justFlagged = true end end -- Win local n = 0 for x = 1, self.x do for y = 1, self.y do if not self.field[x][y] then n = n + 1 end end end -- print(n, self.x * self.y - self.maxBombs) -- CHECK: WORKS ALREADY! if n >= self.x * self.y - self.maxBombs and not (self.gameOver and self.justFlagged) --[[and not (self.count.bombs == 0)]] then -- Start of Project self.gameWon = true for x = 1, self.x do for y = 1, self.y do self.field[x][y] = false end end if self.firstFunctionCall then self.firstFunctionCall = false self.func() end end --[[ Time Updation (Failed version) if not self.gameWon and not self.gameOver and not self.firstMove then self.time.ms = self.time.ms + 1 if self.time.ms > 29 then self.time.ms = 0 self.time.seconds = self.time.seconds + 1 end if self.time.seconds > 59 then self.time.seconds = 0 self.time.minutes = self.time.minutes + 1 end end]] -- Time Updation if not self.gameWon and not self.gameOver and not self.firstMove then local time = os.difftime(os.time(), self.startedTime) --self.time.ms = 0 --print(time) if time >= 60 then time = time - 60 self.startedTime = self.startedTime + 60 self.time.minutes = self.time.minutes + 1 print(time, self.time.minutes) end self.time.seconds = time .. "" end end --[[ Open all empty blocks: for i, j in ipairs(self.freeBlocks) do self.field[j.x+a][j.y+b] = false end ]] Game.PowerUp1 = class() function Game.PowerUp1:init(y, img, powerUpData) self.y = HEIGHT - y * 225 self.activated = false -- enabled or not self.image = img self.notActivated = false -- always disabled if img == nil then self.image = "Project:Default Image" end if (powerUpData == nil) or (powerUpData == 0) then self.notActivated = true end self.powerups = powerUpData end function Game.PowerUp1:draw() fill(0, 0, 0, 255) stroke(0, 0, 0, 255) strokeWidth(10) translate(0, currentPage.powerUpsY) if self.activated then stroke(134, 204, 205, 255) end if self.notActivated then stroke(15, 255) fill(15, 255) end rect(WIDTH-250, self.y, 200, 200) line(WIDTH-250, self.y, WIDTH-250, self.y + 200) line(WIDTH-250, self.y, WIDTH-50, self.y) line(WIDTH-50, self.y, WIDTH-50, self.y + 200) line(WIDTH-250, self.y + 200, WIDTH-50, self.y + 200) sprite(self.image, WIDTH-150, self.y + 100, 175, 175) if self.notActivated then fontSize(150) fill(255, 255, 255, 255) text("šŸš«", WIDTH-150, self.y + 100) end strokeWidth(0) fill(255, 255, 255, 255) font("ArialMT") fontSize(35) text(self.powerups .. " x", WIDTH-50, self.y) translate(0, -currentPage.powerUpsY) end function Game.PowerUp1:touched(t) if t.x > WIDTH-250 and t.x < WIDTH-50 and t.y > self.y + currentPage.powerUpsY and t.y < self.y + 200 + currentPage.powerUpsY and t.state == ENDED then if self.activated then self.activated = false else self.activated = true end end if self.notActivated then self.activated = false end end function Game.PowerUp1:active() return self.activated end --# Map Map = class() function Map:init(levelName, levels, bgImage) self.level = levelName self.unpackedLevelList = levels -- Not used, but here is the unpacked mode of the levels table. self.levelList = {} self.levelConnections = {} for a, b in ipairs(levels) do table.insert(self.levelList, Map.Level(b[1].x, b[1].y, a, b[2], b[3], b[4])) end for c = 1, #levels-1 do table.insert(self.levelConnections, 1, {levels[c][1].x, levels[c][1].y, levels[c+1][1].x, levels[c+1][1].y}) end self.background = bgImage self.exitButton = Button("āŒ", function() currentPage = Lobby() saveCurrentData() end, vec2(50, HEIGHT-75)) self.exitButton.emoji = true end function Map:draw() self.background() --Edits fill(255, 255, 255, 255) fontSize(50) font("SourceSansPro-Regular") text(self.level, WIDTH/2, HEIGHT-50) -- Content for a, b in ipairs(self.levelConnections) do self:levelConnect(b[1] + 25, b[2] + 25, b[3] + 25, b[4] + 25) end for a, b in ipairs(self.levelList) do b:draw() end self.exitButton:draw() end function Map:touched(t) for a, b in ipairs(self.levelList) do b:touched(t) end self.exitButton:touched(t) end function Map:levelConnect(x, y, x1, y1) strokeWidth(5) stroke(255, 200) line(x, y, x1, y1) end Map.Level = class() function Map.Level:init(x, y, id, boss, levelName, goTo) self.pos = vec2(x, y) self.id = id self.final = false if boss == 1 then boss = true elseif boss == 0 then boss = false elseif boss == 2 then boss = true self.final = true end self.boss = boss self.name = levelName self.level = goTo end function Map.Level:draw() fill(255, 255, 255, 255) --strokeWidth(0) --rect(self.pos.x, self.pos.y, 50, 50) fontSize(50) text("šŸ–²", self.pos.x + 25, self.pos.y + 25) if self.boss then text("āš”", self.pos.x + 25, self.pos.y + 25) end if self.final then fontSize(35) fill(255, 255) text("šŸ", self.pos.x + 50, self.pos.y + 50) end end function Map.Level:touched(t) if t.x > self.pos.x and t.x < self.pos.x + 50 and t.y > self.pos.y and t.y < self.pos.y + 50 and t.state == BEGAN then if self.level then self.level() else local b = "" if self.boss then b = "(Boss Level)" end alert("Name: " .. self.name .. " " .. b .. "\n\nThis Map is not asseted with a Game.. You are not able to play it while it won't be fixed. Sorry!", "Error") end end end --# Main function setup() displayMode(FULLSCREEN) supportedOrientations(LANDSCAPE_ANY) parameter.watch("money") parameter.watch("magicScore") parameter.watch("levelXP") --[[parameter.watch("powerups[1]") parameter.watch("powerups[2]") parameter.watch("powerups[3]") parameter.watch("powerups[4]") parameter.watch("achievment[1]") parameter.watch("achievment[2]")]] powerups = {} -- Power Ups Data Stored here items = {} -- Items Data Stored here achievment = {} -- All Achievments stored here vip = {} -- All ViP Data stored here -- Reading save Datas. level = readLocalData("lvl", 0) levelXP = readLocalData("xp", 0) money = readLocalData("coins", 150) magicScore = readLocalData("magic", 10) local time = os.date("*t") lastJoined = time["day"] .. " " .. time["month"] .. " " .. time["year"] print(lastJoined) -- Power Ups & Achievments (Release v1) powerups[4] = readLocalData("power4", 0) powerups[3] = readLocalData("power3", 0) powerups[2] = readLocalData("power2", 0) powerups[1] = readLocalData("power1", 0) achievment[3] = readLocalData("ach3", 0) -- Complete daily missions achievment[2] = readLocalData("ach2", 0) -- Shop Items bought achievment[1] = readLocalData("ach1", 0) -- Games won achievment[5] = readLocalData("ach5", false) -- VIP if level >= 10 then achievment[4] = true else achievment[4] = false end vip.level = 1 vip.active = false vip.expires = nil -- We set the room after any data, to avoid crashes. currentPage = Lobby() -- The entering room. saveCurrentData() -- We shall call it to save the first time, and for some sub-reasons. end function draw() -- Default DATA background(0) fill(255, 255, 255, 255) fontSize(35) font("SourceSansPro-Regular") stroke(127, 127, 127, 255) strokeWidth(0) -- currentPage:draw() end function touched(t) currentPage:touched(t) end function saveCurrentData() saveLocalData("lvl", level) saveLocalData("xp", levelXP) saveLocalData("coins", money) saveLocalData("magic", magicScore) -- Release 1 saveLocalData("power4", powerups[4]) saveLocalData("power3", powerups[3]) saveLocalData("power2", powerups[2]) saveLocalData("power1", powerups[1]) saveLocalData("ach3", achievment[3]) saveLocalData("ach2", achievment[2]) saveLocalData("ach1", achievment[1]) saveLocalData("ach5", achievment[5]) end --# Lobby Lobby = class() function Lobby:init() self.openShop = Button("šŸ’ø Shop šŸ’ø", function() currentPage = Shop() end, vec2(50, HEIGHT-75)) self.translate = 0 self.pointsTranslate = 0 self.maxLevel = 20 ----- Buttons ----- -- Default Mode self.defaultButtons = {Button("Easy", function() currentPage = Game(10, 10, 10, 70, nil) end, vec2(75, 525)), Button("Medium", function() currentPage = Game(20, 15, 75, 55, nil) end, vec2(75, 450))} -- Default Mode (since level 5) self.defaultButtons5 = {Button("Hard", function() currentPage = Game(20, 15, 120, 50, nil) end, vec2(75, 375)), Button("Extreme", function() currentPage = Game(15, 10, 75, 65, nil) end, vec2(75, 300))} -- Achievment Mode (Level 5) self.achievmentButtons = {Button("See Achievments", function() currentPage = Achievment() end, vec2(490, 525))} -- Overworld (Level 10) self.overworldButtons = {Button("Open Map", function() currentPage = Map("Overworld", LevelList.OverWorld, LevelBackground.OverWorld) end, vec2(875, 200))} ----- Check Functions ----- -- ViP Check if vip.active then if readLocalData("ach5", false) == true then print("ViP") end end -- Update Level if level >= self.maxLevel then levelXP = 0 level = self.maxLevel saveCurrentData() else while levelXP > self:levelXPneeded() do levelXP = levelXP - self:levelXPneeded() level = level + 1 end saveCurrentData() end end function Lobby:draw() -- Update Buttons self.defaultButtons[1].pos.x = 75 + self.translate/1.9 self.defaultButtons[2].pos.x = 75 + self.translate/0.9 self.defaultButtons5[1].pos.x = 75 + self.translate/0.65 self.achievmentButtons[1].pos.x = 490 + self.translate/1.05 self.overworldButtons[1].pos.x = 875 + self.translate self.defaultButtons5[2].pos.x = 75 + self.translate/0.4 -- Lobby self:shadowText("Mine Field", WIDTH/2-150, HEIGHT-50) fontSize(25) self:shadowText("Chose Play Options:", WIDTH/2-150, HEIGHT-85) fill(255, 255, 255, 255) rect(0, 150, WIDTH, 500) -- Entire Game Options translate(self.translate, 0) -- Game Options fill(149, 149, 149, 255) rect(50, 175, 350, 450) -- Default rect(450, 175, 350, 450) -- Achievment Mode (since level 5) rect(850, 175, 350, 450) -- Overworld Map rect(1250, 175, 350, 450) -- Comming soon --- Design --- -- Default fill(255, 255, 255, 255) fontSize(35) font("ArialRoundedMTBold") text("Default Mode", 225, 600) if level < 5 then fill(0, 0, 0, 255) text("Since Level 5", 625, 325) end -- Achievment fill(255, 255, 255, 255) fontSize(35) font("ArialRoundedMTBold") text("Achievment Mode", 625, 600) if level >= 5 then font("HelveticaNeue-CondensedBold") text("Daily Missions:", 625, 490) fontSize(25) text("Not supported in this version.", 625, 400) end -- Overworld fill(255, 255, 255, 255) fontSize(35) font("ArialRoundedMTBold") text("Level 1: Overworld", 1025, 600) sprite("Small World:Dirt Patch", 1025, 400, 350, 300) sprite("Small World:Tree 2", 1100, 500, 100, 150) sprite("Small World:Tree 3", 1025, 450, 100, 150) sprite("Small World:House White", 925, 400, 175, 125) sprite("Small World:Tree 3", 1085, 400, 100, 150) -- Comming soon fill(255, 255, 255, 255) fontSize(35) font("ArialRoundedMTBold") text("Comming Soon", 1425, 600) fontSize(350) font("Papyrus") text("?", 1425, 350) -- translate(-self.translate, 0) -- Library for a, b in ipairs(self.defaultButtons) do b:draw() end -- Higher Modifications if level < 5 then fill(0, 0, 0, 255) fontSize(25) font("HoeflerText-Regular") clip(50, 175, 350, 450) local str = "Reach Level 5 to unlock more" clip() local a, b = textSize(str) text(str, 67.5 + a/2 + self.translate/1.7, 375) else for a, b in ipairs(self.defaultButtons5) do b:draw() end for a, b in ipairs(self.achievmentButtons) do b:draw() end end -- if level < 10 then font("AmericanTypewriter-CondensedBold") text("Since Level 10", 1025 + self.translate, 200) else for a, b in ipairs(self.overworldButtons) do b:draw() end end -- Anything else self.openShop:draw() -- Points local width = 510 fill(255) rect(WIDTH-width, HEIGHT-75, width-25, 50) fill(175, 175, 255, 255) rect(WIDTH-(width-5), HEIGHT-70, (width-35) * (levelXP / self:levelXPneeded()), 40) sprite("SpaceCute:Star", WIDTH-25, HEIGHT-50, 125, 125) translate(self.pointsTranslate, 0) fill(255, 255, 255, 255) rect(50, 25, 300, 100) rect(400, 25, 300, 100) rect(750, 25, 300, 100) -- Money font("ArialRoundedMTBold") fontSize(30) fill(255, 150, 0, 255) local money = money .. "" money = string.sub(money, 1, #money-2) if #money > 6 then -- 7 Positions money = string.sub(money, 1, #money - 6) .. "." .. string.sub(money, #money - 5, #money - 5) .. " M" end text(money .. "šŸ’°", 200, 75) -- Magic fill(255, 0, 150, 255) local magicScore = magicScore .. "" magicScore = string.sub(magicScore, 1, #magicScore-2) text(magicScore .. "šŸ”®", 550, 75) if vip.active then fill(0, 0, 0, 255) fontSize(15) font("ArialMT") text("Unlimited Temporary (VIP)", 550, 45) stroke(0) strokeWidth(2) line(425, 75, 675, 75) strokeWidth(0) end -- ViP sprite("Planet Cute:Selector", 800, 75, 50, 75) fill(255, 150, 0, 255) fontSize(40) font("Vegur") text(vip.level, 800, 75) -- Other Data translate(-self.pointsTranslate, 0) font("ArialRoundedMTBold") fontSize(30) fill(127, 127, 127, 255) local levelXP = levelXP .. "" levelXP = string.sub(levelXP, 1, #levelXP-2) text(levelXP .. "/" .. self:levelXPneeded(), WIDTH-width/2, HEIGHT-50) fill(0, 0, 0, 255) local level = level if level >= self.maxLevel then fill(107, 70, 39, 255) level = self.maxLevel else level = level .. "" level = string.sub(level, 1, #level-2) end text(level, WIDTH-26, HEIGHT-52) end function Lobby:touched(t) if t.state == MOVING and t.y > 150 and t.y < 650 then local blocks = 4 self.translate = self.translate + t.deltaX if self.translate >= 0 then self.translate = 0 end local int = WIDTH - ((blocks-0.5) * 400 + 250) if self.translate <= int then self.translate = int end end if t.state == MOVING and t.y < 145 and t.y > 5 then local blocks = 3 self.pointsTranslate = self.pointsTranslate + t.deltaX if self.pointsTranslate >= 0 then self.pointsTranslate = 0 end local int = WIDTH - (blocks * 300 + 200) if self.pointsTranslate <= int then self.pointsTranslate = int end end for a, b in ipairs(self.defaultButtons) do b:touched(t) end if level >= 5 then -- Default for a, b in ipairs(self.defaultButtons5) do b:touched(t) end -- Achievment for a, b in ipairs(self.achievmentButtons) do b:touched(t) end end if level >= 10 then for a, b in ipairs(self.overworldButtons) do b:touched(t) end end self.openShop:touched(t) end function Lobby:shadowText(str, x, y) dis = 1 if fontSize() > 30 then dis = 2 end fill(50, 255) text(str, x + dis * 2, y - dis * 2) fill(150, 255) text(str, x + dis, y - dis) fill(200, 255) text(str, x, y) fill(255, 255) text(str, x - dis, y + dis) end function Lobby:levelXPneeded() if level == 0 then return 100 elseif level == 1 then return 250 elseif level == 2 then return 500 elseif level == 3 then return 750 elseif level == 4 then return 1000 elseif level == 5 then return 2500 elseif level == 6 then return 5000 elseif level == 7 then return 10000 -- 10K elseif level == 8 then return 20000 -- 20K elseif level == 9 then return 50000 -- 50K elseif level == 10 then return 100000 -- 100K elseif level == 11 then return 125000 -- 125K elseif level == 12 then return 150000 -- 150K elseif level == 13 then return 175000 -- 175K elseif level == 14 then return 200000 -- 200K elseif level == 15 then return 250000 -- 250K elseif level == 16 then return 300000 -- 300K elseif level == 17 then return 350000 -- 350K elseif level == 18 then return 400000 -- 400K elseif level == 19 then return 450000 -- 450K elseif level == 20 then return 0 else return math.floor( math.maxinteger / 10 ^ 10 ) -- Return Error Number end end --# Achievment Achievment = class() function Achievment:init() self.y = 0 self.exitButton = Button("Exit", function() currentPage = Lobby() saveCurrentData() end, vec2(50, HEIGHT-75)) self.gameBlocks = { Achievment.Block(1, "Champion", "Win many levels", achievment[1], {15, 50, 100, 250, 500, 1000, 2500, 5000}, "Games"), Achievment.Block(2, "Buisness Man", "Buy many Shop Items.", achievment[2], {5, 35, 50, 100, 250, 400, 650}, "Items"), Achievment.Block(3, "Fan Boy", "Complete Daily Missions", achievment[3], {7, 30, 100, 365, 500, 1000}, "Days"), Achievment.Block(4, "Unlock Overworld", "Higher Maps and more sub-rules", achievment[4], true, "To Unlock OverWorld, reach level 10"), Achievment.Block(5, "Get V. I. P.", "Doubled Coins, Temporary Unlimited magic, ...", achievment[5], true, "You can buy VIP or get it randomly in a game.") } end function Achievment:draw() fill(255, 255, 255, 255) rect(100, 100, WIDTH-200, HEIGHT-200) fill(0, 0, 0, 255) font("Optima-Bold") text("Achievments", WIDTH/2, HEIGHT-125) for a, b in ipairs(self.gameBlocks) do b:draw() end stroke(0, 0, 0, 255) fill(0, 0) strokeWidth(5) rect(125, 125, WIDTH-250, HEIGHT-300) strokeWidth(0) self.exitButton:draw() end function Achievment:touched(t) for a, b in ipairs(self.gameBlocks) do b:touched(t) end self.exitButton:touched(t) -- Moving self.y = self.y + t.deltaY if self.y <= -20 then self.y = -20 end local formula = HEIGHT - 400 + 165 * ( #self.gameBlocks - 5 ) if self.y >= formula then self.y = formula end end Achievment.Block = class() function Achievment.Block:init(pos, name, description, int, values, txt) self.y = HEIGHT - (320 + (pos - 1) * 165) self.yNum = pos self.name = name self.needed = values self.total = int self.desc = description self.txt = txt self.translate = 0 self.buttons = {} self.received = {} self.boalen = false if self.needed == true or self.needed == false then self.boalen = true self.received = self:readOne() end if not self.boalen then for x = 1, #self.needed do self.received[x] = self:read(x) self.buttons[x] = Button(" Receive ", function() if x == 1 then money = money + 50 magicScore = magicScore + 3 levelXP = levelXP + 250 elseif x == 2 then money = money + 250 magicScore = magicScore + 14 levelXP = levelXP + 500 elseif x == 3 then money = money + 500 magicScore = magicScore + 32 levelXP = levelXP + 1000 elseif x == 4 then money = money + 1000 magicScore = magicScore + 55 levelXP = levelXP + 2000 elseif x == 5 then money = money + 2500 magicScore = magicScore + 100 levelXP = levelXP + 5000 elseif x == 6 then money = money + 5000 magicScore = magicScore + 235 levelXP = levelXP + 10000 -- 10 000 elseif x == 7 then money = money + 10000 magicScore = magicScore + 576 levelXP = levelXP + 50000 -- 50 000 elseif x == 8 then money = money + 25000 magicScore = magicScore + 993 levelXP = levelXP + 100000 -- 100 000 elseif x == 9 then money = money + 50000 magicScore = magicScore + 1247 levelXP = levelXP + 200000 -- 200 000 elseif x == 10 then money = money + 100000 -- 100 000 magicScore = magicScore + 2000 levelXP = levelXP + 500000 -- 500 000 end saveCurrentData() self.received[x] = true self:save(x) end, vec2(0, 0) ) self.buttons[x].fontSize = 20 end else self.buttons = Button("Receive", function() money = money + 15000 magicScore = magicScore + 500 levelXP = levelXP + 50000 -- 50 000 saveCurrentData() self.received = true self:saveOne() end, vec2(0, 0)) end end function Achievment.Block:draw() -- Draw clip(125, 125, WIDTH-250, HEIGHT-300) fill(127, 127, 127, 255) rect(150, self.y + currentPage.y, WIDTH-300, 150) fontSize(35) font("MarkerFelt-Wide") local w, _ = textSize(self.name) fill(0, 0, 0, 255) text(self.name, 160 + w/2, self.y + currentPage.y + 125) fill(200, 255) fontSize(20) font("Noteworthy-Light") local s, _ = textSize(self.desc) text(self.desc, 175 + w + s/2, self.y + currentPage.y + 125) if not self.boalen then local str = "Total: " .. self.total str = string.sub(str, 1, #str - 2) font("Optima-Bold") local d, _ = textSize(str) text(str, WIDTH - 175 - d/2, self.y + currentPage.y + 125) else end if not self.boalen then translate(self.translate, 0) for x = 1, #self.needed do clip(150, 125, WIDTH-300, HEIGHT-300) fill(255, 255, 255, 255) if self.total / self.needed[x] >= 1 then fill(150, 255, 150, 255) end rect(175 + (x-1) * 130, self.y + currentPage.y + 5, 125, 100) fill(0, 0, 0, 255) fontSize(35) local p = self.total / self.needed[x] p = p .. "" -- Make p to a string. for n = 0, 9 do if p == "0." .. n and #p == 3 then p = "0." .. n .. "0" end end p = string.sub(p, 3, 4) for n = 0, 9 do if p == "0" .. n and #p == 2 then p = string.sub(p, 2, 2) end end if self.total / self.needed[x] >= 1 then fill(255, 255, 255, 255) text("āœ”ļø", 237.5 + (x-1) * 130, self.y + currentPage.y + 55) else text(p .. "%", 237.5 + (x-1) * 130, self.y + currentPage.y + 55) end fontSize(20) fill(0, 0, 0, 255) text(self.needed[x] .. " " .. self.txt, 237.5 + (x-1) * 130, self.y + currentPage.y + 85) if self.total / self.needed[x] >= 1 then text("Completed", 237.5 + (x-1) * 130, self.y + currentPage.y + 25) end clip(125, 125, WIDTH-250, HEIGHT-300) end translate(-self.translate, 0) else fill(0, 0, 0, 255) fontSize(35) if self.needed == self.total then font("Palatino-Roman") text("Achievment Completed!", WIDTH/2+100, self.y + currentPage.y + 65) else font("Baskerville") text(self.txt, WIDTH/2, self.y + currentPage.y + 50) end end if not self.boalen then for x = 1, #self.needed do if self.total / self.needed[x] >= 1 and not self.received[x] then if not self.received[x] then self.buttons[x].pos = vec2(190 + (x-1) * 130 + self.translate, self.y + currentPage.y + 10) self.buttons[x]:draw() end end end else if self.needed == self.total and not self.received then self.buttons.pos = vec2(200, self.y + currentPage.y + 50) self.buttons:draw() end end clip() end function Achievment.Block:touched(t) if not self.boalen then if t.state == MOVING and #self.needed > 5 then if t.y > self.y + currentPage.y and t.y < self.y + currentPage.y + 150 then self.translate = self.translate + t.deltaX end if self.translate >= 0 then self.translate = 0 end if self.translate <= -((#self.needed-5) * 130 - 25) then self.translate = -((#self.needed-5) * 130 - 25) end elseif t.state == ENDED then if #self.needed <= 5 then self.translate = 0 end end end if not self.boalen then for x = 1, #self.needed do if self.total / self.needed[x] >= 1 and not self.received[x] and t.x > 150 and t.x < WIDTH-150 then self.buttons[x]:touched(t) end end else if self.needed == self.total and not self.received then self.buttons:touched(t) end end end function Achievment.Block:save(x) saveLocalData("ach-received-" .. self.yNum .. "-" .. x, self.received[x]) end function Achievment.Block:read(x) local n = readLocalData("ach-received-" .. self.yNum .. "-" .. x) if n == nil then n = false end return n end function Achievment.Block:saveOne() saveLocalData("ach-received-" .. self.yNum .. "-one", self.received) end function Achievment.Block:readOne() local n = readLocalData("ach-received-" .. self.yNum .. "-one") if n == nil then n = false end return n end --# Shop Shop = class() function Shop:init() self.x = 0 self.exitButton = Button("Exit", function() currentPage = Lobby() saveCurrentData() end, vec2(WIDTH-100, HEIGHT-75)) self.items = { -- Power Ups on Start Shop.Item(1, "Flag 10% Bombs", nil, function() powerups[1] = powerups[1] + 1 end, 25, 5, "10% of all Bombs will be flagged"), Shop.Item(2, "Second Chance", "Project:Second Chance", function() powerups[2] = powerups[2] + 1 end, 100, 15, "You will have a second chance when clicking on a bomb."), Shop.Item(3, "3 Lines", "Project:3 Lines", function() powerups[3] = powerups[3] + 1 end, 150, 5, "3 Random Blocks will be choosen (Small chance of 2 blocks only!). Horizontally and vertically of them all mines will be marked, and other blocks will be opened."), -- Power Ups while Playing Shop.Item(4, "Slow Time", nil, function() powerups[4] = powerups[4] + 1 end, 0, 0, "Will not run the time 30 seconds. (Currently on ToDo List)"), -- V I P Shop.Item(5, "VIP (1 Day)", nil, function() vip.level = 1 end, 0, 0, "This VIP includes:\nā€¢ Temporary Unlimited Magic for Shop\nā€¢ Coins will be multiplied by 1.5 (for Default Mode)\nā€¢ Doubled Level XP"), Shop.Item(6, "VIP (1 Week)", nil, function() vip.level = 2 end, 0, 0, "This VIP includes:\nā€¢ Temporary Unlimited Magic for Shop\nā€¢ Coins will be multiplied by 1.75 (for Default Mode and Overworld)\nā€¢ Doubled Level XP") } -- Only local notWorking = { 4, -- Slow Time Effect not developed. 5, 6 -- VIP not developed. } self.outside = {} for a, b in ipairs(notWorking) do self.items[b].blocked = true table.insert(self.outside, 1, Shop.OutdatedItem(b)) end local reachLevel = { {1, 5}, {2, 10}, {3, 5} } for a, b in ipairs(reachLevel) do if level < b[2] then-- else self.items[b[1]].blocked = true table.insert(self.outside, 1, Shop.ReachLevelItem(b[1], b[2])) end end end function Shop:draw() -- Shop fill(255, 255, 255, 255) fontSize(50) text("Shop", WIDTH/2, HEIGHT-50) -- Exit self.exitButton:draw() -- Body fill(255, 255, 255, 255) rect(0, 100, WIDTH, 550) -- Content for a, b in ipairs(self.items) do b:draw() end translate(self.x, 0) for a, b in ipairs(self.outside) do b:draw() end translate(-self.x, 0) -- Name fill(0, 0, 0, 255) font("Optima-Regular") --[[local subject [{TEMPORARY DISABLED}] if self.x > -1000 then subject = "Power Ups (On Start)" elseif self.x > -1400 then subject = "Power Ups (While Playing)" elseif self.x > -2000 then subject = "V. I. P." else subject = "nil" end local w, h = textSize(subject) text(subject, 100 + w/2, 615)]] -- Money fill(255, 255, 255, 255) fontSize(35) local a, b = textSize(money .. "šŸ’°") text(money .. "šŸ’°", 50 + a/2, HEIGHT-25) local a, b = textSize(magicScore .. "šŸ”®") text(magicScore .. "šŸ”®", 50 + a/2, HEIGHT-60) end function Shop:touched(t) self.x = self.x + t.deltaX * 0.9 self.exitButton:touched(t) for a, b in ipairs(self.items) do b:touched(t) end if self.x >= 0 then self.x = 0 end local formula = -( WIDTH - 200 + 350 * (#self.items-5)) if self.x <= formula then self.x = formula end end -- A class for items Shop.Item = class() function Shop.Item:init(x, name, picture, func, costsMoney, costsMagic, help) self.x = 50 + 350 * (x - 1) self.name = name self.costs = {} self.costs.money = costsMoney self.costs.magic = costsMagic self.image = picture self.infoButton = Button("Info", function() alert(help, "Info") end, vec2(self.x + 115, 150)) self.blocked = false self.buyButton = Button("Buy", function() if self.costs.money <= money and self.costs.magic <= magicScore then func() money = money - self.costs.money magicScore = magicScore - self.costs.magic if level >= 5 then achievment[2] = achievment[2] + 1 end saveCurrentData() else alert("You are not having enough money or magic.", "Not enough money") end end, vec2(self.x + 15, 150)) end function Shop.Item:draw() fill(5, 5, 5, 255) strokeWidth(0) -- translate(currentPage.x, 0) -- BG rect(self.x, 125, 300, 450) -- Text fill(255, 255, 255, 255) font("Baskerville-SemiBold") local w, h = textSize(self.name) text(self.name, self.x + 10 + w/2, 525) -- Picture if self.image then sprite(self.image, self.x + 150, 400, 150, 150) else sprite("Project:Default Image", self.x + 150, 400, 150, 150) fontSize(25) font("Futura-Medium") text("No Image assetted", self.x + 150, 400) end -- Requirments font("Baskerville-SemiBold") fontSize(30) local a, b = textSize(self.costs.money .. "šŸ’°") text(self.costs.money .. "šŸ’°", self.x + 15 + a/2, 300) local a, b = textSize(self.costs.magic .. "šŸ”®") text(self.costs.magic .. "šŸ”®", self.x + 15 + a/2, 265) -- translate(-currentPage.x, 0) -- Library self.buyButton:draw() self.infoButton:draw() -- Update self.buyButton.pos.x = self.x + 15 + currentPage.x self.infoButton.pos.x = self.x + 90 + currentPage.x end function Shop.Item:touched(t) if not self.blocked then self.buyButton:touched(t) self.infoButton:touched(t) end end Shop.OutdatedItem = class() function Shop.OutdatedItem:init(x) self.x = 50 + 350 * (x - 1) end function Shop.OutdatedItem:draw() fill(0, 0) -- Do not display inner stroke(150, 255) -- Display border strokeWidth(35) rect(self.x, 125, 300, 450) line(self.x+20, 175, self.x + 280, 525) translate(self.x + 150, 350) rotate(53.5) fill(150, 0, 0, 255) font("Palatino-Roman") fontSize(35) text("NOT WORKING", 0, -2) rotate(-53.5) translate(-(self.x + 150), -350) end Shop.ReachLevelItem = class() function Shop.ReachLevelItem:init(x, lvl) self.x = 50 + 350 * (x - 1) self.lvl = lvl end function Shop.ReachLevelItem:draw() fill(0, 0) -- Do not display inner stroke(150, 255) -- Display border strokeWidth(35) rect(self.x, 125, 300, 450) line(self.x+20, 175, self.x + 280, 525) translate(self.x + 150, 350) rotate(53.5) fill(150, 0, 0, 255) font("Palatino-Roman") fontSize(35) text("Reach Level " .. self.lvl, 0, -2) rotate(-53.5) translate(-(self.x + 150), -350) end --[[ Special Items Shop.Item.Special = class() function Shop.Item.Special:init(x, name, picture, func, costsMoney, costsMagic, label) self.x = 50 + 350 * (x - 1) self.name = name self.costs = {} self.costs.money = costsMoney self.costs.magic = costsMagic self.image = picture self.label = label -- Security if name == nil then self.name = "Untitled" end self.buyButton = Button("Buy", function() if self.costs.money <= money and self.costs.magic <= magicScore then func() money = money - self.costs.money magicScore = magicScore - self.costs.magic end end, vec2(self.x + 15, 150)) end function Shop.Item.Special:draw() fill(50, 50, 25, 255) strokeWidth(0) -- translate(currentPage.x, 0) -- BG rect(self.x, 125, 300, 450) -- Text fill(200, 150, 50, 255) font("Baskerville-SemiBold") local w, h = textSize(self.name) text(self.name, self.x + 10 + w/2, 525) fill(255, 255, 255, 255) -- Picture if self.image then sprite(self.image, self.x + 150, 400, 150, 150) else sprite("Project:Default Image", self.x + 150, 400, 150, 150) fontSize(25) font("Futura-Medium") text("No Image assetted", self.x + 150, 400) end -- Requirments font("Baskerville-SemiBold") fontSize(30) local a, b = textSize(self.costs.money .. "šŸ’°") text(self.costs.money .. "šŸ’°", self.x + 15 + a/2, 300) local a, b = textSize(self.costs.magic .. "šŸ”®") text(self.costs.magic .. "šŸ”®", self.x + 15 + a/2, 265) -- Label --sprite("Project:Label Cloud v1", self.x + 240, 550, 80, 50) -- translate(-currentPage.x, 0) -- Library self.buyButton:draw() -- Update Button self.buyButton.pos.x = self.x + 15 + currentPage.x end function Shop.Item.Special:touched(t) self.buyButton:touched(t) end]] --# Button Button = class() function Button:init(name, func, pos) self.name = name -- string self.func = func -- function self.pos = pos -- vec2 function self.fontSize = 35 self.size = vec2(0, 0) self.touching = false self.emoji = false end function Button:draw() fontSize(self.fontSize) font("Georgia") local w, h = textSize(self.name) strokeWidth(5) stroke(127, 127, 127, 255) fill(255, 255, 255, 255) if self.touching then fill(171, 171, 171, 255) end rect(self.pos.x - 5, self.pos.y - 5, w + 10, h + 10) fill(0, 0, 0, 255) if self.emoji then fill(255, 255) end text(self.name, self.pos.x + w/2, self.pos.y + h/2) self.size = vec2(w, h) strokeWidth(0) end function Button:touched(t) if t.x > self.pos.x - 5 and t.x < self.pos.x + self.size.x + 5 and t.y > self.pos.y - 5 and t.y < self.pos.y + self.size.y + 5 then if t.state == BEGAN then self.touching = true elseif t.state == ENDED then if self.touching then self.func(t) end self.touching = false end else self.touching = false end end