Hi, everyone
I've programmed C++ for a couple years now, so I'm not brand new to programming, but I'm having a little trouble adapting to DBPRO.
I don't know if i'm being really dumb or just can't seem to find the right snippet out there.
All I'm trying to do for my first trial game is to put a paddle on the bottom of the screen. Use SPACEBAR to launch the ball and after the ball is launched it will bounces around on the screen edges, and when it comes back down, and doesn't hit the paddles on bottom it will fall off the bottom of the screen. If it hits, it will bounces back up.
I've gotton the paddle to properly work, and some basic collision, but I really think there has got to be a better and more ethical way to doing it and also with the ball.
here is the code that I have so far. Fell free to make any changes and if you already know how I could accomplish this, It would be great as I could really use some coding for this type of game for study as I know that this is a basic style and can be applied to a lot of different games out there
sync on
sync rate 0
hide mouse
rem DATA VARIABLES ///////////////////////////
ballx# = 0
bally# = -178
ballz# = 20
paddlex# = 0
paddley# = -200
paddlez# = 20
rem //////////////////////////////////////////
rem MAIN BALL
make object sphere 1,30:position object 1,ballx#,bally#,ballz#
rem MAIN PADDLE
make object box 2,100,10,2:position object 2,paddlex#,paddley#,paddlez#
position camera 0,0,-400
point camera 0,0,0
do
rem MOVEMENT CONTROLS
if leftkey() = 1 and paddlex# > -200 and set_flag = 0 then dec paddlex#
dec ballx#:position object 2, paddlex#, paddley#, paddlez#
position object 1,ballx#,bally#,ballz#
if rightkey()= 1 and paddlex# < 200 and set_flag = 0 then inc paddlex#
inc ballx#:position object 2, paddlex#, paddley#, paddlez#
position object 1,ballx#,bally#,ballz#
if spacekey() = 1 then set_flag = 1
if set_flag = 1 and leftkey() = 1 and paddlex# > -200 then dec paddlex#:position object 2, paddlex#,paddley#,paddlez#
if set_flag = 1 and rightkey() = 1 and paddlex# < 200 then inc paddlex#:position object 2, paddlex#,paddley#,paddlez#
if set_flag = 1 then gosub move_ball
sync
loop
move_ball:
while bally# <= 200
inc bally#:position object 1, ballx#,bally#,ballz#
return
sync
endwhile
while bally# > paddley#+ 23
dec bally#:position object 1,ballx#,bally#,ballz#
if leftkey() = 1 then dec paddlex#:position object 2,paddlex#,paddley#,paddlez#
if rightkey() = 1 then inc paddlex#:position object 2,paddlex#,paddley#,paddlez#
rem MAKE BALL BOUNCE OFF OF THE PADDLE
if bally# = paddley# + 23 and ballx# <= paddlex#+50 and ballx# >= paddlex#-50 and ballx# > 199 then color object 1,rgb(0,255,0): gosub bounce_ball_left
if bally# = paddley# + 23 and ballx# <= paddlex#+50 and ballx# >= paddlex#-50 then color object 1,rgb(0,255,0):gosub bounce_ball
sync
endwhile
while ballx# > paddlex#+50 and ballx# + 23 > paddley#
dec bally#:position object 1, ballx#,bally#,ballz#
sync
endwhile
while ballx# < paddlex#-50 and ballx# + 23 > paddley#
dec bally#:position object 1, ballx#,bally#,ballz#
sync
endwhile
sync
set_flag = 0
return
bounce_ball:
while bally# <= 200 and ballx# <= 200
inc bally#:inc ballx#: position object 1, ballx#,bally#,ballz#
sync
if leftkey() = 1 then dec paddlex#:position object 2,paddlex#,paddley#,paddlez#
if rightkey() = 1 then inc paddlex#:position object 2,paddlex#,paddley#,paddlez#
sync
endwhile
return
bounce_ball_left:
rem TO TEST IF A HIT...COLOR OBJECT RED
color object 1,rgb(255,0,0)
while bally# <=200
inc ballx#:inc bally#: position object 1, ballx#,bally#,ballz#
sync
if leftkey() = 1 then dec paddlex#:position object 2,paddlex#,paddley#,paddlez#
if rightkey() = 1 then inc paddlex#:position object 2,paddlex#,paddley#,paddlez#
sync
return
endwhile
chris