-- bounce1d.adb
--   Purpose: Animation with user controlled speed and direction.
--   Note:    The handler does the animation
--            The main program reads keyboard input
--   Compile: make bounce1d

with
  Terminal_Interface.Curses,
  C_Signals;

with Ticker;
with State_1D;
with Move_Message;

procedure Bouncer_1D is
   use
     Terminal_Interface.Curses,
     C_Signals,
     State_1D;
   Key : Real_Key_Code;
begin
   Init_Screen;
   Set_Cbreak_Mode (True);
   Set_Echo_Mode (False);
   Clear;

   Move_Cursor (Line => Row, Column => Column);
   Add (Str => Message);
   Attach (Handler => Move_Message'Access,
           To      => Signal_Alarm);
   Ticker.Start (Period);

   loop
      Key := Get_Keystroke;
      if Key in Normal_Key_Code then
         case Character'Val (Key) is
            when 'Q' =>
               exit;
            when ' ' =>
               Direction := - Direction;
            when 'f' =>
               if Period > Minimum_Period then
                  Period := Period / 2.0;
                  Ticker.Start (Period);
               end if;
            when 's' =>
               Period := Period * 2.0;
               Ticker.Start (Period);
            when others =>
               null;
         end case;
      end if;
   end loop;

   End_Screen;
exception
   when others =>
      End_Screen;
end Bouncer_1D;

