animation example

master
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) (sdl2 ttf)
(ice-9 match) (ice-9 match)
(srfi srfi-26) (srfi srfi-26)
(tsukundere menu button) (tsukundere animation))
(tsukundere menu)) ; make-menu run-menu
(define (load) (define (load)
(let* ((scene (let* ((scene
(make-scene '(background (make-scene '(background loaders)))
text
menu)))
(paper (load-image "paper.png")) (paper (load-image "paper.png"))
(texture (load-image "unchecked_box.png")) (frames (map
(selected (load-image "checked_box.png")) (compose load-image
(radio (load-image "unselected_radio_button.png")) (cute string-append
(radio-selected (load-image "selected_radio_button.png")) "animation/" <> ".png")
(simple (load-image "round_button_normal.png")) number->string)
(simple-hover (load-image "round_button_hover.png")) (iota 8)))
(simple-pressed (load-image "round_button_mouse_down.png")) (animation-looping
(font (load-font "JuliaMono.ttf" 18)) (make-animation (s32vector 100 100) frames 1000))
(colors (animation-boing
`((none . ,(make-color 80 225 100 255)) (make-animation (s32vector 100 200) frames 1000 #:loop 'rewind))
(selected . ,(make-color 255 0 0 255)) (animation-stop
(pressed . ,(make-color 0 0 255 255)))) (make-animation (s32vector 200 100) frames 8000 #:loop #f))
(textures (animation-looping-slow
`((none . ,texture) (make-animation (s32vector 200 200) frames 4000 #:loop #t)))
(pressed . ,selected))) (map (cute scene-add-object! scene 'loaders <>)
(textures-radio (list animation-looping animation-boing
`((none . ,radio) animation-stop animation-looping-slow))
(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")))
(init-script! (init-script!
(lambda () (lambda ()
(script (script
(begin (background paper)
(background paper) (pause)))
(nixo "This is not an exam!")) scene)))
(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)))
(run-game (run-game
#:game-name ".tsukundere-example-buttons" #:game-name ".tsukundere-example-buttons"