Yet Another First Game

Started by
10 comments, last by Majikkan 18 years, 10 months ago
For my first game (and my first program with more than, say, 2k of source code) I had to be different, so I did a heavily unpolished asteroids clone in DirectDraw. :) The only DD feature I'm really using is page flipping. Otherwise, everything is on manual. I'm using a doubly linked list to track polygons, and the entire project took about two weeks. It's running in 1024x768x32 now. My desktop is 1280x1024x32, so I had the game running in that so I could avoid the screen changing modes every time I wanted to test it. Since not everyone can run in that mode, I simply dropped the res down to 1024x768 rather than muck about with 16 bit color modes or a palette. Arrow keys fly the ship and the space bar fires. The polygons are crude, but everything SEEMS to work. As I said, it's heavily unpolished, but I learned a ton. What confuses me is locking a framerate. I made an attempt on line 192 of asteroids.cpp, but there didn't seem to be anything I could set the number to that didn't result in horrible framerates. Even if I set it to update the game every 1/1000 of a second, the result became a choppy mess. Taking it out completely resulted in a very smooth game. It makes no sense to me. Hit me with comments. I'm mostly curious if this runs. :) http://prime.gushi.org/~phydeaux/asteroids.zip
Advertisement
Runs fine here, but it is taking up 50% of my CPU according to the Task Manager. That's probably because you're not delaying between re-drawing the frames, but you did mention having problems with this. Also, things move very slowly on screen.

Also, when I Ctrl-Alt-Del out to the Task Manager, and then clicked the Taskbar icon to get back into the game, the window reopened as normal but nothing was there. Don't get too hung up on this, there's code available to prevent this from happening.

Please don't take this the wrong way or get disheartened - you've got as far as getting something working, which is a good thing indeed.
Way way way too fast! [smile]
Quote:Original post by ukdeveloper

Also, when I Ctrl-Alt-Del out to the Task Manager, and then clicked the Taskbar icon to get back into the game, the window reopened as normal but nothing was there. Don't get too hung up on this, there's code available to prevent this from happening.



I heard something about in DirectX you have to get back the surfaces when they go out, or something like that. Same way with input devices, they get lost when you alt-tab or anything like that. For input, you have to reaquire the device, but for surfaces, I don't know. Also, I think that for some reason, you have to rebuild/reclaim textures too.



Works like a charm, cool down!
Insufficent Information: we need more infromationhttp://staff.samods.org/aiursrage2k/
I won't say it was exaclty fun to play, but nice work nontheless. It is always impressive to see a beginner complete something more complicated than "Hello world!" [smile]

Quote:Original post by Majikkan
What confuses me is locking a framerate. I made an attempt on line 192 of asteroids.cpp, but there didn't seem to be anything I could set the number to that didn't result in horrible framerates. Even if I set it to update the game every 1/1000 of a second, the result became a choppy mess. Taking it out completely resulted in a very smooth game. It makes no sense to me.

I believe that
while(start_time - GetTickCount() < 1000/FRAMERATE) Sleep(0);
should be
while(GetTickCount() - start_time < 1000/FRAMERATE) Sleep(0);
as GetTickCount() should return a number larger than it did when you initialized start_time, meaning that you will get a negative value if you subtract GetTickCount() from start_time. Flip them and it might start working.

Some simple suggestions to polish your game a bit:
- Make the ship a different color from the asteroids and from the bullets (maybe the ship green, the asteroids kind of a bright/light brown, and then keep the bullets red?).
- Add an engine firing effect. One simple way to do this that looks cool is to place a triangle coming off the back of the ship which is drawn only when the engine is being used. You can make it "glow" by sliding the color back and forth (using simple linear interpolation) between two shades of blue or orange or whatever.

Some more complicated improvements you could make:
- Add a score counter. Simple enough by itself, but you will need to add a text renderer of some sort to make this work.
- Add some sort of explosion and/or "You died!" message when you die; I thought the game had glitched when my ship simply disappeared.
- Fix the issue with minimizing the game. The people on the DirectX forums should be able to help you with this one. (I know how to do it in D3D, but I don't use DD otherwise I would tell you myself.) This one would probably take work because fixing this problem in a program not desgined to deal with it from the start generally requires reworking its organization a bit, but it is something you should really learn to deal with, so you might as well start with this program.

Keep up the good work.
Pretty advanced for a first game. I like it. It got pretty crowded with the asteroids so I died pretty quick.
I couldn't make this, not even next year! Well maybe close. I could probably viewing your source, start seeing how to make my Pacman guy go up and down. Would I need to do physics for him too? I need to study on the physics stuff summor. And do I need to know alot about physics to do stuff like this?
My friend wants to learn to program in C++. If he forgets BASIC right away, well, I am worried.
Quote:Original post by fuchu
I couldn't make this, not even next year! Well maybe close. I could probably viewing your source, start seeing how to make my Pacman guy go up and down. Would I need to do physics for him too? I need to study on the physics stuff summor. And do I need to know alot about physics to do stuff like this?

I can't tell if you are being sarcastic or not, but...

The physics in this game is quite basic (though well done); it is pretty much just basic vector math plus some simple collision detection. Learn about vectors (not the C++ data structure; that is different) some time because they will help you understand how to make reasonably realistic physics without too much trouble, but don't worry about it for Pacman.
Fantastic: truly a starting point to be proud of! My eyes were assaulted at first by the green tone of the game, but as my irrational hatred of greenliness faded, I began to shoot down asteroids with unheard of vigor. And it was good.

As I said, you've managed something that's quite impressive for your first game. The physics are faithful to its ancestor's, and the collisions appear to be flawless. I'd love to see some asteroid->asteroid collisions in a future version, to spicen things up a bit; much to the poor pilot's dismay.

My only additional suggestion would be a slightly bigger playing area. It can get very claustrophobic in space!
---Curses, malidictions and lacerations! There goes my brand new pair of sneakers -- again!

This topic is closed to new replies.

Advertisement