2009-07-13 11:39:34 +00:00
|
|
|
#lang scheme/base
|
2009-07-13 15:01:20 +00:00
|
|
|
(require scheme/class fluxus-016/fluxus "logic.ss" "view.ss")
|
2009-07-13 11:39:34 +00:00
|
|
|
(provide (all-defined-out))
|
|
|
|
|
|
|
|
; reads input events and tells the logic side what to do
|
|
|
|
|
|
|
|
(define controller%
|
|
|
|
(class object%
|
|
|
|
(init-field
|
|
|
|
(game-view #f))
|
2009-07-22 15:35:15 +00:00
|
|
|
|
2009-07-13 11:39:34 +00:00
|
|
|
(field
|
|
|
|
(fwd (vector 0 0 1))
|
|
|
|
(up (vector 0 1 0))
|
|
|
|
(pos (vector 0 0 0))
|
|
|
|
(mtx (mident))
|
|
|
|
(cam (build-locator))
|
|
|
|
(current-twig #f)
|
|
|
|
(current-twig-growing #f)
|
|
|
|
(current-point 0)
|
|
|
|
(tilt 0)
|
|
|
|
(yaw 0)
|
2009-07-22 15:35:15 +00:00
|
|
|
(player-plant #f)
|
2009-07-30 15:03:21 +00:00
|
|
|
(player-pos (vector 0 0 0))
|
2009-08-19 10:29:01 +00:00
|
|
|
(last-pos (vector 0 0 0))
|
2009-08-19 13:41:02 +00:00
|
|
|
(debounce-space #t)
|
|
|
|
(seed-return #f)
|
|
|
|
(seed-return-timer 0)
|
|
|
|
(seed-return-secs-per-point 3)
|
|
|
|
(twig-stack '()))
|
2009-07-13 11:39:34 +00:00
|
|
|
|
|
|
|
(define/public (set-player-plant s)
|
2009-07-22 15:35:15 +00:00
|
|
|
(set! pos (send s get-pos))
|
|
|
|
(set! player-pos (send s get-pos))
|
2009-07-13 11:39:34 +00:00
|
|
|
(set! player-plant s))
|
|
|
|
|
|
|
|
(define/public (get-cam-obj)
|
|
|
|
cam)
|
|
|
|
|
|
|
|
(define/public (set-pos s)
|
|
|
|
(set! pos s))
|
|
|
|
|
|
|
|
(define/public (set-fwd s)
|
|
|
|
(set! fwd s))
|
|
|
|
|
|
|
|
(define/public (get-fwd)
|
|
|
|
fwd)
|
|
|
|
|
|
|
|
(define/public (setup)
|
|
|
|
(lock-camera cam)
|
|
|
|
(camera-lag 0.2)
|
2009-08-21 15:03:36 +00:00
|
|
|
(clip 1 100)
|
2009-07-13 11:39:34 +00:00
|
|
|
(set-camera-transform (mtranslate (vector 0 0 -4))))
|
|
|
|
|
2009-07-30 15:03:21 +00:00
|
|
|
; moveme
|
|
|
|
(define (collide? line objs)
|
|
|
|
(foldl
|
|
|
|
(lambda (ob r)
|
|
|
|
(if r r
|
|
|
|
(with-primitive ob
|
|
|
|
(cond ((bb/point-intersect? (cadr line) 0)
|
|
|
|
(cond
|
|
|
|
((not (null? (geo/line-intersect
|
|
|
|
(car line) (cadr line))))
|
|
|
|
#t)
|
|
|
|
(else #f)))
|
|
|
|
(else #f)))))
|
|
|
|
|
|
|
|
#f
|
|
|
|
objs))
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-04 08:06:14 +00:00
|
|
|
(define/public (update t d)
|
2009-08-19 10:29:01 +00:00
|
|
|
(when (and (key-pressed " ") debounce-space (not current-twig-growing))
|
2009-08-19 13:41:02 +00:00
|
|
|
(set! seed-return #f)
|
2009-08-19 10:29:01 +00:00
|
|
|
(set! debounce-space #f)
|
|
|
|
(set! last-pos pos)
|
2009-07-30 15:03:21 +00:00
|
|
|
(cond (current-twig
|
|
|
|
(let ((new-twig (send player-plant add-sub-twig current-twig current-point
|
2009-07-22 15:35:15 +00:00
|
|
|
(vector 0 1 0) #;(vsub (send current-twig get-point current-point)
|
|
|
|
(send current-twig get-point (- current-point 1))))))
|
2009-07-13 11:39:34 +00:00
|
|
|
(set! current-twig-growing #t)
|
2009-08-19 13:41:02 +00:00
|
|
|
(set! twig-stack (cons (list current-point current-twig) twig-stack))
|
2009-07-13 11:39:34 +00:00
|
|
|
(set! current-twig new-twig)))
|
|
|
|
(else
|
|
|
|
(set! current-twig (make-object twig-logic% (vector 0 0 0) 0 player-plant 'root
|
|
|
|
(vmul fwd -1)
|
2009-08-21 15:03:36 +00:00
|
|
|
start-twig-width (send player-plant get-twig-size) 'extruded))
|
2009-07-22 15:35:15 +00:00
|
|
|
(send player-plant add-twig current-twig)
|
2009-08-19 10:29:01 +00:00
|
|
|
(set! current-twig-growing #t))))
|
2009-07-30 15:03:21 +00:00
|
|
|
|
2009-08-19 10:29:01 +00:00
|
|
|
(when (and (key-pressed " ") current-twig-growing)
|
|
|
|
(let ((vel (vmul fwd (* d -3))))
|
2009-07-30 15:03:21 +00:00
|
|
|
(when
|
|
|
|
(not (collide? (list pos (vadd pos vel)) (send game-view get-stones)))
|
|
|
|
(set! pos (vadd pos vel))
|
|
|
|
(when (> (vdist last-pos pos) (send current-twig get-dist))
|
|
|
|
(set! last-pos pos)
|
|
|
|
(send player-plant grow (vsub pos player-pos))))))
|
2009-08-19 10:29:01 +00:00
|
|
|
|
|
|
|
(when (and (not current-twig-growing) (not (key-pressed " ")))
|
|
|
|
(set! debounce-space #t))
|
2009-07-13 11:39:34 +00:00
|
|
|
|
|
|
|
(when (or (key-pressed "a") (key-special-pressed 100)) (set! yaw (+ yaw 2)))
|
|
|
|
(when (or (key-pressed "d") (key-special-pressed 102)) (set! yaw (- yaw 2)))
|
2009-07-22 15:35:15 +00:00
|
|
|
(when (or (key-pressed "w") (key-special-pressed 101)) (set! tilt (- tilt 2)))
|
2009-07-27 08:26:41 +00:00
|
|
|
(when (or (key-pressed "s") (key-special-pressed 103)) (set! tilt (+ tilt 2)))
|
|
|
|
|
2009-07-13 11:39:34 +00:00
|
|
|
; clamp tilt to prevent gimbal lock
|
|
|
|
(when (> tilt 88) (set! tilt 88))
|
|
|
|
(when (< tilt -88) (set! tilt -88))
|
2009-08-19 13:41:02 +00:00
|
|
|
|
|
|
|
(when seed-return
|
|
|
|
(cond ((< current-point 2)
|
|
|
|
(cond ((null? twig-stack)
|
|
|
|
(set! current-twig #f)
|
|
|
|
(set! pos player-pos)
|
|
|
|
(set! seed-return #f))
|
|
|
|
(else
|
|
|
|
(set! current-point (car (car twig-stack)))
|
|
|
|
(set! current-twig (cadr (car twig-stack)))
|
|
|
|
(set! twig-stack (cdr twig-stack)))))
|
|
|
|
|
|
|
|
(else
|
|
|
|
(set! seed-return-timer (- seed-return-timer d))
|
|
|
|
(set! pos (vadd player-pos (vmix (send current-twig get-point current-point)
|
|
|
|
(send current-twig get-point (- current-point 1))
|
|
|
|
(/ seed-return-timer seed-return-secs-per-point))))
|
|
|
|
(when (< seed-return-timer 0)
|
|
|
|
(set! seed-return-timer seed-return-secs-per-point)
|
|
|
|
(set! current-point (- current-point 1))))))
|
2009-07-22 15:35:15 +00:00
|
|
|
|
|
|
|
; get camera fwd vector from key-presses
|
|
|
|
(set! fwd (vtransform (vector 0 0 1)
|
|
|
|
(mmul
|
|
|
|
(mrotate (vector 0 yaw 0))
|
|
|
|
(mrotate (vector tilt 0 0)))))
|
2009-07-13 11:39:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
; if we are on a twig not growing
|
2009-08-19 13:41:02 +00:00
|
|
|
(when (and current-twig-growing (not (send current-twig growing?)))
|
|
|
|
(set! current-twig-growing #f)
|
|
|
|
(set! seed-return #t)
|
|
|
|
(set! current-point (- (send current-twig get-num-points) 1)))
|
2009-07-30 15:03:21 +00:00
|
|
|
|
2009-07-13 11:39:34 +00:00
|
|
|
(let* ((side (vnormalise (vcross up fwd)))
|
|
|
|
(up (vnormalise (vcross fwd side))))
|
2009-07-22 15:35:15 +00:00
|
|
|
|
2009-07-13 11:39:34 +00:00
|
|
|
(with-primitive cam
|
|
|
|
(identity)
|
|
|
|
(concat (vector (vx side) (vy side) (vz side) 0
|
2009-07-22 15:35:15 +00:00
|
|
|
(vx up) (vy up) (vz up) 0
|
|
|
|
(vx fwd) (vy fwd) (vz fwd) 0
|
|
|
|
(vx pos) (vy pos) (vz pos) 1)))))
|
2009-07-13 11:39:34 +00:00
|
|
|
|
|
|
|
(super-new)))
|