diff options
author | David Thompson <dthompson2@worcester.edu> | 2023-10-23 07:54:11 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2023-10-23 07:54:11 -0400 |
commit | ba705ff0d1de68d36be42330784ab3ab6812c8ea (patch) | |
tree | 6a4bac3ba78a0af2e4d5def8deafdcd09e396676 | |
parent | 4e21f204bfa9f7ad8c949abcb8fe7b13f1325354 (diff) |
Parallax background.
-rw-r--r-- | game.scm | 18 | ||||
-rw-r--r-- | images/background.ase | bin | 0 -> 2359 bytes | |||
-rw-r--r-- | images/background.png | bin | 0 -> 1129 bytes | |||
-rw-r--r-- | images/player-bullet.ase | bin | 439 -> 422 bytes | |||
-rw-r--r-- | index.html | 1 |
5 files changed, 17 insertions, 2 deletions
@@ -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 Binary files differnew file mode 100644 index 0000000..93a3150 --- /dev/null +++ b/images/background.ase diff --git a/images/background.png b/images/background.png Binary files differnew file mode 100644 index 0000000..00db1c4 --- /dev/null +++ b/images/background.png diff --git a/images/player-bullet.ase b/images/player-bullet.ase Binary files differindex 19af10d..5e7a8cf 100644 --- a/images/player-bullet.ase +++ b/images/player-bullet.ase @@ -7,6 +7,7 @@ <body> <canvas id="canvas"></canvas> <div style="display:none;"> + <img id="image-background" src="images/background.png" /> <img id="image-player" src="images/player.png" /> <img id="image-player-bullet" src="images/player-bullet.png" /> <img id="image-enemy-bullets" src="images/enemy-bullets.png" /> |