diff options
| author | Gene Pasquet <dev@etenil.net> | 2026-04-05 14:17:51 +0100 |
|---|---|---|
| committer | Gene Pasquet <dev@etenil.net> | 2026-04-05 14:17:51 +0100 |
| commit | 526e6cdcdf1025d5e29680bc99ab910c79789764 (patch) | |
| tree | 2a91b3e96f2b97cfc81169627f222a5393982830 /entity.scm | |
Initial port of macroknight to an engine
Diffstat (limited to 'entity.scm')
| -rw-r--r-- | entity.scm | 45 |
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))))) +) + |
