diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | examples/images/explosion.png | bin | 0 -> 10781 bytes | |||
-rw-r--r-- | examples/particles.scm | 51 |
3 files changed, 53 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index d80831a..493f415 100644 --- a/Makefile.am +++ b/Makefile.am @@ -84,11 +84,13 @@ EXTRA_DIST += \ examples/lines.scm \ examples/text.scm \ examples/nine-patch.scm \ + examples/particles.scm \ examples/tiled.scm \ examples/grid.scm \ examples/images/AUTHORS \ examples/images/chickadee.png \ examples/images/dialog-box.png \ + examples/images/explosion.png \ examples/images/tiles.png \ examples/maps/example.tmx diff --git a/examples/images/explosion.png b/examples/images/explosion.png Binary files differnew file mode 100644 index 0000000..d64f54b --- /dev/null +++ b/examples/images/explosion.png 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) |