sommercamp fixes on the last day - sounds, space is grow key, fixes

This commit is contained in:
Dave Griffiths 2009-08-19 11:29:01 +01:00
parent 745c5583d7
commit c9c24c7b8d
12 changed files with 132 additions and 33 deletions

View file

@ -22,7 +22,8 @@
(yaw 0) (yaw 0)
(player-plant #f) (player-plant #f)
(player-pos (vector 0 0 0)) (player-pos (vector 0 0 0))
(last-pos (vector 0 0 0))) (last-pos (vector 0 0 0))
(debounce-space #t))
(define/public (set-player-plant s) (define/public (set-player-plant s)
(set! pos (send s get-pos)) (set! pos (send s get-pos))
@ -67,8 +68,9 @@
(define/public (update t d) (define/public (update t d)
(when (and (key-pressed " ") (not current-twig-growing)) (when (and (key-pressed " ") debounce-space (not current-twig-growing))
(set! last-pos pos) (set! debounce-space #f)
(set! last-pos pos)
(cond (current-twig (cond (current-twig
(let ((new-twig (send player-plant add-sub-twig current-twig current-point (let ((new-twig (send player-plant add-sub-twig current-twig current-point
(vector 0 1 0) #;(vsub (send current-twig get-point current-point) (vector 0 1 0) #;(vsub (send current-twig get-point current-point)
@ -80,16 +82,19 @@
(vmul fwd -1) (vmul fwd -1)
start-twig-width max-twig-points 'extruded)) start-twig-width max-twig-points 'extruded))
(send player-plant add-twig current-twig) (send player-plant add-twig current-twig)
(set! current-twig-growing #t)))) (set! current-twig-growing #t))))
(when (and (key-pressed "f") current-twig-growing) (when (and (key-pressed " ") current-twig-growing)
(let ((vel (vmul fwd (* d -3)))) (let ((vel (vmul fwd (* d -3))))
(when (when
(not (collide? (list pos (vadd pos vel)) (send game-view get-stones))) (not (collide? (list pos (vadd pos vel)) (send game-view get-stones)))
(set! pos (vadd pos vel)) (set! pos (vadd pos vel))
(when (> (vdist last-pos pos) (send current-twig get-dist)) (when (> (vdist last-pos pos) (send current-twig get-dist))
(set! last-pos pos) (set! last-pos pos)
(send player-plant grow (vsub pos player-pos)))))) (send player-plant grow (vsub pos player-pos))))))
(when (and (not current-twig-growing) (not (key-pressed " ")))
(set! debounce-space #t))
(when (or (key-pressed "a") (key-special-pressed 100)) (set! yaw (+ yaw 2))) (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))) (when (or (key-pressed "d") (key-special-pressed 102)) (set! yaw (- yaw 2)))
@ -101,7 +106,7 @@
(when (< tilt -88) (set! tilt -88)) (when (< tilt -88) (set! tilt -88))
(when (not current-twig-growing) (when (not current-twig-growing)
(when (key-pressed "q") (when (key-pressed "x")
(cond ((not current-twig) (cond ((not current-twig)
(set! current-twig (send player-plant get-twig-from-dir (vmul fwd -1))) (set! current-twig (send player-plant get-twig-from-dir (vmul fwd -1)))
(set! current-point 2)) (set! current-point 2))

View file

@ -17,6 +17,7 @@
(define ornament-grow-probability 8) (define ornament-grow-probability 8)
(define curl-amount 40) (define curl-amount 40)
(define start-size 50) (define start-size 50)
(define max-ornaments 10) ; per twig
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the base class logic object - all logic side objects can ; the base class logic object - all logic side objects can
@ -198,14 +199,14 @@
(send (cadr (choose twigs)) get-random-twig))) (send (cadr (choose twigs)) get-random-twig)))
(define/public (add-ornament point-index ornament) (define/public (add-ornament point-index ornament)
; todo - check max ornaments (when (< (length ornaments) max-ornaments)
(send-message 'new-ornament (send-message 'new-ornament
(list (list
(list 'plant-id (send plant get-id)) (list 'plant-id (send plant get-id))
(list 'twig-id id) (list 'twig-id id)
(list 'point-index point-index) (list 'point-index point-index)
(list 'property (send ornament get-property)))) (list 'property (send ornament get-property))))
(set! ornaments (cons (list point-index ornament) ornaments))) (set! ornaments (cons (list point-index ornament) ornaments))))
(define/public (get-ornament point-index) (define/public (get-ornament point-index)
(cadr (assq point-index ornaments))) (cadr (assq point-index ornaments)))
@ -487,7 +488,7 @@
(inherit send-message) (inherit send-message)
(define/public (setup world-list) (define/public (setup world-list)
(let ((pickups (list-ref world-list 1))) (let ((pickups '() #;(list-ref world-list 1)))
(let ((i 0)) (let ((i 0))
(for-each (for-each
(lambda (pickup) (lambda (pickup)

View file

@ -0,0 +1,30 @@
varying vec3 N;
varying vec3 L;
varying vec3 V;
varying vec2 T;
uniform sampler2D BaseMap;
void main()
{
vec3 n = normalize(N);
vec3 l = normalize(L);
vec3 v = normalize(V);
float HighlightSize=0.1;
float ShadowSize=0.2;
float OutlineWidth=0.4;
vec4 MidColour=gl_FrontMaterial.diffuse;
vec4 HighlightColour=MidColour*2.0;
vec4 ShadowColour=MidColour*0.5;
HighlightColour.a=1.0;
ShadowColour.a=1.0;
float lambert = dot(l,n);
vec4 colour = MidColour;
if (lambert > 1.0-HighlightSize) colour = HighlightColour;
if (lambert < ShadowSize) colour = ShadowColour;
if (dot(n,v) < OutlineWidth) colour = vec4(0,0,0,1);
gl_FragColor = colour*texture2D(BaseMap, T);
}

View file

@ -0,0 +1,18 @@
// Copyright (C) 2007 Dave Griffiths
// Licence: GPLv2 (see COPYING)
varying vec3 N;
varying vec3 P;
varying vec3 V;
varying vec3 L;
varying vec2 T;
void main()
{
N = normalize(gl_NormalMatrix*gl_Normal);
P = gl_Vertex.xyz;
V = -vec3(gl_ModelViewMatrix*gl_Vertex);
vec4 LightPos = gl_LightSource[1].position;
L = vec3(gl_ModelViewMatrix*(LightPos-gl_Vertex));
T = gl_MultiTexCoord0.xy;
gl_Position = ftransform();
}

View file

@ -0,0 +1,26 @@
varying vec3 normal, lightDir;
varying vec2 texCoord;
uniform sampler2D texture;
void main()
{
float intensity;
vec3 n;
vec4 _color;
n = normalize(normal);
intensity = dot(lightDir, n);
if (intensity > 0.98)
_color = vec4(1.0,1.0,1.0,1.0);
else if (intensity > 0.5)
_color = vec4(0.8,0.8,0.8,1.0);
else if (intensity > 0.35)
_color = vec4(0.4,0.4,0.4,1.0);
else if (intensity > 0)
_color = vec4(0.0,0.0,0.0,1.0);
else _color = texture2D(texture, texCoord);
gl_FragColor = _color;
}

View file

@ -0,0 +1,14 @@
varying vec3 normal, lightDir;
varying vec2 texCoord;
void main()
{
vec4 ecPos;
ecPos = vec4(gl_ModelViewMatrix * gl_Vertex);
lightDir = normalize(vec3(gl_LightSource[0].position) - ecPos.xyz);
normal = normalize(gl_NormalMatrix * gl_Normal);
texCoord = vec2(gl_MultiTexCoord0);
gl_Position = ftransform();
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -15,7 +15,6 @@
(define wire-mode #f) (define wire-mode #f)
(define fog-col (earth-colour)) (define fog-col (earth-colour))
(define fog-strength 0.001) (define fog-strength 0.001)
(define max-ornaments 10) ; per twig
(define default-grow-speed 0.5) (define default-grow-speed 0.5)
(define grow-overshoot 10) (define grow-overshoot 10)
@ -26,6 +25,10 @@
(pdata-copy "p" "rip-pref"))) (pdata-copy "p" "rip-pref")))
(define (clamp v l u)
(if (< v l) l
(if (> v u) u v)))
(define (ripple t speed wave-length) (define (ripple t speed wave-length)
(pdata-map! (pdata-map!
(lambda (p pref) (lambda (p pref)
@ -36,9 +39,9 @@
(vector 0 0 0)))))))))) (vector 0 0 0))))))))))
"p" "rip-pref")) "p" "rip-pref"))
(define (play-sound sound pos freq) (define (play-sound sound pos freq vol)
(when audio-on (let ((growing-noise (oa-load-sample (fullpath "snd/event01.wav")))) (when audio-on (let ((noise (oa-load-sample (fullpath sound))))
(oa-play growing-noise (vector 0 0 0) (rndf) 0.3)))) (oa-play noise pos freq vol))))
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -53,11 +56,13 @@
(time 0) (time 0)
(ev-time 0) (ev-time 0)
(ev-dur 8) (ev-dur 8)
(ev-col (vector 0 0 1))) (ev-col (vector 0 0 1))
(light 0))
(field (field
(const-scale (if (eq? property 'leaf) 2 4)) (const-scale (if (eq? property 'leaf) 2 4))
(rot (vector 0 0 0)) (rot (vector 0 0 0))
(excitation-changed #f)
(root (with-state (root (with-state
(translate pos) (translate pos)
;(hint-frustum-cull) ;(hint-frustum-cull)
@ -128,10 +133,11 @@
0))) 0)))
(define/public (set-excitations! a b) (define/public (set-excitations! a b)
(set! excitation-changed #t)
(set! light a)
(set! ev-dur (if (zero? a) 9999 (/ 1 a))) (set! ev-dur (if (zero? a) 9999 (/ 1 a)))
(set! ev-col (vmix (vector 0 0 1) (vector 1 0 0) b)) (set! ev-col (vmix (vector 0 0 1) (vector 1 0 0) b))
(set! ev-time (* ev-dur 4 (rndf))) (set! ev-time (* ev-dur 4 (rndf))))
(printf "excite: ~a ~a~n" ev-dur ev-col))
(define/public (update t d) (define/public (update t d)
(when (< time 1) (when (< time 1)
@ -143,13 +149,12 @@
(scale (* const-scale sc 0.2 time))) (scale (* const-scale sc 0.2 time)))
(set! time (+ time (* 0.05 d)))) (set! time (+ time (* 0.05 d))))
(when (eq? property 'inflatoe) (when (and (eq? property 'inflatoe) excitation-changed)
(with-primitive root (with-primitive root
(pdata-map! (pdata-map!
(lambda (p p1 p2) (lambda (p p1 p2)
(vmix p1 p2 (+ 0.5 (* 0.5 (sin ev-time))))) (vmix p1 p2 (clamp light 0 1)))
"p" "p1" "p2")) "p" "p1" "p2")))
(set! ev-time (+ ev-time d)))
(when (eq? property 'horn) (when (eq? property 'horn)
(with-primitive particles (with-primitive particles
@ -157,7 +162,8 @@
(pdata-op "*" "c" 0.995)) (pdata-op "*" "c" 0.995))
(when (< ev-time 0) (when (< ev-time 0)
(play-sound "snd/wateringcan.wav" pos (+ 0.1 (rndf)) 0.3)
#;(with-primitive root #;(with-primitive root
(identity) (identity)
(translate pos) (translate pos)
@ -175,7 +181,9 @@
(vector 0 0 0)))) (vector 0 0 0))))
"p")) "p"))
(set! ev-time ev-dur)) (set! ev-time ev-dur))
(set! ev-time (- ev-time d)))) (set! ev-time (- ev-time d)))
(set! excitation-changed #f))
(super-new))) (super-new)))
@ -309,9 +317,7 @@
(set! markers (cons (build-locator) markers))) (set! markers (cons (build-locator) markers)))
(define/pubment (add-point point width) (define/pubment (add-point point width)
(when audio-on (let ((growing-noise (oa-load-sample (fullpath "snd/event01.wav")))) (play-sound "snd/event01.wav" point (+ 0.1 (rndf)) 0.3)
(oa-play growing-noise (vector 0 0 0) (rndf) 0.3)))
(set! markers (append markers (list (with-state (set! markers (append markers (list (with-state
(parent (get-root)) (parent (get-root))
(translate point) (translate point)
@ -322,10 +328,9 @@
(inner (void) add-point point width)) (inner (void) add-point point width))
(define/public (add-ornament point-index property) (define/public (add-ornament point-index property)
(when (and (when (< point-index grow-t)
(< point-index grow-t) (play-sound "snd/nix.00203.wav" (get-point point-index) (+ 0.1 (rndf)) 0.3)
(< (length ornaments) max-ornaments))
(with-state (with-state
(parent (get-root)) (parent (get-root))
; todo - different ornament-view objects per property needed? ; todo - different ornament-view objects per property needed?
@ -353,7 +358,7 @@
(inner (void) update t d) (inner (void) update t d)
(when (< grow-t (+ num-points grow-overshoot)) (when (and (not (eq? grow-t -1)) (< grow-t (+ num-points grow-overshoot)))
(set! grow-t (+ grow-t (* d grow-speed))) (set! grow-t (+ grow-t (* d grow-speed)))
(when (and (not (null? markers)) (> 0 (- marker-destroy-t grow-t))) (when (and (not (null? markers)) (> 0 (- marker-destroy-t grow-t)))
; soundtodo: marker gobble ; soundtodo: marker gobble
@ -475,7 +480,7 @@
(set! index (+ index 1))) (set! index (+ index 1)))
(define/augment (update t d) (define/augment (update t d)
(when (not (eq? grow-t 999)) (when (and (not (eq? grow-t -1)) (not (eq? grow-t 999)))
(with-primitive root (with-primitive root
(partial-extrude grow-t profile path widths (vector 1 0 0) 0.05))) (partial-extrude grow-t profile path widths (vector 1 0 0) 0.05)))