(module downstroke/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))))) )