aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/06-sprite.lisp
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-07-02 06:47:38 -0500
committerColin Okay <colin@cicadas.surf>2022-07-02 06:47:38 -0500
commite264b9febc1bf036c54110b21a346bcfcf01f75e (patch)
treef4171afcbb494eefe89950c4d765157d27b006e4 /examples/06-sprite.lisp
parent04050cf509025ffafb50e13eb82270a471303d2d (diff)
[doc] docstrings added to sprite example. [modified] fps of same
Diffstat (limited to 'examples/06-sprite.lisp')
-rw-r--r--examples/06-sprite.lisp21
1 files changed, 13 insertions, 8 deletions
diff --git a/examples/06-sprite.lisp b/examples/06-sprite.lisp
index 8b6380a..1eade58 100644
--- a/examples/06-sprite.lisp
+++ b/examples/06-sprite.lisp
@@ -10,18 +10,20 @@
(defclass dude (ww::sprite)
((walkingp :accessor walkingp :initform nil)))
-
(defun set-key-if-not (sprite key )
+ "Sets the frameey for sprite if that key is not already set. Also
+sets the frameset's RUNNINGP to T if it is not already."
(unless (eql key (ww::frameset-key sprite))
(setf (ww::runningp (ww::current-frameset sprite)) nil)
(setf (ww::frameset-key sprite) key))
(unless (ww::runningp (ww::current-frameset sprite))
(setf (ww::runningp (ww::current-frameset sprite)) t)))
-(define-symbol-macro +walking-speed+ 10)
+(define-symbol-macro +walking-speed+ 5)
(ww::defhandler move-by-face
(ww::on-perframe (sprite)
+ "When the sprite is walking, adjust its position."
(when (walkingp sprite)
(case (ww::frameset-key sprite)
(:left
@@ -35,6 +37,7 @@
(ww::defhandler move-dude
(ww::on-keydown (target scancode)
+ "Set sprite to walking and set the frameset appropriate to its direction."
(setf (walkingp target) t)
(case scancode
(:scancode-left
@@ -48,6 +51,8 @@
(ww::defhandler stand
(ww::on-keyup (target)
+ "Stop the sprite from walking, and stop its current frameset
+ from animating, setting its frame to the standing position."
(setf (walkingp target) nil)
(let ((current
(ww::current-frameset target)))
@@ -58,9 +63,9 @@
(defmethod ww::boot ((app sprite-example))
(let* ((front
(ww::make-frameset
- '("dude/Front_Stand.png"
+ '("dude/Front_Stand.png" ; this is the order in which frames will render
"dude/Front_Left.png"
- "dude/Front_Stand.png"
+ "dude/Front_Stand.png" ; reusing assets does not add them twice
"dude/Front_Right.png")
:fps 3))
(back
@@ -87,11 +92,11 @@
(dude
(make-instance
'dude
- :framesets (list :front front
- :back back
+ :framesets (list :front front ; a sprite has many framesets
+ :back back ; and are kept in a plist
:left left
:right right)
- :frameset-key :front)))
+ :frameset-key :front))) ; initial frameset to use
(setf (ww::runningp (ww::current-frameset dude)) nil)
(ww::add-handler dude #'move-by-face )
@@ -103,7 +108,7 @@
(defun start ()
(ww::start (make-instance
'sprite-example
- :fps 30
+ :fps 60
:width 800
:height 600
:title "Wheelwork Example: An Animated Sprite"