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.

Author
Message
Big Man
20
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 26th Aug 2005 19:07 Edited at: 26th Aug 2005 19:39
I have had Dark basic classic for about two or three years now and it suddenly occured to me that I have never tryed to program a simple pong game. So I gave it a go.
I have my court and players that one of which moves(The human players bat moves).
I am asking for two things in this thread.

1.Could anybody give me a peice of code that will make the ball bounce around the screen.

2. can anybody give me some code for the AI for the computer player.

The code I have so far is attached.(Sorry for the mess I will tidy it up later)

Thanks for any help anybody can give.

Our aim is to keep the loo's clean, your aim can help.
Osiris
20
Years of Service
User Offline
Joined: 6th Aug 2004
Location: Robbinsdale, MN
Posted: 26th Aug 2005 20:38
Hey man, I stoped using DB for like one year and forgot anything, and now that TDK's editor is out and it looks so much better than the defalt one and the other ones im gonna start to try and relearn eerything and im gonna follow this thread and try some stuff to see if I can get anything.

Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 26th Aug 2005 21:02
I would suggest you go to the newcomers corner and examine the sticky thread of pong..

Immunity and Annihalation makes Immunihalation...
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 26th Aug 2005 21:58
i dunno y ppl say do pong, i tried it and fialed on many occasions due to making things bounce, and ive had DBC for like 4 yrs now. pong is hard!!! - well to me

kR
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 26th Aug 2005 22:20
You don't have to look so far.

An example of simple ball bouncing:

Let's say the ball moves vertically (yspeed) and horizontally: (xspeed).

So the code to move your ball should be something like this:



now the bouncing:
when a ball hits the upper or bottom side of the screen, this would mean the vertical speed would be the vertical speed * -1. The same with the horizontal speed:

The code:


So far for the bouncing code. I hope I helped you continuing your pong code...

Immunity and Annihalation makes Immunihalation...
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 26th Aug 2005 22:48
Big Man,

You mean to say you can't figure this out, after three years of programming? Sorry to be critical.

If you are going for generic ball movement, it is quite simple. The x coordinate has two directions(left and right), and the y coordinate has two directions(up and down). We know that if the ball hits the right wall or the right paddle then it should shift its direction on the x coordinate to go left. It would be vice-versa when hitting the left wall and paddle. The y direction would stay the same, since they are vertical walls.

Now, when the ball hits the ceiling, the ball's y direction should shift to a now downward direction. For the floor, it would be vice-versa. When these two movements are placed together on the ball, we get a specified angled movement.

For understandability, I will use two string variables to flag the direction of the ball on both coorinates. The x coordinate is either "left" or "right", and the y coordinate is either "up" or "down". Let us start the code by giving the ball random start directions.

Example 1:


Now we should place in the main loop, the section of code that will make the ball move, given the two directions. We will use the method I spoke of above.

Example 2:


Now, for the basic collision checking system. We do not need to check for collision with the side walls, well, except to figure if that side has lost the ball to the goal. Lets check if the ball goes above the ceiling or below the floor, and if it comes within a specific deistance from the paddles. When the ball hits the ceiling or the floor, we will shift only it's y direction. When it hits the paddles, we will shift only it's x direction.

Example 3:


The paddle collision I did not code, that I will not be coding the pieces which are unecessary to, in order to show you this method. This is basicly it.


+NanoBrain+
Big Man
20
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 26th Aug 2005 22:52 Edited at: 26th Aug 2005 22:55
Thank you so much sven b!!!!
That was the biggest help I think ever quite possibly!
So if you need any help ask me and I will try and lend A hand.
Oh and nano the reason I found it quite hard is beleive it or not I have never thought about programming this sort of game before I prefer to do fps's or 3d type games.
So you could say that this was too simple for my complex brain(Ha Ha)

Our aim is to keep the loo's clean, your aim can help.
Big Man
20
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 26th Aug 2005 22:59
Oh and nanoBrain thanks for your code aswell all of this has improved my game enormously.
Thanks loads!

Our aim is to keep the loo's clean, your aim can help.
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 27th Aug 2005 11:09
Seems Sven B and I are in competition...hehe. Just kidding.


+NanoBrain+
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 28th Aug 2005 02:21
Lol you too and Sven are of the best, about equal in Programming Knowlege.
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 28th Aug 2005 10:09
Xenocythe,

We all started somewhere. What a man puts into something(might I say any topic at all), is what he will get out of it. By the way, do not forget about the many on these forums that are just as good, and better than us. I appreciate the complement, though, and am sure Sven B does also.


+NanoBrain+
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 28th Aug 2005 18:27
Ofcourse I appreciate the complements. And I can only agree with Nanobrain:

Knowledge isn't something you gain in 10 seconds. I'm sure NanoBrain and me have years of experience in programming (And we're not the only ones).

Cheers

Sven B

Immunity and Annihalation makes Immunihalation...
dab
20
Years of Service
User Offline
Joined: 22nd Sep 2004
Location: Your Temp Folder!
Posted: 31st Aug 2005 21:06
Yah, TDK is awesome too, I think we have the leaders of the forums! Obey them, listen to every word they say and think about it as if it were the survival tips for your life. The leaders of the board are:
Sven B NanoBrain, and TDK. I'm sure there are more out there but these three have helpe out soooo many that it would be hard to compete. Not that this is a competition. LOl!

------------------------
Visit my website of Games!
http://dabip.stonerocket.net
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 31st Aug 2005 21:49
And others... don't forget about others, its just that I see TDK, SvenB, and NanoBrain helping the Most.

Login to post a reply

Server time is: 2025-05-22 08:28:26
Your offset time is: 2025-05-22 08:28:26