From f57d30fd5a1b1eabc745dc267b83e595e270317a Mon Sep 17 00:00:00 2001 From: Peter Tillemans Date: Sun, 28 Apr 2024 14:18:49 +0200 Subject: [PATCH] add random pipes --- TODO.org | 4 ++-- flappy-ball.lisp | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/TODO.org b/TODO.org index 528a321..8e04bf3 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 [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 diff --git a/flappy-ball.lisp b/flappy-ball.lisp index 16b2766..1546dd2 100644 --- a/flappy-ball.lisp +++ b/flappy-ball.lisp @@ -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))