(define max-y (/ (assoc-ref (get-game-properties) 'height) 2))
(define min-y (- max-y))
-(define (update-asteroid! a #:key x y angle vx vy)
- (cond (x (assoc-set! a 'x x)))
- (cond (y (assoc-set! a 'y y)))
- (cond (x (assoc-set! a 'x x)))
- (cond (x (assoc-set! a 'x x)))
- (cond (x (assoc-set! a 'x x)))
-
(define draw-asteroid
(let ((asteroid (load-texture "Asteroid.png")))
(lambda (a)
(cond ((> y max-y) (set! vy -1))
((< y min-y) (set! vy 1)))
- (assoc-set! a 'x x)
- (assoc-set! a 'y y)
- (assoc-set! a 'angle (+ angle 1))
- (assoc-set! a 'vx vx)
- (assoc-set! a 'vy vy)
- a))
+ (assoc-multiple-set! a 'x x 'y y 'angle (+ angle 1) 'vx vx 'vy vy)))
(define draw-ship
(let ((ship1 (load-texture "Ship1.png"))
(else
(set! moving #f)))
- (assoc-set! s 'x x)
- (assoc-set! s 'y y)
- `((x . ,x) (y . ,y) (angle . ,angle) (moving . ,moving))))
+ (assoc-multiple-set! s 'x x 'y y 'angle angle 'moving moving)))
(define (ship-shot s)
(cond ((key-pressed? 'space)
(cond ((= n 0) '())
(else
- (cons `((x . ,(xy max-x 20)) (y . ,(xy max-y 20)) (angle . 0) (vx . 1) (vy . 1)) (make-asteroids (- n 1))))))
+ (cons `((x . ,(xy max-x 20)) (y . ,(xy max-y 20)) (angle . 0) (vx . 1) (vy . 1) (size . 95))
+ (make-asteroids (- n 1))))))
-(define (killed-ship? ship asteroids)
- #f)
+(define (killed-ship? s a)
+ (cond ((null? a) #f)
+ (else
+ (or (< (sqrt (+ (expt (- (assoc-ref s 'x) (assoc-ref (car a) 'x)) 2)
+ (expt (- (assoc-ref s 'y) (assoc-ref (car a) 'y)) 2)))
+ (assoc-ref (car a) 'size))
+ (killed-ship? s (cdr a))))))
(let ((asteroids #f) (ship #f) (shots #f))
(define (new-game n)
(draw-rectangle (* zoom width) (* zoom height) #:texture texture)))))
(define* (draw-line length #:optional color)
- (let ((l
- (cond (color
- (with-color color (draw v1 v2)))
- (else
- (draw v1 v2))))
+ (let ((l (/ length 2)))
+ (cond (color
+ (with-color color (draw (list 0 l) (list 0 (- l)))))
+ (else
+ (draw (list 0 l) (list 0 (- l)))))))
(define* (draw-quad v1 v2 v3 v4 #:key texture color)
(cond (texture
(define-macro (pushnew elem list)
`(cond ((not (find (lambda (e) (eq? e ,elem)) ,list))
(set! ,list (cons ,elem ,list)))))
+
+(define (assoc-multiple-set! alist . pairs)
+ (define (amset! alist pairs)
+ (cond ((< (length pairs) 2)
+ alist)
+ (else
+ (assoc-set! alist (car pairs) (cadr pairs))
+ (amset! alist (cddr pairs)))))
+ (amset! alist pairs))