Pong(after episode 6)

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Pong(after episode 6)

Post by Zedtho » February 22nd, 2017, 6:44 pm

Hi there! After episode 6, I tried making Pong. I guess it's harder than I thought it is.

Here's the github link to it: https://github.com/Zedtho/Pong

Anyways, I wanted to ask you guys what I could've done more efficiently, or what I could've done better about the structure of the program, just because I don't want to make a bigger game when I'd still make many mistakes and get lost in my code.

I also want to thank Chili for the amazing tutorials! I started last tuesday, and it's awesome! They're very helpful, I think they're better than Bjarne Stroustrup's book C++ Programming and Principles.
Simply because I can see programs in action, and people using the programming environment I'm not used to and it's a lot more entertaining.

Oh yes, I'm kind of new to this forum, so tell me if this sort of topic isn't requested or what I should do better next time.

P.S. I've tried adding a system into the program that makes it not immediately start the game, but have a title screen. But that didn't work for me, it skipped my if statements and didn't look at them.
So if you have a solution to that please tell me.

Byteraver
Posts: 60
Joined: May 19th, 2016, 6:48 am
Location: Belgium, Europe

Re: Pong(after episode 6)

Post by Byteraver » February 23rd, 2017, 8:01 pm

Hi Zedtho

Welcome to the forums. Your game is cool, is the ball supposed to keep coming from the center if you missed it? I don't really know the original pong. What I would suggest is to make a class for the player, one for the ball etc. so you can regroup values that belong to the same object (like x and y coordinates).
For the title screen you need a so-called state machine. Chili made a video tutorial about 'm. I use them in my snake game (some shameless self promotion here) for the menu. http://www.planetchili.net/forum/viewto ... 555#p20102

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: Pong(after episode 6)

Post by Zedtho » February 24th, 2017, 6:43 pm

This is the original Pong game I based my version off of: http://www.ponggame.org
In my version the ball does switch on what side it enters the game into, but the ball should respawn in the middle.

Making the program object-oriented is important too, since I noticed it lacked structure already, even though it's a small game. I'll check out your snake game immediately by the way, seems interesting!

What I am wondering though, is how people program the CPU that plays against the player in single player mode. Is it just a function that moves the paddle towards the y coordinate of the ball?
Because then it's impossible to win against the CPU, as far as I know.

I should add this shouldn't be a full-fledged game (nothing compared to your snake game), it was simply me practicing the stuff we had learnt by then.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Pong(after episode 6)

Post by albinopapa » February 24th, 2017, 7:45 pm

Limit the speed of the paddle, if the ball moves too fast or has a decent angle, the paddle won't catch up.
Make it wait 100 ms before reacting to the ball hit, give it a reaction time delay.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: Pong(after episode 6)

Post by Zedtho » February 24th, 2017, 8:21 pm

albinopapa wrote:Limit the speed of the paddle, if the ball moves too fast or has a decent angle, the paddle won't catch up.
Make it wait 100 ms before reacting to the ball hit, give it a reaction time delay.
Sadly I haven't gotten far enough in the tutorial to do things based on time. I would've changed a lot of the code if I had had access to that before.

Edit: After Chili's post I might do this, but just as a question, would this feel laggy? 100 ms isn't much for a Pong game if I think about it.
Last edited by Zedtho on February 25th, 2017, 7:38 pm, edited 1 time in total.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Pong(after episode 6)

Post by chili » February 25th, 2017, 5:08 am

Hey bro, welcome to the forums! Thanks for sharing, game looks good man. Nice job on the number display. The pong game plays well enough (collision detection works well). Do you have random speed each bounce? That's a pretty decent mechanic.

As for your title delay, what you could do is, have a variable (int) in game.h that keeps track of how many frames have passed. Increment it every frame in UpdateModel. So for the first say 120 frames, don't update the game logic, instead just display the title screen, then once 120 frames have passed, start processing game as usually. a simple if statement will suffice for this.

this will also work for what albinopapa proposed above.

Code looks clean, good start.

Have you programmed in another language before?
Chili

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: Pong(after episode 6)

Post by Zedtho » February 25th, 2017, 7:36 pm

Thanks a lot for the tips!
No, I haven't programmed in a different language before (although people have said it isn't the best language to start with), but I used to read C++ Programming and Principles. Also, yes, I do have a different speed each bounce. That isn't really what the normal game is like, but currently I lack the math to have a constant speed where only the direction changes (unless I'd program all the possible directions... oh well).

I'll add the title screen right now too!

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: Pong(after episode 6)

Post by Zedtho » March 18th, 2017, 10:08 am

Update: (2017-03-18)

Added singleplayer and a menu to select it from.

-----------------------------------------------------------

The organization in the code seems crappy though, feedback would be awesome!

Post Reply