summaryrefslogtreecommitdiff
path: root/examples/scenes.scm
blob: 46d995642d7cda2807833a8ecb044c804ff276dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(use-modules (2d game)
             (2d scene)
             (2d stage)
             (2d sprite)
             (2d vector2))

;; Press the RETURN key to toggle between the 2 scenes.

;;;
;;; Scene 1
;;;

(define (make-sprite-1)
  (load-sprite "images/ghost.png"
               #:position (vector2 320 240)))

(define (scene-1-key-down sprite key mod unicode)
  (when (eq? key 'return)
    (replace-scene scene-2)))

(define scene-1
  (make-scene
   "Scene 1"
   #:init make-sprite-1
   #:enter (lambda (sprite) (display "Enter Scene 1\n"))
   #:exit (lambda (sprite) (display "Exit Scene 1\n"))
   #:draw draw-sprite
   #:events (append
             (default-events)
             `((key-down . ,scene-1-key-down)))))

;;;
;;; Scene 2
;;;

(define (make-sprite-2)
  (load-sprite "images/stars.png"
               #:position (vector2 320 240)))

(define (scene-2-key-down sprite key mod unicode)
  (when (eq? key 'return)
    (replace-scene scene-1)))

(define scene-2
  (make-scene
   "Scene 2"
   #:init make-sprite-2
   #:enter (lambda (sprite) (display "Enter Scene 2\n"))
   #:exit (lambda (sprite) (display "Exit Scene 2\n"))
   #:draw draw-sprite
   #:events (append
             (default-events)
             `((key-down . ,scene-2-key-down)))))

(define scenes-demo
  (make-game
   #:title "Scenes"
   #:first-scene scene-1))

(run-game scenes-demo)