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 / Need help with my Pong game!

Author
Message
Eisan
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location:
Posted: 20th Sep 2010 02:52
Hello again.

Currently I am working on a Pong game and have run into a snag with the load menu. I am trying to get it so when you click the \"START GAME\" sprite you will start the game. However, when I use the while/endwhile command, the game crashes.

Here is my code


The code still needs a lot of work, so any input is invaluable, especially since its my first program

~Eisan
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 21st Sep 2010 03:06 Edited at: 21st Sep 2010 03:08
I would suggest you add
to your global variables. Then code your main loop like this:


You are only using sprites, so you don't need the BACKDROP, so put
right after you set the display mode. Notice that I added a CLS in the main loop because of this.

I would also suggest replacing your load_menu() function with this code:


I noticed that you need to put in where if the ball gets past a player, that the score is added and the game restarted.

Hope this helps.

LB

Computers do exactly what you tell them.........don't you hate that sometimes?
Eisan
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location:
Posted: 21st Sep 2010 07:49
Thanks for the reply!! The change to the code worked perfectly. With the use of GameOver it just stops the game completely. Instead I would like it to reroute the game back to the start menu.

Here is my code now. I separated the code into different files so it would be easier to Add different game modes such as Player vs. AI and menu options



Currently the code somewhat works. The start menu loads fine but the issue occurs when I click the Highscores button (which is currently a placeholder). The paddles and the ball both load, but the game freezes stays there (I assume this is due to a lack of the sync command somewhere in the code, as you can tell by my random implementation of sync in every function).

Currently the code doesn't support the START GAME button since i have not added the file yet to support it.

Also, on the issue of the ball not disappearing after it hits a side is something I have been trying to work on, but with no success. I know it will be accomplished by something like

but I am stumped to what I need to do after that.


Sorry for the messy code, I wasn't able to edit it so it makes a bit more sense for people since I need to sleep.

Any suggestions/help is once again greatly appreciated

~Eisan
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 21st Sep 2010 17:10 Edited at: 21st Sep 2010 18:30
The SYNCs should not normally be located at the end of the subroutines like that. They are necessary for a main menu in order to display the info, but for your main loop itself, only sync when you have completed all drawing (i.e. at/near the end of your main game loop).

You don't need floats to count the scores. You could easily put this in an array.

Also, I would set the mode of play (either AI or versus) and use the same game loop instead of a separate one.

I am working on editing the code to help you. I hope to post back when I am done.

EDIT: Here is the revised code:


Computers do exactly what you tell them.........don't you hate that sometimes?
Eisan
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location:
Posted: 22nd Sep 2010 05:59
Wow, thanks a million. This will help a ton

Here's my work for tonight. I still can't seem to get the game to re-loop back to the start menu after the game is over. I tried changing various methods ( I can't remember what I did, since that was a couple hours ago ).
I was able to get the startscreen to reload after the game ended by using the SAVE IMAGE command, but I do not know how to reload sprites after they have been deleted.

I also added a very simple AI, nothing special, that needs a lot of work and added some random ball speeds so the game isn't as predictable all the time.

Thanks for the help again, it has helped me a lot

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 22nd Sep 2010 17:47
You're welcome. Glad to help.

I updated the AI a little bit and the ball Y movement is based upon the direction of the paddle when hit. I also changed the way you were moving the ball. I have left the music and sound stuff remmed out because I keep having to REM it out every time I work on it.

There is a problem in that the ball can go further down the screen than what the paddles can. I left that for you



Computers do exactly what you tell them.........don't you hate that sometimes?
Eisan
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location:
Posted: 23rd Sep 2010 05:58
Once again many thanks =)

Wasn't really able to get much work done on the code tonight.. Mainly just looked over what you changed to make sure I understood it and how you got to it

I like the way you have the ball currently moving, but the ball moves horizontally if one of the paddles isn't moving, and it got stuck that way a couple of times.

I was thinking about something like this (doesn't work of course lol), but honestly, I have no idea how P0Ymove and P1Ymove completely work.



There are also some other things I am confused about what you mean about


What does the rnd(100) > 50 have to do with anything? Especially since movey was originally defined at rnd(2)??

Forgot to mention this is my last post. What is the point of having
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 23rd Sep 2010 15:46 Edited at: 24th Sep 2010 02:18
Quote: "but honestly, I have no idea how P0Ymove and P1Ymove completely work."

The value of the Y position of each of the players is stored. The players are then allowed to move. The resulting Y position after the players have moved is checked versus the old position. If it is less than the old position, then the player has moved upward, if it is more, than the player has moved downward. This value is used to determine the Y direction of the ball.

If you don't want the ball to go straight across the screen, you can replace the Collision() function with this:


Also there are two places where movey is defined - prior to the main game loop and at the Restart() function. Change this line to:


This will ensure that the ball does not move straight across the screen initially.

Quote: "What does the rnd(100) > 50 have to do with anything? Especially since movey was originally defined at rnd(2)??"


Using this code, there is a 50 / 50 chance that the ball will move up or down. The computer randomly picks it. So, we randomly are picking the speed and the direction of the ball.

Quote: "Forgot to mention this is my last post. What is the point of having

backdrop off : randomize timer()"


The backdrop is used primarily for games that display 3D objects. This game uses sprites and 2D images. Consequently, you don't need the backdrop, so it is turned off.

DBP needs a way to generate random numbers, so that your game isn't the same every time. It does this by 'seeding' a random number generator with a number. This 'seed' number is random in itself, as the internal clock of the computer is always counting at 1000 milliseconds per second ever since it was turned on. The internal clock number is obtained by using the TIMER() command. Whatever that number happens to be when the randomize timer() code is executed is the number that is used. Many games will use timer() based movement to make for smoother gameplay, but that is a another topic for another day. (There are many threads on it; if you want to know more, you can easily search the forum).

Computers do exactly what you tell them.........don't you hate that sometimes?
Eisan
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location:
Posted: 26th Sep 2010 05:26
Thanks for the explanations.

I haven't really updated much of the code other then tweaking some values here and there; however, I did update the images for the sprites and stuff so it looks more rounded off than just a black screen and a couple of white paddles lol.

Thank you so much for your help! Once I can figure out how to get all the files to compress so I don't have to include the media files with the .zip/rar I will upload it.

Until then I will probably work on a Mario-type sidescroller or maybe a simple FPS game.

Thanks again.
Maxell Will
14
Years of Service
User Offline
Joined: 28th Sep 2010
Location: United States
Posted: 29th Sep 2010 12:09
Hi.. Can i ask? What is Pong Games? i mean i kind of games is that?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 29th Sep 2010 17:46
Hi Maxwell Will,

A pong game is a simple game where you have two paddles, one on each side of the screen, and a ball that is bounced back and forth around the screen, careening off of the walls and the paddles. A pong game will usually offer the option of two humans to play or one human against an artificially intelligent computer player. The objective is to keep the ball in play. If the ball gets past a player, typically, a point is scored for their opponent. Once a certain score is reached, a player is declared the winner.

Even though it is viewed as an elementary game, it does take at least some programming skill to develop a game like this. It is a good starting place for new programmers, so they can learn to code video games.

Wiki:
http://en.wikipedia.org/wiki/Pong

I'm not really a programmer.....I only play one on TGC.
Maxell Will
14
Years of Service
User Offline
Joined: 28th Sep 2010
Location: United States
Posted: 30th Sep 2010 11:38
@LBFN

Oh! I see.. i already play that games but i don't know the name of that games.. hahaha! anyway thank you for the info now i know Pong Game.

Login to post a reply

Server time is: 2024-09-28 22:30:20
Your offset time is: 2024-09-28 22:30:20