0,]']Б>Sя}WџЭuЇ№p8Зd%qy)6o;]ЩAІіsяїєєє”АТVl†3= 1 and newX <= mazeWidth and newY >= 1 and newY <= mazeHeight then if maze[newY][newX] == 1 then maze[(y + newY) // 2][(x + newX) // 2] = 0 generateMaze(newX, newY) end end end end local topPixelsCounter = 0 local wonWithTopPixels = false -- Variable to track whether the player won with usedTopPixels during the current game session local cheatMessage = false function resetGame() player.x = 0 player.y = 9 player.reachedExit = false -- Reset the "reachedExit" variable player.usedTopPixels = false wonWithTopPixels = false cheatMessage = false -- Generate a new maze starting from the entrance for y = 1, mazeHeight do for x = 1, mazeWidth do maze[y][x] = 1 end end generateMaze(1, 1) -- Display the count for every time usedTopPixels is true and the exit is reached print("Cheated: " .. topPixelsCounter, 4, 120, 4) end function init() -- Generate the maze starting from the entrance for y = 1, mazeHeight do maze[y] = {} for x = 1, mazeWidth do maze[y][x] = 1 end end generateMaze(1, 1) -- Adjust the yOffset to start from 0 (top of the screen) --local yOffset = (screenHeight - mazeHeight * 8) // 2 - 4 --resetGame() end init() function TIC() cls(12) -- Clear the screen with a black color -- Calculate the position to center the maze on the screen local xOffset = (screenWidth - mazeWidth * 8) // 2 local yOffset = (screenHeight - mazeHeight * 8) // 2 -- Draw the border around the maze (top and bottom) for x = 0, screenWidth - 1 do for y = 0, 7 do pix(x, y, 15) -- Draw the top border (black color) pix(x, screenHeight - y - 1, 15) -- Draw the bottom border (black color) end end -- Draw the border around the maze (left and right) for y = 0, screenHeight - 1 do pix(0, y, 15) -- Draw the left border (black color) pix(screenWidth - 1, y, 15) -- Draw the right border (black color) end -- Draw the maze walls for y = 1, mazeHeight do for x = 1, mazeWidth do if maze[y][x] == 1 then local mazeX = xOffset + (x - 1) * 8 local mazeY = yOffset + (y - 1) * 8 rect(mazeX, mazeY, 8, 8, 15) -- White color end end end -- Draw the a small border top for x = 8, screenWidth - 9 do for y = 8, 8 do pix(x, y, 15) -- Draw the top border (black color) -- Check for collision with the player character if x >= player.x and x <= player.x + 7 and y >= player.y and y <= player.y + 6 then -- Handle collision by preventing movement player.x, player.y = player.prevX, player.prevY dx, dy = 0, 0 -- Set the movement to zero to stop the player from moving end end end -- Draw the a small border top for x = screenWidth - 9, screenWidth - 9 do for y = 8, screenHeight - 16 do pix(x, y, 15) -- Draw the top border (black color) -- Check for collision with the player character if x >= player.x and x <= player.x + 6 and y >= player.y and y <= player.y + 6 then -- Handle collision by preventing movement player.x, player.y = player.prevX, player.prevY dx, dy = 0, 0 -- Set the movement to zero to stop the player from moving end end end -- Draw the entrance at the top-left corner rect(0, 8, 8, 8, 11) -- Cyan color -- Draw the exit at the bottom-right corner rect(screenWidth - 16, screenHeight - 16, 8, 8, 10) -- Yellow color -- hint message print("You can work hard, or you can work smart...", 4, 1, 4) print("Cheated: " .. topPixelsCounter, screenWidth - 62, 130, 4) -- Adjust the Y coordinate to the bottom of the screen -- Handle player movement with collision local dx, dy = 0, 0 if not player.reachedExit then -- Only allow movement if the player has not reached the exit if btn(0) then dy = dy - 1 end -- Up if btn(1) then dy = dy + 1 end -- Down if btn(2) then dx = dx - 1 end -- Left if btn(3) then dx = dx + 1 end -- Right end -- Move the player character player.prevX, player.prevY = player.x, player.y -- Store the previous valid position local newX = player.x + dx * player.speed local newY = player.y + dy * player.speed -- Check for collision with maze walls (white color) local collided = false local playerLeft = newX local playerRight = newX + 7 local playerTop = newY + 6 local playerBottom = newY + 6 if playerLeft >= xOffset and playerRight <= xOffset + 232 and playerTop >= 7 and playerBottom <= 136 then -- Collision detection with maze walls (white color) for y = 1, mazeHeight do for x = 1, mazeWidth do if maze[y][x] == 1 then local mazeX = xOffset + (x - 1) * 8 local mazeY = yOffset + (y - 1) * 8 local wallLeft = mazeX local wallRight = mazeX + 7 local wallTop = mazeY local wallBottom = mazeY + 7 if newX <= wallRight and newX + 7 >= wallLeft and newY <= wallBottom and newY + 6 >= wallTop then collided = true break end end end if collided then break end end end -- If there's no collision with maze walls, update the player's position if not collided then -- Check for collision with the edges of the screen if newY >= yOffset - 7 and newY <= screenHeight - yOffset - 7 then player.y = newY end if newX >= xOffset and newX <= screenWidth - xOffset - 7 then player.x = newX end end -- Calculate the grid position of the player and exit tile local playerGridX = math.floor((player.x - xOffset) / 8) + 1 local playerGridY = math.floor((player.y - yOffset) / 8) + 1 local exitGridX = mazeWidth local exitGridY = mazeHeight -- Handle the win condition (touching the edge of the exit tile) if (math.abs(playerGridX - exitGridX) == 1 and playerGridY == exitGridY) or (math.abs(playerGridY - exitGridY) == 1 and playerGridX == exitGridX) then player.reachedExit = true if player.y <= 2 then player.usedTopPixels = true end if player.usedTopPixels and player.reachedExit and not wonWithTopPixels then topPixelsCounter = topPixelsCounter + 1 cheatMessage = true end if cheatMessage then print("You know what you did. Enter / A", 4, 130, 4) wonWithTopPixels = true -- Set the flag to true to indicate that the player won with usedTopPixels during the current game session end if not player.usedTopPixels and player.reachedExit and not wonWithTopPixels and not cheatMessage then print("I'm proud of you. Enter / A", 4, 130, 4) -- Set the flag to true to indicate that the player won without using top pixels during the current game session end if keyp(50) or btn(4) or btn(5) or btn(6) or btn(7) then resetGame() -- Reset the flag when the game is reset end end -- Display "You know what you did" if the player took the top 8 pixels and hasn't reached the exit if player.y <= 2 and not player.reachedExit then player.usedTopPixels = true print("You lazy cheater.", 4, 130, 4) end -- Draw the player character spr(player.sprite, player.x, player.y, 14, 1, 0, 0, 1, 1, 13) end