Class TCastleAliveBehavior

Unit

Declaration

type TCastleAliveBehavior = class(TCastleBehavior)

Description

Behavior that tracks life points, and determines being alive/dead for game purposes.

Using this class in your own games is completely optional. You can implement "alive" functionality yourself trivially, and then make your own decisions about various details (e.g. is life a float, or integer? does life equal "precisely zero" means being still alive, or dead?).

Hierarchy

Overview

Fields

Public nested const DefaultLife = 100.0;

Methods

Protected function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override;
Public constructor Create(AOwner: TComponent); override;
Public function PropertySections(const PropertyName: String): TPropertySections; override;
Public function Dead: Boolean;
Public procedure Hurt(const LifeLoss: Single; const AHurtDirection: TVector3; const AHurtStrength: Single = 0; const AnAttacker: TCastleAliveBehavior = nil); virtual;

Properties

Public property HurtDirection: TVector3 read FHurtDirection;
Public property HurtStrength: Single read FHurtStrength;
Public property Attacker: TCastleAliveBehavior read FAttacker write SetAttacker;
Published property Life: Single read FLife write FLife default DefaultLife;
Published property MaxLife: Single read FMaxLife write FMaxLife default DefaultLife;

Description

Fields

Public nested const DefaultLife = 100.0;

Default value for MaxLife and Life.

Methods

Protected function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override;

This item has no description. Showing description inherited from TCastleBehavior.CanAttachToParent.

Check can this behavior be added to NewParent. When this returns False, it has to set also ReasonWhyCannot. When overriding this, you can use e.g. this code to make sure we are the only behavior of given class:

function TCastleBillboard.CanAttachToParent(const NewParent: TCastleTransform;
  out ReasonWhyCannot: String): Boolean;
begin
  Result := inherited;
  if not Result then Exit;

  if NewParent.FindBehavior(TCastleBillboard) <> nil then
  begin
    ReasonWhyCannot := 'Only one TCastleBillboard behavior can be added to a given TCastleTransform';
    Result := false;
  end;
end;

Public constructor Create(AOwner: TComponent); override;

This item has no description.

Public function PropertySections(const PropertyName: String): TPropertySections; override;

This item has no description. Showing description inherited from TCastleComponent.PropertySections.

Section where to show property in the editor.

Public function Dead: Boolean;

Shortcut for checking Life <= 0.

Public procedure Hurt(const LifeLoss: Single; const AHurtDirection: TVector3; const AHurtStrength: Single = 0; const AnAttacker: TCastleAliveBehavior = nil); virtual;

Hurt given creature, decreasing its Life by LifeLoss, also setting some additional properties that describe the damage. These additional properties do not do anything in this class – but they may be useful by other effects, e.g. "knockback", done by other behaviors.

Note: If all you want to do is to decrease Life, you can also just set Life property directly.

)

Parameters
AHurtDirection
Should be a normalized vector indicating direction from which the attack came.

In this class, it does nothing, merely sets HurtDirection property. Which may be used by other effects.

AHurtStrength
Describes "strength" of the attack. What this "strengh" exactly means is not defined in this class. It may cause a "knockback" effect, in which case it may be a knockback distance, or a physical force strength, and is meaningful only when AHurtDirection parameter is non-zero.

In this class, it does nothing, merely sets HurtStrength property. Which may be used by other effects.

AnAttacker
The other alive creature that caused this damage. It may be Nil if no other TCastleAliveBehavior 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.

In this class, it does nothing, merely sets Attacker property. Which may be used by other effects.

Properties

Public property HurtDirection: TVector3 read FHurtDirection;

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

Public property HurtStrength: Single read FHurtStrength;

Strengh of the last attack, set by Hurt. What this "strengh" exactly means is not defined in this class. It may cause a "knockback" effect, in which case it may be a knockback distance, or a physical force strength, and is meaningful only when HurtDirection is non-zero.

Public property Attacker: TCastleAliveBehavior read FAttacker write SetAttacker;

Last attacker. Set by the last Hurt call, it may also be set directly.

Published property Life: Single read FLife write FLife default DefaultLife;

Current Life. The object is considered "dead" when this is <= 0.

Published property MaxLife: Single read FMaxLife write FMaxLife default DefaultLife;

Maximum amount of life. Can be also used for information (to display on player HUDs and such).

This is not a strict limit on Life, i.e. all the code allows the have Life > MaxLife to account for special game mechanisms, like "magic life boost to make health temporarily larger than normal". It is up to your game whether such situation will actually happen.


Generated by PasDoc 0.16.0-snapshot.