Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Collision not working????

Author
Message
Xatinei
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location:
Posted: 28th Feb 2003 19:14
Why isn't my ball bouncing off the walls? I would be very grateful for any help.

`set display and sync rate
set display mode 800,600,32
sync on
sync rate 40
hide mouse

start:
`define variables
ballx#=400 : ballxvel#=-5 : bally#=500 : ballyvel#=-6
batx#=mousex() : batxvel#=mousemovex()
wallx#=20 : wallx2#=780 : wally#=20 : wally2#=580
lives=4
time#=90
loser=0
winner=0
a1=timer()

`main loop
do
gosub move
gosub collision
gosub draw
loop
`************************************************************
collision:
`check for ball coliding with walls
if ballx#=wallx2# then ballxvel#=0-ballxvel#
if bally#=wally2# then ballyvel#=0-ballyvel#

`check for bat hitting ball
if bally#550 and ballx#=batx#
`reverse the x velocity
ballxvel#=0-ballxvel#
endif
`make sure bat stays on screen
if batx#wallx2#-5
batx#=wallx2#-65 : batxvel#=0
endif
return
`**************************************************************
draw:
line wallx#,wally#,wallx#,wally2#
line wallx#,wally#,wallx2#,wally#
line wallx2#,wally#,wallx2#,wally2#
line wallx#,wally2#,wallx2#,wally2#
line batx#,550,batx#+60,550
circle ballx#,bally#,10
sync
return
`**************************************************************
move:
cls
`get the x velocity of the bat and limit it to 50
batxvel#=mousemovex()
if batxvel#>50 then batxvel#=50
if batxvel#
Xatinei
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location:
Posted: 28th Feb 2003 19:20
Why isn't my ball bouncing off the walls?
Please, I would be grateful for any help I recieve.
Xatinei
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location:
Posted: 28th Feb 2003 21:08
Sorry about the first post. The code is not complete. My browser messed up when I was typing it.

Xatinei
ToXic
22
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Australia
Posted: 28th Feb 2003 22:53
Had a quick look over your code and made a few changes,Hope this answers your post.




ToXic.
Xatinei
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location:
Posted: 28th Feb 2003 23:03
Thanx loads ToXic.
Really apreciate it!

Login to post a reply

Server time is: 2024-09-19 22:43:40
Your offset time is: 2024-09-19 22:43:40