0,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3 135 then pad.y = 135 - PADDLE_HEIGHT end end-- Both paddles end -- Inputs GAME function UPDATES_START() if ACTIVE_PLAYER == 1 then BALL.y = PADDLES.P1.y+(PADDLE_HEIGHT/2)-(BALL_SIZE/2) BALL.dy = PADDLES.P1.last_move else BALL.y = PADDLES.P2.y+(PADDLE_HEIGHT/2)-(BALL_SIZE/2) BALL.dy = PADDLES.P2.last_move end end -- Update Start function UPDATES_GAME() -- Move the damn ball BALL.x = BALL.x + (BALL.dx*Game_speed) BALL.y = BALL.y + (BALL.dy*Game_speed) --Ball edge bounce if(BALL.y < 1) or (BALL.y+BALL_SIZE > 135) then BALL.dy = 0 - BALL.dy sfx(0) end --check if the paddles overlap with the ball edge for i,pad in pairs(PADDLES) do local pad_collide = check_ball_collision(pad) if pad_collide and not pad.prev_collide then pad_hit(pad) end pad.prev_collide = pad_collide end -- for each paddle --Scores if BALL.x > 240 then P1_score = P1_score + 1 sfx(2) ACTIVE_PLAYER = 1 RESET() elseif BALL.x + BALL_SIZE < 0 then P2_score = P2_score + 1 sfx(2) ACTIVE_PLAYER = 2 RESET() end end -- UPDATES GAME function DRAW_GAME() cls() --Boundaries -- line(x0, y0, x1,y1, col) line(0,0,240,0, 14) line(0,135,240,135, 14) -- net(for _i=starting_num, ending_num, step size) -- _i = throwaway variable for _i=2,136,8 do rect(119,_i, 2, 4, 14) end --Paddles for i,pad in pairs(PADDLES) do rect(pad.x,pad.y,4,PADDLE_HEIGHT, 12) end --Ball --rect(x-max 240,y-max 136) rect(BALL.x,BALL.y,BALL_SIZE,BALL_SIZE ,12) --Debug speed print(Game_speed.."x", 0, 0, 12) end--DRAW GAME function DRAW_START() print_center("READY",80,2) local arrow_flip = 0 if BALL.dy > 0 then arrow_flip = 2 end if ACTIVE_PLAYER == 1 then print_center("PLAYER 1",94,2) print_center("Press X to Ball",110,1) spr(272, BALL.x-2, BALL.y-2, 0, 1, arrow_flip) else print_center("PLAYER 2",94,2) print_center("Press m to Ball",110,1) spr(272, BALL.x-2, BALL.y-2, 0, 1, arrow_flip+1) end --Scoreboard -- print_center(txt, y_pos, scale, x_offset) print_center(P1_score, 40, 3, -60) print_center(P2_score, 40, 3, 60) end -- Draw Start function DRAW_MENU() cls(0) print_center("BALLIN'", 30, 3) print_center("PONG", 60, 3) print_center("Press Enter or Spacebar To Start", 100) end -- DRAW MENU -- Axis Aligned Bounding Box (ball collision) function check_ball_collision(pad) if (BALL.x < pad.x+4) --left edge of the ball past the right edge of paddle and (BALL.x+BALL_SIZE > pad.x) -- right edge of the ball past the left edge of paddle and (BALL.y < pad.y+PADDLE_HEIGHT) -- top edge of the ball past the bottom edge of paddle and (BALL.y+BALL_SIZE > pad.y) then -- bottom edge of the ball past the top edge of paddle return true -- ball will bounce off the other way end -- (Check function aren't allow in logic function) return false end --ball collision with paddles function pad_hit (pad) BALL.dx = 0 - BALL.dx if pad.is_moving then BALL.dy = clamp(BALL.dy + (pad.last_move * 0.5),-2, 2) end sfx(1) if Game_speed < 4 then Game_speed = Game_speed + 0.2 end end function clamp(val, min_val, max_val) local lower = math.min(val, max_val) return math.max(lower, min_val) end function print_center(txt, y_pos, scale, x_offset) -- x_offset in lua by default is nil -- Make scale optional if scale == nil then scale = 1 end -- Make x_offset optional if x_offset == nil then x_offset = 0 end local length = print(txt,0,-200, 12,true, scale) print(txt,121-(length/2)+x_offset,y_pos, 12,true, scale) end