Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Game settings
- local WIDTH, HEIGHT = 10, 8
- local DIAMOND_CHANCE = 0.15
- local LAVA_CHANCE = 0.10
- local GAME_SPEED = 0.5
- -- Initialize game field
- local function generateField()
- local field = {}
- for y = 1, HEIGHT do
- field[y] = {}
- for x = 1, WIDTH do
- if math.random() < DIAMOND_CHANCE then
- field[y][x] = "💎"
- elseif math.random() < LAVA_CHANCE then
- field[y][x] = "🌋"
- else
- field[y][x] = "·"
- end
- end
- end
- field[1][1] = "🐢" -- Starting position
- return field
- end
- -- Draw game field
- local function draw(field, score, fuel)
- term.clear()
- print("=== Turtle Miner ===")
- print("Score: "..score.." Fuel: "..fuel)
- for y = 1, HEIGHT do
- local line = ""
- for x = 1, WIDTH do
- line = line .. field[y][x] .. " "
- end
- print(line)
- end
- end
- -- Main game loop
- local function gameLoop()
- local score = 0
- local posX, posY = 1, 1
- local field = generateField()
- turtle.refuel(1) -- Initial fuel
- while true do
- local fuel = turtle.getFuelLevel()
- field[posY][posX] = "·"
- -- Input handling
- local event, key = os.pullEvent("key")
- if key == keys.up and posY > 1 then
- posY = posY - 1
- elseif key == keys.down and posY < HEIGHT then
- posY = posY + 1
- elseif key == keys.left and posX > 1 then
- posX = posX - 1
- elseif key == keys.right and posX < WIDTH then
- posX = posX + 1
- elseif key == keys.space then
- turtle.dig() -- Dig block
- fuel = fuel - 1
- end
- -- Cell checks
- if field[posY][posX] == "💎" then
- score = score + 10
- turtle.suck() -- Collect diamond
- elseif field[posY][posX] == "🌋" then
- print("You hit lava! Game over!")
- return
- end
- -- Fuel management
- fuel = fuel - 0.5
- turtle.refuel(0) -- Auto-refuel from inventory
- -- Update field
- field[posY][posX] = "🐢"
- draw(field, score, fuel)
- -- Lose conditions
- if fuel <= 0 then
- print("Out of fuel!")
- return
- end
- sleep(GAME_SPEED)
- end
- end
- -- Start game
- term.clear()
- print("Welcome to Turtle Miner!")
- print("Controls:")
- print("Arrow keys - movement")
- print("Space - dig block")
- print("Collect diamonds (💎) and avoid lava (🌋)")
- print("Press any key to start...")
- os.pullEvent("key")
- gameLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement