From 204875e7f3851ab2b6e8c2344a7b7d795a900a6c Mon Sep 17 00:00:00 2001 From: nephryte Date: Sat, 25 May 2024 22:03:12 -0400 Subject: [PATCH] Initialize tile map stuff in game manager --- modules/ces/component/tilemap.scm | 4 ++-- modules/ces/system/tilemap-renderer.scm | 4 +++- modules/game/game-manager.scm | 21 +++++++++++++++++++-- modules/game/game-objects.scm | 6 ++++-- modules/game/level-manager.scm | 7 +++++-- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/modules/ces/component/tilemap.scm b/modules/ces/component/tilemap.scm index d51af8b..06f26a7 100644 --- a/modules/ces/component/tilemap.scm +++ b/modules/ces/component/tilemap.scm @@ -32,14 +32,14 @@ (height tile-height)) (define-record-type - (make-tileset tile-width tile-height tiles) + (make-tileset tiles tile-width tile-height) tileset? (tile-width ts-tile-width) (tile-height ts-tile-height) (tiles ts-tiles)) (define-record-type - (make-tile-layer data x y width height) + (make-tilemap-layer data x y width height) tilemap-layer? (data tl-data) (x tl-x) diff --git a/modules/ces/system/tilemap-renderer.scm b/modules/ces/system/tilemap-renderer.scm index d27c284..25177b3 100644 --- a/modules/ces/system/tilemap-renderer.scm +++ b/modules/ces/system/tilemap-renderer.scm @@ -24,7 +24,9 @@ (for-each (lambda (layer) (let ((data (tl-data layer)) (x-offset (tl-x layer)) - (y-offset (tl-y layer))) + (y-offset (tl-y layer)) + (tl-width (tl-width layer)) + (tl-height (tl-height layer))) (for-each (lambda (index) (let* ((tile (vector-ref ts-tiles index)) (img (tile-image tile)) diff --git a/modules/game/game-manager.scm b/modules/game/game-manager.scm index d2a9235..aa99102 100644 --- a/modules/game/game-manager.scm +++ b/modules/game/game-manager.scm @@ -4,14 +4,31 @@ #:use-module (ces system html-canvas-renderer) #:use-module (dom image) #:use-module (media) + #:use-module (ces component tilemap) #:use-module (game level-manager) + #:use-module (logging) #:export (init-game-entities init-game-systems)) (define (init-game-entities) "Returns a list of initial game entities. " - (let ((room-background (get-image (get-media-library) 'room-background)) - (room-tilemap '())) + (write-log! "Init game entities") + (let* ((room-background (get-image (get-media-library) 'room-background)) + (ts-vec (write-log! (vector + (make-tile 'tile-blank 16 16) + (make-tile 'tile-floor 16 16) + (make-tile 'tile-wall 16 16) + (make-tile 'tile-door 16 16)))) + (tl-vec (write-log! + #(2 2 2 2 3 2 2 2 + 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1))) + (room-tilemap + (make-tilemap + (make-tileset ts-vec 16 16) + (list + (make-tilemap-layer tl-vec 0 0 8 4))))) (list (create-player!) (create-room! room-tilemap)))) diff --git a/modules/game/game-objects.scm b/modules/game/game-objects.scm index c372f98..545e723 100644 --- a/modules/game/game-objects.scm +++ b/modules/game/game-objects.scm @@ -9,6 +9,7 @@ #:use-module (ces entity-manager) #:use-module (game-core) #:use-module (dom image) + #:use-module (logging) #:export (add-game-object-components game-object? create-game-object!)) @@ -33,7 +34,8 @@ (has-components? entity 'position 'hitbox 'sprite)) (define (create-game-object! x y width height sprite) - (let* ((e-manager (get-entity-manager)) - (entity (create-entity! e-manager))) + (write-log! "create-game-object!") + (let* ((e-manager (write-log! (get-entity-manager))) + (entity (write-log! (create-entity! e-manager)))) (reset-entity! e-manager (add-game-object-components entity x y width height sprite)))) diff --git a/modules/game/level-manager.scm b/modules/game/level-manager.scm index 235cd2c..0616f52 100644 --- a/modules/game/level-manager.scm +++ b/modules/game/level-manager.scm @@ -11,6 +11,7 @@ #:use-module (game game-objects) #:use-module (game-core) #:use-module (media) + #:use-module (logging) #:export (create-player! create-room!)) @@ -20,8 +21,10 @@ (has-components? entity 'keyboard-input))) (define (create-player!) - (let* ((player-sprite (get-image (get-media-library) 'player)) - (initial-entity (create-game-object! 0 0 16 16 player-sprite))) + (let* ( + (player-sprite (write-log! (get-image (get-media-library) 'player))) + (initial-entity (write-log! (create-game-object! 0 0 16 16 player-sprite))) + ) (set-component initial-entity 'keyboard-input (create-inputs))))