I cant find why after 4 sometimes more bounces collision stops working for pads. Can someone help?
Randomize timer()
Type ObjectData
x as double float
y as double float
xspeed as double float
yspeed as double float
lives as integer
trigger as integer
endtype
Global player as objectData
global Ai as objectdata
global ball as ObjectData
ball.x = 320
ball.y = 240
ball.xspeed = 10
ball.yspeed = 0 `rnd(1)+1
player.x = 590
player.y = 240
AI.x = 50
AI.y = 240
player.lives = 3
AI.lives = 3
AI.trigger = 200
temp as integer
temp = 1
Sync on
sync rate 60
Backdrop on
color backdrop rgb(0,196,0)
Path$ = get dir$()
`load sound "pong.wav",1
`load sound "bounce.wav",2
`load sound "win1.wav",3
`load sound "buzzer.wav",4
`load music "vamps_-_Borderline_(Fantastic_Vamps_8-Bit_Mix).mp3",5
`loop music 5
`set music volume 5,50
do
Draw_screen()
draw_pad(player.x, player.y)
draw_pad(ai.x, ai.y)
screentext()
center text 320, 240, "Press Spacebar to play"
if spacekey()=1 then exit
sync
loop
do
Draw_screen()
AI()
player_control()
draw_pad(player.x, player.y)
draw_pad(ai.x, ai.y)
ball()
screentext()
sync
loop
function draw_screen()
`top line
line 10, 9, 630, 9
line 10, 10, 630, 10
line 10, 11, 630, 11
`botom line
line 10, 469, 630, 469
line 10, 470, 630, 470
line 10, 471, 630, 472
`middle line
line 319, 10, 319, 470
line 320, 10, 320, 470
line 321, 10, 321, 470
`middle circle
circle 320, 240, 39
circle 320, 240, 40
circle 320, 240, 41
endfunction
function draw_pad(x, y)
box x-5, y-40, x+5, y+40
endfunction
function player_control()
if upkey()= 1 then dec player.y, 8
if downkey() = 1 then inc player.y, 8
if player.y > 430 then player.y = 430
if player.y < 50 then player.y = 50
endfunction
function ball()
`update ball position
inc ball.x, ball.xspeed
inc ball.y, ball.yspeed
`boundary
if ball.x < 15
dec AI.lives
center text 320, 240, "Press Any Key to continue"
wait key
reset()
endif
if ball.x > 620
dec player.lives
center text 320, 240, "Press Any Key to continue"
wait key
reset()
endif
if ball.y < 15
ball.yspeed = abs(ball.yspeed)
play sound 2
endif
if ball.y > 465
ball.yspeed = ball.yspeed * (-1)
play sound 2
endif
`Ai player pad colision
if ball.x =< (AI.x + 5) and ball.x >= (AI.x -5) and ball.xspeed =< 0
if ball.y =< (AI.y + 40) and ball.y >= (AI.y - 40)
ball.xspeed = abs(ball.xspeed) + 0.5
`play sound 1
AI.trigger = 0
endif
endif
`Player pad colision
if ball.x >= (player.x - 5) and ball.x =< (player.x + 5) and ball.xspeed >= 0
if ball.y =< (player.y + 40) and ball.y >= (player.y - 40)
ball.xspeed = ball.xspeed * (-1) - 0.5
`play sound 1
AI.trigger = 250 + rnd (250)
if downkey() = 1 then ball.yspeed = ball.yspeed + 0.5
if upkey() = 1 then ball.yspeed = ball.yspeed - 0.5
endif
endif
`draw ball
circle ball.x, ball.y, 5
circle ball.x, ball.y, 4
circle ball.x, ball.y, 3
circle ball.x, ball.y, 2
circle ball.x, ball.y, 1
endfunction
function reset()
tikrinti as integer
if player.lives < 0
center text 320, 240, "Computer wins !!!, Press Any Key to try again"
`stop music 5
`play sound 4
tikrinti = 1
player.lives = 3
ai.lives = 3
sync
wait key
endif
if ai.lives < 0
center text 320, 240, "You win!!!, Press Any Key to play again"
tikrinti = 1
`stop music 5
`play sound 3
ai.lives = 3
player.lives = 3
sync
wait key
endif
ball.x = 320
ball.y = 240
temp = rnd(1)
select temp
case 0
ball.xspeed = 6
endcase
case 1
ball.xspeed = -6
endcase
endselect
temp = rnd(1)
select temp
case 0
ball.yspeed = rnd(1)+1
endcase
case 1
temp2 = ball.yspeed = rnd(1)+1
ball.yspeed = temp2 - (temp2 * 2)
endcase
endselect
if tikrinti = 1
` loop music 5
tikrinti = 0
endif
ball.yspeed = rnd(1)+1
player.x = 590
player.y = 240
AI.x = 50
AI.y = 240
AI.trigger = 350
endfunction
function screentext()
text 10, 10, "AI lives: " + str$(AI.lives)
text 510, 10, "Player lives: "+ str$(player.lives)
text 10, 20, "Ball xspeed = "+str$(ball.xspeed)
text 10, 30, "Ball yspeed = "+str$(ball.yspeed)
text 10, 40, "Ball x = "+str$(ball.x)
text 10, 50, "Ball y = "+str$(ball.y)
text 10, 60, "Player x = "+str$(player.x)
text 10, 70, "Player y = "+str$(player.y)
endfunction
function AI()
if ball.x < AI.trigger
if AI.y > ball.y
temp = AI.y - ball.y
if temp > 8
dec ai.y,8
else
dec AI.y,temp
endif
endif
if AI.y < ball.y
temp = abs(AI.y - ball.y)
if temp > 8
inc ai.y,8
else
inc ai.y, temp
endif
endif
if AI.y > 430 then AI.y = 430
if AI.y < 50 then AI.y = 50
endif
endfunction