aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Letan <contact@thomasletan.fr>2018-07-01 23:19:55 +0200
committerThomas Letan <contact@thomasletan.fr>2018-07-01 23:19:55 +0200
commitd31eb35b5838f01d886491de9f430abadbccc09b (patch)
treef4c2a25d42c20ed03c5b7a987bb0998bb84622ee
parentfeature: Implement a smooth camera movement (diff)
feature(client): Distinguish between looking at and direction
-rw-r--r--lykanc/client.lisp17
-rw-r--r--lykanc/puppet.lisp16
2 files changed, 28 insertions, 5 deletions
diff --git a/lykanc/client.lisp b/lykanc/client.lisp
index 5b8c3eb..77583c8 100644
--- a/lykanc/client.lisp
+++ b/lykanc/client.lisp
@@ -100,10 +100,21 @@
(vy (min (max 0 (+ (get-cursor-y app) dy)) *viewport-height*)))
(force-cursor app vx vy)))
+(defun get-angle (x y)
+ (atan x y))
+
(defmethod force-cursor ((app client) x y)
- (fairy:goto (fairy:get-child (fairy:get-child app :ui) :cursor)
- (gamekit:vec2 x y)
- 100))
+ (let* ((cursor (gamekit:vec2 x y))
+ (center (gamekit:vec2 (/ *viewport-width* 2)
+ (/ *viewport-height* 2)))
+ (dir-vec (gamekit:subt cursor center))
+ (alpha (get-angle (gamekit:x dir-vec)
+ (gamekit:y dir-vec))))
+ (when (map-ready? app)
+ (look-at (get-puppet app (main-puppet app)) alpha))
+ (fairy:goto (fairy:get-child (fairy:get-child app :ui) :cursor)
+ cursor
+ 100)))
(defmethod update-camera ((app client))
(when (map-ready? app)
diff --git a/lykanc/puppet.lisp b/lykanc/puppet.lisp
index 32ab442..40f3ee3 100644
--- a/lykanc/puppet.lisp
+++ b/lykanc/puppet.lisp
@@ -87,5 +87,17 @@
(fairy:height (fairy:get-child p :character)))
(defmethod changes-direction ((p puppet) dir)
- (setf (direction p) dir)
- (update-animation p))
+ (when (not (eq (direction p) dir))
+ (setf (direction p) dir)
+ (update-animation p)))
+
+(defun get-dir (angle)
+ (cond
+ ((<= angle (- (* 3 (/ pi 4)))) :down)
+ ((<= angle (- (* 1 (/ pi 4)))) :left)
+ ((<= angle (* 1 (/ pi 4))) :up)
+ ((<= angle (* 3 (/ pi 4))) :right)
+ (t :down)))
+
+(defmethod look-at ((p puppet) angle)
+ (changes-direction p (get-dir angle)))