(define-module (game model key)
  #:use-module (chickadee math vector)
  #:use-module (game model level)
  #:use-module (game model hero)
  #:use-module (srfi srfi-9)
  #:use-module (srfi srfi-9 gnu)
  #:export (key?
            key-near-position?
            keys-load
            key-position
            make-key
            keys-update
            )
  )


(define-immutable-record-type <key>
  (make-key position)
  key?
  (position key-position)
  )

(define (key-collides? key position)
  (< (vec2-magnitude (vec2- (key-position key) position)) 4))


(define (keys-load level)
  (map make-key (level-find-keys level)))

(define (keys-update keys hero)
  (filter (lambda (key)
            (not (key-collides? key (hero-position hero))))
          keys))

(define (keys-open-door? keys)
  (null? keys))
