level data and parser.
This commit is contained in:
parent
b7adfd4846
commit
dffd74cb8c
10 changed files with 296 additions and 12 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -8,3 +8,5 @@
|
||||||
/config.status
|
/config.status
|
||||||
/configure
|
/configure
|
||||||
/pre-inst-env
|
/pre-inst-env
|
||||||
|
/scripts/run-game
|
||||||
|
/*.log
|
||||||
|
|
28
assets/levels/level-1.map
Normal file
28
assets/levels/level-1.map
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
-- simple map format
|
||||||
|
-- all content after a '-' is ignored
|
||||||
|
--
|
||||||
|
----|----|----|----|----|----|----|----|
|
||||||
|
WWWWGWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
|
||||||
|
W E H E W
|
||||||
|
W H 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
|
||||||
|
W H W
|
||||||
|
W H W
|
||||||
|
W H W
|
||||||
|
W H W -
|
||||||
|
W H W
|
||||||
|
W P HBBBBBBB W
|
||||||
|
W H W
|
||||||
|
W H W
|
||||||
|
W H W -
|
||||||
|
W H W
|
||||||
|
W H W
|
||||||
|
WBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBW
|
||||||
|
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
|
33
assets/levels/level1.tmx
Normal file
33
assets/levels/level1.tmx
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?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">
|
||||||
|
<tileset firstgid="1" source="tiles.tsx"/>
|
||||||
|
<layer id="1" name="Tile Layer 1" width="40" height="25">
|
||||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0,0,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>
|
||||||
|
</layer>
|
||||||
|
</map>
|
4
assets/levels/tiles.tsx
Normal file
4
assets/levels/tiles.tsx
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version = "1.0" encoding = "UTF-8"?>
|
||||||
|
<tileset version="1.10" tiledversion="1.10.2" name="tiles" tilewidth="16" tileheight="16" tilecount="4000" columns="50">
|
||||||
|
<image source="../images/simples_pimples.png" width="800" height="1280" />
|
||||||
|
</tileset>
|
4
assets/tiles.tsx
Normal file
4
assets/tiles.tsx
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<tileset version="1.10" tiledversion="1.10.2" name="tiles" tilewidth="16" tileheight="16" tilecount="4000" columns="50">
|
||||||
|
<image source="images/simples_pimples.png" width="800" height="1280"/>
|
||||||
|
</tileset>
|
14
bloatrunner.tiled-project
Normal file
14
bloatrunner.tiled-project
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"automappingRulesFile": "",
|
||||||
|
"commands": [
|
||||||
|
],
|
||||||
|
"compatibilityVersion": 1100,
|
||||||
|
"extensionsPath": "extensions",
|
||||||
|
"folders": [
|
||||||
|
"."
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
],
|
||||||
|
"propertyTypes": [
|
||||||
|
]
|
||||||
|
}
|
46
bloatrunner.tiled-session
Normal file
46
bloatrunner.tiled-session
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"Map/SizeTest": {
|
||||||
|
"height": 4300,
|
||||||
|
"width": 2
|
||||||
|
},
|
||||||
|
"activeFile": "assets/levels/level1.tmx",
|
||||||
|
"expandedProjectPaths": [
|
||||||
|
"assets",
|
||||||
|
".",
|
||||||
|
"assets/levels"
|
||||||
|
],
|
||||||
|
"fileStates": {
|
||||||
|
"assets/levels/level1.tmx": {
|
||||||
|
"scale": 2.60953125,
|
||||||
|
"selectedLayer": 0,
|
||||||
|
"viewCenter": {
|
||||||
|
"x": 319.59762888449796,
|
||||||
|
"y": 200.03592599245556
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"assets/levels/tiles.tsx": {
|
||||||
|
"scaleInDock": 1,
|
||||||
|
"scaleInEditor": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"last.imagePath": "/home/pti/guile/bloatrunner/assets/images",
|
||||||
|
"map.height": 25,
|
||||||
|
"map.lastUsedFormat": "tmx",
|
||||||
|
"map.tileHeight": 16,
|
||||||
|
"map.tileWidth": 16,
|
||||||
|
"map.width": 40,
|
||||||
|
"openFiles": [
|
||||||
|
"assets/levels/tiles.tsx",
|
||||||
|
"assets/levels/level1.tmx"
|
||||||
|
],
|
||||||
|
"project": "bloatrunner.tiled-project",
|
||||||
|
"recentFiles": [
|
||||||
|
"assets/levels/tiles.tsx",
|
||||||
|
"assets/levels/level1.tmx"
|
||||||
|
],
|
||||||
|
"tileset.lastUsedFormat": "tsx",
|
||||||
|
"tileset.tileSize": {
|
||||||
|
"height": 16,
|
||||||
|
"width": 16
|
||||||
|
}
|
||||||
|
}
|
89
game/level.scm
Normal file
89
game/level.scm
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
(define-module (game level)
|
||||||
|
#:use-module (ice-9 match)
|
||||||
|
#:use-module (ice-9 pretty-print)
|
||||||
|
#:use-module (srfi srfi-1)
|
||||||
|
#:use-module (srfi srfi-9)
|
||||||
|
#:use-module (srfi srfi-64)
|
||||||
|
|
||||||
|
#:export (make-level
|
||||||
|
level-width
|
||||||
|
level-height
|
||||||
|
level-tiles
|
||||||
|
level-entities
|
||||||
|
level-player
|
||||||
|
level-goal)
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
(define-record-type <level>
|
||||||
|
(%make-level width height tiles goal player entities)
|
||||||
|
level?
|
||||||
|
(width level-width)
|
||||||
|
(height level-height)
|
||||||
|
(tiles level-tiles)
|
||||||
|
(goal level-goal)
|
||||||
|
(player level-player)
|
||||||
|
(entities level-entities))
|
||||||
|
|
||||||
|
(define (parse-tile c)
|
||||||
|
(case c
|
||||||
|
((#\W) 'wall)
|
||||||
|
((#\B) 'brick)
|
||||||
|
((#\H) 'ladder)
|
||||||
|
((#\P) 'player)
|
||||||
|
((#\E) 'enemy)
|
||||||
|
((#\G) 'goal)
|
||||||
|
(else 'empty)))
|
||||||
|
|
||||||
|
(define (content->lines content)
|
||||||
|
(map
|
||||||
|
(lambda (line)
|
||||||
|
(string-trim-right
|
||||||
|
(car (string-split line #\-))
|
||||||
|
#\space))
|
||||||
|
(string-split content #\newline)))
|
||||||
|
|
||||||
|
(define (parse-lines lines)
|
||||||
|
(fold append
|
||||||
|
'()
|
||||||
|
(map
|
||||||
|
(lambda (line)
|
||||||
|
(map parse-tile (string->list line)))
|
||||||
|
lines)))
|
||||||
|
|
||||||
|
(define (parse-level content)
|
||||||
|
(let* ((lines (map
|
||||||
|
(lambda (line)
|
||||||
|
(string-trim-right
|
||||||
|
(car (string-split line #\-))
|
||||||
|
#\space))
|
||||||
|
(string-split content #\newline)))
|
||||||
|
(width (string-length (car lines)))
|
||||||
|
(height (length lines))
|
||||||
|
(tiles (list->vector
|
||||||
|
(parse-lines lines)))
|
||||||
|
(entities '()))
|
||||||
|
(%make-level width height tiles #f #f entities)))
|
||||||
|
|
||||||
|
(test-begin "level")
|
||||||
|
|
||||||
|
(test-assert (level? (parse-level "WWWWW\nWP GW\nWWWWW\n")))
|
||||||
|
(test-assert (level-width (parse-level "WWWWW\nWP GW\nWWWWW\n")) 5)
|
||||||
|
(test-assert (level-height (parse-level "WWWWW\nWP GW\nWWWWW\n")) 3)
|
||||||
|
(test-equal (level-tiles (parse-level "W")) #(wall))
|
||||||
|
(test-equal
|
||||||
|
(level-tiles (parse-level "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"))
|
||||||
|
#(wall wall wall wall wall wall player empty goal wall wall wall wall wall wall))
|
||||||
|
|
||||||
|
(test-equal (parse-tile #\W) 'wall)
|
||||||
|
(test-equal (parse-tile #\B) 'brick)
|
||||||
|
(test-equal (parse-tile #\H) 'ladder)
|
||||||
|
(test-equal (parse-tile #\P) 'player)
|
||||||
|
(test-equal (parse-tile #\E) 'enemy)
|
||||||
|
(test-equal (parse-tile #\G) 'goal)
|
||||||
|
(test-equal (parse-tile #\space) 'empty)
|
||||||
|
|
||||||
|
(test-end "level")
|
|
@ -12,27 +12,91 @@
|
||||||
|
|
||||||
(define-module (game main)
|
(define-module (game main)
|
||||||
#:use-module (chickadee)
|
#:use-module (chickadee)
|
||||||
|
#:use-module (chickadee math rect)
|
||||||
#:use-module (chickadee math vector)
|
#:use-module (chickadee math vector)
|
||||||
|
#:use-module (chickadee graphics color)
|
||||||
#:use-module (chickadee graphics sprite)
|
#:use-module (chickadee graphics sprite)
|
||||||
#:use-module (chickadee graphics texture)
|
#:use-module (chickadee graphics texture)
|
||||||
|
#:use-module (chickadee graphics text)
|
||||||
|
#:use-module (chickadee graphics tile-map)
|
||||||
#:use-module (system repl coop-server)
|
#:use-module (system repl coop-server)
|
||||||
#:export (launch-game))
|
#:export (launch-game))
|
||||||
|
|
||||||
(define sprite-position (vec2 256.0 176.0))
|
(define sprite-position (vec2 156.0 176.0))
|
||||||
(define sprite-texture #f)
|
(define sprite-texture #f)
|
||||||
|
(define tile-atlas #f)
|
||||||
|
(define hero-atlas #f)
|
||||||
|
(define text-position (vec2 0.0 280.0))
|
||||||
|
(define tile-index 0)
|
||||||
|
(define tile-map #f)
|
||||||
(define repl #f)
|
(define repl #f)
|
||||||
|
|
||||||
|
|
||||||
(define (load)
|
(define (load)
|
||||||
(set! sprite-texture (load-image "assets/images/chickadee.png"))
|
(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-map (load-tile-map "assets/levels/level1.tmx"))
|
||||||
(set! repl (spawn-coop-repl-server)))
|
(set! repl (spawn-coop-repl-server)))
|
||||||
|
|
||||||
(define (update _dt)
|
(define (update dt)
|
||||||
(poll-coop-repl-server repl))
|
(poll-coop-repl-server repl)
|
||||||
|
(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))
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
(define (draw-tile i)
|
||||||
|
(let ((x (* 16 (remainder i 40)))
|
||||||
|
(y (* 16 (quotient i 40))))
|
||||||
|
(draw-sprite
|
||||||
|
(texture-atlas-ref tile-atlas (+ i 3000 ))
|
||||||
|
(vec2 x y)
|
||||||
|
#: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))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
(define (draw _alpha)
|
(define (draw _alpha)
|
||||||
(draw-sprite sprite-texture sprite-position))
|
(draw-sprite sprite-texture sprite-position)
|
||||||
|
(draw-text "Hello, Chickadee!" text-position )
|
||||||
|
(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)
|
||||||
|
|
||||||
|
;;(do ((i 0 (+ i 1)))
|
||||||
|
;; ((>= i 1000))
|
||||||
|
;; (draw-tile i))
|
||||||
|
(do ((i 0 (+ i 1)))
|
||||||
|
((>= i 64))
|
||||||
|
(draw-hero i)))
|
||||||
|
|
||||||
(define (launch-game args)
|
(define (launch-game args)
|
||||||
(run-game #:load load
|
(run-game #:load (lambda () (load))
|
||||||
#:update update
|
#:update (lambda (dt) (update dt))
|
||||||
#:draw draw))
|
#:draw (lambda (alpha) (draw alpha))))
|
||||||
|
|
10
guix.scm
10
guix.scm
|
@ -11,7 +11,7 @@
|
||||||
(gnu packages pkg-config))
|
(gnu packages pkg-config))
|
||||||
|
|
||||||
(package
|
(package
|
||||||
(name "chickadee-game-template")
|
(name "bloatrunner")
|
||||||
(version "0.1.0-git")
|
(version "0.1.0-git")
|
||||||
(source (git-checkout (url (dirname (current-filename)))))
|
(source (git-checkout (url (dirname (current-filename)))))
|
||||||
(build-system gnu-build-system)
|
(build-system gnu-build-system)
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
(list guile-3.0))
|
(list guile-3.0))
|
||||||
(propagated-inputs
|
(propagated-inputs
|
||||||
(list guile-chickadee))
|
(list guile-chickadee))
|
||||||
(synopsis "Chickadee game template")
|
(synopsis "Loderunner inspired game")
|
||||||
(description "This is an example package for a Chickadee game.")
|
(description "Small game written for the 2024 lisp game jam.")
|
||||||
(home-page "https://dthompson.us/projects/chickadee.html")
|
(home-page "https://www.snamellit.com/projects/bloatrunner.html")
|
||||||
(license license:asl2.0))
|
(license license:gpl3))
|
||||||
|
|
Loading…
Reference in a new issue