My first effort ...for your consideration!

Started by
13 comments, last by Roboguy 19 years, 7 months ago
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...
Advertisement
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
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
Disclaimer: "I am in no way qualified to present advice on any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)"
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]
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!
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...
No bombs, No guns, just an army of game creators...
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!

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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?
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!!!
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.

This topic is closed to new replies.

Advertisement