aboutsummaryrefslogtreecommitdiff
path: root/entity.scm
diff options
context:
space:
mode:
Diffstat (limited to 'entity.scm')
-rw-r--r--entity.scm45
1 files changed, 45 insertions, 0 deletions
diff --git a/entity.scm b/entity.scm
new file mode 100644
index 0000000..cd467eb
--- /dev/null
+++ b/entity.scm
@@ -0,0 +1,45 @@
+(module entity
+ *
+ (import scheme
+ (chicken base)
+ (chicken keyword)
+ (only srfi-1 fold))
+
+ ;; Entities = plists with shared keys (#:type, #:x, #:y, #:width, #:height, ...).
+
+ (define (entity-ref entity key #!optional default)
+ (get-keyword key entity (if (procedure? default) default (lambda () default))))
+
+ (define (entity-type entity)
+ (entity-ref entity #:type #f))
+
+ (define (entity-set entity key val)
+ (let ((cleaned (let loop ((lst entity) (acc '()))
+ (if (null? lst)
+ (reverse acc)
+ (let ((k (car lst))
+ (v (cadr lst)))
+ (if (eq? k key)
+ (loop (cddr lst) acc)
+ (loop (cddr lst) (cons v (cons k acc)))))))))
+ (cons key (cons val cleaned))))
+
+ (define (entity-update entity key proc #!optional default)
+ (entity-set entity key (proc (entity-ref entity key default))))
+
+ (define (make-player-entity x y width height)
+ (list #:type 'player
+ #:x x
+ #:y y
+ #:width width
+ #:height height
+ #:vx 0
+ #:vy 0
+ #:gravity? #t
+ #:on-ground? #f
+ #:tile-id 29
+ #:input-map '((left . (-2 . 0))
+ (right . ( 2 . 0))
+ (down . ( 0 . 2)))))
+)
+