--
--	Occade collision detection test
--	Copyright (C) 2007  University of Kent
--
--	This program is free software; you can redistribute it and/or
--	modify it under the terms of the GNU General Public License as
--	published by the Free Software Foundation, either version 2 of the
--	License, or (at your option) any later version.
--
--	This program is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--	General Public License for more details.
--
--	You should have received a copy of the GNU General Public License
--	along with this program.  If not, see
--	<http://www.gnu.org/licenses/>.
--

--** Test collision detection in Occade.
--
-- This should only show one collision per cycle (twice, because both sprites
-- see the collision).
--
-- @module occade.collision-test

#INCLUDE "occade.module"

--{{{ PROC main
--* Entry point.
PROC main ()
  SHARED OCCADE! occade:
  INITIAL OCCADE.PARAMS params IS occade.default.params:

  OCCADE.SPRITE! big, little:

  FORKING
    TIMER tim:
    INT t:
    SEQ
      params[width] := 640
      params[height] := 480
      occade.start (occade, params, "Occade collision test")

      occade.start.sprite (occade, big, 1)
      big[req] ! load.image; "images/red-spot.png"
      big[req] ! visible; TRUE
      big[req] ! collisions; TRUE
      big[req] ! move; 320; 240; TRUE

      occade.start.sprite (occade, little, 2)
      little[req] ! load.image; "images/green-ball.png"
      little[req] ! visible; TRUE
      little[req] ! collisions; TRUE

      tim ? t
      WHILE TRUE
        SEQ
          occade.write ("start new cycle*n")
          SEQ x = 250 FOR 640 - (250 * 2)
            OCCADE.COLLISION coll:
            PROC show.coll (VAL INT my.id)
              SEQ
                occade.write.int (my.id)
                occade.write (" collides with ")
                occade.write.int (coll[id])
                occade.write ("*n")
            :
            SEQ
              little[req] ! move; x; 240; TRUE

              INITIAL BOOL colliding IS TRUE:
              WHILE colliding
                PRI ALT
                  big[collisions] ? coll
                    show.coll (1)
                  little[collisions] ? coll
                    show.coll (2)
                  tim ? AFTER t PLUS 10000
                    colliding := FALSE

              tim ? t
:
--}}}
