(Help Request) Hello! can you help me?

<< < (2/4) > >>

correct me if i'm wrong but the way i understand your corrections on my code in using delete[] is that i declared it like this:

CWeapon* weaponList[2];

which wrong to use delete[] (with "[]").

but will it be correct if i declared it like this:

CWeapon* weaponList;

and then

weaponList = new CWeapon[2];

this is the right one to use delete[] (with "[]") right?

Richard Marks:
Ok then, so if finding the cause of your current crash isn't the issue, then this will be easier.

I will simply write the current functionality of your game over in a new format for you, along with being heavily commented such that you should have no trouble understanding what function each part of the code performs.

In reply to your question regarding the delete[] operator, here is the answer.


// allocate a single instance of the class Weapon
// I'm using an enumeration type as a parameter to the class constructor just for example
Weapon* lasers = new Weapon(LaserWeaponGradeOne);

// call a member-function of the weapon that we assume exists in this example

// de-allocate the single instance
if (0 != lasers)
delete lasers;
lasers = 0;

// allocate a dynamic array of rocket launchers
Weapon** rocketLaunchers = new Weapon* [ROCKET_LAUNCHER_COUNT];

// now we allocate each launcher in the array
// because at this time we just have an array of uninitialized pointers to the Weapon class
for (int index = 0; index < ROCKET_LAUNCHER_COUNT; index++)
rocketLaunchers[index] = new Weapon(RocketLauncherWeaponGradeFive);

// lets launch the rockets for fun shall we?

// Loop over all the elements of the array and call the Fire() member-function of the class
for (int index = 0; index < ROCKET_LAUNCHER_COUNT; index++)

// de-allocate the array of rocket launchers
// First we loop over all the elements of the array and delete each launcher
// Next we delete the array that we allocated
for (int index = 0; index < ROCKET_LAUNCHER_COUNT; index++)
if (0 != rocketLaunchers[index])
delete rocketLaunchers[index];
rocketLaunchers[index] = 0;
delete [] rocketLaunchers;

Did that help?


// allocate a static array of pointers to the Weapon class
const int MINI_GUNS_COUNT = 4;
Weapon* miniGuns[MINI_GUNS_COUNT];

// allocate each mini-gun
for (int index = 0; index < MINI_GUN_COUNT; index++)
miniGuns[index] = new Weapon(MiniGunWeaponGradeTwo);

// de-allocate the mini-guns
// notice we do NOT use delete [] because the array is NOT a dynamically allocated array
for (int index = 0; index < MINI_GUN_COUNT; index++)
if (0 != miniGuns[index])
delete miniGuns[index];
miniGuns[index] = 0;

That helps?


// allocate a dynamic array of class instances...note that this is NOT an array of pointers
// which means that the array holds objects, not pointers.
const int MINE_COUNT = 200;
Weapon* mines = new Weapon(MineWeaponGradeOne) [MINE_COUNT];

// call the Fire() method on the mines
// take note that we use the DOT syntax instead of the -> pointer syntax
// to call the function, because the mines array is not an array of pointers.
for (int index = 0; index < MINE_COUNT; index++)

// de-allocate the mines
delete [] mines;

Okay man? Did that help you understand how it works?

I'll get started on the re-writing of your game framework as soon as I can. :)

oh yeah! very clean, clear, professional, and easy to understand. I can't wait to see it done. I've downloaded some of your works too and i'd say you're hell of a genius. I think you should write your own books too.  ;D ;D

Richard Marks:
Oh yeah? what of my works have you downloaded?

I've started working on writing books, but every time I do, I get distracted from it. Heh.
Perhaps one day I'll be able to sit and write a book or two, but for now my primary focus is on making games, and in developing my engine in particular.

I am working on building the framework for you now.
Am I to understand that you are looking for a plain and simple GDI game engine?
Cause that is essentially what I'm building for you right now.
If you plan to go into DirectX later, then know that it will be rather easy to build on to this later.
For now though, I'd suggest sticking with GDI for now.

However I think I should throw this out here too.
I am not a fan of windows, nor any microsoft platform.
I'd highly recommend you learn to write cross-platform games.

The Allegro game library, and SDL are the best ways to go that route.
Allegro is easier to learn than SDL.

Some things to think about.

But for now, you will have a professional Win32 GDI game engine framework within a week.

that's very very cool then! I'll be waiting for that. You're such a cool guy, master.

These are some of them i have: SAWD, pong, and FFV menu example. i made a printed copy of pong and FFV menu (i hope you don't mind me having made a hardcopy of your works). Ofcourse your name is in there. I don't have my own computer so I needed them on paper to study at home.

I noticed too that almost all of your works are cross-platform. Well, it's not that i like Windows. The only thing i like in windows is their DirectX. I know DirectX is really hard to learn, that's why i'm getting on the basic first. But as i mentioned in my previous post, my primary concern right now is to learn how to structure better.

BTW, i can't access the link you PMed me. I don't know why, maybe because my internet connection is very weak.


[0] Message Index

[#] Next page

[*] Previous page