Sign in to follow this  
39ster

using const members in classes

Recommended Posts

As i've mentioned a few times, the objects in my games are code wrapped in an AngelScript class like below:
class MyClass
{
  float x;
  float y;
  float depth;
  [code here]
}
I would like to add one more member just under depth called "id" but i only want it to be read-only (and use "objectData->GetPropertyPointer()" to get its pointer and change its value). The value represents the ID of the NPC and can be used in some functions. I tried defining it as "const uint id;" but it woudnt let me use const in a class like that. At the moment i have to use a function called GetId() but i would much rather have "const id". Heres what an NPC file looks like:
WIDTH 32
HEIGHT 32

//Tiles for the bush
TILEBLOCK 2 2
  0x0200 0x0300
  0x0201 0x0301
END

CLIENTCODE
int shadowSprite;
int sprite;
int[] tiles;

void OnCreate()
{
  tiles = GetNpcTiles(id);
  shadowSprite = GetSprite("shadow.gif");
  depth = 0xFFFF;
}

void OnDraw()
{
  DrawTiles(tiles, x, y, 2, 2);
}

void DrawShadow(float shadowX, float shadowY)
{
  DrawSprite(shadowSprite, shadowX + GetNpcWidth(id) / 2 - 12, shadowY + 22);
}

void OnCarryDraw(bool drawShadow, float shadowX, float shadowY)
{
  if(drawShadow)
    DrawShadow(shadowX, shadowY);

  DrawTiles(tiles, x, y, 2, 2);
}

bool OnPlayerCollision(int playerId)
{
  //return true to indicate that this will block the player
  return true;
}


bool OnCarry(int playerId)
{
  //return true to indicate that this can be carried by the player
  return true;
}

bool OnWarpCollision(const string& level, float nextX, float nextY)
{
  //If npc touches a warp rectangle than
  //change its level, x and y
  WarpNpc(id, level, nextX, nextY);
  return true;
}
END

SERVERCODE
//server-side equivelant goes here
END

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