player = Image.load("player.png") ball = Image.load("ball.PNG") Ball = { } Ball[1] = { x = 20, y = 0 } Pscore = 0 Aiscore = 0 aiy = 0 direction = 1 playery = 0 white = Color.new(255, 255, 255) Music.playFile("bgmusic.it", true) while true do screen:clear() rand = math.random(2) -- Paddle bounce if Ball[1].x < 12 and Ball[1].y >= playery and Ball[1].y <= playery + 33 and direction == 3 then direction = 2 end if Ball[1].x < 12 and Ball[1].y >= playery and Ball[1].y <= playery + 33 and direction == 4 then direction = 1 end if Ball[1].x > 450 and Ball[1].y >= aiy and Ball[1].y <= aiy + 33 and direction == 1 then direction = 4 end if Ball[1].x > 450 and Ball[1].y >= aiy and Ball[1].y <= aiy + 33 and direction == 2 then direction = 3 end if Ball[1].y > aiy and rand == 1 then aiy = aiy + 2 end if Ball[1].y < aiy and rand == 1 then aiy = aiy - 2 end if Ball[1].y > aiy and rand == 2 then aiy = aiy + 7 end if Ball[1].y < aiy and rand == 2 then aiy = aiy - 7 end if Ball[1].x < 2 then Aiscore = Aiscore + 2/3 end if Ball[1].x > 470 then Pscore = Pscore + 2 end if Ball[1].y > 262 and direction == 1 then direction = 2 end if Ball[1].x > 468 and direction == 1 then direction = 4 end if Ball[1].y < 0 and direction == 2 then direction = 1 end if Ball[1].x > 470 and direction == 2 then direction = 3 end if Ball[1].y < 0 and direction == 3 then direction = 4 end if Ball[1].x < 0 and direction == 3 then direction = 2 end if Ball[1].y > 262 and direction == 4 then direction = 3 end if Ball[1].x < 0 and direction == 4 then direction = 1 end -- ball directions if direction == 1 then Ball[1].x = Ball[1].x + 4 Ball[1].y = Ball[1].y + 4 end if direction == 2 then Ball[1].x = Ball[1].x + 4 Ball[1].y = Ball[1].y - 4 end if direction == 3 then Ball[1].x = Ball[1].x - 4 Ball[1].y = Ball[1].y - 4 end if direction == 4 then Ball[1].x = Ball[1].x - 4 Ball[1].y = Ball[1].y + 4 end screen:blit(Ball[1].x,Ball[1].y,ball) pad = Controls.read() if pad:down() then playery = playery + 3 end if pad:up() then playery = playery - 3 end if playery > 247 then playery = 247 end if playery < 0 then playery = 0 end screen:blit(0,playery,player) screen:blit(469,aiy,player) screen:print(20,0,"Player 1 = " .. Pscore/2,white) screen:print(150,0,"AI = " .. Aiscore/2,white) screen.waitVblankStart() screen.flip() end