€,"ÌÍ,"ÜÜ,"ÌÍÌÂÌÊ"""ÂÌÂÌÊ,,ÌÌÂÌÂ̬ªÜ߬ªüý¬ªÜßÌÊÌΪªªÎÌÊÌά¬ÌÌÊÌÊÌÌÌÌÌÌÌÌÌ̬ªÌ̪ªÊ̪ªÊ̪ªÊ̬ªÌÌÌÌÌ >º'wwpwpwpwpwpwwpwwwwwpwwwwwpwwwpwwwwwwwpwwwpwwwwpwwwpwwwpwpwwwwwwpwwwwwwwpwppwpwwwwwpwwwwwwwpwwwwpwwwwwwpppwwwpwpwpwwwwpwpwwwpwwwwwwwwpwwppwwppwpwwwwwwwpwwppwpwwpwwwwwwwwpwwwwpwww—-- title: TIC Sports Tennis -- author: Smilure -- Configurações iniciais do jogo local player1 = { x = 20, y = 60, speed = 2, score = 0 } local player2 = { x = 160, y = 60, width = 10, height = 40, speed = 2, score = 0 } local ball = { x = 120, y = 64, speed_x = 2, speed_y = 2 } local gameState = "menu" -- Estado inicial do jogo -- Função de inicialização do jogo function init() -- Inicializa as pontuações dos jogadores player1.score = 0 player2.score = 0 end -- Restaura as posições iniciais function resetPositions() player1.y = 60 player2.y = 60 ball.x = 120 ball.y = 64 ball.speed_x = 2 ball.speed_y = 2 end -- Função para controle da IA (jogador 2) function updateAI() -- A IA tenta prever a posição da bola local prediction = ball.y + (ball.speed_x * (player2.x - ball.x) / ball.speed_x) -- Ajuste a velocidade da IA local aiSpeed = 1.2 -- Move a raquete do jogador 2 em direção à posição prevista da bola if prediction < player2.y + player2.height / 2 then player2.y = player2.y - player2.speed * aiSpeed elseif prediction > player2.y + player2.height / 2 then player2.y = player2.y + player2.speed * aiSpeed end end -- Função para atualizar a tela function drawGame() cls(12) -- Fundo azul -- Desenha a rede rect(120, 0, 1, 128, 7) -- Desenha os sprites spr(1, player1.x, player1.y) -- Sprite do jogador 1 spr(2, player2.x, player2.y) -- Sprite do jogador 2 (IA) spr(3, ball.x, ball.y) -- Sprite da bola -- Desenha a pontuação dos jogadores print("Player 1: " .. player1.score, 4, 4, 7) print("Player 2: " .. player2.score, 177, 4, 7) end -- Função de atualização do jogo function TIC() if gameState == "menu" then cls(0) -- Fundo preto -- Exibe o menu inicial print("TIC-Sports: Tennis", 80, 40, 7) print("Press Z to start", 90, 80, 7) if btn(4) then gameState = "playing" init() end elseif gameState == "playing" then -- Verifica a entrada do jogador 1 (W e S) if btn(0) then player1.y = player1.y - player1.speed elseif btn(1) then player1.y = player1.y + player1.speed end -- Movimenta a bola ball.x = ball.x + ball.speed_x ball.y = ball.y + ball.speed_y -- Verifica se a bola atingiu as raquetes local ballRadius = 5 local playerWidth = 10 local playerHeight = 40 if ball.x - ballRadius < player1.x + playerWidth and ball.x + ballRadius > player1.x and ball.y - ballRadius < player1.y + playerHeight and ball.y + ballRadius > player1.y then ball.speed_x = -ball.speed_x end if ball.x - ballRadius < player2.x + playerWidth and ball.x + ballRadius > player2.x and ball.y - ballRadius < player2.y + playerHeight and ball.y + ballRadius > player2.y then ball.speed_x = -ball.speed_x end -- Verifica se a bola atingiu as bordas da tela if ball.y - ballRadius < 0 or ball.y + ballRadius > 128 then ball.speed_y = -ball.speed_y end -- Verifica se a bola saiu da tela if ball.x + ballRadius < 0 or ball.x - ballRadius > 240 then -- Verifica qual jogador marcou ponto if ball.x + ballRadius < 0 then -- Player 2 (IA) marcou ponto player2.score = player2.score + 1 else -- Player 1 marcou ponto player1.score = player1.score + 1 end if player1.score >= 3 or player2.score >= 3 then gameState = "gameover" else resetPositions() end end -- Chama a função de atualização da IA para o jogador 2 updateAI() -- Desenha o jogo drawGame() elseif gameState == "gameover" then cls(0) -- Fundo preto -- Exibe a tela de fim de jogo com a pontuação print("Game Over", 100, 40, 7) print("Player 1: " .. player1.score, 100, 60, 7) print("Player 2: " .. player2.score, 100, 80, 7) print("Press Z to restart!", 50, 120, 7) if btn(4) then -- Voltar ao menu gameState = "menu" end end end -- Inicialize o jogo no menu gameState = "menu"