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. package Entities.Players.Keen is 
  10.  
  11.     type Keen is new Player with private; 
  12.     type A_Keen is access all Keen'Class; 
  13.  
  14.     -- Checks if Keen can teleport and then queues the events needed to enter 
  15.     -- the teleport state. This is called by a trigger entity that is 
  16.     -- teleporting Keen. 
  17.     procedure Teleport( this         : access Keen; 
  18.                         fromX, fromY : Float; 
  19.                         toX,   toY   : Float ); 
  20.  
  21. private 
  22.  
  23.     -- Time between shots 
  24.     SHOOT_DURATION : constant Time_Span := Milliseconds( 215 ); 
  25.  
  26.     -- The amount of time Keen spends walking into a doorway when teleporting 
  27.     TELEPORT_DURATION : constant Time_Span := Milliseconds( 600 ); 
  28.  
  29.     function Get_Keen_Pref( shortName : String ) return Float; 
  30.  
  31.     ---------------------------------------------------------------------------- 
  32.  
  33.     -- each Action_Type value represents a different state of Keen, in which 
  34.     -- he's performing the action. 
  35.     type Action_Type is 
  36.     ( 
  37.         Act_Moving,        -- standing or moving (on ground and in the air) 
  38.         Act_Looking,       -- standing still, looking up or down 
  39.         Act_Looking_Back,  -- returning to center after looking up or down 
  40.         Act_Teleporting,   -- teleportation animation 
  41.         Act_Idle,          -- performing a bored animation due to idleness 
  42.         Act_Rising,        -- standing up after sitting down bored 
  43.         Act_Dying,         -- death animation 
  44.         Act_Climbing       -- hanging onto a pole (still or moving) 
  45.     ); 
  46.  
  47.     -- Sub actions: 
  48.     -- Shooting 
  49.     -- Pogoing 
  50.  
  51.     type State is abstract tagged limited 
  52.         record 
  53.             action : Action_Type;     -- constant after initialization 
  54.         end record; 
  55.     type A_State is access all State'Class; 
  56.  
  57.     function Get_Frame( this : State; 
  58.                         k    : Keen'Class ) return Natural is abstract; 
  59.  
  60.     procedure Update( this : State; 
  61.                       k    : A_Keen; 
  62.                       time : Tick_Time ) is abstract; 
  63.  
  64.     ---------------------------------------------------------------------------- 
  65.  
  66.     type Keen is new Player with 
  67.         record 
  68.             -- *** these fields are streamed *** 
  69.  
  70.             -- true when keen is jumping (actively accelerating upward) 
  71.             jumping : Boolean := False; 
  72.  
  73.             -- the world y location of where keen will be at the maximum height 
  74.             -- height of his jump. this is set when a jump is started, and 
  75.             -- will be < 0 if no jump is in progress. 
  76.             jumpApexMin : Float := -1.0; 
  77.             jumpApexMax : Float := -1.0; 
  78.  
  79.             -- true if keen is on his pogo stick. note that jumping and grounded 
  80.             -- are independent states and may or may not be true. 
  81.             onPogo : Boolean := False; 
  82.  
  83.             -- true if keen is currently shooting. keen may shoot while 
  84.             -- performing certain actions. (ie: moving, hanging from a pole) 
  85.             shooting : Boolean := False; 
  86.  
  87.             -- the time when keen last fired a shot, used for keeping a delay 
  88.             -- between shots. 
  89.             shootStart : Time_Span := Time_Span_Zero;      -- (relative to .age) 
  90.  
  91.             -- keen's current state 
  92.             state         : A_State := null;               -- streamed as Action_Type 
  93.             stateStart    : Time_Span := Time_Span_Zero;   -- (relative to .age) 
  94.             stateDuration : Time_Span := Time_Span_Zero; 
  95.  
  96.             idleStart  : Time_Span := Time_Span_Zero;      -- (relative to .age) 
  97.             idleNumber : Positive := 1;     -- number of the next idle animation 
  98.  
  99.             -- for the teleporting state 
  100.             teleportX,                                   -- teleport destination 
  101.             teleportY    : Float := 0.0;                 -- 
  102.  
  103.             -- for the climbing state 
  104.             poleId     : Entity_Id := INVALID_ID;   -- id of pole being climbed (action = Act_Climbing) 
  105.             poleTop    : Boolean := False;          -- reached the top of the pole 
  106.             poleBottom : Boolean := False;          -- reached the bottom of the pole (works but not used) 
  107.  
  108.             deathX, 
  109.             deathY : Float := 0.0;      -- location of keen when he died 
  110.  
  111.             -- ** these fields do not need to be streamed ** 
  112.  
  113.             dead : Boolean := False;    -- dead fully dead? (temporary) 
  114.  
  115.             minJumpHeight,                  -- entity.player.keen.min_jump_height 
  116.             maxJumpHeight,                  -- entity.player.keen.max_jump_height 
  117.             minPogoHeight,                  -- entity.player.keen.min_pogo_height 
  118.             maxPogoHeight,                  -- entity.player.keen.max_pogo_height 
  119.             maxBounceHeight : Float := 0.0; -- entity.player.keen.max_bounce_height 
  120.             lookSpeed       : Float := 0.0; -- entity.player.keen.look_speed 
  121.         end record; 
  122.  
  123.     procedure Construct( this : access Keen ); 
  124.  
  125.     procedure Change_State( this   : not null access Keen'Class; 
  126.                             state  : not null A_State; 
  127.                             length : Time_Span := Time_Span_Zero ); 
  128.  
  129.     procedure Die( this : access Keen ); 
  130.  
  131.     -- Returns True if an action duration has not yet been met and False when 
  132.     -- the current action's duration has expired. 
  133.     function Is_Busy( this : not null access Keen'Class ) return Boolean; 
  134.  
  135.     function Object_Input( stream : access Root_Stream_Type'Class ) return Keen; 
  136.     for Keen'Input use Object_Input; 
  137.  
  138.     procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Keen ); 
  139.     for Keen'Read use Object_Read; 
  140.  
  141.     procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Keen ); 
  142.     for Keen'Write use Object_Write; 
  143.  
  144.     procedure On_Hit_Wall( this         : access Keen; 
  145.                            dir          : Cardinal_Direction; 
  146.                            firstContact : Boolean ); 
  147.  
  148.     procedure Reset_Idle( this : not null access Keen'Class ); 
  149.  
  150.     procedure Update( this : access Keen; time : Tick_Time ); 
  151.  
  152.     procedure Update_Frame( this : access Keen; notify : Boolean := True ); 
  153.  
  154. end Entities.Players.Keen;