Advertisement

Classes within Classes

Started by April 27, 2008 04:11 AM
3 comments, last by WitchLord 16 years, 7 months ago
It would be nice if we could created classes inside classes. In the game im making, everything is done using classes. Each npc code is automatically inserted within a class like this:

class SomeNpc
{
  float x;
  float y;
  float depth;
  //Npc code is inserted here
}
But if i wanted to create a boss npc that has projectiles, the npc code would look something like this:


class Projectile
{
  float x;
  float y;
}

Projectile[] projectiles;

void OnCreate()
{
  //add projectiles to array
}

void OnUpdate()
{
  //loop through the projectiles array and check for collisions with
  //players and move the projectiles
}
I cant do it because i cant define a class within another class
What compiler are you using? Nested classes should be possible. IIRC, they automatically get access to the containing class' private members. Still, even if your compiler doesn't support nested classes, I don't see why would that be an obstacle to your implementation (except, maybe, if you are using templates). Just get the class somewhere else.
Advertisement
err, the angelscript compiler lol. The code i showed was angelscript code.
Whoops! I opened the topic from the Recent Threads list, and completely missed the subforum it was posted at. Sorry about that. :)

Have fun!
Declaring classes within classes, will eventually be available in AngelScript as well. For now though, perhaps you can live with declaring all the classes in the global scope.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement