! Copyright (C) 2007 Alex Chapman
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel opengl arrays sequences jamshred.log jamshred.player jamshred.sound jamshred.tunnel math.vectors ;
+USING: accessors kernel opengl arrays sequences jamshred.log jamshred.player jamshred.sound jamshred.tunnel math math.constants math.vectors ;
IN: jamshred.game
TUPLE: jamshred sounds tunnel players running quit ;
: mouse-moved ( x-radians y-radians jamshred -- )
jamshred-player -rot turn-player ;
+: mouse-units-per-full-roll ( -- n ) 50 ;
+
+: mouse-scroll-x ( jamshred x -- )
+ [ jamshred-player ] dip 2 pi * * mouse-units-per-full-roll / roll-player ;
+
+: mouse-scroll-y ( jamshred y -- )
+ neg swap jamshred-player change-player-speed ;
] 2keep >>last-hand-loc drop ;
: handle-mouse-scroll ( jamshred-gadget -- )
- jamshred>> jamshred-player scroll-direction get
- second neg swap change-player-speed ;
+ jamshred>> scroll-direction get
+ [ first mouse-scroll-x ]
+ [ second mouse-scroll-y ] 2bi ;
: quit ( gadget -- )
[ no-fullscreen ] [ close-window ] bi ;
: up-pivot ( oint theta -- )
over up>> rotate-oint ;
+: forward-pivot ( oint theta -- )
+ over forward>> rotate-oint ;
+
: random-float+- ( n -- m )
#! find a random float between -n/2 and n/2
dup 10000 * >fixnum random 10000 / swap 2 / - ;
: turn-player ( player x-radians y-radians -- )
>r over r> left-pivot up-pivot ;
+: roll-player ( player z-radians -- )
+ forward-pivot ;
+
: to-tunnel-start ( player -- )
[ tunnel>> first dup location>> ]
[ tuck (>>location) (>>nearest-segment) ] bi ;