summaryrefslogtreecommitdiff
path: root/game.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2023-10-23 07:54:11 -0400
committerDavid Thompson <dthompson2@worcester.edu>2023-10-23 07:54:11 -0400
commitba705ff0d1de68d36be42330784ab3ab6812c8ea (patch)
tree6a4bac3ba78a0af2e4d5def8deafdcd09e396676 /game.scm
parent4e21f204bfa9f7ad8c949abcb8fe7b13f1325354 (diff)
Parallax background.
Diffstat (limited to 'game.scm')
-rw-r--r--game.scm18
1 files changed, 16 insertions, 2 deletions
diff --git a/game.scm b/game.scm
index 8200f3d..5a6f586 100644
--- a/game.scm
+++ b/game.scm
@@ -233,13 +233,14 @@
;; Screen size stuff
(define game-width 240.0)
(define game-height 320.0)
- (define canvas-scale 2.0)
+ (define canvas-scale 3.0)
(define canvas-width (* game-width canvas-scale))
(define canvas-height (* game-height canvas-scale))
;; Elements
(define canvas (get-element-by-id "canvas"))
(define context (get-context canvas "2d"))
+ (define image:background (get-element-by-id "image-background"))
(define image:player (get-element-by-id "image-player"))
(define image:player-bullet (get-element-by-id "image-player-bullet"))
(define image:enemy-bullets (get-element-by-id "image-enemy-bullets"))
@@ -805,12 +806,25 @@
(define (draw-enemy-bullets)
(draw-bullets enemy-bullets image:enemy-bullets 16.0 16.0))
+ (define (draw-background image parallax)
+ (let ((scroll (remainder (* *scroll* parallax) game-height)))
+ ;; Bottom
+ (draw-image context image:background
+ 0.0 0.0 game-width (- game-height scroll)
+ 0.0 scroll game-width (- game-height scroll))
+ ;; Top
+ (draw-image context image:background
+ 0.0 (- game-height scroll) game-width scroll
+ 0.0 0.0 game-width scroll)
+ ))
+
(define (draw time)
(clear-screen)
(set-transform! context 1.0 0.0 0.0 1.0 0.0 0.0)
(set-scale! context canvas-scale canvas-scale)
- (set-fill-color! context demichrome0)
+ (set-fill-color! context "#3f2832")
(fill-rect context 0.0 0.0 game-width game-height)
+ (draw-background image:background 0.75)
(draw-tiles level)
;; (draw-tiles level 0.0)
(draw-player-bullets)