add parallax background
- scaled assets to 960x540 and adjusted window for that size - adjusted ground level - collect background and foreground actions in functions - tuned physics
This commit is contained in:
parent
b6dd72aeb8
commit
22c7398e63
7 changed files with 33 additions and 12 deletions
4
TODO.org
4
TODO.org
|
@ -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 [7/15]
|
* Game Plan [8/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
|
||||||
|
@ -12,7 +12,7 @@ A flappy bird clone to get experience with Common Lisp and game development.
|
||||||
- [X] Scroll pipes
|
- [X] Scroll pipes
|
||||||
- [X] Detect collisions
|
- [X] Detect collisions
|
||||||
- [X] Add regression tests
|
- [X] Add regression tests
|
||||||
- [ ] Add background
|
- [X] Add background
|
||||||
- [ ] Create random pipes
|
- [ ] Create random pipes
|
||||||
- [ ] Add goal after last pipe
|
- [ ] Add goal after last pipe
|
||||||
- [ ] Create state machine to manage start/play/finish
|
- [ ] Create state machine to manage start/play/finish
|
||||||
|
|
BIN
assets/level1/clouds.png
Normal file
BIN
assets/level1/clouds.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
BIN
assets/level1/far.png
Normal file
BIN
assets/level1/far.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
assets/level1/ground.png
Normal file
BIN
assets/level1/ground.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
BIN
assets/level1/middle.png
Normal file
BIN
assets/level1/middle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
BIN
assets/level1/sky.png
Normal file
BIN
assets/level1/sky.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
|
@ -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
|
(defsketch flappy-ball
|
||||||
((title "Flappy Ball")
|
((title "Flappy Ball")
|
||||||
(width 800)
|
(width 960)
|
||||||
(height 600)
|
(height 540)
|
||||||
|
(ground-level 440)
|
||||||
(copy-pixels nil)
|
(copy-pixels nil)
|
||||||
(ball (make-ball (/ width 10) (/ height 3) 0 10))
|
(ball (make-ball (/ width 10) (/ height 3) 0 10))
|
||||||
(gravity 0.05)
|
(gravity 0.025)
|
||||||
(flap-speed -2.5)
|
(flap-speed -1)
|
||||||
(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 (list
|
(pipes (list
|
||||||
(make-pipe 200 200 100 20)
|
(make-pipe 200 100 100 20)
|
||||||
(make-pipe 400 300 100 20)
|
(make-pipe 400 200 100 20)
|
||||||
(make-pipe 600 400 100 20)))
|
(make-pipe 600 300 100 20)))
|
||||||
(scroll-x 0.0)
|
(scroll-x 0.0)
|
||||||
(scroll-speed 0.2))
|
(scroll-speed 0.2))
|
||||||
|
|
||||||
(dolist (pipe pipes)
|
(draw_background scroll-x)
|
||||||
(pipe-draw pipe pipe-pen scroll-x 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))
|
||||||
|
|
||||||
(setf scroll-x (+ scroll-x scroll-speed))
|
(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)
|
(defmethod on-click ((instance flappy-ball) x y)
|
||||||
(with-slots (ball flap-speed) instance
|
(with-slots (ball flap-speed) instance
|
||||||
|
|
Loading…
Reference in a new issue