diff options
-rw-r--r-- | game.scm | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -176,6 +176,9 @@ (define (vec2-add! v w) (set-vec2-x! v (+ (vec2-x v) (vec2-x w))) (set-vec2-y! v (+ (vec2-y v) (vec2-y w)))) + (define (vec2-sub! v w) + (set-vec2-x! v (- (vec2-x v) (vec2-x w))) + (set-vec2-y! v (- (vec2-y v) (vec2-y w)))) (define (vec2-mul-scalar! v x) (set-vec2-x! v (* (vec2-x v) x)) (set-vec2-y! v (* (vec2-y v) x))) @@ -710,7 +713,7 @@ (enemy-stop! (vector-ref enemies i)) (vector-set! enemies i #f)) (set-enemy-pool-length! pool 0)))) - (define (enemy-pool-update! pool collide) + (define (enemy-pool-update! pool) (match pool (#('enemy-pool length capacity enemies) (let ((padding 16.0)) @@ -749,12 +752,14 @@ (let ((speed 2.0)) (let loop ((theta 0.0)) (let ((dx (* (cos theta) speed)) - (dy (* (sin theta) speed))) + (dy (* (sin theta) speed)) + (v (direction-to-player (enemy-position enemy)))) (bullet-pool-add! enemy-bullets 0 (enemy-x enemy) (enemy-y enemy) - dx dy)) - (wait 2) + (* (vec2-x v) speed) + (* (vec2-y v) speed))) + (wait 30) (loop (+ theta 0.2))))) (let ((enemy (make-enemy 'foo 20 (vec2 x y) (vec2 16.0 16.0) #t (vec2 0.0 0.0) script))) @@ -763,7 +768,7 @@ ;; Player state: (define player-position (vec2 (/ game-width 2.0) (- game-height 12.0))) (define player-velocity (vec2 0.0 0.0)) - (define player-speed 4.0) + (define player-speed 2.9) (define player-bullet-speed 12.0) (define player-width 24.0) (define player-height 24.0) @@ -871,6 +876,11 @@ (vec2-y player-hitbox-position) player-hitbox-width player-hitbox-height)) + (define (direction-to-player v) + (let ((v* (vec2 (vec2-x player-position) (vec2-y player-position)))) + (vec2-sub! v* v) + (vec2-normalize! v*) + v*)) (define *canvas-scale* 0.0) (define *canvas-width* 0) @@ -904,11 +914,11 @@ (define (draw-background image parallax) (let ((scroll (remainder (* *scroll* parallax) game-height))) ;; Bottom - (draw-image context image:background + (draw-image context image 0.0 0.0 game-width (- game-height scroll) 0.0 scroll game-width (- game-height scroll)) ;; Top - (draw-image context image:background + (draw-image context image 0.0 (- game-height scroll) game-width scroll 0.0 0.0 game-width scroll))) @@ -1006,9 +1016,6 @@ #t) #f)))) - (define (enemy-collide x y w h hp) - hp) - (define dt (/ 1000.0 60.0)) (define (update) (scheduler-tick! *scheduler*) @@ -1016,7 +1023,7 @@ (player-update!) (bullet-pool-update! player-bullets player-bullet-collide) (bullet-pool-update! enemy-bullets enemy-bullet-collide) - (enemy-pool-update! enemies enemy-collide) + (enemy-pool-update! enemies) (timeout update dt)) (add-event-listener! (current-window) "resize" (lambda (_) (resize-canvas))) |