class MyClass
{
float x;
float y;
float depth;
}</pre>
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:
<pre>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
</pre>
using const members in classes
As i've mentioned a few times, the objects in my games are code wrapped in an AngelScript class like below:
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement