Couldn’t find it on the FAQ, but thanks @dave1707
So this is what i did during a couple of days when I was really bored - hope you enjoy it
-- Main
supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)
function setup()
-- ADJUSTABLE PARAMETERS
local toggleBot1 = true
local toggleBot2 = false
local botOperationDelay = 60 --min 3
-- bot max speed at 3: 365
-- bot max speed at 5: 250
local botMovementMode = 1 -- 1 || 2
local initialBallSpeed = 12
local bouncesToSpeedIncrease = 5
-- END OF ADJUSTABLE PARAMETERS
doGameSetup(botOperationDelay, initialBallSpeed, bouncesToSpeedIncrease, botMovementMode, toggleBot1, toggleBot2)
end
function doGameSetup(bod, ibs, btsi, bmm, tb1, tb2)
ball = {pos=vec2(WIDTH/2, HEIGHT/2), dir=nil, s=4}
bars = {{x=0, y=HEIGHT/2}, {x=1, y=HEIGHT/2}}
bot1 = {fin = nil, delay = bod, job = false, ball = nil}
bot2 = {fin = nil, delay = bod, job = false, ball = nil}
score = {left=0, right=0}
bgc = color(31, 39, 82, 255)
noSmooth()
parameter.boolean("bot1_enabled", tb1)
parameter.boolean("bot2_enabled", tb2)
parameter.boolean("autorestart", false)
parameter.integer("sysMultiply", 1, 20, 1)
parameter.watch("ballSpeed")
maxBounces = btsi
initBallSpeed = ibs
ballSize = 20
barLength = 200
borderWidth = 15
botMode = bmm
touches = {}
bounces = 0
gameState = 0
ballSpeed = ibs
end
function touched(touch)
if touch.state == ENDED then
touches[touch.id] = nil
started = false
else
touches[touch.id] = touch
end
end
function draw()
handleTouches()
drawField()
drawScore()
drawBall()
for i = 1, sysMultiply do
for i = 1, ballSpeed do
if gameState == 1 then
updateBall()
end
end
if gameState == 1 then
updateGame()
end
if bot1_enabled then bot(1) end
if bot2_enabled then bot(2) end
end
for i,b in pairs(bars) do drawBar(b) end
end
function bot(n)
-- simple bot code
--bars[n].y = ball.pos.y + math.random((-barLength/2.1)*100, (barLength/2.1)*100)/100
-- hardcore bot code
if (n == 1) and not (bot1.ball == nil) then
local b = bot1.ball
--local rand = vec2(0, math.random((-barLength/2.3)*100, (barLength/2.3)*100)/100)
local randRange = barLength/1.1
local rand = vec2(0, math.random()*randRange-randRange/2)
local fin = simulation(b.pos, b.dir) + rand
bot1.job = true
bot1.fin = fin
bot1.speed = (bot1.fin.y-bars[1].y)/bot1.delay
bot1.ball = nil
elseif (n == 2) and not (bot2.ball == nil) then
local b = bot2.ball
--local rand = vec2(0, math.random((-barLength/2.3)*100, (barLength/2.3)*100)/100)
local randRange = barLength/1.1
local rand = vec2(0, math.random()*randRange-randRange/2)
local fin = simulation(b.pos, b.dir) + rand
bot2.job = true
bot2.fin = fin
bot2.speed = (bot2.fin.y-bars[2].y)/bot2.delay
bot2.ball = nil
end
if (bot1.job == true) and (n == 1) then
if botMode == 1 then
bars[1].y = bars[1].y + bot1.speed
elseif botMode == 2 then
bars[1].y = bars[1].y + (bot1.fin.y - bars[1].y)/(bot1.delay/2.2)
end
if math.floor(bot1.fin.y*10) == math.floor(bars[1].y*10) then
bars[1].y = bot1.fin.y
bot1.job = false
--print("bot1 job done")
end
end
if (bot2.job == true) and (n == 2) then
if botMode == 1 then
bars[2].y = bars[2].y + bot2.speed
elseif botMode == 2 then
bars[2].y = bars[2].y + (bot2.fin.y - bars[2].y)/(bot1.delay/2.2)
end
if math.floor(bot2.fin.y*10) == math.floor(bars[2].y*10) then
bars[2].y = bot2.fin.y
bot2.job = false
--print("bot2 job done")
end
end
end
function simulation(startPos, direction)
local pos = startPos
local dir = direction
local targetReached = false
while not targetReached do
pos = pos + dir:normalize()
if pos.y > HEIGHT-borderWidth-ballSize/2 then
dir = vec2(dir.x, -dir.y)
pos.y = HEIGHT-borderWidth-ballSize/2
elseif pos.y < borderWidth+ballSize/2 then
dir = vec2(dir.x, -dir.y)
pos.y = borderWidth+ballSize/2
end
if pos.x > WIDTH-borderWidth-ballSize/2 then
-- rechts
targetReached = true
elseif pos.x < borderWidth+ballSize/2 then
-- links
targetReached = true
end
end
return pos
end
function updateGame()
if bounces >= maxBounces then
bounces = 0
ballSpeed = ballSpeed + 1
end
end
function handleTouches()
local x = 0
local y = 0
for k,touch in pairs(touches) do
x = touch.x
y = touch.y
for i,b in pairs(bars) do
if x < WIDTH/2 then
if b.x == 0 then
b.y = y
end
elseif x > WIDTH/2 then
if b.x == 1 then
b.y = y
end
end
end
end
if gameState == 0 then
local bpos = ball.pos
local dist = bpos:dist(vec2(x, y))
if (dist < ballSize*3) or autorestart then
gameState = 1
local buffer = math.random(1, 2)
local yDir = math.random()*12-6
if buffer == 1 then
ball.dir = vec2(-3, yDir)
bot1.ball = ball
elseif buffer == 2 then
ball.dir = vec2(3, yDir)
bot2.ball = ball
end
end
end
end
function updateBall()
local pos = ball.pos
local dir = ball.dir
pos = pos + dir:normalize()
local x = pos.x
local y = pos.y
local passToBot1 = false
local passToBot2 = false
-- oben + unten
if y > HEIGHT-borderWidth-ballSize/2 then
dir = vec2(dir.x, -dir.y)
pos.y = HEIGHT-borderWidth-ballSize/2
elseif y < borderWidth+ballSize/2 then
dir = vec2(dir.x, -dir.y)
pos.y = borderWidth+ballSize/2
end
if x > WIDTH-borderWidth-ballSize/2 then
-- rechts
local barY = bars[2].y
local ballY = ball.pos.y
if math.abs(barY-ballY) < barLength/2 then
dir = vec2(-dir.x, (ballY-barY)/20)
pos.x = WIDTH-borderWidth-ballSize/2
if bot1_enabled then
passToBot1 = true
end
else
scorePoint(2)
pos = vec2(WIDTH/2, HEIGHT/2)
end
bounces = bounces + 1
elseif x < borderWidth+ballSize/2 then
-- links
local barY = bars[1].y
local ballY = ball.pos.y
if math.abs(barY-ballY) < barLength/2 then
dir = vec2(-dir.x, (ballY-barY)/20)
pos.x = borderWidth+ballSize/2
if bot2_enabled then
passToBot2 = true
end
else
scorePoint(1)
pos = vec2(WIDTH/2, HEIGHT/2)
end
bounces = bounces + 1
end
ball.pos = pos
ball.dir = dir
if passToBot1 then
bot1.ball = ball
end
if passToBot2 then
bot2.ball = ball
end
end
function drawField()
background(bgc)
pushMatrix()
pushStyle()
rectMode(CENTER)
stroke(255, 255, 255, 255)
strokeWidth(borderWidth)
lineCapMode(SQUARE)
fill(bgc)
translate(WIDTH/2, HEIGHT/2)
rect(0, 0, WIDTH+300, HEIGHT)
stroke(255, 255, 255, 106)
line(0, -HEIGHT/2, 0, HEIGHT/2)
popMatrix()
popStyle()
end
function drawBall()
pushMatrix()
pushStyle()
local x = ball.pos.x
local y = ball.pos.y
rectMode(CENTER)
fill(255, 255, 255, 255)
rect(x, y, ballSize, ballSize)
popMatrix()
popStyle()
end
function drawBar(bar)
pushMatrix()
pushStyle()
local h = barLength
local w = borderWidth
local x = bar.x*(WIDTH-w)+w/2
local y = bar.y
rectMode(CENTER)
fill(255, 255, 255, 255)
rect(x, y, w, h)
popMatrix()
popStyle()
end
function scorePoint(side)
if side == 1 then
--print("point for right")
score.right = score.right + 1
elseif side == 2 then
--print("point for left")
score.left = score.left + 1
end
gameState = 0
ballSpeed = initBallSpeed
end
function drawScore()
local size = 50
local str = score.left.." "..score.right
pushMatrix()
pushStyle()
fill(255, 255, 255, 255)
fontSize(size)
font("Arial-BoldMT")
textMode(CENTER)
text(str, WIDTH/2, HEIGHT-borderWidth-size/2)
popMatrix()
popStyle()
end
Edit: Oooooohh, THAT FAQ… I only found that on the wiki ._. Sorry again…