private with Tiles;
package Entities.Sprites is
-- A Sprite in an Entity that doesn't have any internal behavior. It can
-- represent something simply to be displayed, like an explosion, or a
-- phaser blast, or a little animation displayed when an item is collected.
type Sprite is abstract new Entity with private;
private
use Tiles;
type Sprite is abstract new Entity with
record
-- ** constant for the life of the object; fields not streamed **
lifeSpan : Time_Span := Time_Span_Zero;
frameDelay : Time_Span := Time_Span_Zero;
frames : A_Tile_Id_Array := null;
end record;
-- Constructs the Sprite. Subclasses should call this from their constructor.
-- 'frames' is an animation for the sprite, as a list of tile IDs from tile
-- library 'libName'. The animation will loop after the last frame. The
-- sprite will not display an animation if it has only one frame. 'lifeSpan'
-- is the length of time the entity should exist before it automatically
-- deletes itself (0 = unlimited). 'frameDelay' is the amount of time
-- between frames.
procedure Construct( this : access Sprite;
width,
height : Natural;
libName : String;
frames : not null A_Tile_Id_Array;
lifeSpan : Time_Span;
frameDelay : Time_Span );
pragma Precondition( libName'Length > 0 );
procedure Delete( this : in out Sprite );
procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Sprite );
for Sprite'Read use Object_Read;
procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Sprite );
for Sprite'Write use Object_Write;
-- Inherited from Entity. Executes one time frame of the Sprite's logic.
-- This keeps the animation frame up to date and destroy the entity when
-- it's beyond it's lifespan. An overriding implementation should call this
-- first.
procedure Tick( this : access Sprite; time : Tick_Time );
-- Displays the next frame in the sprite's animation, as necssary.. If
-- 'notify' is True and the frame changes, a Frame_Changed event will be
-- sent to the game view.
procedure Update_Frame( this : access Sprite;
notify : Boolean := True );
end Entities.Sprites;