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. with Hashed_Strings;                    use Hashed_Strings; 
  10.  
  11. package Entities.Players.Keen is 
  12.  
  13.     type Keen is new Player with private; 
  14.     type A_Keen is access all Keen'Class; 
  15.  
  16.     -- If Keen was teleporting, he will end the action and go back to the 
  17.     -- moving state. 
  18.     procedure Finish_Teleport( this : not null access Keen'Class ); 
  19.  
  20.     -- Accelerates Keen in the direction 'dir'. 
  21.     procedure Move_Start( this : access Keen; dir : Cardinal_Direction ); 
  22.  
  23.     -- Stops Keen's acceleration in the direction 'dir'. 
  24.     procedure Move_Stop( this : access Keen; dir : Cardinal_Direction ); 
  25.  
  26.     -- Shoots Keen's neural stunner, returning True on success. If 'fire' is 
  27.     -- False, an out of ammo sound will be played and no stunner shot will be 
  28.     -- spawned. 
  29.     function Shoot_Gun( this : not null access Keen'Class; fire : Boolean ) return Boolean; 
  30.  
  31.     -- Notifies the entity that he's not attempting to activate anymore, which 
  32.     -- will allow Try_Activating to work again. 
  33.     procedure Stop_Activating( this : not null access Keen'Class ); 
  34.  
  35.     -- Stops Keen's attempt to jump, if he was attempting to do so. 
  36.     procedure Stop_Jump_Attempt( this : not null access Keen'Class ); 
  37.  
  38.     -- Checks if Keen can teleport and then queues the events needed to enter 
  39.     -- the teleport state. 
  40.     procedure Teleport( this         : access Keen; 
  41.                         fromX, fromY : Float; 
  42.                         toX,   toY   : Float ); 
  43.  
  44.     -- Toggles Keen's pogostick, if it's possible to do so. He can use his 
  45.     -- pogostick when he's moving (walking, standing, jumping). Attempting to 
  46.     -- use the pogo when he's bored will abort the bored action. 
  47.     procedure Toggle_Pogostick( this : not null access Keen'Class ); 
  48.  
  49.     -- Activates the entities that Keen is currently touching, if he is allowed 
  50.     -- to perform the activate action right now. He must be standing flat footed 
  51.     -- on the ground and not already busy activating something. 
  52.     procedure Try_To_Activate( this : not null access Keen'Class ); 
  53.  
  54.     -- Keen tries to grab a pole and enter the climbing action state if he is 
  55.     -- touching a pole and able to climb. 'dir' must be the direction keen is 
  56.     -- trying to climb: either Up or Down. 
  57.     procedure Try_To_Climb( this : not null access Keen'Class; 
  58.                             dir  : Cardinal_Direction ); 
  59.  
  60.     -- Make Keen attempt to jump. The attempt will be in effect until the 
  61.     -- attempt is stopped. The jump will begin on the attempt if he is able to 
  62.     -- do so. 
  63.     procedure Try_To_Jump( this : not null access Keen'Class ); 
  64.  
  65.     ---------------------------------------------------------------------------- 
  66.  
  67.     -- An impulse the Keen entity sends to itself on completion of teleporting 
  68.     Finish_Teleporting : constant Hashed_String := To_Hashed_String( "Finish_Teleporting" ); 
  69.  
  70. private 
  71.  
  72.     type Action_Type is (Act_Moving, Act_Looking, Act_Looking_Back, 
  73.                          Act_Teleporting, Act_Idle, Act_Rising, Act_Dying, 
  74.                          Act_Climbing); 
  75.  
  76.     type Keen is new Player with 
  77.         record 
  78.             -- *** these fields are streamed *** 
  79.  
  80.             -- true when keen is jumping (actively accelerating upward) 
  81.             jumping : Boolean := False; 
  82.  
  83.             -- the world y location of keen when he started his jump. this is 
  84.             -- used to determine when the jump has reached min and max heights. 
  85.             jumpStartY : Float := 0.0; 
  86.  
  87.             -- true if keen is on his pogo stick. note that jumping and grounded 
  88.             -- are independent states and may or may not be true. 
  89.             onPogo : Boolean := False; 
  90.  
  91.             -- true if keen is currently shooting. keen may shoot while 
  92.             -- performing certain actions. (ie: moving, hanging from a pole) 
  93.             shooting : Boolean := False; 
  94.  
  95.             -- the time when keen last fired a shot, used for keeping a delay 
  96.             -- between shots. (relative to .age) 
  97.             shootStart : Time_Span := Time_Span_Zero; 
  98.  
  99.             -- related to keen performing a one-shot action 
  100.             action         : Action_Type := Act_Moving; 
  101.             actionStart    : Time_Span := Time_Span_Zero;  -- (relative to .age) 
  102.             actionDuration : Time_Span := Time_Span_Zero; 
  103.  
  104.             idleStart  : Time_Span := Time_Span_Zero;      -- (relative to .age) 
  105.             idleNumber : Positive := 1;     -- number of the next idle animation 
  106.  
  107.             -- for the teleporting action 
  108.             teleportX,                                   -- teleport destination 
  109.             teleportY    : Float := 0.0;                 -- 
  110.             lastTeleport : Time_Span := Time_Span_Zero;  -- time of previous teleport (relative to .age) 
  111.  
  112.             -- for the climbing action 
  113.             poleId     : Entity_Id := INVALID_ID;   -- id of pole being climbed (action = Act_Climbing) 
  114.             poleTop    : Boolean := False;          -- reached the top of the pole 
  115.             poleBottom : Boolean := False;          -- reached the bottom of the pole (works but not used) 
  116.  
  117.             deathX, 
  118.             deathY : Float := 0.0;      -- location of keen when he died 
  119.  
  120.             -- ** these fields do not need to be streamed ** 
  121.  
  122.             dead : Boolean := False;    -- dead fully dead? (temporary) 
  123.  
  124.             upTime : Time_Span := Time_Span_Zero; 
  125.  
  126.             attemptingJump : Boolean := False;  -- true when the jump key is held down 
  127.             activating     : Boolean := False;  -- true if busy activating something (activate button held down) 
  128.  
  129.             minJumpHeight,                  -- entity.player.keen.min_jump_height 
  130.             maxJumpHeight,                  -- entity.player.keen.max_jump_height 
  131.             minPogoHeight,                  -- entity.player.keen.min_pogo_height 
  132.             maxPogoHeight,                  -- entity.player.keen.max_pogo_height 
  133.             maxBounceHeight : Float := 0.0; -- entity.player.keen.max_bounce_height 
  134.             lookSpeed       : Float := 0.0; -- entity.player.keen.look_speed 
  135.         end record; 
  136.  
  137.     procedure Construct( this : access Keen ); 
  138.  
  139.     procedure Die( this : access Keen ); 
  140.  
  141.     procedure Face( this : access Keen; dir : Direction_Type ); 
  142.  
  143.     function Object_Input( stream : access Root_Stream_Type'Class ) return Keen; 
  144.     for Keen'Input use Object_Input; 
  145.  
  146.     procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Keen ); 
  147.     for Keen'Read use Object_Read; 
  148.  
  149.     procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Keen ); 
  150.     for Keen'Write use Object_Write; 
  151.  
  152.     procedure On_Hit_Wall( this         : access Keen; 
  153.                            dir          : Cardinal_Direction; 
  154.                            firstContact : Boolean ); 
  155.  
  156.     procedure Tick( this : access Keen; time : Tick_Time ); 
  157.  
  158.     procedure Update_Frame( this : access Keen; notify : Boolean := True ); 
  159.  
  160. end Entities.Players.Keen;