0,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3=p_right.max_yv then p_right.yv=p_right.max_yv end else --Else stop moving p_right.yv=0 end --Same as above if btnp(4,1,1) then p_left.yv=p_left.yv-0.5 if p_left.yv<=p_left.min_yv then p_left.yv=p_left.min_yv end elseif btnp(5,1,1) then p_left.yv=p_left.yv+0.5 if p_left.yv>=p_left.max_yv then p_left.yv=p_left.max_yv end else p_left.yv=0 end p_right.y=p_right.y+p_right.yv p_left.y=p_left.y+p_left.yv wall_player_collision() end function move_ball() local collision=player_ball_collision() --If p_left hit if collision==1 then --Ball y velocity gains part of the --players y velocity ball.yv=ball.yv+p_left.yv*0.2 --If max speed cap it if ball.xv>=ball.max_xv then ball.xv=-ball.max_xv else --Else ad 20% to speed ball.xv=ball.xv*-1.2 end --Same as above elseif collision==2 then ball.yv=ball.yv+p_right.yv*0.2 if ball.xv>=ball.max_xv then ball.xv=-ball.max_xv else ball.xv=ball.xv*-1.2 end end --Check wall collision wall_ball_collision() ball.x=ball.x+ball.xv ball.y=ball.y+ball.yv end function move() move_p() move_ball() end function update() --Clear the screen cls() --Load the map map() --Draw the ball spr(ball.sprite,ball.x,ball.y,0) --Draw left player spr(p_left.sprite,p_left.x,p_left.y,0,3) --Draw right player spr(p_right.sprite,p_right.x,p_right.y,0,3,1) --Draw left player points print(game.l_points,100,20,13) --Draw right player points print(game.r_points,126,20,13) end function colide(a,b) --Check collision local ax=a.x local ay=a.y local aw=a.w local ah=a.h local bx=b.x local by=b.y local bw=b.w local bh=b.h if axbx and ayby then --Play a sound effect when they collide sfx(0) --they've colided return true end --no collision return false end function player_ball_collision() --Returns witch player hit the ball if colide(p_left,ball) then return 1 elseif colide(p_right,ball) then return 2 end return 0 end function wall_ball_collision() --Check if it hits the edges --of the screen if ball.y>=128 then ball.yv=-ball.yv sfx(0) elseif ball.y<=3 then ball.yv=-ball.yv sfx(0) end end function wall_player_collision() --If player will go out of bounds --Don't let them move if p_left.y<=2 then p_left.y=2 elseif p_left.y>=110 then p_left.y=110 end if p_right.y<=2 then p_right.y=2 elseif p_right.y>=110 then p_right.y=110 end end function new_round() --If ball hits wall behind --Right player if ball.x>=230 then --Add points to left player game.l_points=game.l_points+1 --Center ball position ball.x=116 ball.y=60 --Reset ball velocity ball.xv=1 ball.yv=0 --Same for left player elseif ball.x<=0 then game.r_points=game.r_points+1 ball.x=116 ball.y=60 ball.xv=-1 ball.yv=0 end end function did_win() --When left player wins run this if game.l_points==game.max_points or game.r_points==game.max_points then state="game over" end end --Sets the needed variables to start --a clean match function restart() p_right.x=229 p_right.y=54 p_left.x=8 p_left.y=54 game.r_points=0 game.l_points=0 ball.xv=1 end init() function TIC() state_manager() end