draw level from the tilemap now works
This commit is contained in:
parent
484ef0ed56
commit
525e671d41
6 changed files with 154 additions and 65 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -10,3 +10,4 @@
|
|||
/pre-inst-env
|
||||
/scripts/run-game
|
||||
/*.log
|
||||
/.envrc
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
--
|
||||
----|----|----|----|----|----|----|----|
|
||||
WWWWGWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
|
||||
W H W
|
||||
W E H E W
|
||||
W H W
|
||||
W E BBBBBBBBBBBBBBBBBBBBBBBBBBBB E W
|
||||
W H W -
|
||||
W H W
|
||||
W E BBBBBBBBBBBBBBBBBBBBBBBBBBBB E W -
|
||||
W H W
|
||||
W H W
|
||||
W H W
|
||||
W H W
|
||||
|
@ -15,14 +15,20 @@ 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 -
|
||||
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
|
||||
WBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBW
|
||||
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
|
||||
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW -
|
|
@ -1,31 +1,60 @@
|
|||
<?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"/>
|
||||
<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">
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,
|
||||
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,
|
||||
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,
|
||||
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,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,
|
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,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,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,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,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,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,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,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,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
|
||||
</data>
|
||||
</layer>
|
||||
<layer id="1" name="Tile Layer 1" width="40" height="25" visible="0">
|
||||
<data encoding="csv">
|
||||
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,
|
||||
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,
|
||||
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,
|
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,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,59,59,59,601,601,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,59,59,59,59,601,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,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,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,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,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,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,
|
||||
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>
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
},
|
||||
"activeFile": "assets/levels/level1.tmx",
|
||||
"expandedProjectPaths": [
|
||||
"assets",
|
||||
".",
|
||||
"assets",
|
||||
"assets/levels"
|
||||
],
|
||||
"fileStates": {
|
||||
|
@ -14,8 +14,8 @@
|
|||
"scale": 2.60953125,
|
||||
"selectedLayer": 0,
|
||||
"viewCenter": {
|
||||
"x": 319.59762888449796,
|
||||
"y": 200.03592599245556
|
||||
"x": 319.2144182983055,
|
||||
"y": 199.65271540626313
|
||||
}
|
||||
},
|
||||
"assets/levels/tiles.tsx": {
|
||||
|
|
|
@ -6,13 +6,15 @@
|
|||
#:use-module (srfi srfi-9)
|
||||
#:use-module (srfi srfi-64)
|
||||
|
||||
#:export (make-level
|
||||
level-width
|
||||
#:export (level-width
|
||||
level-height
|
||||
level-tiles
|
||||
level-entities
|
||||
level-player
|
||||
level-goal)
|
||||
level-goal
|
||||
level-parse-file
|
||||
level-tile-at
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
|
@ -54,7 +56,7 @@
|
|||
(map parse-tile (string->list line)))
|
||||
lines)))
|
||||
|
||||
(define (parse-level content)
|
||||
(define (level-parse content)
|
||||
(let* ((lines (content->lines content))
|
||||
(width (string-length (car lines)))
|
||||
(height (length lines))
|
||||
|
@ -63,21 +65,27 @@
|
|||
(entities '()))
|
||||
(%make-level width height tiles #f #f entities)))
|
||||
|
||||
(define (parse-level-file filename)
|
||||
(parse-level (call-with-input-file filename get-string-all)))
|
||||
(define (level-parse-file filename)
|
||||
(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-assert (level? (parse-level "WWWWW\nWP GW\nWWWWW\n")))
|
||||
(test-equal (level-width (parse-level "WWWWW\nWP GW\nWWWWW\n")) 5)
|
||||
(test-equal (level-height (parse-level "WWWWW\nWP GW\nWWWWW\n")) 3)
|
||||
(test-equal (level-tiles (parse-level "W")) #(wall))
|
||||
(test-assert (level? (level-parse "WWWWW\nWP GW\nWWWWW\n")))
|
||||
(test-equal (level-width (level-parse "WWWWW\nWP GW\nWWWWW\n")) 5)
|
||||
(test-equal (level-height (level-parse "WWWWW\nWP GW\nWWWWW\n")) 3)
|
||||
(test-equal (level-tiles (level-parse "W")) #(wall))
|
||||
(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))
|
||||
(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))
|
||||
|
||||
(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 #\space) 'empty)
|
||||
|
||||
(test-equal (level-width (parse-level-file "assets/levels/level-1.map")) 40)
|
||||
(test-equal (level-height (parse-level-file "assets/levels/level-1.map")) 24)
|
||||
(test-equal (level-width (level-parse-file "assets/levels/level-1.map")) 40)
|
||||
(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")
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
;;; limitations under the License.
|
||||
|
||||
(define-module (game main)
|
||||
#:use-module (game level)
|
||||
#:use-module (chickadee)
|
||||
#:use-module (chickadee math rect)
|
||||
#:use-module (chickadee math vector)
|
||||
|
@ -20,31 +21,32 @@
|
|||
#:use-module (chickadee graphics text)
|
||||
#:use-module (chickadee graphics tile-map)
|
||||
#:use-module (system repl coop-server)
|
||||
#:use-module (srfi srfi-64)
|
||||
#:export (launch-game))
|
||||
|
||||
(define sprite-position (vec2 156.0 176.0))
|
||||
(define sprite-texture #f)
|
||||
(define tile-texture #f)
|
||||
(define tile-atlas #f)
|
||||
(define hero-texture #f)
|
||||
(define hero-atlas #f)
|
||||
(define text-position (vec2 0.0 280.0))
|
||||
(define tile-index 0)
|
||||
(define tile-map #f)
|
||||
(define level #f)
|
||||
(define repl #f)
|
||||
|
||||
(define sprite-batch #f)
|
||||
|
||||
(define (load)
|
||||
(set! sprite-texture (load-image "assets/images/chickadee.png"))
|
||||
(set! tile-atlas
|
||||
(split-texture
|
||||
(load-image "assets/images/simples_pimples.png"
|
||||
#:transparent-color black)
|
||||
16 16))
|
||||
(set! hero-atlas
|
||||
(split-texture
|
||||
(load-image "assets/images/lr_penguin2.png")
|
||||
32 32))
|
||||
|
||||
(set! tile-texture (load-image "assets/images/simples_pimples.png"
|
||||
#:transparent-color black))
|
||||
(set! tile-atlas (split-texture tile-texture 16 16))
|
||||
(set! hero-texture (load-image "assets/images/lr_penguin2.png"))
|
||||
(set! hero-atlas (split-texture hero-texture 32 32))
|
||||
(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)))
|
||||
|
||||
(define (update dt)
|
||||
|
@ -52,9 +54,7 @@
|
|||
(set-vec2-y! sprite-position
|
||||
(floor-remainder (+ (vec2-y sprite-position) (* 50.0 dt)) 400.0))
|
||||
(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)
|
||||
(let ((x (* 16 (remainder i 40)))
|
||||
|
@ -62,41 +62,78 @@
|
|||
(draw-sprite
|
||||
(texture-atlas-ref tile-atlas (+ i 3000 ))
|
||||
(vec2 x y)
|
||||
#:scale (vec2 1.0 1.0)))
|
||||
)
|
||||
#:scale (vec2 1.0 1.0))))
|
||||
|
||||
(define (draw-hero i)
|
||||
(let ((x (* 64 (remainder i 8)))
|
||||
(y (* 32 (quotient i 8)))
|
||||
(id (tile-id))
|
||||
)
|
||||
(draw-sprite
|
||||
(texture-atlas-ref hero-atlas i)
|
||||
(vec2 (+ x 16) y)
|
||||
#: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)
|
||||
(draw-sprite sprite-texture sprite-position)
|
||||
(draw-text "Hello, Chickadee!" text-position )
|
||||
(draw-level level)
|
||||
(let ((hero-position (vec2+ text-position (vec2 -8.0 16.0)))
|
||||
(hero-index (+ 56 (remainder (inexact->exact (floor (vec2-x text-position))) 8))))
|
||||
(draw-sprite
|
||||
(texture-atlas-ref hero-atlas hero-index)
|
||||
hero-position))
|
||||
|
||||
(draw-tile-map tile-map)
|
||||
;; (draw-tile-map tile-map)
|
||||
|
||||
;;(do ((i 0 (+ i 1)))
|
||||
;; ((>= i 1000))
|
||||
;; (draw-tile i))
|
||||
(do ((i 0 (+ i 1)))
|
||||
((>= i 64))
|
||||
(draw-hero i)))
|
||||
;; (do ((i 0 (+ i 1)))
|
||||
;; ((>= i 64))
|
||||
;; (draw-hero i))
|
||||
)
|
||||
|
||||
(define (launch-game args)
|
||||
(run-game #:load (lambda () (load))
|
||||
#:update (lambda (dt) (update dt))
|
||||
#: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")
|
||||
|
|
Loading…
Reference in a new issue