;;;; examples/06-sprite.lisp (defpackage #:ww.examples/6 (:use #:cl) (:export #:start)) (in-package #:ww.examples/6) (defclass sprite-example (ww::application) ()) (defun set-key-if-not (sprite key ) (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) (ww::defhandler move-dude (ww::on-keydown (target scancode) (case scancode (:scancode-left (set-key-if-not target :left) (decf (ww::x target) +walking-speed+)) (:scancode-right (set-key-if-not target :right) (incf (ww::x target) +walking-speed+)) (:scancode-up (set-key-if-not target :back) (incf (ww::y target) +walking-speed+)) (:scancode-down (set-key-if-not target :front) (decf (ww::y target) +walking-speed+))))) (ww::defhandler stand (ww::on-keyup (target) (let ((current (ww::current-frameset target))) (setf (ww::runningp current) nil (ww::frameset-index current) 0)))) (defmethod ww::boot ((app sprite-example)) (let* ((front (ww::make-frameset '("dude/Front_Stand.png" "dude/Front_Left.png" "dude/Front_Stand.png" "dude/Front_Right.png") :fps 3)) (back (ww::make-frameset '("dude/Back_Stand.png" "dude/Back_Left.png" "dude/Back_Stand.png" "dude/Back_Right.png") :fps 3)) (left (ww::make-frameset '("dude/Left_Stand.png" "dude/Left_Left.png" "dude/Left_Stand.png" "dude/Left_Right.png") :fps 3)) (right (ww::make-frameset '("dude/Right_Stand.png" "dude/Right_Left.png" "dude/Right_Stand.png" "dude/Right_Right.png") :fps 3)) (dude (make-instance 'ww::sprite :framesets (list :front front :back back :left left :right right) :frameset-key :front))) (ww::add-handler dude #'move-dude) (ww::add-handler dude #'stand) (ww::refocus-on dude) (ww::add-unit app dude))) (defun start () (ww::start (make-instance 'sprite-example :fps 30 :width 800 :height 600 :title "Wheelwork Example: An Animated Sprite" :asset-root (merge-pathnames "examples/" (asdf:system-source-directory :wheelwork)))))