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 Events.Listeners;                  use Events.Listeners; 
  10.  
  11. private with Allegro.Keyboard; 
  12. private with Entities; 
  13. private with Events; 
  14.  
  15. package Widgets.Containers.Game_Screens.Game_Play is 
  16.  
  17.     -- The game play screen contains the main Scene widget where all game play 
  18.     -- occurs. It is responsible for input to the scene during game play, 
  19.     -- and handling events relevant to the scene, the progress board, and score 
  20.     -- board. 
  21.     type Game_Play_Screen is new Game_Screen and Event_Listener with private; 
  22.  
  23.     -- Creates a new game play screen. 
  24.     function Create_Game_Play_Screen( view : not null access Game_Views.Game_View'Class; 
  25.                                       id   : String ) return A_Game_Screen; 
  26.  
  27. private 
  28.  
  29.     use Allegro.Keyboard; 
  30.     use Entities; 
  31.     use Events; 
  32.  
  33.     type Key_Purpose is ( 
  34.         MOVE_UP,        -- move/look up 
  35.         MOVE_DOWN,      -- move/look down 
  36.         MOVE_LEFT,      -- move left 
  37.         MOVE_RIGHT,     -- move right 
  38.         JUMP,           -- jump up 
  39.         POGO,           -- toggle pogostick 
  40.         SHOOT,          -- shoot stunner gun 
  41.         PROGRESS,       -- toggle progress board 
  42.         PAUSE,          -- pause/resume play 
  43.         MENU            -- exit to menu 
  44.     ); 
  45.  
  46.     type Key_Binding_Array is array (Key_Purpose) of Integer; 
  47.  
  48.     type Boolean_Key_Array is array (1..ALLEGRO_KEY_MAX) of Boolean; 
  49.  
  50.     type Game_Play_Screen is new Game_Screen and Event_Listener with 
  51.         record 
  52.             -- an array of key scancodes bound to key purposes 
  53.             key : Key_Binding_Array; 
  54.  
  55.             -- events from these keys sent to the scene should be ignored until 
  56.             -- the next key press event. 
  57.             ignoreKey : Boolean_Key_Array := Boolean_Key_Array'(others => False); 
  58.  
  59.             -- the id of the player entity, for sending impulses. 
  60.             playerId : Entity_Id := INVALID_ID; 
  61.         end record; 
  62.  
  63.     procedure Construct( this : access Game_Play_Screen; 
  64.                          view : not null access Game_Views.Game_View'Class; 
  65.                          id   : String ); 
  66.  
  67.     procedure Delete( this : in out Game_Play_Screen ); 
  68.  
  69.     procedure Activate( this : access Game_Play_Screen ); 
  70.  
  71.     -- Inherited from the Event_Listener interface. Handles events that the view 
  72.     -- is registered to receive. 
  73.     procedure Handle_Event( this : access Game_Play_Screen; 
  74.                             evt  : in out A_Event; 
  75.                             resp : out Response_Type ); 
  76.     pragma Precondition( evt /= null ); 
  77.  
  78. end Widgets.Containers.Game_Screens.Game_Play;