with Allegro.Bitmaps; use Allegro.Bitmaps;
package Entities.Items is
-- An Item is an animated Entity, unaffected by gravity, that gives the
-- player a bonus when he touches it. It automatically destroys itself on
-- collision so the bonus is only given once.
type Item is abstract new Entity with private;
type A_Item is access all Item'Class;
-- Returns a reference to a bitmap icon that represents the item. This can
-- used for displaying a visual representation of the item, in a palette,
-- for instance. The reference returned is owned by the item. Do not modify
-- it.
function Get_Icon( this : access Item ) return A_Bitmap;
-- Gives the item's bonus to the player. Each item class gives a different
-- bonus. This is called when the Player entity collides with the Item.
procedure Give_Item( this : access Item ) is abstract;
private
type Item is abstract new Entity with
record
frameDelay : Time_Span := Time_Span_Zero;
firstFrame : Natural := 0;
maxFrames : Positive := 1;
end record;
-- Constructs the Item. Constructors of subclasses should call this first.
-- Raises an exception on error.
procedure Construct( this : access Item;
width,
height : Natural;
libName : String;
firstFrame : String;
maxFrames : Positive;
frameDelay : Time_Span );
-- Implements the entity On_Collide behavior to call Give_Item if the
-- colliding entity is a player. An overriding implemetation should call
-- this first.
procedure On_Collide( this : access Item; e : not null A_Entity );
-- Executes one time frame of logic for the Item to keep the frame up to
-- date. An overriding implementation must call this first.
procedure Tick( this : access Item; time : Tick_Time );
procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Item );
for Item'Read use Object_Read;
procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Item );
for Item'Write use Object_Write;
-- Deletes the Item.
procedure Delete( this : in out A_Item );
pragma Postcondition( this = null );
end Entities.Items;