aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Letan <contact@thomasletan.fr>2018-07-06 18:44:59 +0200
committerThomas Letan <contact@thomasletan.fr>2018-07-06 18:44:59 +0200
commit7b25f4e4966e63c1a129de7660a3904a9abda15b (patch)
treeb14c7ef5ce7996e762417531c858fa0f518a495e
parentfeature: Continue to move when entering inside a map (diff)
feature: Distinguish between direction and looks atHEADmain
-rw-r--r--lykanc/client.lisp26
-rw-r--r--lykanc/command.lisp6
-rw-r--r--lykanc/message.lisp13
-rw-r--r--lykanc/parameter.lisp1
-rw-r--r--lykanc/puppet.lisp12
-rw-r--r--lykand/lib/lykan/character.ex5
-rw-r--r--lykand/lib/lykan/puppeteer/player.ex4
-rw-r--r--lykand/lib/lykan/system/physics.ex19
8 files changed, 64 insertions, 22 deletions
diff --git a/lykanc/client.lisp b/lykanc/client.lisp
index f11a892..8be709a 100644
--- a/lykanc/client.lisp
+++ b/lykanc/client.lisp
@@ -58,7 +58,7 @@
(defmethod add-puppet ((app client) key x y dir)
(let ((puppet (new-puppet "character.tsx"
x y)))
- (changes-direction puppet dir)
+ (look-at puppet dir)
(fairy:add-child (get-objects-layer app)
puppet
:with-key key))
@@ -80,6 +80,9 @@
(defmethod puppet-changes-direction ((app client) key dir)
(changes-direction (get-puppet app key) dir))
+(defmethod puppet-looks-at ((app client) key dir)
+ (look-at (get-puppet app key) dir))
+
(defmethod puppet-hurted ((app client) key)
(hurted (get-puppet app key)))
@@ -103,25 +106,26 @@
(gamekit:y (fairy:origin (fairy:get-child (fairy:get-child app :ui) :cursor))))
(defmethod update-cursor ((app client) dx dy)
- (let ((vx (min (max 0 (+ (get-cursor-x app) dx)) *viewport-width*))
- (vy (min (max 0 (+ (get-cursor-y app) dy)) *viewport-height*)))
+ (let* ((dx (* dx *mouse-sensibility*))
+ (dy (* dy *mouse-sensibility*))
+ (vx (min (max 0 (+ (get-cursor-x app) dx)) *viewport-width*))
+ (vy (min (max 0 (+ (get-cursor-y app) dy)) *viewport-height*)))
(force-cursor app vx vy)))
-(defun get-angle (x y)
- (+ (- (atan x y)) (/ pi 2)))
+(defun get-angle (vec)
+ (+ (- (atan (gamekit:x vec) (gamekit:y vec))) (/ pi 2)))
(defmethod force-cursor ((app client) x y)
(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))))
+ (alpha (get-angle 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
- 200)))
+ (wsd:send-text (socket app)
+ (command-look-at alpha)))
+ (setf (fairy:origin (fairy:get-child (fairy:get-child app :ui) :cursor))
+ cursor)))
(defmethod update-camera ((app client))
(when (map-ready? app)
diff --git a/lykanc/command.lisp b/lykanc/command.lisp
index b399c5a..41227a0 100644
--- a/lykanc/command.lisp
+++ b/lykanc/command.lisp
@@ -5,3 +5,9 @@
("opcode" . "SET_DIRECTION")
("arguments" . (:obj
("angle" . ,angle))))))
+
+(defun command-look-at (angle)
+ (jsown:to-json `(:obj
+ ("opcode" . "LOOK_AT")
+ ("arguments" . (:obj
+ ("angle" . ,angle))))))
diff --git a/lykanc/message.lisp b/lykanc/message.lisp
index 0f9ac83..68e70f0 100644
--- a/lykanc/message.lisp
+++ b/lykanc/message.lisp
@@ -18,7 +18,7 @@
(add-puppet app key
(jsown:val puppet-desc "x")
(jsown:val puppet-desc "y")
- (jsown:val puppet-desc "direction"))))))
+ (jsown:val puppet-desc "look_at"))))))
;; PUPPET ENTERS
(defun handle-puppet-enters (message app)
@@ -28,7 +28,7 @@
(add-puppet app key
(jsown:val digest "x")
(jsown:val digest "y")
- (jsown:val digest "direction")))))
+ (jsown:val digest "look_at")))))
;; PUPPET MOVES
(defun handle-puppet-moves (message app)
@@ -57,6 +57,14 @@
(jsown:val message "puppet_key")
(jsown:val message "direction"))))
+;; PUPPET LOOKS AT
+(defun handle-puppet-looks-at (message app)
+ (print "looks at")
+ (in-game-loop
+ (puppet-looks-at app
+ (jsown:val message "puppet_key")
+ (jsown:val message "direction"))))
+
;; PUPPET STARTS ATTACKING
(defun handle-puppet-attacks (message app)
(in-game-loop (puppet-attacks app (jsown:val message "puppet_key"))))
@@ -88,6 +96,7 @@
((string= opcode "PUPPET_STOPS") (handle-puppet-stops cmd app))
((string= opcode "PUPPET_LEAVES") (handle-puppet-leaves cmd app))
((string= opcode "PUPPET_DIRECTION") (handle-puppet-direction cmd app))
+ ((string= opcode "PUPPET_LOOKS_AT") (handle-puppet-looks-at cmd app))
((string= opcode "PUPPET_STARTS_ATTACKING") (handle-puppet-attacks cmd app))
((string= opcode "PUPPET_STOPS_ATTACKING") (handle-puppet-stops-attack cmd app))
((string= opcode "PUPPET_HURTED") (handle-puppet-hurted cmd app))
diff --git a/lykanc/parameter.lisp b/lykanc/parameter.lisp
index 3477a4d..24cd6d3 100644
--- a/lykanc/parameter.lisp
+++ b/lykanc/parameter.lisp
@@ -4,6 +4,7 @@
(defparameter *viewport-height* 240)
(defparameter *scale* 2)
(defparameter *cursor-size* 10)
+(defparameter *mouse-sensibility* 0.5)
(defparameter *server-url* "ws://localhost:4000")
(defparameter *lykan-assets-dir* (uiop:getenv "LYKAN_ASSETS_DIR"))
diff --git a/lykanc/puppet.lisp b/lykanc/puppet.lisp
index c4f8183..14022dc 100644
--- a/lykanc/puppet.lisp
+++ b/lykanc/puppet.lisp
@@ -58,7 +58,6 @@
(defmethod hurted ((p puppet))
(let* ((h (fairy:height p))
- (w (fairy:width p))
(damages (make-instance 'fairy:text
:value "Hit!"
:font (gamekit:make-font :lykanc-font 10)
@@ -86,11 +85,7 @@
(defmethod fairy:height ((p puppet))
(fairy:height (fairy:get-child p :character)))
-(defmethod changes-direction ((p puppet) angle)
- (let ((dir (get-dir angle)))
- (when (not (eq (direction p) dir))
- (setf (direction p) dir)
- (update-animation p))))
+(defmethod changes-direction ((p puppet) angle) ())
(defun get-dir (angle)
(cond
@@ -101,4 +96,7 @@
(t :left)))
(defmethod look-at ((p puppet) angle)
- (changes-direction p angle))
+ (let ((dir (get-dir angle)))
+ (when (not (eq (direction p) dir))
+ (setf (direction p) dir)
+ (update-animation p))))
diff --git a/lykand/lib/lykan/character.ex b/lykand/lib/lykan/character.ex
index 0d5225f..41a6619 100644
--- a/lykand/lib/lykan/character.ex
+++ b/lykand/lib/lykan/character.ex
@@ -54,6 +54,11 @@ defpuppet Lykan.Character do
write(key, :direction, dir)
nil
end
+
+ def looks_at(key, dir, _) do
+ write(key, :look_at, dir)
+ nil
+ end
end
defmodule Appearance do
diff --git a/lykand/lib/lykan/puppeteer/player.ex b/lykand/lib/lykan/puppeteer/player.ex
index 623da92..90a0186 100644
--- a/lykand/lib/lykan/puppeteer/player.ex
+++ b/lykand/lib/lykan/puppeteer/player.ex
@@ -98,8 +98,8 @@ defmodule Lykan.Puppeteer.Player do
cast_return()
end
- defp consume_cmd(cmd = %C.LookAt{}, _state, _instance_key) do
- IO.puts cmd.angle
+ defp consume_cmd(cmd = %C.LookAt{}, state, instance_key) do
+ Lykan.System.Physics.puppet_looks_at(instance_key, state.puppet, cmd.angle)
cast_return()
end
diff --git a/lykand/lib/lykan/system/physics.ex b/lykand/lib/lykan/system/physics.ex
index 1a1635c..e1d7c52 100644
--- a/lykand/lib/lykan/system/physics.ex
+++ b/lykand/lib/lykan/system/physics.ex
@@ -39,6 +39,8 @@ defsystem Lykan.System.Physics do
@call get_direction() :: Lykan.System.Physics.direction
@cast set_direction(dir :: Lykan.System.Physics.direction)
+ @cast looks_at(dir :: Lykan.System.Physics.direction)
+
@call get_position() :: Vector.t
@cast set_position(pos :: Vector.t)
@@ -103,6 +105,15 @@ defsystem Lykan.System.Physics do
]
end
+ defmessage PuppetLooksAt do
+ opcode "PUPPET_LOOKS_AT"
+
+ content [
+ :puppet_key,
+ :direction,
+ ]
+ end
+
#############################################################################
defmodule State do
@moduledoc false
@@ -211,6 +222,14 @@ defsystem Lykan.System.Physics do
cast_return()
end
+ cast puppet_looks_at(puppet_key :: Lkn.Core.Puppet.k, dir :: direction) do
+ Body.looks_at(puppet_key, dir)
+
+ notify(&Lykan.Puppeteer.notify(&1, PuppetLooksAt.craft(puppet_key, dir)))
+
+ cast_return()
+ end
+
cast puppet_starts_moving(puppet_key :: Lkn.Core.Puppet.k) do
if MapSet.member?(puppets, puppet_key) && !State.move?(state, puppet_key) do
{:ok, beac} = Beacon.start(instance_key)