aboutsummaryrefslogtreecommitdiff
path: root/tests/world-test.scm
diff options
context:
space:
mode:
authorGene Pasquet <dev@etenil.net>2026-04-05 19:47:05 +0100
committerGene Pasquet <dev@etenil.net>2026-04-05 19:47:05 +0100
commit027053b11a3a5d861ed2fa2db245388bd95ac246 (patch)
tree84dfd90642bb6d8eb4e0e3fa3a9d651ba29b41e8 /tests/world-test.scm
parent927f37639a3d5a0d881a5c8709f2cf577aadb15e (diff)
Progress
Diffstat (limited to 'tests/world-test.scm')
-rw-r--r--tests/world-test.scm31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/world-test.scm b/tests/world-test.scm
index 38005b2..c4fd887 100644
--- a/tests/world-test.scm
+++ b/tests/world-test.scm
@@ -236,4 +236,35 @@
'player
(entity-ref (car (scene-entities scene)) #:type #f))))
+ (test-group "camera-follow!"
+ (let* ((cam (make-camera x: 0 y: 0))
+ (entity (list #:type 'player #:x 400 #:y 300 #:width 16 #:height 16)))
+ (camera-follow! cam entity 600 400)
+ (test-equal "centers camera x on entity" 100 (camera-x cam))
+ (test-equal "centers camera y on entity" 100 (camera-y cam)))
+ (let* ((cam (make-camera x: 0 y: 0))
+ (entity (list #:type 'player #:x 50 #:y 30 #:width 16 #:height 16)))
+ (camera-follow! cam entity 600 400)
+ (test-equal "clamps camera x to 0 when entity near origin" 0 (camera-x cam))
+ (test-equal "clamps camera y to 0 when entity near origin" 0 (camera-y cam))))
+
+ (test-group "scene-find-tagged"
+ (let* ((p (list #:type 'player #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(player)))
+ (e (list #:type 'enemy #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(enemy npc)))
+ (s (make-scene entities: (list p e) tilemap: #f
+ camera: (make-camera x: 0 y: 0) tileset-texture: #f)))
+ (test-equal "finds entity with matching tag" p (scene-find-tagged s 'player))
+ (test-equal "finds enemy by 'enemy tag" e (scene-find-tagged s 'enemy))
+ (test-equal "finds entity with second tag in list" e (scene-find-tagged s 'npc))
+ (test-equal "returns #f when tag not found" #f (scene-find-tagged s 'boss))))
+
+ (test-group "scene-find-all-tagged"
+ (let* ((p1 (list #:type 'player #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(player friendly)))
+ (p2 (list #:type 'ally #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(ally friendly)))
+ (e (list #:type 'enemy #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(enemy)))
+ (s (make-scene entities: (list p1 p2 e) tilemap: #f
+ camera: (make-camera x: 0 y: 0) tileset-texture: #f)))
+ (test-equal "returns all friendly entities" 2 (length (scene-find-all-tagged s 'friendly)))
+ (test-equal "returns empty list when none match" '() (scene-find-all-tagged s 'boss))))
+
(test-end "world-module")