2024-05-22 23:29:52 +02:00
|
|
|
(define-module (game util assets)
|
2024-05-24 01:22:28 +02:00
|
|
|
#:use-module (ice-9 ftw)
|
|
|
|
#:use-module (ice-9 textual-ports)
|
2024-05-23 21:46:50 +02:00
|
|
|
#:use-module (chickadee graphics texture)
|
|
|
|
#:use-module (chickadee graphics color)
|
2024-05-24 01:22:28 +02:00
|
|
|
#:export (assets-load assets-file-name tile-texture tile-atlas hero-texture hero-atlas assets-map-levels)
|
2024-05-23 21:46:50 +02:00
|
|
|
|
2024-05-22 23:29:52 +02:00
|
|
|
)
|
|
|
|
|
2024-05-23 21:46:50 +02:00
|
|
|
(define tile-texture #f)
|
|
|
|
(define tile-atlas #f)
|
|
|
|
|
|
|
|
(define hero-texture #f)
|
|
|
|
(define hero-atlas #f)
|
2024-05-22 23:29:52 +02:00
|
|
|
|
2024-05-25 13:19:31 +02:00
|
|
|
(define (assets-location)
|
|
|
|
(if (current-filename)
|
|
|
|
(pk "Assets location: " (string-append (dirname (current-filename)) "/../.."))
|
|
|
|
(or (getenv "ASSET_DIR") "." ))
|
2024-05-22 23:29:52 +02:00
|
|
|
)
|
2024-05-23 21:46:50 +02:00
|
|
|
|
2024-05-25 13:19:31 +02:00
|
|
|
(define (assets-file-name . names)
|
|
|
|
"Return the full path of a file in the assets directory. The file is
|
|
|
|
specified by a list of names, which are joined together. The
|
|
|
|
ASSET_DIR environment variable can be used to specify a prefix to the
|
|
|
|
asset directory."
|
|
|
|
(string-append (assets-location) "/" (string-join names "/")))
|
|
|
|
|
2024-05-24 01:22:28 +02:00
|
|
|
|
|
|
|
(define (read-level-map filename)
|
2024-05-25 13:19:31 +02:00
|
|
|
(call-with-input-file filename get-string-all))
|
2024-05-24 01:22:28 +02:00
|
|
|
|
|
|
|
(define (assets-map-levels f)
|
|
|
|
(map f
|
2024-05-25 13:19:31 +02:00
|
|
|
(map (lambda (filename)(assets-file-name "assets/levels/" filename))
|
2024-05-24 01:22:28 +02:00
|
|
|
(scandir (assets-file-name "assets/levels")
|
|
|
|
(lambda (filename) (string-suffix? ".map" filename ))))))
|
|
|
|
|
2024-05-23 21:46:50 +02:00
|
|
|
(define (assets-load)
|
2024-05-24 17:07:17 +02:00
|
|
|
(set! tile-texture (load-image (assets-file-name "assets/images/simples_pimples.png")))
|
2024-05-23 21:46:50 +02:00
|
|
|
(set! tile-atlas (split-texture tile-texture 16 16))
|
|
|
|
|
|
|
|
(set! hero-texture (load-image (assets-file-name "assets/images/lr_penguin2.png")))
|
|
|
|
(set! hero-atlas (split-texture hero-texture 32 32)))
|