blob: 401c171e1853ffb3b5a3a9fb69eb453d37c68d35 (
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
|
(import scheme
(chicken base)
(prefix sdl2 "sdl2:")
(prefix sdl2-ttf "ttf:")
(prefix sdl2-image "img:")
(downstroke engine)
(downstroke renderer)
(downstroke input)
(downstroke assets)
(downstroke sound))
(define *music-on?* #f)
(define +bg-color+ (sdl2:make-color 30 30 60 255))
(define *game*
(make-game
title: "Demo: Audio" width: 600 height: 400
preload: (lambda (game)
(init-audio!)
(load-sounds! '((jump . "demo/assets/jump.wav")))
(load-music! "demo/assets/theme.ogg")
(game-asset-set! game 'font
(ttf:open-font "demo/assets/DejaVuSans.ttf" 20)))
update: (lambda (game dt)
(let ((input (game-input game)))
(when (input-pressed? input 'a) (play-sound 'jump))
(when (input-pressed? input 'b)
(if *music-on?*
(begin (stop-music!) (set! *music-on?* #f))
(begin (play-music! 0.5) (set! *music-on?* #t))))))
render: (lambda (game)
(let ((renderer (game-renderer game))
(font (game-asset game 'font))
(white (sdl2:make-color 255 255 255 255))
(gray (sdl2:make-color 180 180 180 255)))
(set! (sdl2:render-draw-color renderer) +bg-color+)
(sdl2:render-fill-rect! renderer (sdl2:make-rect 0 0 600 400))
(draw-ui-text renderer font "Audio Demo" white 220 80)
(for-each
(lambda (entry)
(draw-ui-text renderer font (car entry) gray (cadr entry) (caddr entry)))
'(("J / Z -- play sound effect" 160 160)
("K / X -- toggle music on/off" 160 200)
("Escape -- quit" 160 240)))
(draw-ui-text renderer font
(if *music-on?* "Music: ON" "Music: OFF")
(if *music-on?*
(sdl2:make-color 100 255 100 255)
(sdl2:make-color 255 100 100 255))
240 310)))))
(game-run! *game*)
|