add random pipes

This commit is contained in:
Peter Tillemans 2024-04-28 14:18:49 +02:00
parent 22c7398e63
commit f57d30fd5a
2 changed files with 11 additions and 6 deletions

View file

@ -4,7 +4,7 @@
A flappy bird clone to get experience with Common Lisp and game development.
* Game Plan [8/15]
* Game Plan [9/15]
- [X] Create bird, well, ball
- [X] Add physics for ball movement
- [X] Add inputs on key and mouse clicks
@ -13,7 +13,7 @@ A flappy bird clone to get experience with Common Lisp and game development.
- [X] Detect collisions
- [X] Add regression tests
- [X] Add background
- [ ] Create random pipes
- [X] Create random pipes
- [ ] Add goal after last pipe
- [ ] Create state machine to manage start/play/finish
- [ ] Create different levels

View file

@ -112,6 +112,14 @@
(pipe-draw pipe pipe-pen scroll-x height))
(draw_image_layer "assets/level1/ground.png" scroll-x))
(defun random-pipes (n spacing max-height gap width)
(let ((padding 25))
(loop repeat n
for x from spacing by (+ spacing )
collect (make-pipe x (+ padding (random (- max-height gap padding padding))) gap width)))
)
(defsketch flappy-ball
((title "Flappy Ball")
(width 960)
@ -124,10 +132,7 @@
(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 100 100 20)
(make-pipe 400 200 100 20)
(make-pipe 600 300 100 20)))
(pipes (random-pipes 15 200 ground-level 100 20))
(scroll-x 0.0)
(scroll-speed 0.2))