summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-08-15 18:59:34 -0400
committerDavid Thompson <dthompson@member.fsf.org>2013-08-15 18:59:34 -0400
commitf5abf968e86cbd55f5a79f8b6826eac42f93ee9f (patch)
tree0108292950e8d5b1ed9c459399f83409acfc59aa /examples
parent8748076e491ac5500c7b05248c6ad1c14458b937 (diff)
Update examples.
Diffstat (limited to 'examples')
-rw-r--r--examples/action.scm21
-rw-r--r--examples/animation.scm39
-rw-r--r--examples/coroutine.scm18
-rw-r--r--examples/particles.scm1
-rw-r--r--examples/simple.scm14
-rw-r--r--examples/tilemap.scm2
6 files changed, 44 insertions, 51 deletions
diff --git a/examples/action.scm b/examples/action.scm
index acc1434..eb2d65e 100644
--- a/examples/action.scm
+++ b/examples/action.scm
@@ -7,11 +7,17 @@
(2d actions)
(2d vector))
-(init-2d)
-
(define window-width 800)
(define window-height 600)
-(define sprite #f)
+
+;; Open the window.
+(open-window window-width window-height)
+
+;; Load a sprite and center it on the screen.
+(define sprite
+ (load-sprite "images/sprite.png"
+ #:position (vector (/ window-width 2)
+ (/ window-height 2))))
(define (key-down key mod unicode)
(cond ((any-equal? key 'escape 'q)
@@ -26,15 +32,6 @@
(add-hook! on-render-hook (lambda () (render)))
(add-hook! on-key-down-hook (lambda (key mod unicode) (key-down key mod unicode)))
-;; Open the window.
-(open-window window-width window-height)
-
-;; Load a sprite and center it on the screen.
-(set! sprite
- (load-sprite "images/sprite.png"
- #:position (vector (/ window-width 2)
- (/ window-height 2))))
-
;; Simple script that moves the sprite to a random location every
;; second.
(agenda-schedule
diff --git a/examples/animation.scm b/examples/animation.scm
index 1e478a3..d00a9df 100644
--- a/examples/animation.scm
+++ b/examples/animation.scm
@@ -6,11 +6,11 @@
(2d vector)
(2d window))
-(init-2d)
-
(define window-width 800)
(define window-height 600)
-(define sprite #f)
+
+;; Open the window.
+(open-window window-width window-height)
(define (key-down key mod unicode)
(cond ((any-equal? key 'escape 'q)
@@ -25,23 +25,24 @@
(add-hook! on-render-hook (lambda () (render)))
(add-hook! on-key-down-hook (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)))))
+(define animation
+ (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))))
+ (make-animation frames 6 #t)))
+
+(define sprite
+ (make-sprite animation
+ #:position (vector (/ window-width 2)
+ (/ window-height 2))))
+
(run-game-loop)
diff --git a/examples/coroutine.scm b/examples/coroutine.scm
index 2bf7ecb..250cdbb 100644
--- a/examples/coroutine.scm
+++ b/examples/coroutine.scm
@@ -5,11 +5,16 @@
(2d agenda)
(2d coroutine))
-(init-2d)
-
(define window-width 800)
(define window-height 600)
-(define sprite #f)
+
+;; Open the window.
+(open-window window-width window-height)
+
+(define sprite
+ (load-sprite "images/sprite.png"
+ #:position (vector (/ window-width 2)
+ (/ window-height 2))))
(define (key-down key mod unicode)
(cond ((any-equal? key 'escape 'q)
@@ -24,13 +29,6 @@
(add-hook! on-render-hook (lambda () (render)))
(add-hook! on-key-down-hook (lambda (key mod unicode) (key-down key mod unicode)))
-;; Open the window.
-(open-window window-width window-height)
-
-;; Load a sprite and center it on the screen.
-(set! sprite (load-sprite "images/sprite.png" #:position (vector (/ window-width 2)
- (/ window-height 2))))
-
;; Simple script that moves the sprite to a random location every
;; second.
(agenda-schedule
diff --git a/examples/particles.scm b/examples/particles.scm
index a71bc13..5251ac0 100644
--- a/examples/particles.scm
+++ b/examples/particles.scm
@@ -9,7 +9,6 @@
(2d window))
(set! *random-state* (random-state-from-platform))
-(init-2d)
;;;
;;; Particles
diff --git a/examples/simple.scm b/examples/simple.scm
index c55de6f..751c214 100644
--- a/examples/simple.scm
+++ b/examples/simple.scm
@@ -3,11 +3,14 @@
(2d window)
(2d helpers))
-(init-2d)
-
(define window-width 800)
(define window-height 600)
-(define sprite #f)
+
+;; Open the window.
+(open-window window-width window-height)
+
+(define sprite (load-sprite "images/grass.jpg" #:position (vector (/ window-width 2)
+ (/ window-height 2))))
(define (quit-demo)
(close-window)
@@ -26,13 +29,10 @@
(add-hook! on-render-hook (lambda () (render)))
(add-hook! on-key-down-hook (lambda (key mod unicode) (key-down key mod unicode)))
-;; Open the window.
-(open-window window-width window-height)
;; Load a sprite and center it on the screen.
;; Must be done AFTER opening the window.
-(set! sprite (load-sprite "images/sprite.png" #:position (vector (/ window-width 2)
- (/ window-height 2))))
+;; (set! )
;; Start the game loop.
;; The render callback will be called through this procedure.
diff --git a/examples/tilemap.scm b/examples/tilemap.scm
index 1f19eb3..5655527 100644
--- a/examples/tilemap.scm
+++ b/examples/tilemap.scm
@@ -8,8 +8,6 @@
(2d vector)
(2d window))
-(init-2d)
-
;;;
;;; Orthogonal tile map example
;;;