Sign in to follow this  
whaleyboy

My first effort ...for your consideration!

Recommended Posts

I've been steadily working my way through half a ton of c++ books (and very helpful gamedev posts) and am slowly building up my programming skills so that I can create a shoot-em-up of sorts. I haven't got very far as yet, but I have a small demo I would like some of the more experienced of you to take a look at it and give me some feedback on its construction thus far. I think it would also be useful for other starting-out programmers to take a look and learn from the feedback this program gets. As it evolves I will be uploading new versions as they become available. I am currently working with Visual C++ 6 and GapiDraw graphics library (http://www.gapidraw.com/gapidraw-features.php for those interested) but even if you haven't used gapidraw the basics are still the same. Anyways, here's my source (with a compiled demo to show what it does)... http://members.gamedev.net/whaleyboy/GapiTest/source.zip Keep in mind, I am just starting out on this (long and arduous) journey, so saying "use assembly to speed things up" isn't going to help! :) At it's current state it basically creates 3 waves of alien spaceships (using an alien class) that move in 3 seperate paths (a path class that is passed to the alien class) around the screen. It also uses vectors to store the aliens and I have tried to make it as 'object oriented' as I know how. If any beginners would like to ask questions about it feel free! Teaching can often be the best way to learn...

Share this post


Link to post
Share on other sites
Oh, by the way, alot of the code in 'myapplication.cpp' is generated by gapidraw incase it looks a bit daunting! This kind of stuff for example:

//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything, and goes into a
// message-processing loop. Exit the loop by calling Shutdown().
//-----------------------------------------------------------------------------
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR pCmdLine, int nCmdShow)
{
GDAPPCONFIG config;
::ZeroMemory(&config, sizeof(GDAPPCONFIG));

config.hInstance = hInst;
config.pAppTitle = _T("Finite State Machines");
config.dwWindowIcon = IDI_APP;
config.dwDisplayMode = GDDISPMODE_NORMAL;
config.dwTargetFPS = 60;
#ifdef _DEBUG
config.dwDisplayFlags = GDDISPLAY_WINDOW;
config.dwWindowBorder = WS_DLGFRAME;
config.dwDisplayWidth = 320;
config.dwDisplayHeight = 320;
config.dwDisplayZoomWidth = 640;
config.dwDisplayZoomHeight = 640;
#else
config.dwDisplayFlags = GDDISPLAY_WINDOW;
config.dwWindowBorder = WS_DLGFRAME;
config.dwDisplayWidth = 320;
config.dwDisplayHeight = 320;
config.dwDisplayZoomWidth = 640;
config.dwDisplayZoomHeight = 640;
#endif

// Create the CGapiApplication subclass
CMyApplication* pMyApp = new CMyApplication(config);


...and so forth

Share this post


Link to post
Share on other sites
I felt compelled to shoot them [grin]. The only graphical flaw I see is in the artwork, there is a black border around the ships. This is barely noticeable, even when they overlap. Nice job

Share this post


Link to post
Share on other sites
i was bored so i had a quick glance at your code and the first thing that strikes me is this:


vector<Alien_Object> vAliens;

//... later on

for (int i=0; i<8; i++) {
pAliens = new Alien_Object(&m_alien, &myPath, i);
vAliens.push_back(*pAliens);
}

for (i=0; i<5; i++) {
pAliens = new Alien_Object(&m_alien, &myPath2, i);
vAliens.push_back(*pAliens);
}

for (i=0; i<3; i++) {
pAliens = new Alien_Object(&m_alien, &myPath3, i);
vAliens.push_back(*pAliens);
}


Your causing memory leaks there, you first allocate "Alien_Object"s on the heap then you push a copy in the vector of Alien_Objects and never release the memory back.

[Edited by - snk_kid on September 1, 2004 6:21:48 PM]

Share this post


Link to post
Share on other sites
Shooting will be added in short time hopefully (I've figured out some collision detection and player movement routines in a seperate file that I will incorporate into this project).

Yeah, I thought I might be getting some memory leaks...I'll try and fix that asap. Thanks for the advice!

Share this post


Link to post
Share on other sites
Quote:
Original post by whaleyboy
Oh, by the way, alot of the code in 'myapplication.cpp' is generated by gapidraw incase it looks a bit daunting! This kind of stuff for example...


Wait until you hit DirectX...

Share this post


Link to post
Share on other sites
Quote:
Original post by davidx9
Quote:
Original post by whaleyboy
Oh, by the way, alot of the code in 'myapplication.cpp' is generated by gapidraw incase it looks a bit daunting! This kind of stuff for example...


Wait until you hit DirectX...

Then again, 99% of DX code is initialisation!

Share this post


Link to post
Share on other sites
snk_kid, to release the memory like you said do I just need to "delete pAliens". I tried adding that to the destructor and now the program makes a windows error sound when I close it...does that mean it's crashing as it closes? Anyone?

Share this post


Link to post
Share on other sites
Quote:
Original post by whaleyboy
snk_kid, to release the memory like you said do I just need to "delete pAliens".


There should be no reason for calling new, STL containers already handle memory managment, also looking at your code your Alien_Object type has data members that are pointers so you'll need to define what means to copy & assign by providing an "appropriate" copy constructor & assignement operator because the default provided just does a member wise copy that might not be what you wont thats why i say appropriate.

Quote:
Original post by whaleyboy
I tried adding that to the destructor and now the program makes a windows error sound when I close it...does that mean it's crashing as it closes? Anyone?


i hope you don't mean with-in the destructor of Alien_Object!!!

Share this post


Link to post
Share on other sites
I realize your knew, and you are far more into the on screen results than the quality of code, but I do have a few suggestions that will help you as your projects get bigger.

1. I would not name your alien class Alian_object, because it is not an object, it is a class. An object is a specific instance of a class. Instead name it Alian or CAlian.

2. It looks like you have prefixed a few member variables with m, be consistant and do this with all of them.

Share this post


Link to post
Share on other sites
Cheers, corrington_j! Don't worry about thinking you'll upset me by making suggestions about the poor state of my code...that's why I posted so I could learn! Thanks for your comments, I'll definetely make some changes to my code!

Share this post


Link to post
Share on other sites
I did something like what you done for my frist game.i was learning C++ at the time as well.for my aliens(well, chickens...) i used a linked list to store the objects.i dont know if thats what youre doing here but if youre not then i think you should think about using them.had lots of problems with memory leaks but it was good learning!also for my collision, i did it with circles instead of of squares, but i guess i was just making it hard on my self!nice work, keep it up!

Share this post


Link to post
Share on other sites
New version available! Now with shooting! :)

I've incorporated several suggestions made to me, like not name my alien class 'alien_object', not using 'new' when adding objects to my STL vector and several others. The code is still messy compared to the pros, but I am learning! ;)

As before it contains an executable demo allowing you to try it out! Keep those suggestions/comments coming folks!

http://members.gamedev.net/whaleyboy/GapiTest/source2.zip

Oh and the graphics (which are only stand in) are better! (I borrowed them from Thunderforce 4 on the megadrive)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this