aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-07-16 07:07:30 -0500
committerColin Okay <colin@cicadas.surf>2022-07-16 07:07:30 -0500
commitb20698fa4cc47bc092b54a338aa37f8771ddf091 (patch)
tree7cc3f88b102d23e8eb51c89248bdfeb68bc4bc5c
parent55acc817ad919c47de39e0febe8630304792793f (diff)
[example] more tweaking with canvas example
-rw-r--r--examples/10-canvas.lisp36
1 files changed, 18 insertions, 18 deletions
diff --git a/examples/10-canvas.lisp b/examples/10-canvas.lisp
index 5539bdf..453ef0e 100644
--- a/examples/10-canvas.lisp
+++ b/examples/10-canvas.lisp
@@ -9,8 +9,9 @@
;;; CLASSES
-(defclass/std sneking (ww::application)
- ((sneks snek-pit)))
+(defclass/std sneking (ww:application)
+ ((sneks snek-pit)
+ (population :std 10)))
(defclass/std snek ()
((x y)
@@ -27,11 +28,13 @@
(and (<= left x (1- right))
(<= bottom y (1- top))))))
+(defun random-between (lo hi)
+ (+ lo (random (1+ (- hi lo)))))
+
(defun snek-change-mind (snek)
- (when (zerop (random 2))
- (setf (dx snek) (* -1 (dx snek))))
- (when (zerop (random 2))
- (setf (dy snek) (* -1 (dy snek)))))
+ (if (zerop (random 2))
+ (setf (dx snek) (random-between -1 1))
+ (setf (dy snek) (random-between -1 1))))
(defun advance-snek-pos (snek)
(with-slots (x y dx dy home bod len) snek
@@ -66,16 +69,12 @@
(setf r red g green b blue a alpha))
(setf alpha (max 0 (- alpha 10))))))))
-
-(defun random-between (lo hi)
- (+ lo (random (- hi lo))))
-
(defun random-snek (&optional (boundx 100) (boundy 100))
(make-instance 'snek
:color (list (random 256) (random 256) (random 256))
:dy (random-between -1 1)
:dx (random-between -1 1)
- :len (random-between 50 70)
+ :len (random-between 50 100)
:home (list 0 0 boundx boundy)
:x (random boundx)
:y (random boundy)))
@@ -94,19 +93,20 @@
(setf (snek-pit app)
(make-instance 'ww:canvas :pixel-width 100 :pixel-height 100)
(sneks app)
- (loop repeat 60 collect (random-snek 100 100)))
- (setf (ww:width (snek-pit app)) 800
- (ww:height (snek-pit app)) 800)
+ (loop repeat (population app) collect (random-snek 100 100)))
+ (setf (ww:width (snek-pit app)) (ww::application-width app)
+ (ww:height (snek-pit app)) (ww::application-width app))
(ww::add-unit app (snek-pit app))
(ww:add-handler app #'sneks-a-go-go))
-(defun start ()
+(defun start (&key (side 800) (population 50))
(ww::start
(make-instance
'sneking
- :fps 20
- :width 800
- :height 800
+ :population population
+ :fps 60
+ :width side
+ :height side
:refocus-on-mousedown-p nil
:title "sneks"
:asset-root