--
-- 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.
--
package Entities.Players.Keen is
type Keen is new Player with private;
type A_Keen is access all Keen'Class;
-- Checks if Keen can teleport and then queues the events needed to enter
-- the teleport state. This is called by a trigger entity that is
-- teleporting Keen.
procedure Teleport( this : access Keen;
fromX, fromY : Float;
toX, toY : Float );
private
-- Time between shots
SHOOT_DURATION : constant Time_Span := Milliseconds( 215 );
-- The amount of time Keen spends walking into a doorway when teleporting
TELEPORT_DURATION : constant Time_Span := Milliseconds( 600 );
function Get_Keen_Pref( shortName : String ) return Float;
----------------------------------------------------------------------------
-- each Action_Type value represents a different state of Keen, in which
-- he's performing the action.
type Action_Type is
(
Act_Moving, -- standing or moving (on ground and in the air)
Act_Looking, -- standing still, looking up or down
Act_Looking_Back, -- returning to center after looking up or down
Act_Teleporting, -- teleportation animation
Act_Idle, -- performing a bored animation due to idleness
Act_Rising, -- standing up after sitting down bored
Act_Dying, -- death animation
Act_Climbing -- hanging onto a pole (still or moving)
);
-- Sub actions:
-- Shooting
-- Pogoing
type State is abstract tagged limited
record
action : Action_Type; -- constant after initialization
end record;
type A_State is access all State'Class;
function Get_Frame( this : State;
k : Keen'Class ) return Natural is abstract;
procedure Update( this : State;
k : A_Keen;
time : Tick_Time ) is abstract;
----------------------------------------------------------------------------
type Keen is new Player with
record
-- *** these fields are streamed ***
-- true when keen is jumping (actively accelerating upward)
jumping : Boolean := False;
-- the world y location of where keen will be at the maximum height
-- height of his jump. this is set when a jump is started, and
-- will be < 0 if no jump is in progress.
jumpApexMin : Float := -1.0;
jumpApexMax : Float := -1.0;
-- true if keen is on his pogo stick. note that jumping and grounded
-- are independent states and may or may not be true.
onPogo : Boolean := False;
-- true if keen is currently shooting. keen may shoot while
-- performing certain actions. (ie: moving, hanging from a pole)
shooting : Boolean := False;
-- the time when keen last fired a shot, used for keeping a delay
-- between shots.
shootStart : Time_Span := Time_Span_Zero; -- (relative to .age)
-- keen's current state
state : A_State := null; -- streamed as Action_Type
stateStart : Time_Span := Time_Span_Zero; -- (relative to .age)
stateDuration : Time_Span := Time_Span_Zero;
idleStart : Time_Span := Time_Span_Zero; -- (relative to .age)
idleNumber : Positive := 1; -- number of the next idle animation
-- for the teleporting state
teleportX, -- teleport destination
teleportY : Float := 0.0; --
-- for the climbing state
poleId : Entity_Id := INVALID_ID; -- id of pole being climbed (action = Act_Climbing)
poleTop : Boolean := False; -- reached the top of the pole
poleBottom : Boolean := False; -- reached the bottom of the pole (works but not used)
deathX,
deathY : Float := 0.0; -- location of keen when he died
-- ** these fields do not need to be streamed **
dead : Boolean := False; -- dead fully dead? (temporary)
minJumpHeight, -- entity.player.keen.min_jump_height
maxJumpHeight, -- entity.player.keen.max_jump_height
minPogoHeight, -- entity.player.keen.min_pogo_height
maxPogoHeight, -- entity.player.keen.max_pogo_height
maxBounceHeight : Float := 0.0; -- entity.player.keen.max_bounce_height
lookSpeed : Float := 0.0; -- entity.player.keen.look_speed
end record;
procedure Construct( this : access Keen );
procedure Change_State( this : not null access Keen'Class;
state : not null A_State;
length : Time_Span := Time_Span_Zero );
procedure Die( this : access Keen );
-- Returns True if an action duration has not yet been met and False when
-- the current action's duration has expired.
function Is_Busy( this : not null access Keen'Class ) return Boolean;
function Object_Input( stream : access Root_Stream_Type'Class ) return Keen;
for Keen'Input use Object_Input;
procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Keen );
for Keen'Read use Object_Read;
procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Keen );
for Keen'Write use Object_Write;
procedure On_Hit_Wall( this : access Keen;
dir : Cardinal_Direction;
firstContact : Boolean );
procedure Reset_Idle( this : not null access Keen'Class );
procedure Update( this : access Keen; time : Tick_Time );
procedure Update_Frame( this : access Keen; notify : Boolean := True );
end Entities.Players.Keen;