require assets.fs

: clear-screen page ;
: print-nl 10 emit ;


: clear-screen-funny ( n -- )
  form nip 1 - 0 ?do
    i over at-xy ."  "
    0 ms
  loop
  drop
  ;

: clear-screen-funny ( -- )
  form drop 1 - 0 ?do
    i clear-screen-funny
  loop
  ;

: banner-screen ( -- )
  clear-screen

  form ( height width )
  2 / swap 2 /
  banner
  print-nl print-nl print-nl
  ."     "
  ;

: help-screen ( -- )
  clear-screen
  ." Welcome to Forth Invaders" print-nl
  print-nl
  ." Here is how you control your ship" print-nl
  ." LEFT/RIGHT-Arrow: move left/right" print-nl
  ." INSERT: shoot" print-nl
  ." END: Quit the game immediately" print-nl
  ." ESCAPE: Display the pause menu" print-nl

  print-nl
  ;

: end-screen ( level points -- )
  >r >r
  clear-screen

  form 2 / swap 2 / 2dup 4 - game-over-banner
  swap 6 - swap
  2dup     at-xy ." Level:  " r> .
  2dup 1 + at-xy ." Points: " r> .
  swap 5 - swap
       3 + at-xy ." Press ENTER to quit"
  ;

: pause-screen ( -- continue? )
  form 2 / swap 2 /
  ( centerx centery )
  3 - swap 10 -
  swap
  2dup     at-xy ."                      "
  2dup 1 + at-xy ."  /=================\ "
  2dup 2 + at-xy ."  |  Keep playing?  | "
  2dup 3 + at-xy ."  |  [Y]es  [N]o    | "
  2dup 4 + at-xy ."  \=================/ "
       5 + at-xy ."                      "
  begin
    ekey
    case
      k-end of clear-screen bye endof
      121 of 1 endof \ y-key
      89 of 1 endof \ Y-key
      110 of 0 endof \ n-key
      78 of 0 endof \ N-key
      27 of 1 endof \ ESC-key
      -1 swap
    endcase
    dup -1 = while drop
  repeat
  ;
