blob: c64f7b6a195679ce83170dc022e1477af02d3914 (
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
|
(use-modules (chickadee)
(chickadee math vector)
(chickadee math rect)
(chickadee graphics font)
(chickadee graphics tiled)
(ice-9 format)
(ice-9 match)
(srfi srfi-11))
(define map #f)
(define camera #v(0.0 0.0))
(define text-position #v(4.0 4.0))
(define text "0, 0")
(define (load)
(set! map (load-tile-map "maps/example.tmx")))
(define (draw alpha)
(draw-tile-map map #:position camera)
(draw-text text text-position))
(define inc 8.0)
(define (key-press key 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)))
(define (mouse-move x y x-rel y-rel buttons)
(let-values (((tx ty) (point->tile map x y)))
(set! text (format #f "~d, ~d" tx ty))))
(run-game #:window-width 320
#:window-height 240
#:window-title "tile map demo"
#:load load
#:draw draw
#:key-press key-press
#:mouse-move mouse-move)
|