summaryrefslogtreecommitdiff
path: root/examples/simple.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-06-24 21:03:57 -0400
committerDavid Thompson <dthompson@member.fsf.org>2013-06-24 21:03:57 -0400
commit17a61d9d0c5675a1b5bf8a3abac15c62a0eb1181 (patch)
tree827272287d92e3b96295b8a2f405833bae6a9e87 /examples/simple.scm
parentcb07110140be0bd3d57e76b5eace17c1efccf4a8 (diff)
Add some rough example programs.
Diffstat (limited to 'examples/simple.scm')
-rw-r--r--examples/simple.scm36
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/simple.scm b/examples/simple.scm
new file mode 100644
index 0000000..f9ee142
--- /dev/null
+++ b/examples/simple.scm
@@ -0,0 +1,36 @@
+(use-modules ((sdl sdl) #:prefix SDL:)
+ (figl gl)
+ (2d sprite)
+ (2d game-loop)
+ (2d window)
+ (2d vector))
+
+(define window-width 800)
+(define window-height 600)
+(define sprite #f)
+
+(define (key-down key)
+ (case key
+ ;; Quit program when ESCAPE or Q is pressed.
+ ((SDLK_ESCAPE SDLK_q)
+ (close-window)
+ (quit))))
+
+(define (render)
+ (draw-sprite sprite))
+
+;; Register callbacks.
+(set-render-callback (lambda () (render)))
+(set-key-down-callback (lambda (key) (key-down key)))
+
+;; Open the window.
+(open-window window-width window-height)
+
+;; Load a sprite.
+;; Must be done AFTER opening the window.
+(set! sprite (load-sprite "sprite.png" #:position (vector (/ window-width 2)
+ (/ window-height 2))))
+
+;; Start the game loop.
+;; The render callback will be called through this procedure.
+(run-game-loop)