rethink asset loading

This commit is contained in:
Peter Tillemans 2024-05-25 14:10:23 +02:00
parent 548cddc89d
commit f8647695a0
3 changed files with 15 additions and 15 deletions

View file

@ -18,7 +18,7 @@
(define (food-index food cycle)
(let ((x (coord->cell (vec2-x (food-position food))))
(y (coord->cell (vec2-y (food-position food)))))
(pk "food remainder : " (remainder (+ (* x 37) (* 73 y)) cycle))))
(remainder (+ (* x 37) (* 73 y)) cycle)))
(define (render-food food)
(let ((index (food-index food (if (food-healthy? food) healthy-food-cycle bad-food-cycle)))

View file

@ -63,17 +63,13 @@
(if (equal? tile 'ladder)
;; add background behind ladder
(if (or (equal? (level-tile-at level (vec2+ position (vec2 16 0))) 'brick)
(equal? (level-tile-at level (vec2- position (vec2 -16 0))) 'brick)
)
(equal? (level-tile-at level (vec2- position (vec2 -16 0))) 'brick))
(sprite-batch-add! sprite-batch position
#:texture-region (texture-atlas-ref tile-atlas brick-index))
(sprite-batch-add! sprite-batch position
#:texture-region (texture-atlas-ref tile-atlas empty-index))))
(sprite-batch-add! sprite-batch position
#:texture-region texture-region)))
(iota (level-width level) 0)))
(iota (level-height level) 0)))
@ -84,10 +80,10 @@
(define (render-victory)
(draw-sprite (load-image (assets-file-name "assets/images/victory.jpg")) (vec2 0 0)))
(draw-sprite (assets-load-image "victory.jpg") (vec2 0 0)))
(define (render-defeat)
(draw-sprite (load-image (assets-file-name "assets/images/defeat.jpg")) (vec2 0 0)))
(draw-sprite (assets-load-image "defeat.jpg") (vec2 0 0)))
(test-begin "tile translation")

View file

@ -14,9 +14,10 @@
(define hero-atlas #f)
(define (assets-location)
(if (current-filename)
(pk "Assets location: " (string-append (dirname (current-filename)) "/../.."))
(or (getenv "ASSET_DIR") "." ))
(pk "Assets location: "
(if (current-filename)
(string-append (dirname (current-filename)) "/../../assets")
(or (getenv "ASSET_DIR") "." )))
)
(define (assets-file-name . names)
@ -32,13 +33,16 @@
(define (assets-map-levels f)
(map f
(map (lambda (filename)(assets-file-name "assets/levels/" filename))
(scandir (assets-file-name "assets/levels")
(map (lambda (filename)(assets-file-name "levels" filename))
(scandir (assets-file-name "levels")
(lambda (filename) (string-suffix? ".map" filename ))))))
(define (assets-load-image filename)
(load-image (assets-file-name "images" filename)))
(define (assets-load)
(set! tile-texture (load-image (assets-file-name "assets/images/simples_pimples.png")))
(set! tile-texture (assets-load-image "simples_pimples.png"))
(set! tile-atlas (split-texture tile-texture 16 16))
(set! hero-texture (load-image (assets-file-name "assets/images/lr_penguin2.png")))
(set! hero-texture (assets-load-image "lr_penguin2.png"))
(set! hero-atlas (split-texture hero-texture 32 32)))