summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-12-14 08:37:05 -0500
committerDavid Thompson <dthompson2@worcester.edu>2018-12-14 08:37:05 -0500
commit86a3254c8ed0f29be6e07be5538d9c3b3222cb76 (patch)
tree5e7a1e6b0b302424397d44d74fb47fe26ec4682e
parentf2f90e8992420c3c3dd0b3ffa5e17ced4e9a4589 (diff)
Add particles example.
* examples/images/explosion.png: New file. * examples/particles.scm: New file. * Makefile.am (EXTRA_DIST): Add them.
-rw-r--r--Makefile.am2
-rw-r--r--examples/images/explosion.pngbin0 -> 10781 bytes
-rw-r--r--examples/particles.scm51
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
new file mode 100644
index 0000000..d64f54b
--- /dev/null
+++ b/examples/images/explosion.png
Binary files 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)