animation example

This commit is contained in:
nixo 2021-01-15 23:02:07 +01:00
parent f5557c6179
commit a7456499f3
9 changed files with 22 additions and 120 deletions

BIN
animation/0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
animation/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
animation/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
animation/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
animation/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
animation/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
animation/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
animation/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

142
run.scm
View File

@ -3,133 +3,35 @@
(sdl2 ttf)
(ice-9 match)
(srfi srfi-26)
(tsukundere menu button)
(tsukundere menu)) ; make-menu run-menu
(tsukundere animation))
(define (load)
(let* ((scene
(make-scene '(background
text
menu)))
(make-scene '(background loaders)))
(paper (load-image "paper.png"))
(texture (load-image "unchecked_box.png"))
(selected (load-image "checked_box.png"))
(radio (load-image "unselected_radio_button.png"))
(radio-selected (load-image "selected_radio_button.png"))
(simple (load-image "round_button_normal.png"))
(simple-hover (load-image "round_button_hover.png"))
(simple-pressed (load-image "round_button_mouse_down.png"))
(font (load-font "JuliaMono.ttf" 18))
(colors
`((none . ,(make-color 80 225 100 255))
(selected . ,(make-color 255 0 0 255))
(pressed . ,(make-color 0 0 255 255))))
(textures
`((none . ,texture)
(pressed . ,selected)))
(textures-radio
`((none . ,radio)
(pressed . ,radio-selected)))
(textures-button
`((none . ,simple)
(selected . ,simple-hover)
(pressed . ,simple-pressed)))
(checkbox-button
(make-button (s32vector 0 0) "" 0 font textures
#:dimensions (s32vector 25 25)
#:text-colors colors
#:anchor 'center
#:text-pos (s32vector 30 -7)
#:text-alignment '(left . top)
#:callback checkbox-button-callback))
(checkbox-menu
(make-menu '() #:pos #s32(100 100) #:spacing #s32(0 50)
#:button-prototype checkbox-button
#:accumulator
(cute menu-fold <> '() cons)))
(radio-button
(make-button (s32vector 0 0) "" 0 font textures-radio
#:text-colors colors
#:dimensions (s32vector 200 20)
#:anchor 'top-left
#:text-alignment '(left . top)
#:text-pos (s32vector 30 0)
#:callback radio-button-callback))
(radio-menu
(make-menu '() #:pos #s32(100 100) #:spacing #s32(0 50)
#:button-prototype radio-button))
(simple-button
(make-button (s32vector 0 0) "" 0 font textures-button
#:text-colors colors
;; Put text at the center of the button
#:text-pos (s32vector 0 0)
#:anchor 'center
#:text-alignment '(center . center)
#:callback simple-button-callback))
(simple-menu
(make-menu '() #:pos #s32(100 100) #:spacing #s32(0 50)
#:accumulator
(cute menu-fold <> *unspecified* (lambda (val seed) val))
#:button-prototype simple-button))
(nixo (make-speaker "nixo")))
(frames (map
(compose load-image
(cute string-append
"animation/" <> ".png")
number->string)
(iota 8)))
(animation-looping
(make-animation (s32vector 100 100) frames 1000))
(animation-boing
(make-animation (s32vector 100 200) frames 1000 #:loop 'rewind))
(animation-stop
(make-animation (s32vector 200 100) frames 8000 #:loop #f))
(animation-looping-slow
(make-animation (s32vector 200 200) frames 4000 #:loop #t)))
(map (cute scene-add-object! scene 'loaders <>)
(list animation-looping animation-boing
animation-stop animation-looping-slow))
(init-script!
(lambda ()
(script
(begin
(background paper)
(nixo "This is not an exam!"))
(nixo "Choose one and press enter!")
(nixo
(format #f "You chose: ~a\n"
(run-menu
(make-menu '(("Select me!")
("Or me!")
("No, select me!"))
#:accumulator
(cute menu-fold <> *unspecified* (lambda (val seed) val))
#:prototype radio-menu))))
(nixo "Choose as many as you want!")
(nixo
(format #f "You chose ~a\n"
(run-menu
(make-menu '(("A" 0)
("B" 1)
("C" 2))
#:accumulator (cute menu-fold <> '() cons)
#:prototype checkbox-menu))))
(nixo "Choose as many as you want!")
(nixo
(format #f "You chose ~a\n"
(run-menu
(make-menu '(("A" 0 (pressed))
("B" 1 (selected))
("C" 2 (pressed)))
#:accumulator (cute menu-fold <> '() cons)
#:prototype checkbox-menu))))
(nixo "Click it!")
(nixo
(format #f "You chose the element number: ~a\n"
(menu ("Yes" "Maybe" "No way"))))
(nixo "Click it again!")
(nixo
(format #f "You chose the element: ~a\n"
(menu (("Yes") ("Maybe") ("No way")))))
;; (nixo "Once more!" #f eol)
(nixo
(format #f "You chose the element: ~a\n"
(menu (("Yes" yep) ("Maybe" maybe) ("No way" nope)))))
*unspecified*))
scene)
(init-menu! simple-menu) ; equal to
;; (scene-add-object! scene 'menu simple-menu)
;; roughly equivalent to init-menu! below
;; (init-menu! #:pos #s32(100 100) #:spacing #s32(0 50)
;; #:prototype simple-button
;; #:accumulator (cute menu-fold <> *unspecified*
;; (lambda (val seed) val))
;; #:scene scene)
(init-text! 10 300 280 font font #:scene scene)))
(background paper)
(pause)))
scene)))
(run-game
#:game-name ".tsukundere-example-buttons"