The control/player.cs module defines the player datablock and methods for use by this datablock for various things. The datablock will use the standard male model, which in this case has been named player.dts. Figure 4.3 shows the standard male avatar in the Emaga4 game world.
Figure 4.3: Player-avatar in Emaga4.
Here is the control/player.cs module. Type it in and save it as Emaga4\control\player.cs.
//------------------------------------------------------------------------ // control/player.cs // // player definition module for 3DGPAI1 emaga4 tutorial game // // Copyright (c) 2003 by Kenneth C. Finney. //------------------------------------------------------------------------ datablock PlayerData(HumanMaleAvatar) { className = Avatar; shapeFile = "~/player.dts"; emap = true; renderFirstPerson = false; cameraMaxDist = 4; mass = 100; density = 10; drag = 0.1; maxdrag = 0.5; maxEnergy = 100; maxDamage = 100; maxForwardSpeed = 15; maxBackwardSpeed = 10; maxSideSpeed = 12; minJumpSpeed = 20; maxJumpSpeed = 30; runForce = 4000; jumpForce = 1000; runSurfaceAngle = 70; jumpSurfaceAngle = 80; }; //---------------------------------------------------------------------------- // Avatar Datablock methods //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- function Avatar::onAdd(%this,%obj) { } function Avatar::onRemove(%this, %obj) { if (%obj.client.player == %obj) %obj.client.player = 0; }
The datablock used is the PlayerData class. It is piled to the gunwales with useful stuff. Table 4.2 provides a summary description of each of the properties.
Property | Description |
---|---|
className | Defines an arbitrary class that the avatar can belong to. |
shapeFile | Specifies the file that contains the 3D model of the avatar. |
emap | Enables environment mapping on the avatar model. |
renderFirstPerson | When true, causes the avatar model to be visible when in first-person point-of-view mode. |
cameraMaxDist | Maximum distance from the avatar for the camera in third-person point-of-view mode. |
mass | The mass of the avatar in terms of the game world. |
density | Arbitrarily defined density. |
drag | Slows down the avatar through simulated friction. |
maxdrag | Maximum allowable drag. |
maxEnergy | Maximum energy allowed. |
maxDamage | Maximum damage points that can be sustained before the avatar is killed. |
maxForwardSpeed | Maximum speed allowable when moving forward. |
maxBackwardSpeed | Maximum speed allowable when moving backward. |
maxSideSpeed | Maximum speed allowable when moving sideways (strafing). |
minJumpSpeed | Below this speed, you can't make the avatar jump. |
maxJumpSpeed | Above this speed, you can't make the avatar jump. |
jumpForce | The force, and therefore the acceleration, when jumping. |
runForce | The force, and therefore the acceleration, when starting to run. |
runSurfaceAngle | Maximum slope (in degrees) that the avatar can run on. |
jumpSurfaceAngle | Maximum slope (in degrees) that the avatar can jump on, usually somewhat less than runSurfaceAngle. |
There are many more properties available for the avatar, which we aren't using right now. We can also define our own properties for the datablock and access them, through an instance object of this datablock, from anywhere in the scripts.
Last but not least, there are two methods defined for the datablock. The two basically define what happens when we add a datablock and when we remove it. We will encounter many others in later chapters.