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 / Apologies its pong again

Author
Message
Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 7th May 2008 15:53
Right after reading the helpful tutorials by TDK which i would suggest everyone does read before trying anything in DBPro if you new to coding like i was, I've done a couple of text games just simple guess the number and a lil text adventure with about 4 rooms. Now i decided to go ahead with a 2D Pong game, easy enough but i just cannot figure out how to bounce the ball i've spent days searching the codebase and forums and everyone is either using simple 2D like line and box etc or they are using 3D objects so it got a little confusing. Anyways i cannot get this ball to move i found TDKs pong tutorial and i can get the Position of the balls x and y but i do not understand how to get the balls direction in x and y and i've tried a lot of things =D

Please somebody explain how i would do this. Many thanks to any who answer! (Code Below)



"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 7th May 2008 17:42
You please think about this.
You may have already learned it at school.
Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 7th May 2008 18:02 Edited at: 7th May 2008 18:03
Erm..... I will admit im not a how do you say... enlighted pupil from my education i ditched out and went to work so could you break it down coz that doesnt make sense to me sorry! I dont understand why draw a circle when theres a sprite in the code for it and how does it make it move and rebound in that code?

Thanks
Zen

"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock
Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 7th May 2008 19:14
Ok after much confusion and grabbing a piece of graph paper If x and y are increasing it is going to the bottom right of the screen, if both decrease to top left if x increase and y decrease then its going to the top right and if x decrease and y increase then its going to the bottom left. But how would i put this into DBPro as an interger variable? Because beyond figuring that out im stumped.

Thanks
Zen

"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock
procyon
16
Years of Service
User Offline
Joined: 29th Feb 2008
Location:
Posted: 7th May 2008 19:17
The following code may help you start. Sorry its not tested or finished as i don't have the time at the moment. You will need to add more code to check for bat collision and end of screen collision.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th May 2008 20:56
First, you are probably better off keeping the ball position within the ballposx# and ballposy# variables, rather than continually resetting them from the sprite position.

Next, the Ballspeedx# and Ballspeedy# can be used both to control the speed and the direction of the ball. Each loop, simply add their values to the Ballposx# and Ballposy# variables and update the sprite position from those variables. If the speed variable is negative, the ball will move up or left (depending on x or y), and if positive, will move down or right.

Assuming the paddles are left & right, when you detect collision with a paddle, simply multiply the Ballspeedx# by -1.0 - this will reverse the direction but keep the same speed. Do the same with Ballspeedy# when detecting collision with top/bottom walls.

Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 8th May 2008 04:07
Thank you so much both of you i sat and tested your code procyon it worked great but earlier 2day im on UK time so not many people here i searched in vain hope through a lot of pong threads and IanM had left a small basic example of a ball bouncing off the edge of the screen and fixed it into code take a peek below you may not recognise it without the border_width() but i needed exact coordinates



"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 8th May 2008 16:57
gosub is global.

Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 8th May 2008 20:54
Aha! So variable set at the top go sub uses them globally? that would explain why my curvevalue for paddle 2 ai is all funky, shame my paddle likes to jump out of bounds when chasing balls as well, i'll clean it up get some rudimentary ai n stuff n prob turn it into a tutorial coz there doesnt seem to be many deep 2d pong tutorials even though its many peoples first game.

"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock

Login to post a reply

Server time is: 2024-11-25 03:51:09
Your offset time is: 2024-11-25 03:51:09