From ba705ff0d1de68d36be42330784ab3ab6812c8ea Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 23 Oct 2023 07:54:11 -0400 Subject: Parallax background. --- game.scm | 18 ++++++++++++++++-- images/background.ase | Bin 0 -> 2359 bytes images/background.png | Bin 0 -> 1129 bytes images/player-bullet.ase | Bin 439 -> 422 bytes index.html | 1 + 5 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 images/background.ase create mode 100644 images/background.png 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) diff --git a/images/background.ase b/images/background.ase new file mode 100644 index 0000000..93a3150 Binary files /dev/null and b/images/background.ase differ diff --git a/images/background.png b/images/background.png new file mode 100644 index 0000000..00db1c4 Binary files /dev/null and b/images/background.png differ diff --git a/images/player-bullet.ase b/images/player-bullet.ase index 19af10d..5e7a8cf 100644 Binary files a/images/player-bullet.ase and b/images/player-bullet.ase differ diff --git a/index.html b/index.html index 499bf49..162fc93 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,7 @@
+ -- cgit v1.2.3