can some one fix this broken colision for me??

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
imDread
Prole
Posts: 6
Joined: Mon May 20, 2024 10:39 am

can some one fix this broken colision for me??

Post by imDread »

--starting
function explo(x)
if x*x <=30 then
return ((x*x)*1.1)/(x*1.01)
else
return x
end
end
--Colisions (borders)
function borderUp(y)
if y <= 10 then
return 10
else
return y
end
end

function borderDown(y)
if y >= 390 then
return 390
else
return y
end
end
--Colisions (ball colisions)
function BallColision(x, speed)
if x >= 490 or x <= 10 then
return speed*-1
else
return speed
end
end
--Love
function love.load()
_G.st = (love.math.random(15,20))/10
_G.draw = false
_G.paddle1 = {
x = 20,y=200,speed=1.5
}
_G.paddle2 = {
x = 460,y=200,speed=1.5
}
_G.ball = {
x=250,y=250,speedx=5.5,speedy=5.5,size=10
}
end

function love.update(dt)

ball.x = ball.x + ball.speedx/st
ball.y = ball.y + ball.speedy

ball.speedx = BallColision(ball.x, ball.speedx)
ball.speedy = BallColision(ball.y, ball.speedy)


if ball.x <= paddle1.x+30 and ball.y >= paddle1.y and ball.y <= paddle1.y +100 then
ball.speedx = ball.speedx * -1

end
if ball.x >= paddle2.x+10 and ball.y >= paddle2.y and ball.y <= paddle2.y +100 then
ball.speedx = ball.speedx * -1
end

if love.keyboard.isDown("up") then
paddle2.y = paddle2.y - paddle2.speed
paddle2.speed = explo(paddle2.speed)
paddle2.y = borderUp(paddle2.y)

elseif love.keyboard.isDown("down") then
paddle2.y = paddle2.y + paddle2.speed
paddle2.speed = explo(paddle2.speed)
paddle2.y = borderDown(paddle2.y)
else
paddle2.speed = 1.5
end
if love.keyboard.isDown("z") then
paddle1.y = paddle1.y - paddle1.speed
paddle1.speed = explo(paddle1.speed)
paddle1.y = borderUp(paddle1.y)
elseif love.keyboard.isDown("s") then
paddle1.y = paddle1.y + paddle1.speed
paddle1.speed = explo(paddle1.speed)
paddle1.y = borderDown(paddle1.y)
else
paddle1.speed = 1.5
end

end

function love.draw()

love.graphics.rectangle("fill",paddle1.x,paddle1.y,20,100)
love.graphics.rectangle("fill",paddle2.x,paddle2.y,20,100)
love.graphics.circle("fill",ball.x,ball.y,ball.size)
if draw then
love.graphics.setColor(1,0,0)
love.graphics.circle("fill",ball.x,ball.y,ball.size)
love.graphics.setColor(1,1,1)
end

end
guys i created this colision (for the ball and paddles) and i tried it it seems so broken pls fix :(
User avatar
togFox
Party member
Posts: 794
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: can some one fix this broken colision for me??

Post by togFox »

Double post. See other thread.
Current project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life. Simple to learn, hard to master. Learn when to advance, dodge, strike and counter. Learn how to strike without being struck.
https://discord.gg/HeHgwE5nsZ
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 7 guests