The keyword npc specifies that a variable is a pointer (a reference) to a non-playing character, such as an enemy, on the screen.
- 1 Syntax and Initialization
- 2 Properties and Methods
- 2.1 Properties
- 2.2 Methods
Syntax and Initialization
Declare a variable as type npc as follows:
Until you initialze the variable, it does not actually "point to" any particular non-playing character, and thus any properties or methods you attempt to use will be invalid. You must initialize the variable by using the Screen->CreateNPC or Screen->LoadNPC methods, as follows:
// You can initialize at declaration... npc AnEnemy = Screen->LoadNPC(1); // ...or you can initialize later. AnEnemy = Screen->LoadNPC(1);
Properties and Methods
The syntax for accessing the methods and properties associated with an npc type variable is as follows:
where npc-variable is a variable of type npc and method-or-property is one of the methods or properties listed below. For instance, the following snippet would get the hitpoints of the first enemy on the screen.
// Create an npc variable and set it // to the first enemy on the screen npc AnEnemy = Screen->LoadNPC(1); int Hitpoints = 0; Hitpoints = AnEnemy->HP;
As with any expression, you can use these methods or properties as the evaluation criteria in control loops, if statements, and so forth.
The speed of the NPC's animation, in screen frames.
The boss pallete used by this NPC; this pallete is only used if CSet is 14 (the reserved boss cset). Use the BPAL_ constants in std.zh to set or compare this value.
The CSet used by this NPC.
The amount of damage dealt to a naked Link when he touches this NPC, in quarter-hearts.
The direction the NPC is facing. Use the DIR_ constants in std.zh to set and compare this value.
The way the NPC is animated. Use the DS_ constants in std.zh to set or compare this value.
Whether to extend the sprite of an item or enemy, as with extended Link tile modifiers.
The NPC's current hitpoints. Each swing of the wooden sword removes 2 hitpoints.
The extent to which the NPC stands still while moving around the screen. As a point of reference, the Zols and Gels have haltrate of 16.
The items that the NPC might drop when killed. Use the IS_ constants in std.zh to set or compare this value.
The rate at which the NPC changes direction. For a point of reference, the Octorok on Crack has a rate of 16.
The sound effects emitted by the enemy. Use the SFX_ constants in std.zh to set or compare this value.
The NPC's movement rate. As a point of reference, the Octorok on Crack has a step of 200.
The number of the starting tile used by this NPC.
The weapon used by this enemy. Use the WPN_ constants in std.zh to set or compare this value. Note that it typically only makes sense to assign weapons labelled as enemy weapons (WPN_ENEMY) (with the exception of WPN_NONE) to this value.
The amount of damage dealt to a naked Link by this NPC's weapon, in quarter-hearts.
The NPC's current X coordinate, in pixels.
The NPC's current Y coordinate, in pixels.
The isValid method indicates whether or not this NPC pointer is still valid. A return value of true indicates the pointer is still valid.
A pointer becomes invalid if the enemy dies or Link leaves the screen. Trying to access any variable of an invalid NPC pointer prints an error to allegro.log and does nothing.
- Introduced in Version
- 2.5 (beta)
- Prototype and Arguments