1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. private with Tiles; 
  10.  
  11. package Entities.Sprites is 
  12.  
  13.     -- A Sprite in an Entity that doesn't have any internal behavior. It can 
  14.     -- represent something simply to be displayed, like an explosion, or a 
  15.     -- phaser blast, or a little animation displayed when an item is collected. 
  16.     type Sprite is abstract new Entity with private; 
  17.  
  18. private 
  19.  
  20.     use Tiles; 
  21.  
  22.     type Sprite is abstract new Entity with 
  23.         record 
  24.             -- begin streamed fields 
  25.  
  26.             -- these fields are streamed because they can differ between 
  27.             -- instances of the same class. 
  28.             lifeSpan   : Time_Span := Time_Span_Zero; 
  29.             frameDelay : Time_Span := Time_Span_Zero; 
  30.             frames     : A_Tile_Id_Array := null; 
  31.  
  32.             -- end streamed fields 
  33.         end record; 
  34.  
  35.     -- Constructs the Sprite. Subclasses should call this from their constructor. 
  36.     -- 'frames' is an animation for the sprite, as a list of tile IDs from tile 
  37.     -- library 'libName'. The animation will loop after the last frame. The 
  38.     -- sprite will not display an animation if it has only one frame. 'lifeSpan' 
  39.     -- is the length of time the entity should exist before it automatically 
  40.     -- deletes itself (0 = unlimited). 'frameDelay' is the amount of time 
  41.     -- between frames. 
  42.     procedure Construct( this       : access Sprite; 
  43.                          width, 
  44.                          height     : Natural; 
  45.                          libName    : String; 
  46.                          frames     : Tile_Id_Array; 
  47.                          lifeSpan   : Time_Span := Time_Span_Zero; 
  48.                          frameDelay : Time_Span := Time_Span_Zero ); 
  49.     pragma Precondition( libName'Length > 0 ); 
  50.  
  51.     procedure Delete( this : in out Sprite ); 
  52.  
  53.     procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Sprite ); 
  54.     for Sprite'Read use Object_Read; 
  55.  
  56.     procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Sprite ); 
  57.     for Sprite'Write use Object_Write; 
  58.  
  59.     -- Keeps the animation frame up to date and destroy the entity when it's 
  60.     -- beyond it's lifespan. An overriding implementation should call this 
  61.     -- first. 
  62.     procedure Update( this : access Sprite; time : Tick_Time ); 
  63.  
  64.     -- Displays the next frame in the sprite's animation, as necessary. If 
  65.     -- 'notify' is True and the frame changes, a Frame_Changed event will be 
  66.     -- sent to the game view. 
  67.     procedure Update_Frame( this   : access Sprite; 
  68.                             notify : Boolean := True ); 
  69.  
  70. end Entities.Sprites;