diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/animation.scm | 46 | ||||
-rw-r--r-- | examples/images/princess.png | bin | 0 -> 18491 bytes |
2 files changed, 46 insertions, 0 deletions
diff --git a/examples/animation.scm b/examples/animation.scm new file mode 100644 index 0000000..df713c5 --- /dev/null +++ b/examples/animation.scm @@ -0,0 +1,46 @@ +(use-modules (2d sprite) + (2d game-loop) + (2d window) + (2d vector) + (2d input) + (2d helpers)) + +(init-2d) + +(define window-width 800) +(define window-height 600) +(define sprite #f) + +(define (key-down key mod unicode) + (cond ((any-equal? key (keycode escape) (keycode q)) + (close-window) + (quit)))) + +;; Draw our sprite +(define (render) + (draw-sprite sprite)) + +;; Register callbacks. +(set-render-callback (lambda () (render))) +(set-key-down-callback (lambda (key mod unicode) (key-down key mod unicode))) + +;; Open the window. +(open-window window-width window-height) + +;; Load a texture, split it into 64x64 tiles, and build an animated +;; sprite out of it. +(let* ((tiles (split-texture (load-texture "images/princess.png") 64 64)) + (frames (vector (vector-ref tiles 19) + (vector-ref tiles 20) + (vector-ref tiles 21) + (vector-ref tiles 22) + (vector-ref tiles 23) + (vector-ref tiles 24) + (vector-ref tiles 25) + (vector-ref tiles 26))) + (animation (make-animation frames 6 #t))) + (set! sprite (make-sprite animation + #:position (vector (/ window-width 2) + (/ window-height 2))))) + +(run-game-loop) diff --git a/examples/images/princess.png b/examples/images/princess.png Binary files differnew file mode 100644 index 0000000..ee21753 --- /dev/null +++ b/examples/images/princess.png |