first draft of level support

This commit is contained in:
Peter Tillemans 2024-05-09 23:02:40 +02:00
parent e10f22ceb1
commit 9cd0cba597

View file

@ -161,7 +161,7 @@ Hash-table with level name => file name => resource.")
(defun %read-static-files-in-memory () (defun %read-static-files-in-memory ()
"load all resources for all levels in memory" "load all resources for all levels in memory"
(setf *resources* (serapeum:dict)) (setf *resources* (serapeum:dict))
(loop for level in (list "level1") (loop for level in (list "level1" "level2" "level3" "level4")
do (read-level-assets level) do (read-level-assets level)
finally (return *resources*))) finally (return *resources*)))
@ -235,11 +235,11 @@ Hash-table with level name => file name => resource.")
(score 0) (score 0)
(high-scores (load-high-scores "highscores")) (high-scores (load-high-scores "highscores"))
(on-exit (lambda () ())) (on-exit (lambda () ()))
(play-level 0) (play-level 1)
) )
(let ((ball-collides (some (lambda (pipe) (pipe-collides pipe ball scroll-x)) pipes)) (let ((ball-collides (some (lambda (pipe) (pipe-collides pipe ball scroll-x)) pipes))
(level (format nil "level~a" (1+ play-level)))) (level (format nil "level~a" play-level)))
(draw-background level scroll-x) (draw-background level scroll-x)
(draw-foreground level pipes scroll-x pipe-pen height) (draw-foreground level pipes scroll-x pipe-pen height)
@ -267,16 +267,25 @@ Hash-table with level name => file name => resource.")
(with-slots (score state (with-slots (score state
width ground-level width ground-level
scroll-x scroll-speed scroll-x scroll-speed
pipes-width pipes-spacing pipes-amount pipes pipes-width pipes-spacing pipes-amount
ball gravity ball gravity
play-level
high-scores) instance high-scores) instance
(setf score (1+ (/ (- scroll-x pipes-width (/ width 10)) pipes-spacing))) (setf score (1+ (/ (- scroll-x pipes-width (/ width 10)) pipes-spacing)))
(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))
(when (> (round score) pipes-amount) (when (> (round score) pipes-amount)
(if (eq play-level 4)
(progn
(setf state 'won) (setf state 'won)
(setf high-scores (high-scores-add high-scores score)) (setf high-scores (high-scores-add high-scores score))
(save-high-scores "highscores" high-scores)))) (save-high-scores "highscores" high-scores))
(progn
(setf play-level (1+ play-level))
(setf pipes (random-pipes pipes-amount pipes-spacing ground-level 100 pipes-width))
(setf scroll-x 0.0)
(setf scroll-speed (* 0.8 scroll-speed)))))))
(defmethod on-death ((instance flappy-ball)) (defmethod on-death ((instance flappy-ball))
(with-slots (state high-scores score) instance (with-slots (state high-scores score) instance