Castle Game EngineIntroduction Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers |
Class TPlayer
Unit
CastlePlayer
Declaration
type TPlayer = class(T3DAliveWithInventory)
Description
Player, 3D object controlling the camera, main enemy of hostile creatures, carries a backpack, may cause fadeout effects on screen and such.
Note that you can operate on player even before level is loaded, before TCastleSceneManager and such are initialized. This allows to create player before level is started (create it from scratch, or by loading from save game), and "carry" the same player instance across various loaded levels.
Dead or Blocked player behaves much like alive and normal player. For example, it still has an associated Camera that can animate by code (e.g. to apply physics to the dead player body, because player was killed when he was flying, or it's corpse lays on some moving object of the level — like elevator). However, Camera input shortcuts will be cleared, to prevent user from directly moving the camera and player.
Do not do some stuff when player is dead:
No calling PickItem, DropItem, UseItem.
No increasing Life (further decreasing Life is OK). This implies that once Player is Dead, (s)he cannot be alive again.
No changing EquippedWeapon, no calling Attack.
Note that every player, just like every T3DOrient actually, has an associated and magically synchronized T3DOrient.Camera instance. Ancestor T3DOrient only takes care about synchronizing the view vectors (position, direciton, up) and doesn't care about camera otherwise. We synchronize more in TPlayer class:
The outside code may still directly access and change many camera properties. Camera view vectors (position, direciton, up), TWalkCamera.PreferredHeight, TWalkCamera.RotationHorizontalSpeed TWalkCamera.RotationVerticalSpeed. In fact, it's Ok to call TWalkCamera.Init, and it's Ok to assign this Camera to TCastleSceneManager.Camera, and TGameSceneManager.LoadLevel does this automatically. So scene manager will update Camera.ProjectionMatrix, call camera events like TCamera.Press, TCamera.Update and such.)
Hierarchy
Overview
Fields
Methods
Properties
Description
Fields
 |
DefaultMoveHorizontalSpeed: Single; |
Various navigation properties that may depend on loaded level.
|
 |
DefaultMoveVerticalSpeed: Single; |
|
 |
DefaultPreferredHeight: Single; |
|
 |
internal const DefaultLife = 100; |
|
 |
internal const DefaultSickProjectionSpeed = 2.0; |
|
 |
internal const DefaultRenderOnTop = true; |
|
 |
internal const DefaultPlayerKnockBackSpeed = 20.0; |
|
 |
internal const DefaultSwimBreath = 30.0; |
|
 |
internal const DefaultDrownPause = 5.0; |
|
 |
internal const DefaultDrownDamageConst = 5.0; |
|
 |
internal const DefaultDrownDamageRandom = 10.0; |
|
 |
internal const DefaultSwimSoundPause = 3.11111111; |
|
Methods
 |
procedure SetLife(const Value: Single); override; |
|
 |
function GetChild: T3D; override; |
|
 |
procedure Notification(AComponent: TComponent; Operation: TOperation); override; |
|
 |
procedure Fall(const FallHeight: Single); override; |
|
 |
constructor Create(AOwner: TComponent); override; |
|
 |
destructor Destroy; override; |
|
 |
procedure UseCurrentItem; |
|
 |
procedure ChangeInventoryCurrentItem(Change: Integer); |
Change InventoryCurrentItem, cycling, and automatically showing the inventory afterwards (if it's not empty). Note that you can also always directly change InventoryCurrentItem property.
|
 |
procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override; |
|
 |
procedure FadeOut(const Color: TCastleColor); |
Cause a fade-out effect on the screen, tinting the screen to the given Color. The TPlayer class doesn't do the actual drawing of the fade-out effect on the screen, we merely store and animate the FadeOutColor and FadeOutIntensity properties. To draw the effect, use a procedure like GLFadeRectangle inside your 2D controls drawing code, see engine tutorial for example.
|
 |
procedure Attack; virtual; |
|
 |
procedure LoadFromFile; |
Load various player properties from an XML file. Properties not specified in the indicated file will be reset to their default values. This is handy to use in a game to allow to configure player behavior by simply editing an XML file (instead of hacking code).
Overloaded parameterless version reads from file ApplicationData('player.xml') .
Note that the indicated file may not exist, and it will not cause errors. Not existing file is equivalent to a file with everything set at default values.
It is Ok to call this multiple times, at any moment. This way you can make some debug command to reload player.xml file, very useful to test various player properties without restarting the game.
|
 |
procedure LoadFromFile(const URL: string); |
|
 |
procedure LevelChanged; |
|
 |
function Sphere(out Radius: Single): boolean; override; |
|
Properties
 |
property Flying: boolean read FFlying write SetFlying; |
Flying. How it interacts with FlyingTimeout: Setting this property to any value removes any timeout set by FlyingTimeout. That is, setting this to True makes player fly indefinitely, and setting this to False makes player stop flying (regardless if flying was initialized by Flying := true or FlyingTimeout ).
|
 |
property FlyingTimeOut: TFloatTime read FFlyingTimeOut write SetFlyingTimeOut; |
Set this to something > 0 to start flying for a given number of seconds. The Flying property will also change to True for this time. It will automatically change back to False after given number of seconds (you can also always just manually switch Flying back to False ).
Set this only with value > 0.
When this is > 0 it means flying with a timeout (always Flying = True then), otherwise it's = 0 (which means were not flying, or flying indefinitely long, depending on Flying).
|
 |
property EquippedWeapon: TItemWeapon read FEquippedWeapon write SetEquippedWeapon; |
Weapon the player is using right now, or nil if none.
You can set this property only to some item existing on Inventory. When you drop the current weapon, DeleteItem will automatically set this to Nil .
When setting this property (to nil or non-nil) player may get GameMessage about using/not using a weapon.
|
 |
property FadeOutIntensity: Single read FFadeOutIntensity; |
|
 |
property Swimming: TPlayerSwimming read FSwimming write SetSwimming; |
You should set this property as appropriate. This object will just use this property (changing it's Camera properties etc.).
|
 |
property InventoryCurrentItem: Integer
read FInventoryCurrentItem write FInventoryCurrentItem
default -1; |
Currently selected inventory item.
Note: while we try to always sensibly update InventoryCurrentItem , to keep the assumptions that
Inventory.Count = 0 => InventoryCurrentItem = -1
Inventory.Count > 0 => InventoryCurrentItem between 0 and Inventory.Count - 1
but you should nowhere depend on these assuptions. That's because I want to allow myself freedom to modify Inventory in various situations, so InventoryCurrentItem can become invalid in many situations.
So every code should check that
If InventoryCurrentItem between 0 and Inventory.Count - 1 then InventoryCurrentItem is selected
Else no item is selected (possibly Inventory.Count = 0, possibly not)
|
 |
property InventoryVisible: boolean
read FInventoryVisible write FInventoryVisible default false; |
|
 |
property CollidesWithMoving default true; |
|
 |
property Blocked: boolean read FBlocked write FBlocked; |
Disables changing the camera by user. It's useful when you want to temporarily force camera to some specific setting (you can even use handy Player.Camera.AnimateTo method to do this easily, see TWalkCamera.AnimateTo).
|
 |
property RenderOnTop: boolean read FRenderOnTop write FRenderOnTop
default DefaultRenderOnTop; |
Render 3D children (like EquippedWeapon) on top of everything else.
|
 |
property FallSound: TSoundType
read FFallSound write FFallSound; |
Sound when falling. The default is the sound named 'player_fall'.
|
 |
property SwimBreath: Single read FSwimBreath write FSwimBreath default DefaultSwimBreath; |
How many seconds you can swin before you start to drown.
|
 |
property SwimSoundPause: Single read FSwimSoundPause write FSwimSoundPause default DefaultSwimSoundPause; |
Pause, in seconds, between playing stPlayerSwimming sound. This should be something that is not easily synchronized with SwimDrownPause.
|
 |
property KnockBackSpeed default DefaultPlayerKnockBackSpeed; |
|
 |
property EnableCameraDragging: boolean
read FEnableCameraDragging write SetEnableCameraDragging default false; |
Enable camera navigation by dragging. This results in including ciMouseDragging in TCamera.Input (when player is not Dead or Blocked).
|
Generated by PasDoc 0.13.0 on 2014-04-30 22:06:44
|