rethink asset loading
This commit is contained in:
parent
548cddc89d
commit
f8647695a0
3 changed files with 15 additions and 15 deletions
|
@ -18,7 +18,7 @@
|
||||||
(define (food-index food cycle)
|
(define (food-index food cycle)
|
||||||
(let ((x (coord->cell (vec2-x (food-position food))))
|
(let ((x (coord->cell (vec2-x (food-position food))))
|
||||||
(y (coord->cell (vec2-y (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)
|
(define (render-food food)
|
||||||
(let ((index (food-index food (if (food-healthy? food) healthy-food-cycle bad-food-cycle)))
|
(let ((index (food-index food (if (food-healthy? food) healthy-food-cycle bad-food-cycle)))
|
||||||
|
|
|
@ -63,17 +63,13 @@
|
||||||
(if (equal? tile 'ladder)
|
(if (equal? tile 'ladder)
|
||||||
;; add background behind ladder
|
;; add background behind ladder
|
||||||
(if (or (equal? (level-tile-at level (vec2+ position (vec2 16 0))) 'brick)
|
(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
|
(sprite-batch-add! sprite-batch position
|
||||||
#:texture-region (texture-atlas-ref tile-atlas brick-index))
|
#:texture-region (texture-atlas-ref tile-atlas brick-index))
|
||||||
(sprite-batch-add! sprite-batch position
|
(sprite-batch-add! sprite-batch position
|
||||||
#:texture-region (texture-atlas-ref tile-atlas empty-index))))
|
#:texture-region (texture-atlas-ref tile-atlas empty-index))))
|
||||||
|
|
||||||
(sprite-batch-add! sprite-batch position
|
(sprite-batch-add! sprite-batch position
|
||||||
#:texture-region texture-region)))
|
#:texture-region texture-region)))
|
||||||
|
|
||||||
(iota (level-width level) 0)))
|
(iota (level-width level) 0)))
|
||||||
(iota (level-height level) 0)))
|
(iota (level-height level) 0)))
|
||||||
|
|
||||||
|
@ -84,10 +80,10 @@
|
||||||
|
|
||||||
|
|
||||||
(define (render-victory)
|
(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)
|
(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")
|
(test-begin "tile translation")
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,10 @@
|
||||||
(define hero-atlas #f)
|
(define hero-atlas #f)
|
||||||
|
|
||||||
(define (assets-location)
|
(define (assets-location)
|
||||||
(if (current-filename)
|
(pk "Assets location: "
|
||||||
(pk "Assets location: " (string-append (dirname (current-filename)) "/../.."))
|
(if (current-filename)
|
||||||
(or (getenv "ASSET_DIR") "." ))
|
(string-append (dirname (current-filename)) "/../../assets")
|
||||||
|
(or (getenv "ASSET_DIR") "." )))
|
||||||
)
|
)
|
||||||
|
|
||||||
(define (assets-file-name . names)
|
(define (assets-file-name . names)
|
||||||
|
@ -32,13 +33,16 @@
|
||||||
|
|
||||||
(define (assets-map-levels f)
|
(define (assets-map-levels f)
|
||||||
(map f
|
(map f
|
||||||
(map (lambda (filename)(assets-file-name "assets/levels/" filename))
|
(map (lambda (filename)(assets-file-name "levels" filename))
|
||||||
(scandir (assets-file-name "assets/levels")
|
(scandir (assets-file-name "levels")
|
||||||
(lambda (filename) (string-suffix? ".map" filename ))))))
|
(lambda (filename) (string-suffix? ".map" filename ))))))
|
||||||
|
|
||||||
|
(define (assets-load-image filename)
|
||||||
|
(load-image (assets-file-name "images" filename)))
|
||||||
|
|
||||||
(define (assets-load)
|
(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! 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)))
|
(set! hero-atlas (split-texture hero-texture 32 32)))
|
||||||
|
|
Loading…
Reference in a new issue