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 / Classic Pong

Author
Message
Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 29th Jan 2011 23:37


This Was my first attempt at making pong, but with little success. I would like to know if there was a way to have the ball bounce off at a random angle (within certain perameters) to make the game more interesting. I have had several people comment upon my use of SpeedY=SpeedY*-1 but as of yet i have not found a faster way of changing the direction of the ball (without using endless 'If' statements). The second version (which i am still working on) is a lot more aesthetically pleasing however the collisions are likely to stay the same until i get help.

Any help would be greatly appreciated as this is my first attempt at completing a code.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 30th Jan 2011 01:53 Edited at: 30th Jan 2011 01:54
First off, it is blazing fast and unplayable as is on my computer. Suggest you manually use SYNC at 60.

To help speed up your game, calculate variables prior to your main loop. It takes time for the computer to calculate the screen height and width. Assign them to a variable prior to the main loop and then access the variables within the main loop.

It is recommended that you indent your code. When in an if - endif, a function, for - next loops, a do - loop, etc., indent the code inbetween. This will help with you forgetting to close out the loop and improve readability. Many that would otherwise help a newbie will be turned off if your code is not indented.

DBP allows you to grab images within the code. Why not draw the ball and paddles, grab the images and then use sprites? It would be faster and easier. If you need help with this, just post.

I revised your code a little bit. It bounces like I think you want it to. You could code a change in direction based upon the movement of the paddle before the collision with the ball took place to make it more interesting.




Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 30th Jan 2011 02:08
Thankyou for the advice LBFN. I am unsure of how to turn the ball and paddles into sprites though and would greatly appreciate advice there.

Also, if it is too quick just change the SpeedX and SpeedY variables of the ball. When i get further into the development of this i plan on incorporating a difficulty factor by changing the SpeedX and SpeedY.
Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 30th Jan 2011 02:49
Thankyou for your help. I have not used sprites before and would greatly appreciate some advice in regards to that. I will add a second improved copy in a few hours that has a score system and difficult settings aswell.
Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 30th Jan 2011 05:31
This is my completed game (with your help LBFN). Please post your scores here once you have finished.

(It does start off slow but can get a lot more complicated depending on your computer)
Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 30th Jan 2011 07:22
wow it seems i'm not the only one interested in Pong. I read back a year in the forums and discovered an almost identical post written by you, yet strangely enough i didn't actually use it to code this.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 30th Jan 2011 07:22
I have not checked out your code yet.

I did a fair amount of work to revise the code (more than I planned to ). Apparently you are on post-approval, so I waited until a MOD approved them before I posted. This code includes the use of subroutines. Please take a look and see how they are used to help structure the code. I made images for everything (even the background screen) and made the ball and paddles sprites. I hope that it will be helpful to you.



I used the same numbers for the sprites as their images, so don't get confused about that. Sprite numbers and image numbers can be the same or they can be different. I chose to make them the same, but you don't have to do it that way.

By the way, you will never beat the enemy opponent the way you have it coded. You might want to have the AI opponent move so much at a time based upon where the ball is located on the Y.

I didn't code it to where the scores are printed all the time, though that should be easy for you to put in.

Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 30th Jan 2011 08:30
What would i replace the // with?
I have once of the first DBP versions so i can run it at school and home. Most of the other scripts on here work so i am assuming there is a simple translation for my version of DBP.
Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 30th Jan 2011 08:41
Could you please explain all of this new content, i can understand it as far as getting and creating images, but what about the sprites and bitmaps?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 30th Jan 2011 15:14 Edited at: 30th Jan 2011 19:24
Quote: "I read back a year in the forums and discovered an almost identical post written by you, yet strangely enough i didn't actually use it to code this."
Yes, I have helped others with PONG issues; I didn't think to reference the past stuff.

Quote: "What would i replace the // with?"
REM or `
I have a newer version of the IDE for DBPro then you do. It accepts // as REM.

Quote: "Could you please explain all of this new content, i can understand it as far as getting and creating images, but what about the sprites and bitmaps?"

Sure, getting ready for church right now, but will re-submit a commented version to try and help you with it later today.

EDIT: here is a commented version that should explain what is happening.


Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 30th Jan 2011 22:00
I am making a game menu for this Pong but i have run into some issues. I have the basic function which puts all the words on the screen and highlights them when the mouse is over them, but i can't find a way to replace my 'goto' commands.



All of this may seem like unneccesary code, but i have added it so that i may center the text on the screen without having to just estimate the distances. For some reason it would not accept variables in place of the words so i have had to do it the hard way.

Please not this is not my full function; just the section i would be like to change.
Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 30th Jan 2011 22:01
Also with the AI, i had attempted one that only moves once the ball is towards the edge of the paddle, but thtis almost always resulted in a bad collision with the ball. Would you have any suggestions of how i could ammend this issue?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 31st Jan 2011 00:56 Edited at: 31st Jan 2011 01:04
Quote: "but i can't find a way to replace my 'goto' commands"

Losing GOTO commands is a great idea. I view using GOTOs as a bad programming practice; if you structure your code properly, they are almost never needed. That said, there are some on here that think they are okay. To each his own.

Anyway, to eliminate the need for them, you could simply use GOSUB instead and make subroutines out of New_Game, HighScores, Difficulty, etc.

Quote: "Also with the AI, i had attempted one that only moves once the ball is towards the edge of the paddle, but thtis almost always resulted in a bad collision with the ball. Would you have any suggestions of how i could ammend this issue?"


I made a few quick changes to the code to give you an AI that is at least beatable. Check it out:



Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 31st Jan 2011 03:34
Quote: "All of this may seem like unneccesary code, but i have added it so that i may center the text on the screen without having to just estimate the distances. For some reason it would not accept variables in place of the words so i have had to do it the hard way."


You're using the TEXT command for the menu? There are cooler methods that'll look better for your game. You can use images instead or even sprites with a small sprite at the mouse coordinates to check for sprite collision with each menu item.

Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 31st Jan 2011 06:45
Thanyou for your ideas Grueslayer and LBFN

I understand the value of sprites and images, however i prefer text with boxes surrounding it. I have made a code similar to the HALO 2 or 3 system, where they have partially transparent boxes that enlargen as you get nearer to them with the cursor.

Perhaps when i learn some more sprite and image commands, i can venture into that aspect of gaming but for now i am content with simple text effects, however i would be more than happy to impliment some interesting text effects if anyone has created them.

I have been looking into the aspects of gosub, however i have also been told it is as bad as goto. One thing i have done in practice is to replace the goto with a variable, however that makes my main loop allot slower because it has to check all the 'If' commands

[/code]
then Goto New_Game


to


then New_Game=1
[code]

i understand that goto makes the code hard to follow, however does it actually affect the performance of the program?
Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 31st Jan 2011 06:53
Is there any other way to exit this loop without the use of GOTO? or would i have to use a repeat_until loop?
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 31st Jan 2011 07:38 Edited at: 31st Jan 2011 07:39
Yes, you can use EXIT to leave any loop (DO/LOOP, REPEAT/UNTIL, WHILE/ENDWHILE, and FOR/NEXT). It'll continue from the line under the end of the loop.

What LBFN told you is 100% right. If you have to GOTO then change it to a GOSUB instead so that you may use RETURN to go back to the command after the original GOSUB. Or use functions instead (the only method I use now).



Skulduggery
14
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 31st Jan 2011 07:45
WOW, this shows i still have allot to learn!
Thankyou for your advice and i hope to be finishing my menu soon!

Login to post a reply

Server time is: 2024-11-24 07:54:50
Your offset time is: 2024-11-24 07:54:50