aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/02-moving-bitmp.lisp
blob: 200a1d194c4a2a59a9e809f78406c98bcc04d4ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
;;; 01-bitmap-display.lisp

(defpackage #:ww.examples/2
  (:use #:cl)
  (:export #:start))

(in-package :ww.examples/2)

(defclass bitmap-display (ww::application ) ())

(ww::defhandler move-thing
    (ww::on-keydown ()
      (case scancode
        (:scancode-left (decf (ww::unit-x target) (ww::unit-width target)))
        (:scancode-right (incf (ww::unit-x target) (ww::unit-width target)))
        (:scancode-down (decf (ww::unit-y target) (ww::unit-height target)))
        (:scancode-up (incf (ww::unit-y target) (ww::unit-height target)))
        (:scancode-equals
         (when (or (member :lshift modifiers) (member :rshift modifiers))
           (incf (ww::unit-height target) 20.0)
           (incf                  (ww::unit-width target) 20.0)))
        (:scancode-minus
         (decf (ww::unit-height target) 20.0)
         (decf                (ww::unit-width target) 20.0)))
      (format t "ghoul pos: ~a,~a~%"
              (ww::unit-x target) (ww::unit-y target))))

(ww::defhandler thing-clicked
    (ww::on-mousedown ()
      (format t "~a was clicked at ~a,~a!~%" target x y)))

(ww::defhandler mouse-over
    (ww::on-mousemotion ()
      (print (list target x y xrel yrel state))))

(defmethod ww::boot ((app bitmap-display))
  (let ((bm
          (make-instance 'ww::bitmap
                         :texture (ww::get-asset "Fezghoul.png")))
        (bm2
          (make-instance 'ww::bitmap
                         :texture (ww::get-asset "RootBear.png"))))
    ;; first 
    (ww::refocus-on bm)
    (ww::set-handler bm #'move-thing)
    (ww::set-handler bm #'thing-clicked)
    (ww::set-handler bm #'mouse-over)
    (ww::add-unit app bm)
    ;;second
    (setf (ww::unit-x bm2) 90
          (ww::unit-y bm2) 90)
    (ww::set-handler bm2 #'move-thing)
    (ww::set-handler bm2 #'thing-clicked)
    (ww::add-unit app bm2)))


(defun start ()
  (ww::start (make-instance 'bitmap-display
                            :scale 2.0
                            :asset-root #P"~/projects/wheelwork/examples/")))