# Rate my first game anyone (DX8 Pong)?

This topic is 4555 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey everyone, I finally finished my first game of pong using C++ and DirectX 8.0. Took me about a month of solid work , but I struggled through it and triumphed with this simple pong game. I welcome all constructive criticism. BTW, this is my first game ever. I have zipped the source and the exe in this zip. I know there are a few problems with the angle of reflection based on angle of impact on the paddle and if anyone can point it out that'd be awesome. I guess my next project will be the vertical style pong with the blocks you can take out, I can't seem to think of the name of that style of pong. Thanks everyone for all of your help while I struggled through some of the snaffus. I've never been a member of a more helpful and positive forum. Anyways, let me know what you guys think! Here's the zip file: http://www.p0wn3d.net/DXP.zip Sorry guys, forgot to say, the controls are W and S for the left paddle and Up and Down for the right paddle.

##### Share on other sites
Hey,

Are you using any timing to control the speed of the ball? When I tried it, the ball was to the other side in the blink of an eye.

If you don't know what I mean, different computers have different speeds. The game may run at a certain speed on your computer, but on someone's with a different speed, the ball will go much faster. By using a timer, you can control the update speed and the speed of the ball on any computer. (If you already knew this or are using a timer, sorry. I don't have time to look into your source code).

Slaru

##### Share on other sites
No, I havent used any timers at all. The ball seems to flow normally on my computer. I'm going to try it on my other computer and see how it runs. Anyone else experiencing this?

##### Share on other sites
Since you aren't using timers (I just looked at your source...), others will undoubtedly encounter this.

Here's an article on using a timer to control game rate. Article

##### Share on other sites
Alright, after reading that article I'm trying to implement a timer for the code really quick. I have a question though, which clock are you guys using to control the timer? I've noticed that the timeGetTime function is readily available and returns the time in milliseconds, is that a valid function to use?

##### Share on other sites
Yes, timeGetTime() will be just fine.

But, there are more accurate timers such as RDTSC and QueryPerformanceCounter(). For your purposes though, timeGetTime should be just fine. There seems to be a debate as to whether the supposedly more accurate timers I mentioned above are actually worth it.

For now, use timeGetTime(). When you finish your current project, you can look into creating timer classes. Do some research on RDTSC and QueryPerformanceCounter() then.

If you need some more explaining on how to use the timing to control game rate, just ask.

Slaru

##### Share on other sites
Ok awesome, I added a timer but it made the game pretty slow, so I made a few changes to the code to speed it up. Hope I did it correctly. I reuploaded the source and exe to the same link above. Hope it runs this time, heh. Thanks for your help on this.

http://www.p0wn3d.net/DXP.zip

##### Share on other sites
Actually, the ideal forum to post this thread is in "Your Announcements". You would obtain better replies there.

##### Share on other sites
Hey,

I see you have added the timer in there... but, sorry to say this, it does nothing. Your use of the timer does absolutely nothing to help the game rate. I don't want to put you down.

I need to get some sleep now, so I can't help you anymore. Hopefully someone else on this forum will help you. (I know many people should be able to help as this is actually a basic thing) It is getting late here, and so I wish you luck in getting the timing right. If know one picks up on the thread and helps you, PM me and a day from now I should be able to help you out.

Slaru

##### Share on other sites
I'm not sure what is wrong then. I ran the game on my machine (2.2 ghz), my gf's machine (1.4 Ghz) and my work computer (2.5 Ghz) and it worked perfect on all three. I guess I don't completely understand the concept of the timer based on that article you sent. It seemed to me that it was saying to determine the frame time and use a value derived from that to slow the movement of the objects to compensate for the speed of faster computers. If anyone has any input or a better tutorial I'd like to look into timers some more since it seems to be such an important subject.

##### Share on other sites
Can't seem to use the resolution you built it in either... any chance of a 1024x768 version? Or the option for us to control it? :P

##### Share on other sites
Oh good shot, forgot about that. I reuploaded a copy that is in 1024x768. Also, if you want to adjust the resolution, it is set in the first few lines of main.cpp. The new zip is at http://www.p0wn3d.net/DXP.zip
Thanks for pointing that out for me. My home computer has a pretty high res.

##### Share on other sites
Although I haven't downloaded the game (I am at work, heh), I'd like to follow up Slaru on the Timer discussion.

What you can do is calculate the time delta of each frame and multiply that by your movement.

Here's some psuedo code:

Update
{
timer->update();
game->update( timer->getDelta() );
game->render();
}

Game::update( float fFrameTime );
{
ball.pos.x += (xVel * fFrameTime);
ball.pos.y += (yVel * fFrameTime);
}

Hope this helps!

##### Share on other sites
Hmm, that seems to be what I'm doing in my code. Maybe it's not, here's the code from within my game loop:

f_start = ftime();do {          CGame::Render();          f_end = ftime();} while(f_end==f_start);f_time = f_end - f_start;

Here is the ftime() method:

float CGame::ftime() {   return (float) timeGetTime()/20;}

Then in my render statement I do what you said and multiply each movement by f_time. It does indeed slow down the movement of all of the objects in the game but I guess I may be doing something wrong? I implemented the code from that article above so maybe Im not understanding something. I did note that in the ftime method of the article you are supposed to divide your clock by it's rate, well I tried doing it just using the timegettime and not dividing it by anything and of course it ran too fast, so I tried dividing it by 1000 since there are 1000 ms in a second and then it was way too slow so I had to narrow it down to 20 to get a decent speed. I guess that could be the problem? Im not sure. I'm at work too, heh, we shoud be fired, lol.

##### Share on other sites
Try it like this:

f_start = ftime();CGame::Render();f_time = ftime() - f_start;float CGame::ftime() {   return (float) timeGetTime()/1000;}

This should be good enough for now. You may have to change your velocity increments to a different value to speed up/slow down things but you should leave the division by 1000 or use the macro TICKS_PER_SECOND (don't quote me on the actual name). But what you get should be consistent on all machines (or close enough anyway).

##### Share on other sites
I went ahead and tried that and it seems to make a little more sense to me now. I reuploaded the source for anyone who wants to look through it. I had to move the values up pretty high to get everything to move faster, but Im guess that should be fine as long as it's moving at a constant frame rate. Thanks for that revised code nomonkey, that helped quite a bit. Man this has gone on quite a bit, thanks for everyones help on this.

http://www.p0wn3d.net/DXP.zip

[Edited by - jrmiller84 on September 6, 2005 11:11:43 PM]

##### Share on other sites

I tested out the game and it worked great. You should look at getting a GDNet+ Subscription and putting it in the showcase. You'll get some constructive criticism on it as well as helpful ideas.

Keep up the good work.

Rate++

##### Share on other sites
Thanks! I didnt even know there was a subscription service offered here. After reading it, it sounds like a good idea. I'll def. sign up once I get some extra \$. Thanks for the review. Took me a while but I'm glad to put this one to rest and move on to the next project. I hope others find it helpful!