draw level from the tilemap now works

This commit is contained in:
Peter Tillemans 2024-05-19 21:54:30 +02:00
parent 484ef0ed56
commit 525e671d41
6 changed files with 154 additions and 65 deletions

1
.gitignore vendored
View file

@ -10,3 +10,4 @@
/pre-inst-env /pre-inst-env
/scripts/run-game /scripts/run-game
/*.log /*.log
/.envrc

View file

@ -3,10 +3,10 @@
-- --
----|----|----|----|----|----|----|----| ----|----|----|----|----|----|----|----|
WWWWGWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW WWWWGWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
W H W
W E H E W W E H E W
W H W W H W
W E BBBBBBBBBBBBBBBBBBBBBBBBBBBB E W W E BBBBBBBBBBBBBBBBBBBBBBBBBBBB E W -
W H W -
W H W W H W
W H W W H W
W H W W H W
@ -18,11 +18,17 @@ W H W
W H W W H W
W H W - W H W -
W H W W H W
W H W
W H W
W H W
W H W -
W P BHBBBBBBB W W P BHBBBBBBB W
W H W W H W
W H W W H W
W H W
W H W - W H W -
W H W W H W
W H W W H W
W H W
WBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBW WBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBW
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW -

View file

@ -1,31 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="40" height="25" tilewidth="16" tileheight="16" infinite="0" nextlayerid="2" nextobjectid="1"> <map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="40" height="25" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="1">
<tileset firstgid="1" source="tiles.tsx"/> <tileset firstgid="1" source="tiles.tsx"/>
<layer id="1" name="Tile Layer 1" width="40" height="25"> <layer id="2" name="Tile Layer 2" width="40" height="25">
<data encoding="csv"> <data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 59,59,59,59,59,59,59,59,59,59,59,59,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 59,59,59,59,59,59,59,59,59,59,59,59,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 59,59,59,59,59,59,59,59,59,59,59,59,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 59,59,59,59,59,59,59,59,59,59,59,59,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,59,59,59,59,59,59,59,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,59,59,59,59,59,59,59,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,59,59,59,601,601,59,59,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,601,601,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,59,59,601,601,59,59,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,601,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,59,59,59,59,601,59,59,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,601,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,59,59,59,59,601,59,59,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,601,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,59,59,59,59,601,59,59,0,0,0,0,
201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201, 201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,
251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251 251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251
</data> </data>

View file

@ -5,8 +5,8 @@
}, },
"activeFile": "assets/levels/level1.tmx", "activeFile": "assets/levels/level1.tmx",
"expandedProjectPaths": [ "expandedProjectPaths": [
"assets",
".", ".",
"assets",
"assets/levels" "assets/levels"
], ],
"fileStates": { "fileStates": {
@ -14,8 +14,8 @@
"scale": 2.60953125, "scale": 2.60953125,
"selectedLayer": 0, "selectedLayer": 0,
"viewCenter": { "viewCenter": {
"x": 319.59762888449796, "x": 319.2144182983055,
"y": 200.03592599245556 "y": 199.65271540626313
} }
}, },
"assets/levels/tiles.tsx": { "assets/levels/tiles.tsx": {

View file

@ -6,13 +6,15 @@
#:use-module (srfi srfi-9) #:use-module (srfi srfi-9)
#:use-module (srfi srfi-64) #:use-module (srfi srfi-64)
#:export (make-level #:export (level-width
level-width
level-height level-height
level-tiles level-tiles
level-entities level-entities
level-player level-player
level-goal) level-goal
level-parse-file
level-tile-at
)
) )
@ -54,7 +56,7 @@
(map parse-tile (string->list line))) (map parse-tile (string->list line)))
lines))) lines)))
(define (parse-level content) (define (level-parse content)
(let* ((lines (content->lines content)) (let* ((lines (content->lines content))
(width (string-length (car lines))) (width (string-length (car lines)))
(height (length lines)) (height (length lines))
@ -63,21 +65,27 @@
(entities '())) (entities '()))
(%make-level width height tiles #f #f entities))) (%make-level width height tiles #f #f entities)))
(define (parse-level-file filename) (define (level-parse-file filename)
(parse-level (call-with-input-file filename get-string-all))) (level-parse (call-with-input-file filename get-string-all)))
(define (level-tile-at level x y)
(let ((index (+ (* y (level-width level)) x)))
(vector-ref (level-tiles level) index)))
(test-begin "level") (test-begin "level")
(test-assert (level? (parse-level "WWWWW\nWP GW\nWWWWW\n"))) (test-assert (level? (level-parse "WWWWW\nWP GW\nWWWWW\n")))
(test-equal (level-width (parse-level "WWWWW\nWP GW\nWWWWW\n")) 5) (test-equal (level-width (level-parse "WWWWW\nWP GW\nWWWWW\n")) 5)
(test-equal (level-height (parse-level "WWWWW\nWP GW\nWWWWW\n")) 3) (test-equal (level-height (level-parse "WWWWW\nWP GW\nWWWWW\n")) 3)
(test-equal (level-tiles (parse-level "W")) #(wall)) (test-equal (level-tiles (level-parse "W")) #(wall))
(test-equal (test-equal
(level-tiles (parse-level "WWWWW\nWP GW\nWWWWW\n")) (level-tiles (level-parse "WWWWW\nWP GW\nWWWWW\n"))
#(wall wall wall wall wall wall player empty goal wall wall wall wall wall wall)) #(wall wall wall wall wall wall player empty goal wall wall wall wall wall wall))
(test-equal (test-equal
(level-tiles (parse-level "--- ignore this line\nWWWWW\nWP GW - must be ignored\nWWWWW\n")) (level-tiles (level-parse "--- ignore this line\nWWWWW\nWP GW - must be ignored\nWWWWW\n"))
#(wall wall wall wall wall wall player empty goal wall wall wall wall wall wall)) #(wall wall wall wall wall wall player empty goal wall wall wall wall wall wall))
(test-equal (content->lines "WWWWW\nWP GW\nWWWWW\n") '("WWWWW" "WP GW" "WWWWW")) (test-equal (content->lines "WWWWW\nWP GW\nWWWWW\n") '("WWWWW" "WP GW" "WWWWW"))
@ -90,7 +98,15 @@
(test-equal (parse-tile #\G) 'goal) (test-equal (parse-tile #\G) 'goal)
(test-equal (parse-tile #\space) 'empty) (test-equal (parse-tile #\space) 'empty)
(test-equal (level-width (parse-level-file "assets/levels/level-1.map")) 40) (test-equal (level-width (level-parse-file "assets/levels/level-1.map")) 40)
(test-equal (level-height (parse-level-file "assets/levels/level-1.map")) 24) (test-equal (level-height (level-parse-file "assets/levels/level-1.map")) 30)
(test-equal
(level-tile-at (level-parse "WWWWW\nWP GW\nWWWWW\n") 1 1)
'player)
(test-equal
(level-tile-at (level-parse "WWWWW\nWP GW\nWWWWW\n") 3 1)
'goal)
(test-end "level") (test-end "level")

View file

@ -11,6 +11,7 @@
;;; limitations under the License. ;;; limitations under the License.
(define-module (game main) (define-module (game main)
#:use-module (game level)
#:use-module (chickadee) #:use-module (chickadee)
#:use-module (chickadee math rect) #:use-module (chickadee math rect)
#:use-module (chickadee math vector) #:use-module (chickadee math vector)
@ -20,31 +21,32 @@
#:use-module (chickadee graphics text) #:use-module (chickadee graphics text)
#:use-module (chickadee graphics tile-map) #:use-module (chickadee graphics tile-map)
#:use-module (system repl coop-server) #:use-module (system repl coop-server)
#:use-module (srfi srfi-64)
#:export (launch-game)) #:export (launch-game))
(define sprite-position (vec2 156.0 176.0)) (define sprite-position (vec2 156.0 176.0))
(define sprite-texture #f) (define sprite-texture #f)
(define tile-texture #f)
(define tile-atlas #f) (define tile-atlas #f)
(define hero-texture #f)
(define hero-atlas #f) (define hero-atlas #f)
(define text-position (vec2 0.0 280.0)) (define text-position (vec2 0.0 280.0))
(define tile-index 0) (define tile-index 0)
(define tile-map #f) (define tile-map #f)
(define level #f)
(define repl #f) (define repl #f)
(define sprite-batch #f)
(define (load) (define (load)
(set! sprite-texture (load-image "assets/images/chickadee.png")) (set! tile-texture (load-image "assets/images/simples_pimples.png"
(set! tile-atlas #:transparent-color black))
(split-texture (set! tile-atlas (split-texture tile-texture 16 16))
(load-image "assets/images/simples_pimples.png" (set! hero-texture (load-image "assets/images/lr_penguin2.png"))
#:transparent-color black) (set! hero-atlas (split-texture hero-texture 32 32))
16 16))
(set! hero-atlas
(split-texture
(load-image "assets/images/lr_penguin2.png")
32 32))
(set! tile-map (load-tile-map "assets/levels/level1.tmx")) (set! tile-map (load-tile-map "assets/levels/level1.tmx"))
(set! sprite-batch (make-sprite-batch tile-texture #:capacity 1000))
(set! level (level-parse-file "assets/levels/level-1.map"))
(set! repl (spawn-coop-repl-server))) (set! repl (spawn-coop-repl-server)))
(define (update dt) (define (update dt)
@ -52,9 +54,7 @@
(set-vec2-y! sprite-position (set-vec2-y! sprite-position
(floor-remainder (+ (vec2-y sprite-position) (* 50.0 dt)) 400.0)) (floor-remainder (+ (vec2-y sprite-position) (* 50.0 dt)) 400.0))
(set-vec2-x! text-position (set-vec2-x! text-position
(floor-remainder (+ (vec2-x text-position) (* 25.0 dt)) 640.0)) (floor-remainder (+ (vec2-x text-position) (* 25.0 dt)) 640.0)))
)
(define (draw-tile i) (define (draw-tile i)
(let ((x (* 16 (remainder i 40))) (let ((x (* 16 (remainder i 40)))
@ -62,41 +62,78 @@
(draw-sprite (draw-sprite
(texture-atlas-ref tile-atlas (+ i 3000 )) (texture-atlas-ref tile-atlas (+ i 3000 ))
(vec2 x y) (vec2 x y)
#:scale (vec2 1.0 1.0))) #:scale (vec2 1.0 1.0))))
)
(define (draw-hero i) (define (draw-hero i)
(let ((x (* 64 (remainder i 8))) (let ((x (* 64 (remainder i 8)))
(y (* 32 (quotient i 8))) (y (* 32 (quotient i 8)))
(id (tile-id))
) )
(draw-sprite (draw-sprite
(texture-atlas-ref hero-atlas i) (texture-atlas-ref hero-atlas i)
(vec2 (+ x 16) y) (vec2 (+ x 16) y)
#:scale (vec2 1.0 1.0)) #:scale (vec2 1.0 1.0))
(draw-text (format #f "~2d" i) (vec2 x y) #:color white)) (draw-text (format #f "~A" i) (vec2 x y) #:color white))
) )
(define (level-tile-index tile)
(case tile
((empty) 3800)
((brick) 3750)
((wall) 3709)
((ladder) 3350)
((goal) 3404)
(else 3326)))
(define (draw-level level)
(sprite-batch-clear! sprite-batch)
(for-each
(lambda (row)
(for-each
(lambda (column)
(let*
((x (* 16 column))
(y (* 16 row))
(tile (level-tile-at level column row))
(texture-region (texture-atlas-ref tile-atlas (level-tile-index tile))))
(sprite-batch-add! sprite-batch (vec2 x y)
#:texture-region texture-region)))
(iota (level-width level) 0)))
(iota (level-height level) 0))
(draw-sprite-batch sprite-batch))
(define (draw _alpha) (define (draw _alpha)
(draw-sprite sprite-texture sprite-position) (draw-level level)
(draw-text "Hello, Chickadee!" text-position )
(let ((hero-position (vec2+ text-position (vec2 -8.0 16.0))) (let ((hero-position (vec2+ text-position (vec2 -8.0 16.0)))
(hero-index (+ 56 (remainder (inexact->exact (floor (vec2-x text-position))) 8)))) (hero-index (+ 56 (remainder (inexact->exact (floor (vec2-x text-position))) 8))))
(draw-sprite (draw-sprite
(texture-atlas-ref hero-atlas hero-index) (texture-atlas-ref hero-atlas hero-index)
hero-position)) hero-position))
(draw-tile-map tile-map) ;; (draw-tile-map tile-map)
;;(do ((i 0 (+ i 1))) ;;(do ((i 0 (+ i 1)))
;; ((>= i 1000)) ;; ((>= i 1000))
;; (draw-tile i)) ;; (draw-tile i))
(do ((i 0 (+ i 1))) ;; (do ((i 0 (+ i 1)))
((>= i 64)) ;; ((>= i 64))
(draw-hero i))) ;; (draw-hero i))
)
(define (launch-game args) (define (launch-game args)
(run-game #:load (lambda () (load)) (run-game #:load (lambda () (load))
#:update (lambda (dt) (update dt)) #:update (lambda (dt) (update dt))
#:draw (lambda (alpha) (draw alpha)))) #:draw (lambda (alpha) (draw alpha))))
(test-begin "tile draw")
(test-equal "tile index"
(level-tile-index 'empty)
3800)
(test-equal (level-tile-index 'brick) 3750)
(test-end "tile draw")