aboutsummaryrefslogtreecommitdiff
path: root/world.scm
diff options
context:
space:
mode:
Diffstat (limited to 'world.scm')
-rw-r--r--world.scm19
1 files changed, 19 insertions, 0 deletions
diff --git a/world.scm b/world.scm
index 2cd0feb..8e1651a 100644
--- a/world.scm
+++ b/world.scm
@@ -56,4 +56,23 @@
(scene-entities-set! scene
(filter pred (scene-entities scene)))
scene)
+
+ ;; Center camera on entity. Clamps to >= 0 on both axes.
+ ;; viewport-w and viewport-h are the game window dimensions (pixels).
+ (define (camera-follow! camera entity viewport-w viewport-h)
+ (camera-x-set! camera (max 0 (- (entity-ref entity #:x 0) (/ viewport-w 2))))
+ (camera-y-set! camera (max 0 (- (entity-ref entity #:y 0) (/ viewport-h 2)))))
+
+ ;; Returns the first entity in scene whose #:tags list contains tag, or #f.
+ (define (scene-find-tagged scene tag)
+ (let loop ((entities (scene-entities scene)))
+ (cond
+ ((null? entities) #f)
+ ((member tag (entity-ref (car entities) #:tags '())) (car entities))
+ (else (loop (cdr entities))))))
+
+ ;; Returns all entities in scene whose #:tags list contains tag.
+ (define (scene-find-all-tagged scene tag)
+ (filter (lambda (e) (member tag (entity-ref e #:tags '())))
+ (scene-entities scene)))
)