Class TCastleAlive

Unit

Declaration

type TCastleAlive = class(TCastleTransform)

Description

Transform representing an alive thing. Basis for players, creatures and everything else that has some position, direction and that can be killed.

Note that the TCastleAlive doesn't remove dead objects, doesn't make any dead animations or such. TCastleAlive class merely keeps track of Life, Dead and such properties, and allows you to call Hurt doing eventual knockback. If your own code doesn't call Hurt, or even doesn't look at Life value, then they have no implication for given 3D object, so it may be indestructible just like other 3D objects.

Hierarchy

Overview

Fields

Public nested const DefaultKnockBackSpeed = 1.0;

Methods

Protected procedure SetLife(const Value: Single); virtual;
Protected procedure CancelKnockback;
Public constructor Create(AOwner: TComponent); override;
Public function Dead: boolean;
Public procedure Hurt(const LifeLoss: Single; const HurtDirection: TVector3; const AKnockbackDistance: Single; const Attacker: TCastleAlive); virtual;
Public procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;

Properties

Public property LastHurtDirection: TVector3 read FLastHurtDirection;
Public property LifeTime: Single read FLifeTime;
Public property DieTime: Single read FDieTime;
Published property Life: Single read FLife write SetLife;
Published property MaxLife: Single read FMaxLife write FMaxLife;
Published property KnockBackSpeed: Single read FKnockBackSpeed write FKnockBackSpeed default DefaultKnockBackSpeed;

Description

Fields

Public nested const DefaultKnockBackSpeed = 1.0;
 

Methods

Protected procedure SetLife(const Value: Single); virtual;
 
Protected procedure CancelKnockback;
 
Public constructor Create(AOwner: TComponent); override;
 
Public function Dead: boolean;

Shortcut for checking Life <= 0.

Public procedure Hurt(const LifeLoss: Single; const HurtDirection: TVector3; const AKnockbackDistance: Single; const Attacker: TCastleAlive); virtual;

Hurt given creature, decreasing it's life by LifeLoss, setting last attack direction (used by knockback and some other effects), optionally doing a knockback. If all you want to do is to decrease Life, you can also just set Life property. Unless your code depends on LastHurtDirection being always updated (only TCreature in CastleCreatures unit depends on it now).

HurtDirection should be a normalized vector indicating direction in which the attack came.

AKnockbackDistance, if non-zero, indicates to push creature by given length in the direction given by HurtDirection. Ignored if HurtDirection is zero.

Attacker is the other alive creature that caused this damage. It may be Nil if no other TCastleAlive is directly responsible for this damage. This may be useful for various purposes, for example the victim may become aware of attacker presence when it's attacked.

Public procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;
 

Properties

Public property LastHurtDirection: TVector3 read FLastHurtDirection;

Direction from where the attack came. Zero if there was no specific direction of last attack, otherwise a normalized (length 1) vector.

Public property LifeTime: Single read FLifeTime;
 
Public property DieTime: Single read FDieTime;

Time of death, only valid if Dead, taken from LifeTime.

Published property Life: Single read FLife write SetLife;

Current Life. We're dead when this is <= 0.

Published property MaxLife: Single read FMaxLife write FMaxLife;

Maximum amount of life. Used as default value for Life when sensible. Can be also used for information (to display on player HUDs and such).

It's not really a limit, that is you can set Life to something larger than MaxLife if you want. It's normal in some games, where you can get some "magic life boost" that makes your health temporarily larger than normal. Whether it's sensible in your game (and whether your HUD will display it sensibly) is up to you.

Published property KnockBackSpeed: Single read FKnockBackSpeed write FKnockBackSpeed default DefaultKnockBackSpeed;

Scales how far the knockback effect pushes this creature/player.


Generated by PasDoc 0.15.0.