├── images ├── card-highlighted │ ├── animation.txt │ ├── 1.png │ ├── 2.png │ └── 3.png ├── bg.gif ├── card.png ├── sky.png ├── block0.png ├── block1.png ├── block2.png ├── block3.png ├── block4.png ├── block5.png ├── block6.png ├── block7.png ├── clear.gif ├── clearbig.gif ├── clouds1.png ├── clouds2.png ├── highscore.gif └── launchImage.png ├── sounds ├── hold.wav ├── land.wav ├── lock.wav ├── rotate.wav ├── shift.wav ├── collide.wav ├── gameOver.wav ├── hardDrop.wav ├── softDrop.wav ├── lineClear1.wav ├── lineClear2.wav ├── lineClear3.wav └── lineClear4.wav ├── music ├── mundane.wav ├── whatever.wav ├── yesterday.wav ├── pretty_little_lies.wav ├── shut_up_or_shut_in.wav ├── something_in_the_air.wav └── glad_to_be_stuck_inside.wav ├── pdxinfo ├── README.md ├── fonts └── krull.fnt ├── scene.lua ├── main.lua ├── tetromino.lua ├── LICENSE └── stage.lua /images/card-highlighted/animation.txt: -------------------------------------------------------------------------------- 1 | frames = 1x15, 2x15, 3x15 -------------------------------------------------------------------------------- /images/bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/bg.gif -------------------------------------------------------------------------------- /images/card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/card.png -------------------------------------------------------------------------------- /images/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/sky.png -------------------------------------------------------------------------------- /sounds/hold.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/hold.wav -------------------------------------------------------------------------------- /sounds/land.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/land.wav -------------------------------------------------------------------------------- /sounds/lock.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/lock.wav -------------------------------------------------------------------------------- /images/block0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/block0.png -------------------------------------------------------------------------------- /images/block1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/block1.png -------------------------------------------------------------------------------- /images/block2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/block2.png -------------------------------------------------------------------------------- /images/block3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/block3.png -------------------------------------------------------------------------------- /images/block4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/block4.png -------------------------------------------------------------------------------- /images/block5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/block5.png -------------------------------------------------------------------------------- /images/block6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/block6.png -------------------------------------------------------------------------------- /images/block7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/block7.png -------------------------------------------------------------------------------- /images/clear.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/clear.gif -------------------------------------------------------------------------------- /music/mundane.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/music/mundane.wav -------------------------------------------------------------------------------- /sounds/rotate.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/rotate.wav -------------------------------------------------------------------------------- /sounds/shift.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/shift.wav -------------------------------------------------------------------------------- /images/clearbig.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/clearbig.gif -------------------------------------------------------------------------------- /images/clouds1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/clouds1.png -------------------------------------------------------------------------------- /images/clouds2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/clouds2.png -------------------------------------------------------------------------------- /images/highscore.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/highscore.gif -------------------------------------------------------------------------------- /music/whatever.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/music/whatever.wav -------------------------------------------------------------------------------- /music/yesterday.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/music/yesterday.wav -------------------------------------------------------------------------------- /sounds/collide.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/collide.wav -------------------------------------------------------------------------------- /sounds/gameOver.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/gameOver.wav -------------------------------------------------------------------------------- /sounds/hardDrop.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/hardDrop.wav -------------------------------------------------------------------------------- /sounds/softDrop.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/softDrop.wav -------------------------------------------------------------------------------- /images/launchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/launchImage.png -------------------------------------------------------------------------------- /sounds/lineClear1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/lineClear1.wav -------------------------------------------------------------------------------- /sounds/lineClear2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/lineClear2.wav -------------------------------------------------------------------------------- /sounds/lineClear3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/lineClear3.wav -------------------------------------------------------------------------------- /sounds/lineClear4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/sounds/lineClear4.wav -------------------------------------------------------------------------------- /images/card-highlighted/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/card-highlighted/1.png -------------------------------------------------------------------------------- /images/card-highlighted/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/card-highlighted/2.png -------------------------------------------------------------------------------- /images/card-highlighted/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/images/card-highlighted/3.png -------------------------------------------------------------------------------- /music/pretty_little_lies.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/music/pretty_little_lies.wav -------------------------------------------------------------------------------- /music/shut_up_or_shut_in.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/music/shut_up_or_shut_in.wav -------------------------------------------------------------------------------- /music/something_in_the_air.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/music/something_in_the_air.wav -------------------------------------------------------------------------------- /music/glad_to_be_stuck_inside.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenzoa/rainblocks/HEAD/music/glad_to_be_stuck_inside.wav -------------------------------------------------------------------------------- /pdxinfo: -------------------------------------------------------------------------------- 1 | name=Rainblocks 2 | author=Zenzoa 3 | description=A chill falling blocks game for the Playdate. 4 | bundleID=com.zenzoa.rainblocks 5 | version=1.0.1 6 | imagePath=images -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rainblocks 2 | 3 | A falling tetromino game for the Playdate. 4 | 5 | ## Credits 6 | - Music by [Holizna](https://freemusicarchive.org/music/holiznacc0/lo-fi-and-chill) 7 | - Sound effects by [JDWasabi](https://jdwasabi.itch.io/8-bit-16-bit-sound-effects-pack), [ColorAlpha](https://coloralpha.itch.io/50-menu-interface-sfx), and [ObsydianX](https://obsydianx.itch.io/interface-sfx-pack-1) 8 | 9 | ## License 10 | [Creative Commons BY-NC-SA 4.0]( https://creativecommons.org/licenses/by-nc-sa/4.0/) 11 | -------------------------------------------------------------------------------- /fonts/krull.fnt: -------------------------------------------------------------------------------- 1 | --metrics={"baseline":8,"xHeight":1,"capHeight":1,"pairs":{},"left":[],"right":[]} 2 | datalen=976 3 | data=iVBORw0KGgoAAAANSUhEUgAAADgAAAAwCAYAAABE1blzAAAAAXNSR0IArs4c6QAAApRJREFUaIHlWNFyxCAIxEz+/5fThzY9j+wCq7a5Xnfm5hIFRKMsaPbmaN3zQdo9DtJ/uHcvk/VHPnjdzP7F9uEEkMEDyEX6FXvMRmQLAdkys8+ZHt2zF2KrlH1hVQa9+z4PpvuEveCMgmxyaBtlOmwr+w8Aj8BuGNmWiHSixfIONXvsIrTNoklXznzbgHDFUQ+kE51B5Nz569tO2Uyf+SNF0WjFqueE6aNxlCiq2L8dI8eDohqpkEy1T8HKXfSkn+3x6ByMnBGEqg+MjyH3bl8vKLp5qF9MmSQLSJ74fSDycpc+TxPR5NikUJ+CLOPx41VtNa8U0QOLbEokVByrLliaiW1WR8Rxs5GvQleIK1OwTAY5kG3R2Uh62un/FayK5H8Lq3huJJMZGT9L0C/tO+swvE367ZhRCYKank1vs40Yj5zJvooKdXwJlSCj1HjVqqJSDCO5aFGh7WoUrWB0ezI5lMWYa0sR8SAzMlIvqlhWUexW5zE102dySGYFj/5PVKvijIeqgWjGnnqjcLl0GjrEvwS0AIynex0p2WaDjepX+9B45bERTWRlU5oekX7/HLUpYPab2SOTUQh01KHm/lH/TPHc3M/MYh5kRqzgBFu0mdBfrfyfcF78eqfU64Fef2Xx699VH98f0zwzod/LRDwYcWKqvwGB6Jz1h5hVCUjf36XIdyujYPXgyH2KGZ7oakhZlFIP+mcWDMrXCRUHRVx4GtFEdF4Y+aOJ/0S6Jy9GP0F/sH/rysJj9Iv2V47f6HnwFIKCATyPqg4iHkbI7GaZ0nuiwjMKDyH7t0KtJlh/NPlbwb5AFMqzcor13QJl5auXTi8zObMHTVRKkcpl7UtN7oQPzyxcq+0vgdFs3YAss38rPgAMzRg8tNb94wAAAABJRU5ErkJggg== 4 | width=8 5 | height=8 6 | 7 | tracking=1 8 | 9 | 0 7 10 | 1 6 11 | 2 7 12 | 3 7 13 | 4 7 14 | 5 7 15 | 6 7 16 | 7 7 17 | 8 7 18 | 9 7 19 | space 8 20 | � 8 21 | A 7 22 | B 7 23 | C 7 24 | D 7 25 | E 7 26 | F 7 27 | G 7 28 | H 7 29 | I 5 30 | J 7 31 | K 7 32 | L 7 33 | M 7 34 | N 7 35 | O 7 36 | P 7 37 | Q 7 38 | R 7 39 | S 7 40 | T 7 41 | U 7 42 | V 7 43 | W 7 44 | X 7 45 | Y 7 46 | Z 7 47 | 48 | -------------------------------------------------------------------------------- /scene.lua: -------------------------------------------------------------------------------- 1 | local scene = { 2 | create = function() 3 | local s = { 4 | bgImageTable = Gfx.imagetable.new('images/bg.gif'), 5 | bgImageIndex = 1, 6 | skyImage = Gfx.image.new('images/sky.png'), 7 | clouds1Image = Gfx.image.new('images/clouds1.png'), 8 | clouds2Image = Gfx.image.new('images/clouds2.png'), 9 | clouds1X = 0, 10 | clouds2X = 0, 11 | animationTimer = nil, 12 | setup = function(self) 13 | self.animationTimer = playdate.timer.new(500, function() self:nextFrame() end) 14 | self.animationTimer.repeats = true 15 | end, 16 | nextFrame = function(self) 17 | self.clouds1X = self.clouds1X + 0.24 18 | self.clouds2X = self.clouds2X + 0.51 19 | if self.clouds1X > 800 then 20 | self.clouds1X = 0 21 | end 22 | if self.clouds2X > 800 then 23 | self.clouds2X = 0 24 | end 25 | self.bgImageIndex = self.bgImageIndex + 1 26 | if self.bgImageIndex > self.bgImageTable:getLength() then 27 | self.bgImageIndex = 1 28 | end 29 | end, 30 | draw = function(self) 31 | self.skyImage:drawIgnoringOffset(0, 0) 32 | self.clouds1Image:drawIgnoringOffset(math.floor(self.clouds1X) - 800, 0) 33 | self.clouds1Image:drawIgnoringOffset(math.floor(self.clouds1X), 0) 34 | self.clouds2Image:drawIgnoringOffset(math.floor(self.clouds2X) - 800, 0) 35 | self.clouds2Image:drawIgnoringOffset(math.floor(self.clouds2X), 0) 36 | local bgImage = self.bgImageTable:getImage(self.bgImageIndex) 37 | bgImage:drawIgnoringOffset(0, 0) 38 | end 39 | } 40 | 41 | s:setup() 42 | return s 43 | end 44 | } 45 | 46 | return scene -------------------------------------------------------------------------------- /main.lua: -------------------------------------------------------------------------------- 1 | import "CoreLibs/object" 2 | import "CoreLibs/graphics" 3 | import "CoreLibs/sprites" 4 | import "CoreLibs/timer" 5 | 6 | Gfx = playdate.graphics 7 | Tetromino = import "tetromino" 8 | Stage = import "stage" 9 | Scene = import "scene" 10 | 11 | local currentStage 12 | local buttonRepeatTimerLeft = nil 13 | local buttonRepeatTimerRight = nil 14 | local upHoldTimer = nil 15 | 16 | local defaultFont 17 | 18 | local scene = {} 19 | local songs = {} 20 | local songIndex = 1 21 | local songNames = { 22 | "something_in_the_air", 23 | "glad_to_be_stuck_inside", 24 | "mundane", 25 | "pretty_little_lies", 26 | "shut_up_or_shut_in", 27 | "yesterday", 28 | "whatever", 29 | } 30 | 31 | local startMusic = function() 32 | songIndex = 1 33 | songs[songIndex]:play(0) 34 | end 35 | 36 | local nextSong = function() 37 | songs[songIndex]:stop() 38 | songIndex = songIndex + 1 39 | if songIndex > #songs then 40 | songIndex = 1 41 | end 42 | songs[songIndex]:play(0) 43 | end 44 | 45 | local stopMusic = function() 46 | songs[songIndex]:stop() 47 | end 48 | 49 | local setup = function() 50 | math.randomseed(playdate.getSecondsSinceEpoch()) 51 | 52 | defaultFont = Gfx.font.new("fonts/krull") 53 | Gfx.setFont(defaultFont) 54 | 55 | scene = Scene.create() 56 | scene:setup() 57 | 58 | for i, songName in pairs(songNames) do 59 | songs[i] = playdate.sound.fileplayer.new("music/" .. songName) 60 | songs[i]:setStopOnUnderrun(false) 61 | songs[i]:setVolume(0.5) 62 | end 63 | 64 | Tetromino:loadImages() 65 | currentStage = Stage.create(startMusic, nextSong, stopMusic) 66 | 67 | local width, height = playdate.display.getSize() 68 | local stageWidth = (currentStage.width * Tetromino.minoSize) 69 | local stageHeight = (currentStage.visibleHeight * Tetromino.minoSize) 70 | local offsetX = math.floor((width - stageWidth) / 2) 71 | local offsetY = math.floor((height - stageHeight) / 2) 72 | Gfx.setDrawOffset(offsetX, offsetY) 73 | 74 | local menu = playdate.getSystemMenu() 75 | ModeOption = menu:addOptionsMenuItem("mode", { "regular", "dynamic", "chill" }, currentStage.mode, function(option) 76 | currentStage:setMode(option) 77 | end) 78 | LevelOption = menu:addOptionsMenuItem("level", Stage.levelStrings, Stage.levelStrings[1], function(option) 79 | currentStage:setLevel(math.tointeger(option), true) 80 | end) 81 | GhostOption = menu:addCheckmarkMenuItem("ghost", currentStage.enableGhost, function(value) 82 | currentStage.enableGhost = value 83 | end) 84 | end 85 | 86 | setup() 87 | currentStage:loadData() 88 | 89 | playdate.AButtonDown = function() 90 | if currentStage.isGameOver and not currentStage.fillTimer then 91 | currentStage:setup() 92 | else 93 | currentStage:rotateClockwise() 94 | end 95 | end 96 | 97 | playdate.BButtonDown = function() 98 | currentStage:rotateCounterClockwise() 99 | end 100 | 101 | playdate.upButtonDown = function() 102 | if currentStage.enableHold then 103 | if not currentStage.isWaitingForHoldLock then 104 | currentStage.tickTimer:pause() 105 | end 106 | upHoldTimer = playdate.timer.performAfterDelay(currentStage.holdDelay, function() 107 | currentStage:switchHold() 108 | end) 109 | else 110 | currentStage:hardDrop() 111 | end 112 | end 113 | 114 | playdate.upButtonUp = function() 115 | currentStage.tickTimer._lastTime = nil 116 | currentStage.tickTimer:start() 117 | if currentStage.enableHold and upHoldTimer.timeLeft > 0 then 118 | upHoldTimer:remove() 119 | currentStage:hardDrop() 120 | end 121 | end 122 | 123 | playdate.downButtonDown = function() 124 | currentStage:startSoftDrop() 125 | end 126 | 127 | playdate.downButtonUp = function() 128 | currentStage:stopSoftDrop() 129 | end 130 | 131 | playdate.leftButtonDown = function() 132 | buttonRepeatTimerLeft = playdate.timer.keyRepeatTimer(function() currentStage:shiftLeft() end) 133 | end 134 | 135 | playdate.leftButtonUp = function() 136 | buttonRepeatTimerLeft:remove() 137 | end 138 | 139 | playdate.rightButtonDown = function() 140 | buttonRepeatTimerRight = playdate.timer.keyRepeatTimer(function() currentStage:shiftRight() end) 141 | end 142 | 143 | playdate.rightButtonUp = function() 144 | buttonRepeatTimerRight:remove() 145 | end 146 | 147 | playdate.update = function() 148 | Gfx.clear() 149 | 150 | scene:draw() 151 | 152 | currentStage:draw() 153 | 154 | playdate.timer.updateTimers() 155 | end 156 | 157 | playdate.gameWillTerminate = function() 158 | currentStage:saveData() 159 | end 160 | 161 | playdate.deviceWillSleep = function() 162 | currentStage:saveData() 163 | end -------------------------------------------------------------------------------- /tetromino.lua: -------------------------------------------------------------------------------- 1 | local tetromino = { 2 | minoSize = 10, 3 | 4 | types = { 5 | "I", 6 | "J", 7 | "L", 8 | "S", 9 | "Z", 10 | "T", 11 | "O", 12 | }, 13 | 14 | width = { 15 | I = 4, 16 | J = 3, 17 | L = 3, 18 | S = 3, 19 | Z = 3, 20 | T = 3, 21 | O = 3, 22 | }, 23 | 24 | pattern = { 25 | I = { 26 | { 27 | { 0, 0, 0, 0 }, 28 | { 1, 1, 1, 1 }, 29 | { 0, 0, 0, 0 }, 30 | { 0, 0, 0, 0 }, 31 | }, 32 | { 33 | { 0, 0, 1, 0 }, 34 | { 0, 0, 1, 0 }, 35 | { 0, 0, 1, 0 }, 36 | { 0, 0, 1, 0 }, 37 | }, 38 | { 39 | { 0, 0, 0, 0 }, 40 | { 0, 0, 0, 0 }, 41 | { 1, 1, 1, 1 }, 42 | { 0, 0, 0, 0 }, 43 | }, 44 | { 45 | { 0, 1, 0, 0 }, 46 | { 0, 1, 0, 0 }, 47 | { 0, 1, 0, 0 }, 48 | { 0, 1, 0, 0 }, 49 | }, 50 | }, 51 | J = { 52 | { 53 | { 2, 0, 0 }, 54 | { 2, 2, 2 }, 55 | { 0, 0, 0 }, 56 | }, 57 | { 58 | { 0, 2, 2 }, 59 | { 0, 2, 0 }, 60 | { 0, 2, 0 }, 61 | }, 62 | { 63 | { 0, 0, 0 }, 64 | { 2, 2, 2 }, 65 | { 0, 0, 2 }, 66 | }, 67 | { 68 | { 0, 2, 0 }, 69 | { 0, 2, 0 }, 70 | { 2, 2, 0 }, 71 | }, 72 | }, 73 | L = { 74 | { 75 | { 0, 0, 3 }, 76 | { 3, 3, 3 }, 77 | { 0, 0, 0 }, 78 | }, 79 | { 80 | { 0, 3, 0 }, 81 | { 0, 3, 0 }, 82 | { 0, 3, 3 }, 83 | }, 84 | { 85 | { 0, 0, 0 }, 86 | { 3, 3, 3 }, 87 | { 3, 0, 0 }, 88 | }, 89 | { 90 | { 3, 3, 0 }, 91 | { 0, 3, 0 }, 92 | { 0, 3, 0 }, 93 | }, 94 | }, 95 | S = { 96 | { 97 | { 0, 4, 4 }, 98 | { 4, 4, 0 }, 99 | { 0, 0, 0 }, 100 | }, 101 | { 102 | { 0, 4, 0 }, 103 | { 0, 4, 4 }, 104 | { 0, 0, 4 }, 105 | }, 106 | { 107 | { 0, 0, 0 }, 108 | { 0, 4, 4 }, 109 | { 4, 4, 0 }, 110 | }, 111 | { 112 | { 4, 0, 0 }, 113 | { 4, 4, 0 }, 114 | { 0, 4, 0 }, 115 | }, 116 | }, 117 | Z = { 118 | { 119 | { 5, 5, 0 }, 120 | { 0, 5, 5 }, 121 | { 0, 0, 0 }, 122 | }, 123 | { 124 | { 0, 0, 5 }, 125 | { 0, 5, 5 }, 126 | { 0, 5, 0 }, 127 | }, 128 | { 129 | { 0, 0, 0 }, 130 | { 5, 5, 0 }, 131 | { 0, 5, 5 }, 132 | }, 133 | { 134 | { 0, 5, 0 }, 135 | { 5, 5, 0 }, 136 | { 5, 0, 0 }, 137 | }, 138 | }, 139 | T = { 140 | { 141 | { 0, 6, 0 }, 142 | { 6, 6, 6 }, 143 | { 0, 0, 0 }, 144 | }, 145 | { 146 | { 0, 6, 0 }, 147 | { 0, 6, 6 }, 148 | { 0, 6, 0 }, 149 | }, 150 | { 151 | { 0, 0, 0 }, 152 | { 6, 6, 6 }, 153 | { 0, 6, 0 }, 154 | }, 155 | { 156 | { 0, 6, 0 }, 157 | { 6, 6, 0 }, 158 | { 0, 6, 0 }, 159 | }, 160 | }, 161 | O = { 162 | { 163 | { 0, 7, 7, 0 }, 164 | { 0, 7, 7, 0 }, 165 | { 0, 0, 0, 0 }, 166 | }, 167 | { 168 | { 0, 7, 7, 0 }, 169 | { 0, 7, 7, 0 }, 170 | { 0, 0, 0, 0 }, 171 | }, 172 | { 173 | { 0, 7, 7, 0 }, 174 | { 0, 7, 7, 0 }, 175 | { 0, 0, 0, 0 }, 176 | }, 177 | { 178 | { 0, 7, 7, 0 }, 179 | { 0, 7, 7, 0 }, 180 | { 0, 0, 0, 0 }, 181 | }, 182 | }, 183 | }, 184 | 185 | images = {}, 186 | 187 | loadImages = function(self) 188 | self.images = { 189 | Gfx.image.new('images/block2.png'), 190 | Gfx.image.new('images/block6.png'), 191 | Gfx.image.new('images/block7.png'), 192 | Gfx.image.new('images/block4.png'), 193 | Gfx.image.new('images/block5.png'), 194 | Gfx.image.new('images/block1.png'), 195 | Gfx.image.new('images/block3.png'), 196 | ghost = Gfx.image.new('images/block0.png') 197 | } 198 | end, 199 | 200 | create = function(type, xStart, yStart) 201 | local t = { 202 | 203 | type = type, 204 | x = xStart, 205 | y = yStart, 206 | rotationIndex = 1, 207 | isGhost = false, 208 | 209 | moveDown = function(self, stage) 210 | if self:checkCollision(stage, 0, 1) then 211 | return false 212 | else 213 | self.y = self.y + 1 214 | return true 215 | end 216 | end, 217 | 218 | moveLeft = function(self, stage) 219 | if self:checkCollision(stage, -1, 0) then 220 | return false 221 | else 222 | self.x = self.x - 1 223 | return true 224 | end 225 | end, 226 | 227 | moveRight = function(self, stage) 228 | if self:checkCollision(stage, 1, 0) then 229 | return false 230 | else 231 | self.x = self.x + 1 232 | return true 233 | end 234 | end, 235 | 236 | rotateClockwise = function(self, stage) 237 | local newRotationIndex = self.rotationIndex + 1 238 | if newRotationIndex > 4 then 239 | newRotationIndex = 1 240 | end 241 | return self:rotate(stage, newRotationIndex) 242 | end, 243 | 244 | rotateCounterClockwise = function(self, stage) 245 | local newRotationIndex = self.rotationIndex - 1 246 | if newRotationIndex < 1 then 247 | newRotationIndex = 4 248 | end 249 | return self:rotate(stage, newRotationIndex) 250 | end, 251 | 252 | rotate = function(self, stage, newRotationIndex) 253 | if not self:checkCollision(stage, 0, 0, newRotationIndex) then 254 | self.rotationIndex = newRotationIndex 255 | return true 256 | elseif not self:checkCollision(stage, 1, 0, newRotationIndex) then 257 | self.x = self.x + 1 258 | self.rotationIndex = newRotationIndex 259 | return true 260 | elseif not self:checkCollision(stage, -1, 0, newRotationIndex) then 261 | self.x = self.x - 1 262 | self.rotationIndex = newRotationIndex 263 | return true 264 | else 265 | return false 266 | end 267 | end, 268 | 269 | checkCollision = function(self, stage, dx, dy, rotationIndex) 270 | if not rotationIndex then 271 | rotationIndex = self.rotationIndex 272 | end 273 | local pattern = Tetromino.pattern[self.type] 274 | local rotation = pattern[rotationIndex] 275 | for row = 1, #rotation do 276 | for col = 1, #rotation[row] do 277 | if rotation[row][col] > 0 then 278 | local x = self.x + dx + col - 1 279 | local y = self.y + dy + row - 1 280 | if x < 1 then 281 | return true 282 | elseif x > stage.width then 283 | return true 284 | elseif y > stage.height then 285 | return true 286 | elseif stage.tiles[y][x] > 0 then 287 | return true 288 | end 289 | end 290 | end 291 | end 292 | return false 293 | end, 294 | 295 | drawMino = function(self, tx, ty, blockIndex, drawBackground) 296 | local x = tx * Tetromino.minoSize 297 | local y = ty * Tetromino.minoSize 298 | if drawBackground then 299 | Gfx.setColor(Gfx.kColorWhite) 300 | Gfx.fillRoundRect(x - 1, y - 1, Tetromino.minoSize + 1, Tetromino.minoSize + 1, 1) 301 | Gfx.setColor(Gfx.kColorBlack) 302 | end 303 | if self.isGhost then 304 | Tetromino.images.ghost:draw(x, y) 305 | else 306 | Tetromino.images[blockIndex]:draw(x, y) 307 | end 308 | end, 309 | 310 | draw = function(self, drawBackground) 311 | local pattern = Tetromino.pattern[self.type] 312 | local rotation = pattern[self.rotationIndex] 313 | for row = 1, #rotation do 314 | for col = 1, #rotation[row] do 315 | if rotation[row][col] > 0 then 316 | local x = self.x + col - 2 317 | local y = self.y + row - 4 318 | self:drawMino(x, y, rotation[row][col], drawBackground) 319 | end 320 | end 321 | end 322 | end, 323 | 324 | } 325 | return t 326 | end 327 | } 328 | 329 | return tetromino -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-NonCommercial-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International 58 | Public License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-NonCommercial-ShareAlike 4.0 International Public License 63 | ("Public License"). To the extent this Public License may be 64 | interpreted as a contract, You are granted the Licensed Rights in 65 | consideration of Your acceptance of these terms and conditions, and the 66 | Licensor grants You such rights in consideration of benefits the 67 | Licensor receives from making the Licensed Material available under 68 | these terms and conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-NC-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution, NonCommercial, and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. NonCommercial means not primarily intended for or directed towards 126 | commercial advantage or monetary compensation. For purposes of 127 | this Public License, the exchange of the Licensed Material for 128 | other material subject to Copyright and Similar Rights by digital 129 | file-sharing or similar means is NonCommercial provided there is 130 | no payment of monetary compensation in connection with the 131 | exchange. 132 | 133 | l. Share means to provide material to the public by any means or 134 | process that requires permission under the Licensed Rights, such 135 | as reproduction, public display, public performance, distribution, 136 | dissemination, communication, or importation, and to make material 137 | available to the public including in ways that members of the 138 | public may access the material from a place and at a time 139 | individually chosen by them. 140 | 141 | m. Sui Generis Database Rights means rights other than copyright 142 | resulting from Directive 96/9/EC of the European Parliament and of 143 | the Council of 11 March 1996 on the legal protection of databases, 144 | as amended and/or succeeded, as well as other essentially 145 | equivalent rights anywhere in the world. 146 | 147 | n. You means the individual or entity exercising the Licensed Rights 148 | under this Public License. Your has a corresponding meaning. 149 | 150 | 151 | Section 2 -- Scope. 152 | 153 | a. License grant. 154 | 155 | 1. Subject to the terms and conditions of this Public License, 156 | the Licensor hereby grants You a worldwide, royalty-free, 157 | non-sublicensable, non-exclusive, irrevocable license to 158 | exercise the Licensed Rights in the Licensed Material to: 159 | 160 | a. reproduce and Share the Licensed Material, in whole or 161 | in part, for NonCommercial purposes only; and 162 | 163 | b. produce, reproduce, and Share Adapted Material for 164 | NonCommercial purposes only. 165 | 166 | 2. Exceptions and Limitations. For the avoidance of doubt, where 167 | Exceptions and Limitations apply to Your use, this Public 168 | License does not apply, and You do not need to comply with 169 | its terms and conditions. 170 | 171 | 3. Term. The term of this Public License is specified in Section 172 | 6(a). 173 | 174 | 4. Media and formats; technical modifications allowed. The 175 | Licensor authorizes You to exercise the Licensed Rights in 176 | all media and formats whether now known or hereafter created, 177 | and to make technical modifications necessary to do so. The 178 | Licensor waives and/or agrees not to assert any right or 179 | authority to forbid You from making technical modifications 180 | necessary to exercise the Licensed Rights, including 181 | technical modifications necessary to circumvent Effective 182 | Technological Measures. For purposes of this Public License, 183 | simply making modifications authorized by this Section 2(a) 184 | (4) never produces Adapted Material. 185 | 186 | 5. Downstream recipients. 187 | 188 | a. Offer from the Licensor -- Licensed Material. Every 189 | recipient of the Licensed Material automatically 190 | receives an offer from the Licensor to exercise the 191 | Licensed Rights under the terms and conditions of this 192 | Public License. 193 | 194 | b. Additional offer from the Licensor -- Adapted Material. 195 | Every recipient of Adapted Material from You 196 | automatically receives an offer from the Licensor to 197 | exercise the Licensed Rights in the Adapted Material 198 | under the conditions of the Adapter's License You apply. 199 | 200 | c. No downstream restrictions. You may not offer or impose 201 | any additional or different terms or conditions on, or 202 | apply any Effective Technological Measures to, the 203 | Licensed Material if doing so restricts exercise of the 204 | Licensed Rights by any recipient of the Licensed 205 | Material. 206 | 207 | 6. No endorsement. Nothing in this Public License constitutes or 208 | may be construed as permission to assert or imply that You 209 | are, or that Your use of the Licensed Material is, connected 210 | with, or sponsored, endorsed, or granted official status by, 211 | the Licensor or others designated to receive attribution as 212 | provided in Section 3(a)(1)(A)(i). 213 | 214 | b. Other rights. 215 | 216 | 1. Moral rights, such as the right of integrity, are not 217 | licensed under this Public License, nor are publicity, 218 | privacy, and/or other similar personality rights; however, to 219 | the extent possible, the Licensor waives and/or agrees not to 220 | assert any such rights held by the Licensor to the limited 221 | extent necessary to allow You to exercise the Licensed 222 | Rights, but not otherwise. 223 | 224 | 2. Patent and trademark rights are not licensed under this 225 | Public License. 226 | 227 | 3. To the extent possible, the Licensor waives any right to 228 | collect royalties from You for the exercise of the Licensed 229 | Rights, whether directly or through a collecting society 230 | under any voluntary or waivable statutory or compulsory 231 | licensing scheme. In all other cases the Licensor expressly 232 | reserves any right to collect such royalties, including when 233 | the Licensed Material is used other than for NonCommercial 234 | purposes. 235 | 236 | 237 | Section 3 -- License Conditions. 238 | 239 | Your exercise of the Licensed Rights is expressly made subject to the 240 | following conditions. 241 | 242 | a. Attribution. 243 | 244 | 1. If You Share the Licensed Material (including in modified 245 | form), You must: 246 | 247 | a. retain the following if it is supplied by the Licensor 248 | with the Licensed Material: 249 | 250 | i. identification of the creator(s) of the Licensed 251 | Material and any others designated to receive 252 | attribution, in any reasonable manner requested by 253 | the Licensor (including by pseudonym if 254 | designated); 255 | 256 | ii. a copyright notice; 257 | 258 | iii. a notice that refers to this Public License; 259 | 260 | iv. a notice that refers to the disclaimer of 261 | warranties; 262 | 263 | v. a URI or hyperlink to the Licensed Material to the 264 | extent reasonably practicable; 265 | 266 | b. indicate if You modified the Licensed Material and 267 | retain an indication of any previous modifications; and 268 | 269 | c. indicate the Licensed Material is licensed under this 270 | Public License, and include the text of, or the URI or 271 | hyperlink to, this Public License. 272 | 273 | 2. You may satisfy the conditions in Section 3(a)(1) in any 274 | reasonable manner based on the medium, means, and context in 275 | which You Share the Licensed Material. For example, it may be 276 | reasonable to satisfy the conditions by providing a URI or 277 | hyperlink to a resource that includes the required 278 | information. 279 | 3. If requested by the Licensor, You must remove any of the 280 | information required by Section 3(a)(1)(A) to the extent 281 | reasonably practicable. 282 | 283 | b. ShareAlike. 284 | 285 | In addition to the conditions in Section 3(a), if You Share 286 | Adapted Material You produce, the following conditions also apply. 287 | 288 | 1. The Adapter's License You apply must be a Creative Commons 289 | license with the same License Elements, this version or 290 | later, or a BY-NC-SA Compatible License. 291 | 292 | 2. You must include the text of, or the URI or hyperlink to, the 293 | Adapter's License You apply. You may satisfy this condition 294 | in any reasonable manner based on the medium, means, and 295 | context in which You Share Adapted Material. 296 | 297 | 3. You may not offer or impose any additional or different terms 298 | or conditions on, or apply any Effective Technological 299 | Measures to, Adapted Material that restrict exercise of the 300 | rights granted under the Adapter's License You apply. 301 | 302 | 303 | Section 4 -- Sui Generis Database Rights. 304 | 305 | Where the Licensed Rights include Sui Generis Database Rights that 306 | apply to Your use of the Licensed Material: 307 | 308 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 309 | to extract, reuse, reproduce, and Share all or a substantial 310 | portion of the contents of the database for NonCommercial purposes 311 | only; 312 | 313 | b. if You include all or a substantial portion of the database 314 | contents in a database in which You have Sui Generis Database 315 | Rights, then the database in which You have Sui Generis Database 316 | Rights (but not its individual contents) is Adapted Material, 317 | including for purposes of Section 3(b); and 318 | 319 | c. You must comply with the conditions in Section 3(a) if You Share 320 | all or a substantial portion of the contents of the database. 321 | 322 | For the avoidance of doubt, this Section 4 supplements and does not 323 | replace Your obligations under this Public License where the Licensed 324 | Rights include other Copyright and Similar Rights. 325 | 326 | 327 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 328 | 329 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 330 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 331 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 332 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 333 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 334 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 335 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 336 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 337 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 338 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 339 | 340 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 341 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 342 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 343 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 344 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 345 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 346 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 347 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 348 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 349 | 350 | c. The disclaimer of warranties and limitation of liability provided 351 | above shall be interpreted in a manner that, to the extent 352 | possible, most closely approximates an absolute disclaimer and 353 | waiver of all liability. 354 | 355 | 356 | Section 6 -- Term and Termination. 357 | 358 | a. This Public License applies for the term of the Copyright and 359 | Similar Rights licensed here. However, if You fail to comply with 360 | this Public License, then Your rights under this Public License 361 | terminate automatically. 362 | 363 | b. Where Your right to use the Licensed Material has terminated under 364 | Section 6(a), it reinstates: 365 | 366 | 1. automatically as of the date the violation is cured, provided 367 | it is cured within 30 days of Your discovery of the 368 | violation; or 369 | 370 | 2. upon express reinstatement by the Licensor. 371 | 372 | For the avoidance of doubt, this Section 6(b) does not affect any 373 | right the Licensor may have to seek remedies for Your violations 374 | of this Public License. 375 | 376 | c. For the avoidance of doubt, the Licensor may also offer the 377 | Licensed Material under separate terms or conditions or stop 378 | distributing the Licensed Material at any time; however, doing so 379 | will not terminate this Public License. 380 | 381 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 382 | License. 383 | 384 | 385 | Section 7 -- Other Terms and Conditions. 386 | 387 | a. The Licensor shall not be bound by any additional or different 388 | terms or conditions communicated by You unless expressly agreed. 389 | 390 | b. Any arrangements, understandings, or agreements regarding the 391 | Licensed Material not stated herein are separate from and 392 | independent of the terms and conditions of this Public License. 393 | 394 | 395 | Section 8 -- Interpretation. 396 | 397 | a. For the avoidance of doubt, this Public License does not, and 398 | shall not be interpreted to, reduce, limit, restrict, or impose 399 | conditions on any use of the Licensed Material that could lawfully 400 | be made without permission under this Public License. 401 | 402 | b. To the extent possible, if any provision of this Public License is 403 | deemed unenforceable, it shall be automatically reformed to the 404 | minimum extent necessary to make it enforceable. If the provision 405 | cannot be reformed, it shall be severed from this Public License 406 | without affecting the enforceability of the remaining terms and 407 | conditions. 408 | 409 | c. No term or condition of this Public License will be waived and no 410 | failure to comply consented to unless expressly agreed to by the 411 | Licensor. 412 | 413 | d. Nothing in this Public License constitutes or may be interpreted 414 | as a limitation upon, or waiver of, any privileges and immunities 415 | that apply to the Licensor or You, including from the legal 416 | processes of any jurisdiction or authority. 417 | 418 | ======================================================================= 419 | 420 | Creative Commons is not a party to its public 421 | licenses. Notwithstanding, Creative Commons may elect to apply one of 422 | its public licenses to material it publishes and in those instances 423 | will be considered the “Licensor.” The text of the Creative Commons 424 | public licenses is dedicated to the public domain under the CC0 Public 425 | Domain Dedication. Except for the limited purpose of indicating that 426 | material is shared under a Creative Commons public license or as 427 | otherwise permitted by the Creative Commons policies published at 428 | creativecommons.org/policies, Creative Commons does not authorize the 429 | use of the trademark "Creative Commons" or any other trademark or logo 430 | of Creative Commons without its prior written consent including, 431 | without limitation, in connection with any unauthorized modifications 432 | to any of its public licenses or any other arrangements, 433 | understandings, or agreements concerning use of licensed material. For 434 | the avoidance of doubt, this paragraph does not form part of the 435 | public licenses. 436 | 437 | Creative Commons may be contacted at creativecommons.org. 438 | -------------------------------------------------------------------------------- /stage.lua: -------------------------------------------------------------------------------- 1 | local stage = { 2 | maxLevel = 10, 3 | levelStrings = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10" }, 4 | speeds = { 1000, 793, 618, 473, 355, 262, 190, 135, 94, 64 }, 5 | 6 | create = function(startMusic, nextSong, stopMusic) 7 | local s = { 8 | startMusic = startMusic, 9 | nextSong = nextSong, 10 | stopMusic = stopMusic, 11 | 12 | width = 10, 13 | height = 22, 14 | visibleHeight = 20, 15 | 16 | tetromino = nil, 17 | enablePreview = true, 18 | preview = nil, 19 | enableHold = true, 20 | hold = nil, 21 | enableGhost = true, 22 | ghost = nil, 23 | 24 | tiles = {}, 25 | bag = {}, 26 | 27 | highScore = 0, 28 | score = 0, 29 | scoreDisplay = 0, 30 | combo = -1, 31 | linesCleared = 0, 32 | fourLinesCleared = 0, 33 | level = 1, 34 | 35 | speed = 1000, 36 | lockDelay = 500, 37 | lockTimer = nil, 38 | tickTimer = nil, 39 | holdDelay = 500, 40 | isHardDropping = false, 41 | isWaitingForHoldLock = false, 42 | lastRowCleared = 1, 43 | 44 | isGameOver = false, 45 | fillSpeed = 1, 46 | fillTimer = nil, 47 | fillRow = 22, 48 | fillCol = 1, 49 | 50 | mode = "dynamic", 51 | 52 | levelLabelWidth = Gfx.getTextSize("LEVEL"), 53 | holdLabelWidth = Gfx.getTextSize("HOLD"), 54 | 55 | lineClearAnimation = Gfx.imagetable.new('images/clear.gif'), 56 | lineClearAnimationTimer = nil, 57 | lineClearIndex = 1, 58 | 59 | bigLineClearAnimation = Gfx.imagetable.new('images/clearbig.gif'), 60 | bigLineClearAnimationTimer = nil, 61 | bigLineClearIndex = 1, 62 | 63 | highScoreAnimation = Gfx.imagetable.new('images/highscore.gif'), 64 | highScoreAnimationTimer = nil, 65 | highScoreIndex = 1, 66 | hasReachedHighScore = false, 67 | 68 | soundEffects = { 69 | shift = playdate.sound.sampleplayer.new("sounds/shift"), 70 | rotate = playdate.sound.sampleplayer.new("sounds/rotate"), 71 | hold = playdate.sound.sampleplayer.new("sounds/hold"), 72 | softDrop = playdate.sound.sampleplayer.new("sounds/softDrop"), 73 | hardDrop = playdate.sound.sampleplayer.new("sounds/hardDrop"), 74 | collide = playdate.sound.sampleplayer.new("sounds/collide"), 75 | land = playdate.sound.sampleplayer.new("sounds/land"), 76 | lock = playdate.sound.sampleplayer.new("sounds/lock"), 77 | lineClear1 = playdate.sound.sampleplayer.new("sounds/lineClear1"), 78 | lineClear2 = playdate.sound.sampleplayer.new("sounds/lineClear2"), 79 | lineClear3 = playdate.sound.sampleplayer.new("sounds/lineClear3"), 80 | lineClear4 = playdate.sound.sampleplayer.new("sounds/lineClear4"), 81 | gameOver = playdate.sound.sampleplayer.new("sounds/gameOver") 82 | }, 83 | 84 | setup = function(self) 85 | self.isGameOver = false 86 | 87 | self.score = 0 88 | self.scoreDisplay = 0 89 | self.combo = -1 90 | self.linesCleared = 0 91 | self.fourLinesCleared = 0 92 | self.hasReachedHighScore = false 93 | 94 | self.tetromino = nil 95 | self.hold = nil 96 | self.preview = nil 97 | self.ghost = nil 98 | 99 | if self.mode ~= "chill" then 100 | self:setLevel(1, true) 101 | end 102 | 103 | self.tiles = {} 104 | for row = 1, self.height do 105 | self.tiles[row] = {} 106 | for col = 1, self.width do 107 | self.tiles[row][col] = 0 108 | end 109 | end 110 | 111 | self:resetBag() 112 | 113 | self:startMusic() 114 | 115 | self.tickTimer = playdate.timer.new(self.speed, function() self:tick() end) 116 | self.tickTimer.repeats = true 117 | end, 118 | 119 | gameOver = function(self) 120 | self.isGameOver = true 121 | self.soundEffects.gameOver:play() 122 | self:stopMusic() 123 | self.tickTimer:remove() 124 | self.tetromino = nil 125 | 126 | self.fillRow = 22 127 | self.fillCol = 1 128 | self.fillTimer = playdate.timer.new(self.fillSpeed, function() self:fill() end) 129 | self.fillTimer.repeats = true 130 | end, 131 | 132 | setMode = function(self, mode) 133 | if self.mode ~= mode then 134 | self.mode = mode 135 | ModeOption:setValue(mode) 136 | end 137 | end, 138 | 139 | setLevel = function(self, level, setManually) 140 | if level ~= self.level then 141 | if self.mode == "chill" and not setManually then 142 | level = self.level 143 | end 144 | 145 | if level > Stage.maxLevel then 146 | level = Stage.maxLevel 147 | end 148 | 149 | self.level = level 150 | 151 | self.speed = Stage.speeds[level] 152 | if self.tickTimer then 153 | self.tickTimer.duration = self.speed 154 | end 155 | 156 | if not setManually then 157 | LevelOption:setValue(Stage.levelStrings[level]) 158 | end 159 | end 160 | end, 161 | 162 | resetBag = function(self) 163 | self.bag = {} 164 | for i = 1, #Tetromino.types do 165 | table.insert(self.bag, Tetromino.types[i]) 166 | end 167 | for i = #self.bag, 2, -1 do 168 | local j = math.random(i) 169 | self.bag[i], self.bag[j] = self.bag[j], self.bag[i] 170 | end 171 | end, 172 | 173 | chooseFromBag = function(self) 174 | local type = self.bag[1] 175 | table.remove(self.bag, 1) 176 | if #self.bag == 0 then 177 | self:resetBag() 178 | end 179 | return type 180 | end, 181 | 182 | spawnTetromino = function(self) 183 | local type = self:chooseFromBag() 184 | local x = 4 185 | local y = 2 186 | if type == "I" then 187 | y = 1 188 | end 189 | 190 | self.tetromino = Tetromino.create(type, x, y) 191 | if self.tetromino:checkCollision(self, 0, 0) then 192 | self:gameOver() 193 | else 194 | if self.enableGhost then 195 | self.ghost = Tetromino.create(type, x, y) 196 | self.ghost.isGhost = true 197 | end 198 | 199 | if self.enablePreview then 200 | self.preview = Tetromino.create(self.bag[1], 0, 0) 201 | end 202 | 203 | self:tick() 204 | end 205 | end, 206 | 207 | shiftLeft = function(self) 208 | if self.tetromino then 209 | local success = self.tetromino:moveLeft(self) 210 | if success then 211 | self.soundEffects.shift:play() 212 | else 213 | self.soundEffects.collide:play() 214 | end 215 | end 216 | end, 217 | 218 | shiftRight = function(self) 219 | if self.tetromino then 220 | local success = self.tetromino:moveRight(self) 221 | if success then 222 | self.soundEffects.shift:play() 223 | else 224 | self.soundEffects.collide:play() 225 | end 226 | end 227 | end, 228 | 229 | rotateClockwise = function(self) 230 | if self.tetromino then 231 | local success = self.tetromino:rotateClockwise(self) 232 | if success then 233 | self.soundEffects.rotate:play() 234 | else 235 | self.soundEffects.collide:play() 236 | end 237 | end 238 | end, 239 | 240 | rotateCounterClockwise = function(self) 241 | if self.tetromino then 242 | local success = self.tetromino:rotateCounterClockwise(self) 243 | if success then 244 | self.soundEffects.rotate:play() 245 | else 246 | self.soundEffects.collide:play() 247 | end 248 | end 249 | end, 250 | 251 | startSoftDrop = function(self) 252 | if self.tetromino then 253 | self.soundEffects.softDrop:play(0) 254 | self.tickTimer.duration = math.floor(self.speed / 20) 255 | end 256 | end, 257 | 258 | stopSoftDrop = function(self) 259 | if self.tetromino then 260 | self.soundEffects.softDrop:stop() 261 | self.tickTimer.duration = self.speed 262 | end 263 | end, 264 | 265 | hardDrop = function(self) 266 | if self.tetromino then 267 | self.isHardDropping = true 268 | self:tick() 269 | end 270 | end, 271 | 272 | switchHold = function(self) 273 | if self.enableHold and not self.isWaitingForHoldLock and self.tetromino ~= nil then 274 | self.isHardDropping = false 275 | self.soundEffects.hold:play() 276 | if self.hold then 277 | table.insert(self.bag, 1, self.hold.type) 278 | self.isWaitingForHoldLock = true 279 | end 280 | self.hold = self.tetromino 281 | self.hold.rotationIndex = 1 282 | self:spawnTetromino() 283 | end 284 | end, 285 | 286 | lock = function(self) 287 | if self.lockTimer then 288 | self.lockTimer:remove() 289 | self.lockTimer = nil 290 | end 291 | 292 | if self.tetromino and self.tetromino:checkCollision(self, 0, 1) then 293 | self:tetrominoToTiles() 294 | self.tetromino = nil 295 | local lineCount = self:checkForLines() 296 | self:calculateScore(lineCount) 297 | 298 | if self:checkForLockOut() then 299 | self:gameOver() 300 | else 301 | self:checkForSlowDown() 302 | if lineCount == 0 then 303 | if self.isHardDropping then 304 | self.soundEffects.hardDrop:play() 305 | else 306 | self.soundEffects.lock:play() 307 | end 308 | elseif 1 <= lineCount and lineCount <= 4 then 309 | self.soundEffects["lineClear" .. lineCount]:play() 310 | end 311 | end 312 | end 313 | 314 | self.isWaitingForHoldLock = false 315 | self.isHardDropping = false 316 | end, 317 | 318 | countAirBubbles = function(self) 319 | local airBubbles = 0 320 | local lastAirBubbleRow = 0 321 | local tilesLookedAt = {} 322 | for row = 1, self.height do 323 | local rowTiles = {} 324 | for col = 1, self.width do 325 | table.insert(rowTiles, false) 326 | end 327 | table.insert(tilesLookedAt, rowTiles) 328 | end 329 | 330 | local lookAtTile 331 | lookAtTile = function(row, col) 332 | if self.tiles[row][col] == 0 and not tilesLookedAt[row][col] then 333 | tilesLookedAt[row][col] = true 334 | if row - 1 >= 1 then 335 | lookAtTile(row - 1, col) 336 | end 337 | if row + 1 <= self.height then 338 | lookAtTile(row + 1, col) 339 | end 340 | if col - 1 >= 1 then 341 | lookAtTile(row, col - 1) 342 | end 343 | if col + 1 <= self.width then 344 | lookAtTile(row, col + 1) 345 | end 346 | end 347 | end 348 | 349 | for row = 1, self.height do 350 | for col = 1, self.width do 351 | if self.tiles[row][col] == 0 and not tilesLookedAt[row][col] then 352 | if row > lastAirBubbleRow then 353 | airBubbles = airBubbles + 1 354 | lastAirBubbleRow = row 355 | end 356 | lookAtTile(row, col) 357 | end 358 | end 359 | end 360 | 361 | return airBubbles - 1 362 | end, 363 | 364 | checkForSlowDown = function(self) 365 | if self.mode == "dynamic" and self.level > 1 then 366 | local airBubbles = self:countAirBubbles() 367 | local newMaxLevel = Stage.maxLevel - (airBubbles - 1) 368 | if self.level > newMaxLevel then 369 | self:setLevel(self.level - 1) 370 | end 371 | end 372 | end, 373 | 374 | checkForLockOut = function(self) 375 | local tilesAboveVisibleStage = false 376 | for row = 1, 2 do 377 | for col = 1, self.width do 378 | if self.tiles[row][col] > 0 then 379 | tilesAboveVisibleStage = true 380 | break 381 | end 382 | end 383 | end 384 | return tilesAboveVisibleStage 385 | end, 386 | 387 | checkForLines = function(self) 388 | local lineCount = 0 389 | self.lastRowCleared = 1 390 | for row = 3, self.height do 391 | local isLine = true 392 | for col = 1, self.width do 393 | if self.tiles[row][col] == 0 then 394 | isLine = false 395 | end 396 | end 397 | if isLine then 398 | self:clearLine(row) 399 | lineCount = lineCount + 1 400 | if row > self.lastRowCleared then 401 | self.lastRowCleared = row 402 | end 403 | end 404 | end 405 | return lineCount 406 | end, 407 | 408 | clearLine = function(self, y) 409 | for row = y, 2, -1 do 410 | for col = 1, self.width do 411 | self.tiles[row][col] = self.tiles[row - 1][col] 412 | end 413 | end 414 | end, 415 | 416 | tetrominoToTiles = function(self) 417 | local pattern = Tetromino.pattern[self.tetromino.type] 418 | local rotation = pattern[self.tetromino.rotationIndex] 419 | for row = 1, #rotation do 420 | for col = 1, #rotation[row] do 421 | if rotation[row][col] > 0 then 422 | local x = self.tetromino.x + col - 1 423 | local y = self.tetromino.y + row - 1 424 | self.tiles[y][x] = rotation[row][col] 425 | end 426 | end 427 | end 428 | end, 429 | 430 | calculateScore = function(self, lineCount) 431 | local score = 0 432 | 433 | if lineCount == 1 then 434 | score = 100 * self.level 435 | elseif lineCount == 2 then 436 | score = 300 * self.level 437 | elseif lineCount == 3 then 438 | score = 500 * self.level 439 | elseif lineCount >= 4 then 440 | score = 800 * self.level 441 | end 442 | 443 | if lineCount >= 1 then 444 | self.combo = self.combo + 1 445 | score = score + (50 * self.combo * self.level) 446 | else 447 | self.combo = -1 448 | end 449 | 450 | self.linesCleared = self.linesCleared + lineCount 451 | if self.linesCleared >= 10 then 452 | self.linesCleared = 0 453 | self:setLevel(self.level + 1) 454 | end 455 | 456 | if lineCount >= 4 then 457 | self.fourLinesCleared = self.fourLinesCleared + 1 458 | if self.fourLinesCleared >= 2 then 459 | self.fourLinesCleared = 0 460 | self:nextSong() 461 | end 462 | end 463 | 464 | if lineCount >= 1 then 465 | self.lineClearIndex = 1 466 | self.lineClearAnimationTimer = playdate.timer.new(25, function() self:nextLineClearFrame() end) 467 | self.lineClearAnimationTimer.repeats = true 468 | end 469 | if lineCount >= 4 then 470 | self.bigLineClearIndex = 1 471 | self.bigLineClearAnimationTimer = playdate.timer.new(30, function() self:nextBigLineClearFrame() end) 472 | self.bigLineClearAnimationTimer.repeats = true 473 | end 474 | 475 | self.score = self.score + score 476 | 477 | if self.score > self.highScore then 478 | if self.highScoreAnimationTimer == nil and not self.hasReachedHighScore then 479 | self.highScoreIndex = 1 480 | self.highScoreAnimationTimer = playdate.timer.new(30, function() self:nextHighScoreFrame() end) 481 | self.highScoreAnimationTimer.repeats = true 482 | end 483 | self.highScore = self.score 484 | self.hasReachedHighScore = true 485 | end 486 | end, 487 | 488 | tick = function(self) 489 | if self.tetromino then 490 | 491 | local success = false 492 | if self.isHardDropping then 493 | while self.tetromino:moveDown(self) do 494 | -- nothing, we're hard-dropping until we hit the bottom 495 | end 496 | else 497 | success = self.tetromino:moveDown(self) 498 | end 499 | 500 | if success then 501 | if self.lockTimer then 502 | self.lockTimer:remove() 503 | self.lockTimer = nil 504 | end 505 | elseif not self.lockTimer then 506 | local lockDelay = self.lockDelay 507 | if self.isHardDropping then 508 | lockDelay = 1 509 | else 510 | self.soundEffects.land:play() 511 | end 512 | self.lockTimer = playdate.timer.new(lockDelay, function() self:lock() end) 513 | end 514 | 515 | else 516 | self:spawnTetromino() 517 | end 518 | end, 519 | 520 | fill = function(self) 521 | self.tiles[self.fillRow][self.fillCol] = math.random(1, 7) 522 | 523 | if self.fillRow % 2 == 0 then 524 | self.fillCol = self.fillCol + 1 525 | else 526 | self.fillCol = self.fillCol - 1 527 | end 528 | 529 | if self.fillCol < 1 or self.fillCol > self.width then 530 | self.fillRow = self.fillRow - 1 531 | if self.fillRow % 2 == 0 then 532 | self.fillCol = 1 533 | else 534 | self.fillCol = self.width 535 | end 536 | if self.fillRow > 2 then 537 | self.soundEffects.collide:play() 538 | end 539 | end 540 | 541 | if self.fillRow <= 2 then 542 | self.soundEffects.land:play() 543 | self.fillTimer:remove() 544 | self.fillTimer = nil 545 | end 546 | end, 547 | 548 | drawTile = function(self, tx, ty, blockIndex) 549 | local x = tx * Tetromino.minoSize 550 | local y = ty * Tetromino.minoSize 551 | Tetromino.images[blockIndex]:draw(x, y) 552 | end, 553 | 554 | draw = function(self) 555 | local displayWidth = self.width * Tetromino.minoSize 556 | local displayHeight = self.visibleHeight * Tetromino.minoSize 557 | 558 | if self.score > self.scoreDisplay then 559 | if self.score - self.scoreDisplay >= 1000 then 560 | self.scoreDisplay = math.min(self.score, self.scoreDisplay + 100) 561 | elseif self.score - self.scoreDisplay >= 100 then 562 | self.scoreDisplay = math.min(self.score, self.scoreDisplay + 20) 563 | else 564 | self.scoreDisplay = math.min(self.score, self.scoreDisplay + 10) 565 | end 566 | end 567 | Gfx.drawText("SCORE", displayWidth + 10, displayHeight - 26) 568 | Gfx.drawText(self.scoreDisplay, displayWidth + 10, displayHeight - 10) 569 | 570 | Gfx.drawText("LEVEL", -self.levelLabelWidth - 10, displayHeight - 26) 571 | self.levelTextWidth = Gfx.getTextSize(self.level) 572 | Gfx.drawText(self.level, -self.levelTextWidth - 10, displayHeight - 10) 573 | 574 | if self.enablePreview then 575 | playdate.graphics.setImageDrawMode(playdate.graphics.kDrawModeFillWhite) 576 | Gfx.drawText("NEXT", displayWidth + 9, -1) 577 | Gfx.drawText("NEXT", displayWidth + 9, 0) 578 | Gfx.drawText("NEXT", displayWidth + 9, 1) 579 | Gfx.drawText("NEXT", displayWidth + 11, -1) 580 | Gfx.drawText("NEXT", displayWidth + 11, 0) 581 | Gfx.drawText("NEXT", displayWidth + 11, 1) 582 | Gfx.drawText("NEXT", displayWidth + 10, -1) 583 | Gfx.drawText("NEXT", displayWidth + 10, 1) 584 | playdate.graphics.setImageDrawMode(playdate.graphics.kDrawModeCopy) 585 | Gfx.drawText("NEXT", displayWidth + 10, 0) 586 | end 587 | 588 | if self.enableHold then 589 | playdate.graphics.setImageDrawMode(playdate.graphics.kDrawModeFillWhite) 590 | Gfx.drawText("HOLD", -self.holdLabelWidth - 9, -1) 591 | Gfx.drawText("HOLD", -self.holdLabelWidth - 9, 0) 592 | Gfx.drawText("HOLD", -self.holdLabelWidth - 9, 1) 593 | Gfx.drawText("HOLD", -self.holdLabelWidth - 11, -1) 594 | Gfx.drawText("HOLD", -self.holdLabelWidth - 11, 0) 595 | Gfx.drawText("HOLD", -self.holdLabelWidth - 11, 1) 596 | Gfx.drawText("HOLD", -self.holdLabelWidth - 10, -1) 597 | Gfx.drawText("HOLD", -self.holdLabelWidth - 10, 1) 598 | playdate.graphics.setImageDrawMode(playdate.graphics.kDrawModeCopy) 599 | Gfx.drawText("HOLD", -self.holdLabelWidth - 10, 0) 600 | end 601 | 602 | if self.enablePreview and self.preview then 603 | self.preview.x = self.width + 2 604 | self.preview.y = 5 605 | self.preview:draw(true) 606 | end 607 | 608 | if self.enableHold and self.hold then 609 | self.hold.x = -Tetromino.width[self.hold.type] 610 | self.hold.y = 5 611 | self.hold:draw(true) 612 | end 613 | 614 | Gfx.setColor(Gfx.kColorWhite) 615 | Gfx.fillRect(-3, -3, displayWidth + 5, displayHeight + 5) 616 | Gfx.setColor(Gfx.kColorBlack) 617 | Gfx.drawRect(-2, -2, displayWidth + 3, displayHeight + 3) 618 | Gfx.setClipRect(0, 0, displayWidth, displayHeight) 619 | 620 | if self.tetromino then 621 | if self.ghost and self.enableGhost then 622 | self.ghost.x = self.tetromino.x 623 | self.ghost.y = self.tetromino.y 624 | self.ghost.rotationIndex = self.tetromino.rotationIndex 625 | while self.ghost:moveDown(self) do end 626 | self.ghost:draw() 627 | end 628 | 629 | self.tetromino:draw() 630 | end 631 | 632 | for row = 1, self.height do 633 | for col = 1, self.width do 634 | if self.tiles[row][col] > 0 then 635 | local x = col - 1 636 | local y = row - 3 637 | self:drawTile(x, y, self.tiles[row][col]) 638 | end 639 | end 640 | end 641 | 642 | playdate.graphics.clearClipRect() 643 | 644 | if self.lineClearAnimationTimer ~= nil then 645 | local lineClearImage = self.lineClearAnimation:getImage(self.lineClearIndex) 646 | local lineClearY = (self.lastRowCleared - 3) * Tetromino.minoSize - 5 647 | lineClearImage:draw(-13, lineClearY) 648 | end 649 | 650 | if self.bigLineClearAnimationTimer ~= nil then 651 | local bigLineClearImage = self.bigLineClearAnimation:getImage(self.bigLineClearIndex) 652 | local bigLineClearY = (self.lastRowCleared - 3) * Tetromino.minoSize - 10 653 | bigLineClearImage:draw(-13, bigLineClearY) 654 | end 655 | 656 | if self.highScoreAnimationTimer ~= nil then 657 | local highScoreImage = self.highScoreAnimation:getImage(self.highScoreIndex) 658 | local scoreWidth = playdate.graphics.getTextSize(self.score) 659 | highScoreImage:draw(displayWidth + scoreWidth + 12, displayHeight - 17) 660 | elseif self.hasReachedHighScore then 661 | local highScoreImage = self.highScoreAnimation:getImage(4) 662 | local scoreWidth = playdate.graphics.getTextSize(self.score) 663 | highScoreImage:draw(displayWidth + scoreWidth + 12, displayHeight - 17) 664 | end 665 | 666 | if self.isGameOver then 667 | local highScoreText = "HIGH SCORE\n" .. self.highScore 668 | local highScoreW, highScoreH = playdate.graphics.getTextSize(highScoreText, nil, 4) 669 | local highScoreX = displayWidth / 2 - math.floor(highScoreW / 2) 670 | local highScoreY = displayHeight / 2 - math.floor(highScoreH / 2) 671 | playdate.graphics.setColor(playdate.graphics.kColorWhite) 672 | playdate.graphics.fillRoundRect(highScoreX - 4, highScoreY - 4, highScoreW + 8, highScoreH + 8, 4) 673 | Gfx.drawTextAligned(highScoreText, displayWidth / 2, highScoreY, kTextAlignment.center, 4) 674 | end 675 | 676 | end, 677 | 678 | nextLineClearFrame = function(self) 679 | self.lineClearIndex = self.lineClearIndex + 1 680 | if self.lineClearIndex >= self.lineClearAnimation:getLength() then 681 | self.lineClearAnimationTimer:remove() 682 | self.lineClearAnimationTimer = nil 683 | end 684 | end, 685 | 686 | nextBigLineClearFrame = function(self) 687 | self.bigLineClearIndex = self.bigLineClearIndex + 1 688 | if self.bigLineClearIndex >= self.bigLineClearAnimation:getLength() then 689 | self.bigLineClearAnimationTimer:remove() 690 | self.bigLineClearAnimationTimer = nil 691 | end 692 | end, 693 | 694 | nextHighScoreFrame = function(self) 695 | self.highScoreIndex = self.highScoreIndex + 1 696 | if self.highScoreIndex >= self.highScoreAnimation:getLength() then 697 | self.highScoreAnimationTimer:remove() 698 | self.highScoreAnimationTimer = nil 699 | end 700 | end, 701 | 702 | saveData = function(self) 703 | playdate.datastore.write({ 704 | highScore = self.highScore, 705 | mode = self.mode, 706 | level = self.level 707 | }) 708 | end, 709 | 710 | loadData = function(self) 711 | local data = playdate.datastore.read() 712 | if data ~= nil then 713 | if data.highScore ~= nil then 714 | self.highScore = data.highScore 715 | end 716 | if data.mode ~= nil then 717 | self:setMode(data.mode) 718 | end 719 | if data.level ~= nil and data.mode == "chill" then 720 | self:setLevel(data.level, true) 721 | LevelOption:setValue(Stage.levelStrings[data.level]) 722 | end 723 | end 724 | end, 725 | } 726 | 727 | s:setup() 728 | return s 729 | end 730 | } 731 | 732 | return stage --------------------------------------------------------------------------------