From 86a3254c8ed0f29be6e07be5538d9c3b3222cb76 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 14 Dec 2018 08:37:05 -0500 Subject: Add particles example. * examples/images/explosion.png: New file. * examples/particles.scm: New file. * Makefile.am (EXTRA_DIST): Add them. --- examples/images/explosion.png | Bin 0 -> 10781 bytes examples/particles.scm | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 examples/images/explosion.png create mode 100644 examples/particles.scm (limited to 'examples') diff --git a/examples/images/explosion.png b/examples/images/explosion.png new file mode 100644 index 0000000..d64f54b Binary files /dev/null and b/examples/images/explosion.png differ diff --git a/examples/particles.scm b/examples/particles.scm new file mode 100644 index 0000000..4fd7ea3 --- /dev/null +++ b/examples/particles.scm @@ -0,0 +1,51 @@ +(use-modules (chickadee) + (chickadee math rect) + (chickadee math vector) + (chickadee render) + (chickadee render font) + (chickadee render particles) + (chickadee render texture) + (chickadee scripting) + (ice-9 format) + ((sdl2) #:select (sdl-ticks))) + +(define particles #f) +(define texture #f) +(define start-time (sdl-ticks)) +(define avg-frame-time 0) +(define stats-text "") + +(define (load) + (set! *random-state* (random-state-from-platform)) + (set! texture (load-image "images/explosion.png")) + (set! particles (make-particles 1000 + #:texture texture + #: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)) + (script + (forever + (sleep 60) + (set! stats-text (format #f "particles: ~d fps: ~1,2f" + (particles-size particles) + (/ 1000.0 avg-frame-time)))))) + +(define stats-text-pos (vec2 4.0 464.0)) +(define (draw alpha) + (draw-particles particles) + (draw-text stats-text stats-text-pos) + (let ((current-time (sdl-ticks))) + (set! avg-frame-time + (+ (* (- current-time start-time) 0.1) + (* avg-frame-time 0.9))) + (set! start-time current-time))) + +(define (update dt) + (update-agenda 1) + (update-particles particles)) + +(run-game #:load load #:draw draw #:update update) -- cgit v1.2.3