diff --git a/TODO.org b/TODO.org index b9c9d61..528a321 100644 --- a/TODO.org +++ b/TODO.org @@ -4,7 +4,7 @@ A flappy bird clone to get experience with Common Lisp and game development. -* Game Plan [7/15] +* Game Plan [8/15] - [X] Create bird, well, ball - [X] Add physics for ball movement - [X] Add inputs on key and mouse clicks @@ -12,7 +12,7 @@ A flappy bird clone to get experience with Common Lisp and game development. - [X] Scroll pipes - [X] Detect collisions - [X] Add regression tests -- [ ] Add background +- [X] Add background - [ ] Create random pipes - [ ] Add goal after last pipe - [ ] Create state machine to manage start/play/finish diff --git a/assets/level1/clouds.png b/assets/level1/clouds.png new file mode 100644 index 0000000..d70d5c4 Binary files /dev/null and b/assets/level1/clouds.png differ diff --git a/assets/level1/far.png b/assets/level1/far.png new file mode 100644 index 0000000..3a356a0 Binary files /dev/null and b/assets/level1/far.png differ diff --git a/assets/level1/ground.png b/assets/level1/ground.png new file mode 100644 index 0000000..2d2be78 Binary files /dev/null and b/assets/level1/ground.png differ diff --git a/assets/level1/middle.png b/assets/level1/middle.png new file mode 100644 index 0000000..a026587 Binary files /dev/null and b/assets/level1/middle.png differ diff --git a/assets/level1/sky.png b/assets/level1/sky.png new file mode 100644 index 0000000..0c3fb74 Binary files /dev/null and b/assets/level1/sky.png differ diff --git a/flappy-ball.lisp b/flappy-ball.lisp index 426259d..16b2766 100644 --- a/flappy-ball.lisp +++ b/flappy-ball.lisp @@ -93,33 +93,54 @@ ;; ------------------------------------------------------------- +(defun draw_image_layer(resource scroll-x) + (let ((pic (load-resource resource)) + (offset (mod scroll-x 960)) + ) + (draw (crop pic offset 0 960 540) + :x 0 :y 0 :width 960 :height 540))) + + +(defun draw_background (scroll-x) + (draw_image_layer "assets/level1/sky.png" 0) + (draw_image_layer "assets/level1/clouds.png" (* -0.15 scroll-x)) + (draw_image_layer "assets/level1/far.png" (* 0.25 scroll-x)) + (draw_image_layer "assets/level1/middle.png" (* 0.6 scroll-x))) + +(defun draw_foreground (pipes scroll-x pipe-pen height) + (dolist (pipe pipes) + (pipe-draw pipe pipe-pen scroll-x height)) + (draw_image_layer "assets/level1/ground.png" scroll-x)) + (defsketch flappy-ball ((title "Flappy Ball") - (width 800) - (height 600) + (width 960) + (height 540) + (ground-level 440) (copy-pixels nil) (ball (make-ball (/ width 10) (/ height 3) 0 10)) - (gravity 0.05) - (flap-speed -2.5) + (gravity 0.025) + (flap-speed -1) (ball-pen (make-pen :stroke (gray 0.5) :fill sketch:+yellow+ :weight 1)) (collision-pen (make-pen :stroke (gray 0.5) :fill sketch:+red+ :weight 1)) (pipe-pen (make-pen :stroke (gray 0.5) :fill sketch:+green+ :weight 1)) (pipes (list - (make-pipe 200 200 100 20) - (make-pipe 400 300 100 20) - (make-pipe 600 400 100 20))) + (make-pipe 200 100 100 20) + (make-pipe 400 200 100 20) + (make-pipe 600 300 100 20))) (scroll-x 0.0) (scroll-speed 0.2)) - (dolist (pipe pipes) - (pipe-draw pipe pipe-pen scroll-x height)) + (draw_background scroll-x) + (draw_foreground pipes scroll-x pipe-pen height) + (ball-draw ball (if (some (lambda (pipe) (pipe-collides pipe ball scroll-x)) pipes) collision-pen ball-pen)) (setf scroll-x (+ scroll-x scroll-speed)) - (setf ball (ball-move ball gravity height))) + (setf ball (ball-move ball gravity ground-level))) (defmethod on-click ((instance flappy-ball) x y) (with-slots (ball flap-speed) instance