diff options
author | David Thompson <dthompson2@worcester.edu> | 2019-07-24 16:41:07 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2019-07-24 16:41:07 -0400 |
commit | e2ead85d6157299566e9aaaf0437a001aad7a6d9 (patch) | |
tree | 2e64563be0013c8d424a8458a0c6829815c13001 /examples | |
parent | 50d0f6777f6bb131dedb053de2116cc414ef1ae8 (diff) |
examples: Update particle example.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/particles.scm | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/examples/particles.scm b/examples/particles.scm index 4fd7ea3..c51f62f 100644 --- a/examples/particles.scm +++ b/examples/particles.scm @@ -2,31 +2,49 @@ (chickadee math rect) (chickadee math vector) (chickadee render) + (chickadee render color) (chickadee render font) (chickadee render particles) + (chickadee render sprite) (chickadee render texture) (chickadee scripting) (ice-9 format) ((sdl2) #:select (sdl-ticks))) +(define window-width 800) +(define window-height 600) (define particles #f) -(define texture #f) +(define emitter #f) +(define particle-texture #f) +(define sprite-texture #f) (define start-time (sdl-ticks)) (define avg-frame-time 0) (define stats-text "") +(define (center-x w) + (- (/ window-width 2.0) (/ w 2.0))) + +(define (center-y h) + (- (/ window-height 2.0) (/ h 2.0))) + (define (load) (set! *random-state* (random-state-from-platform)) - (set! texture (load-image "images/explosion.png")) - (set! particles (make-particles 1000 - #:texture texture + (set! particle-texture (load-image "images/explosion.png")) + (set! sprite-texture (load-image "images/chickadee.png")) + (set! particles (make-particles 2000 + #:texture particle-texture + #:end-color (make-color 1.0 1.0 1.0 0.8) + #:end-color (make-color 1.0 1.0 1.0 0.0) + #:speed-range (vec2 1.0 5.0) + ;;#:acceleration-range (vec2 -0.1 -0.2) + #:lifetime 40 #:animation-columns 12 - #:speed-range (vec2 1.0 10.0) - #:lifetime 50 #:sort 'young)) - (add-particle-emitter particles - (make-particle-emitter (make-rect 320.0 240.0 0.0 0.0) - 8)) + (set! emitter (make-particle-emitter (make-rect (center-x 0.0) + (center-y 0.0) + 0.0 0.0) + 8)) + (add-particle-emitter particles emitter) (script (forever (sleep 60) @@ -34,9 +52,11 @@ (particles-size particles) (/ 1000.0 avg-frame-time)))))) -(define stats-text-pos (vec2 4.0 464.0)) +(define stats-text-pos (vec2 4.0 (- window-height 16.0))) +(define sprite-position (vec2 (center-x 128.0) (center-y 128.0))) (define (draw alpha) (draw-particles particles) + (draw-sprite sprite-texture sprite-position) (draw-text stats-text stats-text-pos) (let ((current-time (sdl-ticks))) (set! avg-frame-time @@ -48,4 +68,15 @@ (update-agenda 1) (update-particles particles)) -(run-game #:load load #:draw draw #:update update) +(define (mouse-move x y dx dy buttons) + (let ((area (particle-emitter-spawn-area emitter))) + (set-rect-x! area x) + (set-rect-y! area y) + (set-vec2! sprite-position (- x 64.0) (- y 64.0)))) + +(run-game #:load load + #:draw draw + #:update update + #:mouse-move mouse-move + #:window-width window-width + #:window-height window-height) |