--
-- Copyright (c) 2012 Kevin Wellwood
-- All rights reserved.
--
-- This source code is distributed under the Modified BSD License. For terms and
-- conditions, see license.txt.
--
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
-- begin streamed fields
-- these fields are streamed because they can differ between
-- instances of the same class.
lifeSpan : Time_Span := Time_Span_Zero;
frameDelay : Time_Span := Time_Span_Zero;
frames : A_Tile_Id_Array := null;
-- end streamed fields
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 : Tile_Id_Array;
lifeSpan : Time_Span := Time_Span_Zero;
frameDelay : Time_Span := Time_Span_Zero );
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;
-- 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 Update( this : access Sprite; time : Tick_Time );
-- Displays the next frame in the sprite's animation, as necessary. 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;