aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/02-moving-bitmp.lisp
blob: 425457b148c4a14a5c74362fce692dc34ccfeaed (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
;;; 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 (unit code mods)
      (case code
        (:scancode-left (decf (ww::unit-x unit) (ww::unit-width unit)))
        (:scancode-right (incf (ww::unit-x unit) (ww::unit-width unit)))
        (:scancode-down (decf (ww::unit-y unit) (ww::unit-height unit)))
        (:scancode-up (incf (ww::unit-y unit) (ww::unit-height unit)))
        (:scancode-equals
         (when (or (member :lshift mods) (member :rshift mods))
           (incf (ww::unit-height unit) 20.0)
           (incf                  (ww::unit-width unit) 20.0)))
        (:scancode-minus
         (decf (ww::unit-height unit) 20.0)
         (decf                (ww::unit-width unit) 20.0)))))

(defmethod ww::boot ((app bitmap-display))
  (let ((bm
          (make-instance 'ww::bitmap
                         :texture (ww::get-asset "Fezghoul.png"))))
    (ww::refocus-on bm)
    (ww::set-handler bm #'move-thing)
    (ww::add-unit app bm)))


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


(start)