Archived

This topic is now archived and is closed to further replies.

MadButch

Could someone review my HaCKeR source?

Recommended Posts

I just upped the source code for HaCKeR (multiplayer) to my site. The game is finished, and I wonder if some of the experts on here would like to check out my source code. It's a MS Visual C++ project with all source included. Homepage: http://www.GamePlayHeaven.com Direct Links: HaCKeR (9 Mb) HaCKeR Source (445 K) Any comments are welcome! [edited by - madbutch on April 24, 2002 3:43:32 AM]

Share this post


Link to post
Share on other sites
I haven't looked all the source yet, but there are something like 113 .h and .cpp files. Isn't that a bit much for a Tetris clone?

Its going to take some time to go through.

-EDIT-Plus its missing fmod.h and HaCkeR.ico

Edited by - Big B on June 13, 2001 4:24:24 PM

Share this post


Link to post
Share on other sites
I added those files to the zip...

Because of the object oriented approach there are indeed many files.

For example, each image file (23 bitmaps) has it''s own controller class... that alone are 46 files

And of course it can be done in far less files, but my goal was to write a 2D game engine running hacker. So everything has been written in a well layed out object oriented way.

If it''s to much work, then just take a quick look at the layout... and check out the game. Any comments are welcome... and the ones you just made are valid to... how much files are to many? I don''t know.. I would love to hear some comments on it.
Is OO wanted in games development?

btw. If you want to run the game, you''ll need to download the game itself to... you need the graphics packs included therein...

This is not just a Tetris clone to me.
It''s my life dream taking form... developing games!

Share this post


Link to post
Share on other sites
Yea 113 is way too much. I haven''t downloaded the soruce, but clearly there is somehting you are doing wrong.

My tetris game (see GDShowcase - BlockCraZe) has about 14 files, and 5000 lines of code, give or take a few thousand. It''s a VB one, but in C++ there would have been roughly the same amount of files with my design.

Resist Windows XP''s Invasive Production Activation Technology!

Share this post


Link to post
Share on other sites
For example, there probably should be only one image controller class for all the images - and one instance of that that class for each image loaded.

Magmai Kai Holmlor
- The disgruntled & disillusioned

Share this post


Link to post
Share on other sites
Where would you then store all the bitmap specifics.

I have a DDrawLayer class which is exactly that.. my Direct Draw Layer. It creates the primary and back surface and does the flipping.

I have a DDrawImage class. This class has the direct draw surface and the load bitmap code. It also has the blit and fastblit functionality.

For background images (main background, SP background) I have 1 class. They handle the same... they just need 1 draw funtion. So an instance for each background is no problem here.

But lets take the SP game for example. It uses a SPGame bitmap, which contains all the little graphics that have to be blit over the background. Every little graphics part in this bitmap has a place on the bitmap (source rectangle) and a destination X Y coordinate (the place it has to be blit on the SPBackground).
This bitmap has it's own controller class which inherits from my DDrawImage class. It contains all the rectangles for all the graphics within the bitmap, knows all the target coordinates and has all the Draw functions to (like DrawLevelMatrix() and DrawProgressBar() etc...).

This means that in game, my SPLevel class does not know anything at all about what is where in the bitmap... it just tells the SPGame class to draw this or that.

I could take out my DDraw classes and put D3D classes in place, and my game code would not change at all! Want to switch to open GL? No problem... just replace the drawing class...


Again... this is NOT just a tetris clone... it's my first 2D game engine... and I tried to make it very flexible.

What Tetris game has smooth downwards scrolling? Single player, coop and battle mode? Multiple levels? Saving and loading games? Control redefinition?

I'm NOT trying to make my game look great here... but it would be nice if we could drop the "it's just a tetris clone"

I started games developing august last year... I've had some slow periods, but I kept going on this one... If I have to start with a Tetris clone, a Tetris clone it will be! But I will do my best to make it special in someway...
Looks like I won the biggest code for a tetris clone award hehehe

I better not make an Arkanoid clone then


Edited by - MadButch on June 14, 2001 2:21:18 AM

Share this post


Link to post
Share on other sites
ok... you got me....

I never wrote all that myself... I downloaded the Quake source and added my Tetris code to it ;(

lol...

Share this post


Link to post
Share on other sites
Hey MadButch. How long have you been programming and how old are you? Im just wondering because I am 14 and I dont really know how far I am from being able to program something like tetris.

"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.

Share this post


Link to post
Share on other sites
I'm one month away from 30....

I have done a 4 year IT study (business side, not technical). 2 of those 4 years where programming study.

I've been working as a developer now for 6 years I think... This probably explains why I use so many classes

But I only started C++ and games development last august. I first read the book from Ander Lamoth? (called "Tips and tricks of the windows game programming gurus"). This book gave me all the insight I needed to get started...

My 2D engine (and HaCKeR) have been in development ever since... so it took me 11 months, but with very slow ones in there, and mostly after work hours.

The only tip I can give you, is read that book and learn C++... if you got the touch, it really isn't that hard...
I used to be wondering "How does it work" and "how did they do that"... after reading that book I no longer do!

And the very best tip I can give you is this one:
You have to do it all by yourself... no one is going to teach you!

I've spend to long waiting for someone to learn me how to build games... When in the end it only took me less then a month to get going! The startup is rough... and you'll be extremely happy when you finally get anything on screen, but after that it goes super fast!

Building tetris is step 1 btw... do a search on the articles here, there is a "how to get started" which explains it nicely.

Edited by - MadButch on June 16, 2001 6:14:52 AM

Share this post


Link to post
Share on other sites
I've been thinking about Magmai's comment, about only using 1 image controller, and let all images be an instance of that class.

This would be possible if the image controller had a way to store information about what's in the image (ImageComponents).
So you would need another class (or structure) ImageComponent, which then contained a Label and the top, left, bottom and right values.

For each Image you have, you would then fill the Components array with the components in the image. This would require defines (the Labels should be defines).
Currently all image coordinates are stored in defines to, this would be the nicest way to keep it.
But where do you define those defines? Each Image class should then probably get it's own Defines file.

I'm not sure which approach would be better.
This approach would have 50% less files (only .h (defines) files for images, no .cpp files), but the initialisation would be a huge piece of code in the graphics controller.

My current approach has a very clear layout. Because all the initialisations are done in the specific image controller class itself.

Btw. All CImg* files are in a seperate folder in my workspace. So you don't see them unless you open that folder!


Let's see some other opinions on the subject...


Edited by - MadButch on June 26, 2001 5:45:00 AM

Share this post


Link to post
Share on other sites
The amount of source files it is doesn''t really change the game. If it helps out in organization (for him, not us), then let it be! My current tile-based game has several hundred files. I haven''t looked at the source for the game yet, I''ll go download it now.

Share this post


Link to post
Share on other sites
quote:
Original post by Midnight Coder
The amount of source files it is doesn''t really change the game. If it helps out in organization (for him, not us), then let it be! My current tile-based game has several hundred files. I haven''t looked at the source for the game yet, I''ll go download it now.


No, how the source code looks doesn''t change the game at all. And from the screenshots it does look like a great game.
However, hard coding everything into seperate files can be a nightmare. It takes longer to code, tons longer to compile, makes it much tougher to change things dynamically, creates a larger executables, etc, etc.

Remember, he asked us what we thought of the code, and this jumped out at most people, which is why it was mentioned. As for the rest of the code, I took a cursory glance and it looked very readable. Although he probably does comment a little more than needed (At one point in the code he commented a "var ++;" with "// increment counter").


- Houdini

Share this post


Link to post
Share on other sites
One thing I don''t like about my own code is that there is no clear function description. I only use one comment line to describe the purpose of the function.

I would like a function description that explained the parameters and return values and all that to...

I''m currently reading the "Game Architecture and Design" book, which mentions addind documentation files for each class. So you would have a .cpp a .h and a .doc file (or .txt).

This documentation then should contain all the info about the class and also about all the funtions and what they''re supposed to do. It can also contain the history of the changes in that class..

I like the idea... but it would be a pain to maintain...
still... I like the idea

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
madbutch, i like your enthusiam man.

take the criticism you''ve asked for and
learn from it....but you can still design the
way you want.
if your game runs and is stable...then you''ve done
your job because you obviously understand how you''ve done things.

bruce lee said it best: absorb what is useful and
discard the rest.


keep developing....

Share this post


Link to post
Share on other sites
133 files? YOWZA!

Shouldn''t a Tetris game be around 100-200 lines? (Not counting the DX stuff of course)

-M

Share this post


Link to post
Share on other sites
While working on Bombahman I decided to take indeed a good look at all the graphics classes. I''m now using a much easier way to do it

So I went back to HaCKeR and implemented it there to (I''m a freak It''s much nicer now...

Still much files.. but that''s because off all the DPlay Packets... They have a queue per packet type, I''m already doing that better in Bombahman.. but I''ve not yet found time to adjust it in HaCKeR (don''t wanna kill the now working code).

I''ve also created a sub-project. Instead of opting for a standard reply to all people missing DirectX (and not paying attention I made a new GameName.EXE which only checks the version of DirectX, it starts an IExplorer at the MS DirectX download site if not found! It also checks for some other required files, and then runs the Game.EXE.

No more emails about missing DInput8.dll

Ah well.. just thought I''de let you know

Check my games out at:
http://www.MadButch.com

Share this post


Link to post
Share on other sites
At this point I don''t think it would make sense to make wholesale changes. I do think it is worthwhile to find a better way for future projects. I didn''t look at the code, but from the posts here it sounds like you should have had one image class. There are many alternatives.

Most closely linked to what you did would be to put all the initialization code into an array or arrays of structures. You then spin through those arrays at startup to initialize the classes. As an example you might have an array indexing all of your images. You might use a define there just to tag the images so you are not dealing with entry 62 in the array. Since you most likely don''t use every image in the same way you have other arrays that initialize classes that have an attribute of image. Within that class that attribute is a pointer to the instance of the image class for the particular image. Within the array it is just the define for its key.

As an example say you have a set of images that are used for the static part of your game screen, i.e. the overlay. To keep the example simple your master list of images just has an id and file name. You then have an image list class that takes that array as an arguement to its constructor. The container class in turn passes one entry of the array to the constuctor for the image class. The image class in turn stores id as well as the other required stuff such as loading the image. The container allows you to search on the id and get a handle (address) back. All of this is regardless of the usage made of the image.

Now for the images making the overlay you build a seperate array. As a simple example the only additional attribute is where it goes on the screen. So you have an array with an image id and a region. You have another container class that is the overlay. When you need to draw the overlay you just call its paint function. It contains a list of regions and the regions point to the image that goes in that region. You pass the array of regions and ids into the constructor for the overlay class. For each of those entries it calls the image list, gets the handle of the image and passes that into the constructor for the region. When the overlay paints itself it just calls each region and tells it to paint itself which inturn calls the image and tells it where to paint.

That gives the basic flavor of how you handle it. The arrays serve the purpose of the defines. The only defines you need is for the id of the image. That is just so that when you are coding you can link the arrays together. Once up and running you are actually using pointers. The id should have nothing to do with the position in the array so that it is easy to maintain. There is some overhead from the lookup, but no one is going to care if you save a 1/1000th of a second when loading a level so why give yourself headaches for no reason. You don''t use defines for the other attributes just as top, left, width and height in the regions. You can format your array so that it lines up in a nice little column with one entry per line. Defines just makes it harder to read and maintain since you can just edit the list but instead have to jump all over the source for the finding the right define and changing it. Once initialized you use the attribute name. There are certainly going to be places where defines or enums are needed, but the arrays pretty well take the place of defines done just to give a central location to edit values such as file names.

As said above I wouldn''t do all this on a program that is basically finished. There are also many ways to do the same thing. You could use ini files/registry hives, resources, some type of text file or a binary file. This does provide a baby step in that direction. Within this type of game using a source for the information that is not compiled into your program may have little advantage. As things get more complex, such as Quake, external editors become pretty essential since you need help with visualization and a gui has advantages over text files when there are a large number of attributes. This approach basically lets you use the compiler as a file parser and loader.

Share this post


Link to post
Share on other sites
Thanks for posting that ellaborate story! It was a good read and great info.

I''m kinda doing something like you said now.. but indeed a litle different.

My graphics class now has an array of Images. The header contains an enum with all the image IDs. I use an enum because it''s very easy to maintain.. like this:

enum ImageIDs
{ IMG_UNDEFINED = 0, // Initial image id
IMG_BACKGROUND,
IMG_BLOCK,

MAX_IMAGES // Nr of Images to load
}

The MAX_IMAGES is used to determine the length of the image array. IMG_UNDEFINED is the initial value for all images.

the image array is an object array.. like this:
CDDrawImage m_theDDrawImage[MAX_IMAGES];

To use IMG_BACKGROUND and IMG_BLOCK, I only have to initialize the DDrawImage in the array. Like this:
m_theDDrawImage[IMG_UNDEFINED].SetProperties("UNDEFINED.BMP", false, 0 );
m_theDDrawImage[IMG_BACKGROUND].SetProperties("BACKGROUND.BMP", false, 0 );
m_theDDrawImage[IMG_BLOCK].SetProperties("BLOCK.BMP", false, 0 );


The difference between your and my version is that yours handles memory better. Because all my image classes are always in memory. Which is ok for small games, but it will have to change for bigger projects. It would then indeed become a pointer array instead of an object array.

and it was indeed a huge pile of work to change my old code into this new format.. but I still think it was worth it

Share this post


Link to post
Share on other sites
Hugo here, from UniteK Michael,
just to tell ya Congrats for the finished engine and game.
You''re a game coder now.
Good luck on all you''re future projects, see u out there...

Hugo Ferreira
UniteK Future
"Concentrate, and you can see it. If you see it, then it is possible. If it is possible, you can Achieve it."

Share this post


Link to post
Share on other sites
I havent looked at the code (bit busy wrestling with my own code), but lurve the game, kicks ass. Just thought I should let the peeps know it is indeed a bit more than the standard first-attempt-at-programming-tetris-clone.

Share this post


Link to post
Share on other sites