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 / ball movement in pong?

Author
Message
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 31st Mar 2005 01:00 Edited at: 31st Mar 2005 01:01
Need help here, I know there is a lot of posts here in the forum about this problem but i don´t understand the answers can someone help me with this and explain as good as possible (some text behind every line would be the best ) I attached the game becuse i have some own models in the game. But here is also the code so far.


You never fail, only make mistakes.

Attachments

Login to view attachments
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 31st Mar 2005 01:39
Is there no one that can help me? I really need the help to continue this game

You never fail, only make mistakes.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 31st Mar 2005 02:06
You need to ask more specific questions. There are plenty of tutorials around, but you can always ask specific questions here, once you've tried to work it out yourself.

Oh, and waiting more than 40 minutes is a good idea . This is a Forum, not a chat room.

BatVink
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 31st Mar 2005 02:26 Edited at: 31st Mar 2005 02:29
hehe....ok my question is then how do i make the ball to move around between the walls and how do i make the paddles take it? Becuse i am a really n00b i can´t do the ballmovement by myself at all, i really need help (but please make comments so i learn something about it

You never fail, only make mistakes.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 2nd Apr 2005 01:25
its ok man, i see the problem...im working on a decent commented code fix now.
BadMonkey91
20
Years of Service
User Offline
Joined: 13th Jan 2004
Location:
Posted: 2nd Apr 2005 01:59


-uncompleted

Badmonkey91@hotmail.com
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 2nd Apr 2005 09:37 Edited at: 2nd Apr 2005 11:02
Strange...im having some code problems at the mo...i think its related to the new patch...im stumped currently, but ill work on it tommorow ... im too tired now.
Sorry man

<Edit> had some icecream to wake me up... made this, turns out there was a bug in the latest update...so thats been found now, hope you can grasp the code, its not brilliantly commented, im still pretty tired.
If you need more commenting or improvments just post or email me (or both !)
Hope it helps
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 2nd Apr 2005 20:20 Edited at: 2nd Apr 2005 20:25
Ok for the first thing tnx a lot Baggers you´re the best, this helped me a lot, tnx for taking time to help me. The things i dont understand is this code below
I have bolded the 4 things i dont understand


` ok so if the ball hits the wall then we want it to bounce off...which mean reversing the y speed
if bally#>24 then ballspeed#(2)=(ballspeed#(2)*-1) : bally#=24 : ` here we check if its at the top wall and if it is reverse..
` the speed and also put the ball at position 21...now we have to set up the same kind of thing for the bottom wall.
if bally#<-24 then ballspeed#(2)=(ballspeed#(2)*-1) : bally#=-24: ` and that is the y boucing handled

You never fail, only make mistakes.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 3rd Apr 2005 00:38
Ok these are nice and simple questions so here you go.
"*-1" Ok this bit is to reverse the speed of the ball. We know that 0 is no speed...and 0.2 was your starting y speed and it was traveling up.
So we have to change it from 0.2 to -0.2 so that it travels the same speed down...also this will give you an oportunity to add some more challenge to the game, try setting all the *-1's in the game to *-1.1...did you see the difference?....the ball will gradualy increase speed each time it hits a paddal or wall.

ok so the other question now
"bally#=24" This is more of a safety feature, we know that the ball is further up than 24 and so we reversed the speed, but if the ball was still a little over 24 the next loop it would reverse speed again and the ball would be stuck ...to see the effect try setting 'bally#=24' to 'bally#=25'...youll get the idea.
By setting it to 'bally#=24' we protect ourselves from this kind of bug.

Hope it helps man !
As always if you have any more questions im an email away !
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 3rd Apr 2005 19:51
tnx bagger you really explain in a good way so i understand, even with my bad english tnx man

You never fail, only make mistakes.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 3rd Apr 2005 20:12
Wow, I didnt know it wasnt your first language!...well done, any no problem!
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 3rd Apr 2005 22:15
hehe i am from sweden, and my english sucks, think thats why i am so bad at learning dbp becuse programming have some to do with english to the commands and so on, but i have learned a greath deal now with your help

tnx baggers

You never fail, only make mistakes.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 3rd Apr 2005 22:38 Edited at: 3rd Apr 2005 22:40
Your code



Quote: "
if ballx#>34
player1score#=player1score#+1
endif
"

Ok so this is the bit from the main loop to see if the ball is has gone past one of the players.
The problem is that you are checking ballx# for the balls position.
The reason that this does not work is that ballx# is a local variable , so it cannot be read except in the function it was made.
The solution to this is that we replace...
Quote: "
if ballx#>34
player1score#=player1score#+1
endif
"

..with...
Quote: "
if Object position x(3)>34
player1score#=player1score#+1
endif
"


That should fix the problem, you will have to move the ball back to the starting line though, youll see why when you run the modified code !

Now i assumed that you know about local and global variable in this answer, however if you dont just ask again and ill explain them.

Hope this helps !
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 3rd Apr 2005 22:56
ok tnx baggers this really is good explaination, ever thought about making some tutorials? the ones that i have found is so bad commented that it is hard to understand them. But guess you aint have so much time, becuse i have seen your project with jazzrabbit and it is really good.

But tnx again this really helps me.

You never fail, only make mistakes.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 3rd Apr 2005 23:05
Thanks man, any time.
Ive thought about writing tutorials, but im a bit impatient and so i dont get them finsished, i prefer things like this which i can tackle one problem at a time... Hope to see your game in the WIP soon !
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 4th Apr 2005 02:51
Ok baggers it didnt work that way either, any other idea?



You never fail, only make mistakes.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 4th Apr 2005 03:57
Line 39, replace what youve
p1score#=0
with
Global p1score#=0
This will set the variable to be global so it can be effected inside other functions.
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 4th Apr 2005 04:37
ok tnx now it works i see now why yau said it hade to go back into the start again to hehe tnx m8 for the help

You never fail, only make mistakes.
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 5th Apr 2005 04:09 Edited at: 5th Apr 2005 05:50
ok bagger, it seems like I never get my code right, or maby i think wrong when i code.

Ok here is the problem i speeded up the ball and made the ball start over when someone got goal/or when the game starts, but the ball really did go to fast when it started over so my idea was that the ball should go slower until someone hit it first time then it go fast again until someone got an new goal

here is the variabels i used


If you look for them in the code below you see how my idéa was thought to behave



You never fail, only make mistakes.
Johnny Bolt
19
Years of Service
User Offline
Joined: 30th Dec 2004
Location: South Jersey
Posted: 5th Apr 2005 14:44 Edited at: 5th Apr 2005 15:01
Not to Shabby Slooper. Nice Models. Never tried to model in CAD yet. Gonna have to try.

For your speed problem. What you could do is first create a variable to hold the multiplier speed value (speed#). This will allow you to change this through out the program with 1 command. You could then use the variable ballspeed# as the variable that chages after the ball hits the paddles so many times.

You would then need to keep track of how many times the ball hits the paddles either each one or a combination of both (that code goes into where you check to see if the ball hits the paddle to reverse it). You then use this to change the speed# variable to speed up the ball. Just remember when you start the ball off or when someone misses the ball to reset speed# back to the starting speed. It would look something like this:

ballspeed# = 0.4 ` your starting speed
if paddlehit# =>10 and paddlehit# =<30 then speed# = 1.2 `ballspeed# would = 0.4 * 1.2 = 0.48
if paddlehit# =>31 and paddlehit# =<50 then speed# = 1.3 `ballspeed# would = 0.48 * 1.3 = 0.62
if paddlehit# =>51 then speed# = 1.4 `ballspeed# would = 0.62 * 1.4 = 0.87
ballspeed# = ballspeed# * speed#

this should speed the ball up over time incressing the multiplier each time the ball hits the paddles until it reaches it max multiplier.

This might be over simplfied but you get the basic idea. Give it a try and see if that will work for you.

The only true failure is not to try at all...
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 5th Apr 2005 20:26
Ahhh someones steeling my job !
Ah its ok, i just writing to say ill be away till saturday as im hiking . So i wont be able to help for a few days.
Sorry !
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 5th Apr 2005 23:22 Edited at: 5th Apr 2005 23:24
ok bagger have a nice vacation (or how it is spelled) then tell me when you are back

You never fail, only make mistakes.
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 5th Apr 2005 23:24
hmm ok, don´t think this was the thing i meant, the thing is that i want it to start at speed 0.2 (firstball=1) when its a new ball or when the game just have started, and when one of the paddles hit the ball for the first time the ball speed goes up to 0.4 (firstball=0) any soloution for this? If you check for all the



in the code below, you will probably know better how i want it to be.



You never fail, only make mistakes.
Vixen
19
Years of Service
User Offline
Joined: 6th Apr 2005
Location: Netherlands
Posted: 6th Apr 2005 18:46
I've also got a question about ball movement.

How do you stop the ball from going back and forth in a straight line all the time so that it's not bouncing sides anymore?
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 9th Apr 2005 02:17 Edited at: 9th Apr 2005 02:19
Hey Vixen, not ment to me rude, but please if you aint got same question make your own topic with your own question,

ok baggers please help me with my question when you are back from vacation

You never fail, only make mistakes.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 12th Apr 2005 05:23
Ok try this code, i havnt commented it yet. Your scoring method was perfect and the idea of storing when the ball first hit a player was very good. What i did was that when the ball is not hit and leaves the screen, afte adding the score i stored the speed it was doing in ballspeed#(3)&(4), then i set the ballspeeds back to 0.2...

Ok so now the game continues, and when the ball hits the paddel it checks to see if firstball#=1..if i does then it sets the ball speeds to the stored values!
Viola, i think thats what you were after...as always any problems just ask ! ive got this post on mailback so as soon as you post here ill be emailed from now on.

Hope it helps !

Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 12th Apr 2005 06:26
Hehe well baggers it was both good and bad, the good thing is that it allways starts at speed 0.2 , the bad thing is that it seems like the ball goes faster every time it hits the player, the function i want is that

every time the firstball#=1 it always has the speed 0.2
every time the firstball#=0 it always has the speed 0.4

i post the new code i use here to, becuse i have changed a few other things in game and just dont want to change those things again



You never fail, only make mistakes.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 12th Apr 2005 07:12 Edited at: 12th Apr 2005 07:22
Oh i see, i thought thats what you wanted, never mind, ill fix that now !

<EDIT>
Made it do what'i do babe !

The changes i made where at lines
43: global firstball#=1.0

149&161: if firstball#=1
ballspeed#(1)=0.4
ballspeed#(2)=0.4
firstball#=0
endif

174&182: ballspeed#(1)=0.2
ballspeed#(2)=0.2

I feel kinda bad for not putting decent descriptions with these but i assume your gettin better at understanding the code now !


ok heres the code
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 12th Apr 2005 23:17
do not fel bad for that, okay it would be more nice with some descriptions, but you have already helped me a lot with my project so, the only thing you have to feel i happines for helping me so much that you have done so far, tnx again for your help baggers

You never fail, only make mistakes.

Login to post a reply

Server time is: 2024-09-23 17:19:11
Your offset time is: 2024-09-23 17:19:11