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 / Small issue with collision detection

Author
Message
Renegade Andy
19
Years of Service
User Offline
Joined: 16th Oct 2004
Location: Scotland
Posted: 19th Oct 2004 03:29
Ok guys- sorry for posting a new topic the last one wasnt supposed to be sent! Yeah so this time, i have resized a playing board of my pong game - and altered my two paddles and their movement limits appropriatly leaving just the balls collision detection to be sorted - i have given this a bash but simply havent found out how to do it. Im sure it has to do with the

"rem the balls bouncing movement if it hits the paddles
if ballx#>4 and ballx#<4.5 and ABS(player1pos#-ballz#)<1.5 then balla#=360-balla#
if ballx#<-4 and ballx#>-4.5 and ABS(player2pos#-ballz#)<1.5 then balla#=360-balla#
if ballz#>4 or ballz#<-4 then balla#=180-balla#"

Bit but i simply cannot no matter what i change thoose numbers to work out, how to stop the ball at the new paddles locations, the ball just kiks about in the middle of the field where the old paddle locations were. If some pro would help me out i would be very very appreciative and explain what i am doing wrong so i learn and thus are able to not only program better but also teach others.

Many thanks in advance, Andy

NO KEYBOARD DETECED - PRESS F11 TO CONTINUE - FOOKED BIOS
Renegade Andy
19
Years of Service
User Offline
Joined: 16th Oct 2004
Location: Scotland
Posted: 19th Oct 2004 04:08
Ok guys- sorry for posting a new topic the last one wasnt supposed to be sent! Yeah so this time, i have resized a playing board of my pong game - and altered my two paddles and their movement limits appropriatly leaving just the balls collision detection to be sorted - i have given this a bash but simply havent found out how to do it. Im sure it has to do with the

\"rem the balls bouncing movement if it hits the paddles
if ballx#>4 and ballx#<4.5 and ABS(player1pos#-ballz#)<1.5 then balla#=360-balla#
if ballx#<-4 and ballx#>-4.5 and ABS(player2pos#-ballz#)<1.5 then balla#=360-balla#
if ballz#>4 or ballz#<-4 then balla#=180-balla#\"

Bit but i simply cannot no matter what i change thoose numbers to work out, how to stop the ball at the new paddles locations, the ball just kiks about in the middle of the field where the old paddle locations were. If some pro would help me out i would be very very appreciative a nd explain what i am doing wrong so i learn and thus are able to not only program better but also teach others.

This is the whole code :




set display mode 1024,768,32

rem hides the mouse
hide mouse

rem makes the refresh rate 40
sync rate 40

rem makes both the paddles - the ball and the table
make object box 1,1,2,3:color object 1,rgb(255,0,0)
make object box 2,1,2,3:color object 2,rgb(0,255,0)
make object sphere 3,1:color object 3,rgb(0,0,50)
make object box 4,60,0.1,35:position object 4,0,-0.55,0
rem makes the starting angle of the ball at 70 degrees
balla#=70

rem starts the main loop and insures vsync is on
sync on:do

rem the scoring code if the ball is past the bat then its +1 to the score and the creation of the scoreboard
if ballx#>29 then player2score#=player2score#+1:ballx#=0:ballz#=0:balla#=270
if ballx#<-29 then player1score#=player1score#+1:ballx#=0:ballz#=0:balla#=90
set cursor 300,50:print player2score#
set cursor 320,50:print \"-\"
set cursor 340,50:print player1score#

rem making the ball move forwards all the time at the angle is travelling at
ballx#=newxvalue(ballx#,balla#,0.3):ballz#=newzvalue(ballz#,balla#,0.3)

rem paddle 1 movement - up and down keys - whilst limiting its area of movement
IF upkey()=1 and player1pos#<15.9 then player1pos#=player1pos# +0.5
IF downkey()=1 and player1pos#>-15.9 then player1pos#=player1pos# -0.5
if upkey()=1 and ballx#>4 and ballx#<4.5 then balla#=balla#+8
if downkey()=1 and ballx#>4 and ballx#<4.5 then balla#=balla#-8


rem paddle 2 movement - up and down keys - whilst limiting its area of movement
IF keystate(17)=1 and player2pos#<15.9 then player2pos#=player2pos#+0.5
IF keystate(31)=1 and player2pos#>-15.9 then player2pos#=player2pos#-0.5
if keystate(17)=1 and ballx#<-4 and ballx#>-4.5 then balla#=balla#+8
if keystate(31)=1 and ballx#<-4 and ballx#>-4.5 then balla#=balla#-8


rem the balls bouncing movement if it hits the paddles
if ballx#>4 and ballx#<4.5 and ABS(player1pos#-ballz#)<1.5 then balla#=360-balla#
if ballx#<-4 and ballx#>-4.5 and ABS(player2pos#-ballz#)<1.5 then balla#=360-balla#
if ballz#>4 or ballz#<-4 then balla#=180-balla#

rem verification that the angle of the ball is between 0 and 360 or problems arise
balla#=wrapvalue(balla#)

rem the positioning of all the objects - player 1 paddle, player 2 paddle, the ball, and finally the camera
position object 1,29,0,player1pos#:position object 2,-29,0,player2pos#
position object 3,ballx#,0,ballz#:yrotate object 3,balla#
position camera 0,50,-10:point camera 0,0,0

rem verification that vsync is still running and the code for the end of a loop
sync:loop

Many thanks in advance, Andy

NO KEYBOARD DETECED - PRESS F11 TO CONTINUE - FOOKED BIOS
Osiris
20
Years of Service
User Offline
Joined: 6th Aug 2004
Location: Robbinsdale, MN
Posted: 19th Oct 2004 06:54
next time could you use the code button (helps save space on the page )

anyone can be a hero, but a soldier can be a hero five minuets longer....
Renegade Andy
19
Years of Service
User Offline
Joined: 16th Oct 2004
Location: Scotland
Posted: 19th Oct 2004 07:03
hey - yea i did but i think the site was having some technical difficulty as it wasnt working sorry! Anyway , any thoughts?

NO KEYBOARD DETECED - PRESS F11 TO CONTINUE - FOOKED BIOS
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 19th Oct 2004 14:32 Edited at: 19th Oct 2004 14:34
Just go back and put a
Quote: "[ c o d e ]"
before your code and a
Quote: "[ / c o d e ]"
after your code with no spaces of course. As far as the code. All hard coded numbers will have to be refigured for the new size. I would probably just re-write the whole thing using object positions instead of numbers. Like -4 will now be closer to -30 as the field is larger.
[edit]
also this part :ballx#=0:ballz#=0 in the scoring routine will put the ball in the center of the board everytime it hits the outer walls instead of just turning around.

Renegade Andy
19
Years of Service
User Offline
Joined: 16th Oct 2004
Location: Scotland
Posted: 19th Oct 2004 22:13
thanks but please can you help me farher but giving me the changes and then explaining those? That is what im really looking for - thanks for the superb start!

NO KEYBOARD DETECED - PRESS F11 TO CONTINUE - FOOKED BIOS
Renegade Andy
19
Years of Service
User Offline
Joined: 16th Oct 2004
Location: Scotland
Posted: 20th Oct 2004 23:49
Hello! Guys is there ANY1 out there who can help me :S

NO KEYBOARD DETECED - PRESS F11 TO CONTINUE - FOOKED BIOS

Login to post a reply

Server time is: 2024-09-23 03:20:17
Your offset time is: 2024-09-23 03:20:17