show prize after last pipe

This commit is contained in:
Peter Tillemans 2024-04-28 15:11:20 +02:00
parent f57d30fd5a
commit d946b38235
4 changed files with 23 additions and 16 deletions

View file

@ -4,7 +4,7 @@
A flappy bird clone to get experience with Common Lisp and game development. A flappy bird clone to get experience with Common Lisp and game development.
* Game Plan [9/15] * Game Plan [10/15]
- [X] Create bird, well, ball - [X] Create bird, well, ball
- [X] Add physics for ball movement - [X] Add physics for ball movement
- [X] Add inputs on key and mouse clicks - [X] Add inputs on key and mouse clicks
@ -14,11 +14,11 @@ A flappy bird clone to get experience with Common Lisp and game development.
- [X] Add regression tests - [X] Add regression tests
- [X] Add background - [X] Add background
- [X] Create random pipes - [X] Create random pipes
- [ ] Add goal after last pipe - [X] Add goal after last pipe
- [ ] Create state machine to manage start/play/finish - [ ] Create state machine to manage start/play/finish
- [ ] Create different levels
- [ ] Add scores - [ ] Add scores
- [ ] Add high scores - [ ] Add high scores
- [ ] Package for Mac/Linux/(Windows?) - [ ] Package for Mac/Linux/(Windows?)
- [ ] Create different levels

BIN
assets/level1/prize.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
assets/level1/prize.xcf Normal file

Binary file not shown.

View file

@ -93,7 +93,7 @@
;; ------------------------------------------------------------- ;; -------------------------------------------------------------
(defun draw_image_layer(resource scroll-x) (defun draw-image-layer(resource scroll-x)
(let ((pic (load-resource resource)) (let ((pic (load-resource resource))
(offset (mod scroll-x 960)) (offset (mod scroll-x 960))
) )
@ -101,16 +101,16 @@
:x 0 :y 0 :width 960 :height 540))) :x 0 :y 0 :width 960 :height 540)))
(defun draw_background (scroll-x) (defun draw-background (scroll-x)
(draw_image_layer "assets/level1/sky.png" 0) (draw-image-layer "assets/level1/sky.png" 0)
(draw_image_layer "assets/level1/clouds.png" (* -0.15 scroll-x)) (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/far.png" (* 0.25 scroll-x))
(draw_image_layer "assets/level1/middle.png" (* 0.6 scroll-x))) (draw-image-layer "assets/level1/middle.png" (* 0.6 scroll-x)))
(defun draw_foreground (pipes scroll-x pipe-pen height) (defun draw-foreground (pipes scroll-x pipe-pen height)
(dolist (pipe pipes) (dolist (pipe pipes)
(pipe-draw pipe pipe-pen scroll-x height)) (pipe-draw pipe pipe-pen scroll-x height))
(draw_image_layer "assets/level1/ground.png" scroll-x)) (draw-image-layer "assets/level1/ground.png" scroll-x))
(defun random-pipes (n spacing max-height gap width) (defun random-pipes (n spacing max-height gap width)
(let ((padding 25)) (let ((padding 25))
@ -132,18 +132,25 @@
(ball-pen (make-pen :stroke (gray 0.5) :fill sketch:+yellow+ :weight 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)) (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)) (pipe-pen (make-pen :stroke (gray 0.5) :fill sketch:+green+ :weight 1))
(pipes (random-pipes 15 200 ground-level 100 20)) (pipes-amount 5)
(pipes-spacing 200)
(pipes (random-pipes pipes-amount pipes-spacing ground-level 100 20))
(scroll-x 0.0) (scroll-x 0.0)
(scroll-speed 0.2)) (scroll-speed 0.2)
(target-x (- (* pipes-amount pipes-spacing) 720)))
(draw_background scroll-x) (draw-background scroll-x)
(draw_foreground pipes scroll-x pipe-pen height) (draw-foreground pipes scroll-x pipe-pen height)
(ball-draw ball (ball-draw ball
(if (some (lambda (pipe) (pipe-collides pipe ball scroll-x)) pipes) (if (some (lambda (pipe) (pipe-collides pipe ball scroll-x)) pipes)
collision-pen collision-pen
ball-pen)) ball-pen))
(if (>= scroll-x target-x)
(let ((pic (load-resource "assets/level1/prize.png")))
(draw pic :x (- (+ 960 target-x) scroll-x) :y 0 )))
(setf scroll-x (+ scroll-x scroll-speed)) (setf scroll-x (+ scroll-x scroll-speed))
(setf ball (ball-move ball gravity ground-level))) (setf ball (ball-move ball gravity ground-level)))