═нлллл┬┬┬╛╙╙╙╛┬┬┬╛ллл╛люл╛люл╛люлллЛН┬┬лН╙╙юН┬╗юНл╛юлю╛ююю╛ююю╛ююнлллл┬┬┬╛╙╙╙╛┬┬┬╛ллл╛ллл╛люл╛люлллЛН┬┬лН╙╙юН┬╗юНл╛юлл╛ююю╛ююю╛юю╛ллл╛╙╙╙╛╙╛╙╛╙йл╛╙╙╙▄┬┬┬люлнллнл╛л╙╙юЛ╛╙юН╙╙юН╙╙юН┬┬лНюЛНллНН╛ллл╛╙╙╙╛╙╛╙╛╙йл╛╙╙╙▄┬┬┬люлнллнл╛л╙╙юЛ╛╙юН╙╙юН╙╙юН┬┬лНюЛНллНН >ю?юлллллллллЛПллЛПщллщЧПлллллэЮмллМПлллллЛОмллщЧплллллллллЛллЛЮлллллл ЮлллллллЭплллллэЮллл ллЛчллллллюллллллллл,ОллэмллллллПллллллллПмллллллЛПлллЛлл,плллллллэюлллллллллЛЯлл,пллллллллллллллл юлллллллл ллллллэмлллллллэмллллэмллэямЮллЛмллЛмллЛАмллЮллллРллЛплллЛ.мэмллЮллЛПлллЯ-ПллэЮллэЮлллялллПллллЭлл,оллэП=млллл,пллэПлл,ллэпллЛлллллллэллэмллмллПллэюллЮллэПллLюллалл ЮллэллллЛлллмллЮлл,аллПлл,ЮллэаллоллПлл,лл лл,ллэбллПллэнллллэПнллЛнллюлл ллмлллэЮлл<млллл,нллЧЮллллллллнлл юллЮллолэлл,ЮллЛЮллллмллЮллэмллПллллллллмллРпллПллЮллллЛЮллЛЮлллл мллПллЛалл ПлллллллЯблл юлллллл ллэЮллэЮллллмлллл,нллЮлллллл-оллюллПллнллл,ллэ лллл мллЮллэюллПллЛЯюлл нллллюлэллЛлллаллцллПлл,пллэллэплл,лллПллЮллллэмлл юлл мллЮллэлллП Юлл,ЮлллпллэЮллдллл,алл,юллмллллЛмллэЧОмПллэмллЛЮмлл,ПллнлллЛплллЛнлл мллПлл,@лллллллПлл,аллллллллллплллэмллллллллРнллЮллэмллллллЮллэПлллллллэПллллл,плллллллл мллПлл,Юлллллл-Плл,плллллэЮллмллЛблллллл-мллЮллэ щллэБллэ мллщПллаллэчмллщПллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллПЪПЪПЪПЪПЪПЪ^UУПЪ!"PUUUПЪ """UeUUПЪ""ПUУPUПЪ" "PUPUПЪ" "PUPUПЪ " "PUPUПЪ " "PUPU " "UUUPU`U " """"UUUPUPU " """"UUU`UPU" """"UUUU_U" """"UUUUUUUПЪ"""""""UUUPUUUПЪ """"""UUUVUУлл !""""UUUюллл"""UUUлллл """UUUюллллл"""UUUлллллл """UUUлллллл """UUUлллллл """UUUлллллл """UUUлллллл """UUUюллллл"""UUUлллл """UUUюллл"""UUUлл """UUUПЪ"""UUUПЪ"""UUUПЪ"""UUUПЪ"""UUU"""UUU"""UUU"""UUU"""UUU"""UUUПЪ"""UUUПЪ"""UUUПЪ"""UUUПЪ"""UUUПЪ"""ПЪПЪПЪПЪПЪюллмпэюлюлло ълЛллэллэщлЩюлэлллЛллэллМллМпЛм ю юЭаЭоЭюлнлло лНллПЪпэлю о н ллПллПлЪлЪлюЭюЭЮэдюэ элло лллЪЪо м юЭюЭа лллллнMЛюлл лэюЛЛлло лэ ллЛллЛн н ю о н ллЛлПллПл@л ю пЛюЭю л лло плLллн бюллолллЭллЭПлюЭп<ю ю нлло Пллла м ю н н ллЮллЮллю пЛю ю лммПлллпэлю пЛа ллмлмлюллю ю лплтдлЩллэлNл юЭлн ллэла ла ПлППЪПЪПЪПЪПЪПЪПЪ@DD4DD E4@DD4DDD0DЦDD Т $П$@@$ЮD4@T4Юd@? ТBTC@Ю$PT d@@DПd@?OП4T 4@`$NП$@BT@BP@@D/$O@D4D4`Т0D4 ТC d@D4O@O@@cТd0D4@4DDПS`$F`4@Ю$B5@C@@D$ПS@TПD %_C0ТBCПD@F$`D@OBd0EOП44D?D% %BPDЦO@Т D@@P$PD#ПЪПЪПЪПЪПЪПЪПЪллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллM-- title: TIC Pong -- author: Muse for Terry -- desc: Pong for TIC-80 - you vs the computer, first to 7, ball gets faster every rally -- script: lua -- input: gamepad -- saveid: tic_pong -- TIC Pong for TIC-80, 240x136 -- Up / Down: move your paddle (left side). -- X: serve the ball. First to 7 wins. -- Where the ball hits your paddle sets its angle, and every -- paddle hit makes it a little faster. local WIN_SCORE = 7 local PADDLE_H = 24 local PADDLE_W = 4 local state = "title" -- title, serve, play, point, gameover local player_score = 0 local ai_score = 0 local rally = 0 local best_rally = 0 local point_t = 0 local point_msg = "" local winner = "" local player = {x = 8, y = 56} local ai = {x = 228, y = 56} local ball = {x = 120, y = 68, vx = 0, vy = 0} local function reset_ball(dir) ball.x = 120 ball.y = 68 local speed = 2.2 ball.vx = speed * dir ball.vy = (math.random() * 2 - 1) * 1.0 end local function new_game() player_score = 0 ai_score = 0 rally = 0 best_rally = 0 player.y = 56 ai.y = 56 reset_ball(1) state = "serve" end local function serve_ball() reset_ball(1) state = "play" end local function score_point(who) if who == "player" then player_score = player_score + 1 point_msg = "YOU SCORE!" else ai_score = ai_score + 1 point_msg = "COMPUTER SCORES" end if rally > best_rally then best_rally = rally end rally = 0 point_t = 60 if player_score >= WIN_SCORE then winner = "YOU WIN!" state = "gameover" elseif ai_score >= WIN_SCORE then winner = "COMPUTER WINS" state = "gameover" else state = "point" end end local function bounce_paddle(paddle, dir) -- dir is the new horizontal direction: 1 to the right, -1 to the left local offset = (ball.y - (paddle.y + PADDLE_H / 2)) / (PADDLE_H / 2) if offset > 1 then offset = 1 end if offset < -1 then offset = -1 end local speed = math.sqrt(ball.vx * ball.vx + ball.vy * ball.vy) * 1.05 if speed > 4.5 then speed = 4.5 end if speed < 2.2 then speed = 2.2 end ball.vx = speed * dir ball.vy = offset * 2.0 rally = rally + 1 end local function update_play() -- player paddle if btn(0) then player.y = player.y - 3.2 if player.y < 4 then player.y = 4 end end if btn(1) then player.y = player.y + 3.2 if player.y > 136 - 4 - PADDLE_H then player.y = 136 - 4 - PADDLE_H end end -- computer paddle: follow the ball, a little slower than the player if ball.vx > 0 then local target = ball.y - PADDLE_H / 2 local diff = target - ai.y local step = 2.6 if diff > 2 then ai.y = ai.y + step elseif diff < -2 then ai.y = ai.y - step end if ai.y < 4 then ai.y = 4 end if ai.y > 136 - 4 - PADDLE_H then ai.y = 136 - 4 - PADDLE_H end end -- ball ball.x = ball.x + ball.vx ball.y = ball.y + ball.vy -- top / bottom walls if ball.y < 6 then ball.y = 6 ball.vy = -ball.vy elseif ball.y > 130 then ball.y = 130 ball.vy = -ball.vy end -- player paddle (left) if ball.vx < 0 and ball.x - 3 <= player.x + PADDLE_W and ball.x - 3 >= player.x - 4 and ball.y >= player.y - 3 and ball.y <= player.y + PADDLE_H + 3 then ball.x = player.x + PADDLE_W + 3 bounce_paddle(player, 1) end -- computer paddle (right) if ball.vx > 0 and ball.x + 3 >= ai.x and ball.x + 3 <= ai.x + PADDLE_W + 4 and ball.y >= ai.y - 3 and ball.y <= ai.y + PADDLE_H + 3 then ball.x = ai.x - 3 bounce_paddle(ai, -1) end -- scoring if ball.x < 0 then score_point("ai") elseif ball.x > 240 then score_point("player") end end local function update() if state == "title" then if btnp(4) or btnp(5) then new_game() end elseif state == "serve" then if btn(0) then player.y = player.y - 3.2 if player.y < 4 then player.y = 4 end end if btn(1) then player.y = player.y + 3.2 if player.y > 136 - 4 - PADDLE_H then player.y = 136 - 4 - PADDLE_H end end if btnp(4) or btnp(5) then serve_ball() end elseif state == "play" then update_play() elseif state == "point" then point_t = point_t - 1 if point_t <= 0 then reset_ball(1) state = "serve" end elseif state == "gameover" then if btnp(4) or btnp(5) then state = "title" end end end -- ---- drawing ---- local function draw_table() cls(0) -- centre line for y = 8, 128, 12 do rect(118, y, 2, 6, 15) end -- top / bottom walls rect(0, 2, 240, 2, 12) rect(0, 132, 240, 2, 12) -- scores print(tostring(player_score), 96, 10, 12) print(tostring(ai_score), 136, 10, 12) print("YOU", 88, 26, 5) print("CPU", 136, 26, 2) end local function draw_paddles() rect(player.x, math.floor(player.y), PADDLE_W, PADDLE_H, 5) rect(ai.x, math.floor(ai.y), PADDLE_W, PADDLE_H, 2) end local function draw_ball() circ(math.floor(ball.x), math.floor(ball.y), 3, 12) end local function draw_title() cls(0) draw_table() draw_paddles() draw_ball() rect(0, 48, 240, 40, 0) print("TIC PONG", 88, 54, 4) print("TIC PONG", 87, 53, 12) print("BY MUSE FOR TERRY", 78, 68, 5) print("UP/DOWN: PADDLE X: SERVE", 56, 78, 12) print("FIRST TO 7 WINS", 76, 108, 4) print("PRESS X TO START", 76, 120, 12) end local function draw_serve() draw_table() draw_paddles() draw_ball() print("PRESS X TO SERVE", 76, 60, 4) print("RALLY " .. rally .. " BEST " .. best_rally, 72, 76, 12) end local function draw_point() draw_table() draw_paddles() print(point_msg, 88, 60, 4) print(player_score .. " - " .. ai_score, 108, 76, 12) end local function draw_gameover() cls(0) print(winner, 88, 40, 2) print(player_score .. " - " .. ai_score, 108, 56, 12) print("BEST RALLY " .. best_rally, 76, 72, 4) print("PRESS X TO PLAY AGAIN", 64, 96, 12) end local function draw() if state == "title" then draw_title() return end if state == "gameover" then draw_gameover() return end if state == "serve" then draw_serve() return end if state == "point" then draw_point() return end draw_table() draw_paddles() draw_ball() print("RALLY " .. rally, 100, 124, 12) end function TIC() update() draw() end