From b20698fa4cc47bc092b54a338aa37f8771ddf091 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sat, 16 Jul 2022 07:07:30 -0500 Subject: [example] more tweaking with canvas example --- examples/10-canvas.lisp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'examples/10-canvas.lisp') 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 -- cgit v1.2.3