From: jsancho Date: Tue, 30 Aug 2011 15:14:29 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=e562aad852e11b0ac7f9d94f65bff8b984240d02;p=gacela.git --- diff --git a/games/asteroids/asteroids.scm b/games/asteroids/asteroids.scm index 3109431..d684e07 100644 --- a/games/asteroids/asteroids.scm +++ b/games/asteroids/asteroids.scm @@ -5,13 +5,6 @@ (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) @@ -31,12 +24,7 @@ (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")) @@ -66,9 +54,7 @@ (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) @@ -109,10 +95,16 @@ (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) diff --git a/src/gacela_draw.scm b/src/gacela_draw.scm index 9500429..f72c751 100644 --- a/src/gacela_draw.scm +++ b/src/gacela_draw.scm @@ -114,11 +114,11 @@ (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 diff --git a/src/gacela_misc.scm b/src/gacela_misc.scm index 9dc10aa..a9393ca 100644 --- a/src/gacela_misc.scm +++ b/src/gacela_misc.scm @@ -43,3 +43,12 @@ (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))