summaryrefslogtreecommitdiff
path: root/examples/tiled.scm
blob: 19332bbe8a952f4e85f4507d0ca84bccba5ea793 (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
(use-modules (chickadee)
             (chickadee math vector)
             (chickadee math rect)
             (chickadee render tiled)
             (chickadee sdl)
             (ice-9 match))

(define map #f)
(define camera #v(0.0 0.0))

(define (load)
  (set! map (load-tile-map "maps/example.tmx")))

(define (draw alpha)
  (draw-tile-map map #:position camera))

(define inc 8.0)
(define (key-press key scancode modifiers repeat?)
  (match key
    ('up (set-vec2-y! camera (- (vec2-y camera) inc)))
    ('down (set-vec2-y! camera (+ (vec2-y camera) inc)))
    ('right (set-vec2-x! camera (- (vec2-x camera) inc)))
    ('left (set-vec2-x! camera (+ (vec2-x camera) inc)))
    ('q (abort-game))
    (_ #t)))

(run-game/sdl #:window-width 320
              #:window-height 240
              #:window-title "tile map demo"
              #:load load
              #:draw draw
              #:key-press key-press)