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.

DarkBASIC Discussion / Bouncing ball problem

Author
Message
Xatinei
22
Years of Service
User Offline
Joined: 26th Feb 2003
Location:
Posted: 28th Feb 2003 21:58
Err...Look at this code. I cant find any prob with the actual code but when it comes to actually running the program the ball doesn't bounce off the walls. Anyway take a look. I would really appreciate any help you guys give me.

`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#
The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 28th Feb 2003 22:30
Half the code is missing because of the > and < operators. Use code tags to post the code.

Once I was but the learner,
now, I am the Master.
Xatinei
22
Years of Service
User Offline
Joined: 26th Feb 2003
Location:
Posted: 28th Feb 2003 22:43
Not again! Sorry. Here it is.

Login to post a reply

Server time is: 2025-08-08 20:39:54
Your offset time is: 2025-08-08 20:39:54