!"""!33#!"2"!"#"!2""!33#!"""gfffgefegVVfgfefgVVfgefegfffwwww""" 3332DDD23DD 333"""""""3333DDDDDDDD3333"""""""333DD3#DDD#333"""ppgvpVegUUvgUUvpVepgvp ? 03 03 033 033 03 03 03 03 0333 0333 " 3 2C# 2C# 2D# 2D# 2D# 2D# 2D# 2D# 2D# 2D# 2D# 2D# 2D# 2D# 2D# 2D# 2D# 2D# 24# 24# 3 " -- title: Pong Game Remake -- author: Pedro G. H. Andrade -- desc: A remake of the 72's Pong Arcade game (keyboard or gamepad 1 or 2 players). -- site: website link -- license: MIT License (change this to your license of choice) -- version: 1.2 -- script: lua game = { w = 240, h = 136, mapa = { x = 0, y = 0 }, } player = { x = 0, y = game.h // 2, points = 0, sprs = 256, fr = 1, px = 2, invs = 0, reflet = 0, pro = 1, vyp = 1, vyn = 1, ky = 0, draw = function(self) spr(0%(30*self.fr)//30*self.px+self.sprs, self.x,self.y,self.invs,self.pro,self.reflet,1,3,1) end, move = function(self) if btn(0) and self.y > 0 then self.y = self.y - self.vyn end if btn(1) and (self.y+24) < 136 then self.y = self.y + self.vyp end end } player2 = { ai = false, -- Artificial Intelligence x = 232, y = game.h // 2, points = 0, sprs = 272, fr = 1, px = 2, invs = 0, reflet = 0, pro = 1, vyp = 1, vyn = 1, ky = 0, draw = function(self) spr(0%(30*self.fr)//30*self.px+self.sprs, self.x,self.y,self.invs,self.pro,self.reflet,1,3,1) end, move = function(self) if self.ai == true and ball.x+4 >= 120 then if ball.y+4 < self.y+12 and self.y > 0 then if player.points <= 2 or player2.points-player.points >= 0 then self.y = self.y - 0.8 else self.y = self.y - 0.9 end end if ball.y+4 > self.y+12 and (self.y+24) < 136 then if player.points <= 2 or player2.points-player.points >= 0 then self.y = self.y + 0.8 else self.y = self.y + 0.9 end end end if input == 'keyboard' then if btn(4) and self.y > 0 then self.y = self.y - self.vyn end if btn(5) and (self.y+24) < 136 then self.y = self.y + self.vyp end end if input == 'gamepad' then if btn(8) and self.y > 0 then self.y = self.y - self.vyn end if btn(9) and (self.y+24) < 136 then self.y = self.y + self.vyp end end end } ball = { t = 0, x = game.w // 2, y = game.h // 2, sprs = 259,-- Sprite inicial fr = 1,-- Frames px = 2,-- Pixels invs = 0,-- Cor invisivel reflet = 0,-- Refletido pro = 1,-- Proporcao vx = 1,-- vel. x vy = 1,-- vel. y sx = -1, sy = 0, tock = false, mov_h = function(sx) move = ball.x + sx return move end, mov_v = function(sy) move = ball.y + sy return move end, draw = function(self) spr(self.t%(30*self.fr)//30*self.px+self.sprs, self.x,self.y,self.invs,self.pro,self.reflet,1,1,1) end, move = function(self) self.x = self.mov_h(ball.sx) self.y = self.mov_v(ball.sy) -- Collision walls if self.y <= 0 then self.sy = 1 sfx(0, 37, 8, 0, 3) elseif self.y+8 >= 136 then self.sy = -1 sfx(0, 37, 8, 0, 3) end -- Collision Players if self.x <= player.x + 6 then if CheckCollision(self.x, self.y, 1) then if ball.tock == false then self.sy = -1 ball.tock = true end if self.y+4 >= player.y and self.y+4 <= player.y + 4 then self.sy = -1 end if self.y+4 >= player.y + 20 and self.y+4 <= player.y + 24 then self.sy = 1 end self.sx = 1 sfx(0, 40, 8, 0, 3) end end if self.x + 6 >= player2.x then if CheckCollision(self.x, self.y, 2) then if ball.tock == false then self.sy = -1 ball.tock = true end if self.y+4 >= player2.y and self.y+4 <= player2.y + 4 then self.sy = -1 end if self.y+4 >= player2.y + 20 and self.y+4 <= player2.y + 24 then self.sy = 1 end self.sx = -1 sfx(0, 40, 8, 0, 3) end end end } function CheckCollision(x, y, p) local collision = false if p == 1 then if y+4 >= player.y and y+4 <= player.y + 24 then collision = true end else if y+4 >= player2.y and y+4 <= player2.y + 24 then collision = true end end return collision end function Point() if ball.x < -9 then player2.points = player2.points + 1 ball.x = game.w // 2 ball.y = game.h // 2 ball.sy = 0 ball.tock = false elseif ball.x > 249 then player.points = player.points + 1 ball.x = game.w // 2 ball.y = game.h // 2 ball.sy = 0 ball.tock = false end end menu = true input = 'keyboard' function TIC() cls(0) if menu then rect(game.w//2, 0, 1, 136, 12) player:draw() player2:draw() if player.y >= 0 and player.y+25 <= 136 or player2.y >= 0 and player2.y+25 <= 136 then player.y = ball.y player2.y = ball.y elseif ball.y <= 112 then player.y = ball.y player2.y = ball.y end ball:draw() ball:move() print('Pong Game', 70, 10, 4, 1, 2) print('Remake', 150, 21, 4, 1, 1, 1) print('1 Player', 101, 30, 4) print('Press A(X) to play with A.I', 70, 40, 4, 1, 1, 1) print('This option can make', 85, 50, 1, 1, 1, 1) print('the game more difficult.', 80, 60, 1, 1, 1, 1) print('2 Players', 98, 70, 4) print('Press Z(A) to play with keyboard', 60, 80, 4, 1, 1, 1) print('P1: up and down P2: Z and X', 65, 90, 1, 1, 1, 1) print('Press X(B) to play with gamepad', 61, 100, 4, 1, 1, 1) print('P1: up and down P2: up and down', 60, 110, 1, 1, 1, 1) if btn(4) then input = 'keyboard' menu = false player.y = game.h // 2 player2.y = game.h // 2 ball.x = game.w // 2 ball.y = game.h // 2 ball.sx = -1 ball.sy = 0 ball.tock = false elseif btn(5) then input = 'gamepad' menu = false player.y = game.h // 2 player2.y = game.h // 2 ball.x = game.w // 2 ball.y = game.h // 2 ball.sx = -1 ball.sy = 0 ball.tock = false elseif btn(6) then input = 'AI' player2.ai = true menu = false player.y = game.h // 2 player2.y = game.h // 2 ball.x = game.w // 2 ball.y = game.h // 2 ball.sx = -1 ball.sy = 0 ball.tock = false end else -- Game Layout rect(game.w//2, 0, 1, 136, 12) print(player.points, 45, 10, 10, 1, 2) print(player2.points, 185, 10, 3, 1, 2) Point() -- Game Checks if input == 'keyboard' then spr(260, 40, 120, 0, 1, 0, 0, 1, 1) spr(261, 50, 120, 0, 1, 0, 0, 1, 1) spr(262, 170, 120, 0, 1, 0, 0, 1, 1) spr(263, 180, 120, 0, 1, 0, 0, 1, 1) elseif input == 'gamepad' then spr(260, 40, 120, 0, 1, 0, 0, 1, 1) spr(261, 50, 120, 0, 1, 0, 0, 1, 1) spr(260, 170, 120, 0, 1, 0, 0, 1, 1) spr(261, 180, 120, 0, 1, 0, 0, 1, 1) else spr(260, 40, 120, 0, 1, 0, 0, 1, 1) spr(261, 50, 120, 0, 1, 0, 0, 1, 1) spr(276, 185, 120, 0, 1, 0, 0, 1, 1) end player:draw() player:move() player2:draw() player2:move() ball:draw() ball:move() end end