simplify stuff, start work on message commands
This commit is contained in:
parent
6e1a2e9fd4
commit
6db1804330
|
@ -1,8 +1,8 @@
|
|||
(load "~/quicklisp/setup.lisp") ; need to load quicklisp
|
||||
(ql:quickload '(:cl-raylib :cl-bcrypt :websocket-driver-client :bordeaux-threads :alexandria :com.inuoe.jzon))
|
||||
(ql:quickload '(:cl-raylib :cl-bcrypt :websocket-driver-client :alexandria :com.inuoe.jzon))
|
||||
|
||||
(defpackage :mmo-client
|
||||
(:use :common-lisp :cl-raylib :3d-vectors :websocket-driver-client :bordeaux-threads :alexandria :com.inuoe.jzon))
|
||||
(:use :common-lisp :cl-raylib :raylib :3d-vectors :websocket-driver-client :alexandria :com.inuoe.jzon))
|
||||
|
||||
(in-package :mmo-client)
|
||||
|
||||
|
@ -11,12 +11,11 @@
|
|||
(wsd:start-connection *client*)
|
||||
(wsd:on :message *client*
|
||||
(lambda (message)
|
||||
(format t "~&Got: ~A~%" message)))
|
||||
(format t "~A~%" message)))
|
||||
|
||||
(defun game-loop ()
|
||||
(let* ((screen-width 800)
|
||||
(let* ((screen-width 800)
|
||||
(screen-height 450)
|
||||
(username "username")
|
||||
(username "zongor")
|
||||
(title "mmo client - common lisp")
|
||||
(camera (make-camera3d :position (vec 4.0 2.0 4.0)
|
||||
:target (vec 0.0 0.5 0.0)
|
||||
|
@ -26,13 +25,24 @@
|
|||
(cube-screen-pos (vec 0.0 0.0)))
|
||||
|
||||
(with-window (screen-width screen-height title)
|
||||
(disable-cursor)
|
||||
;; (disable-cursor)
|
||||
(set-target-fps 60) ; Set our game to run at 60 FPS
|
||||
|
||||
(wsd:send *client* (com.inuoe.jzon:stringify (list :login username)))
|
||||
(loop
|
||||
until (window-should-close) ; detect window close button or ESC key
|
||||
do
|
||||
(update-camera camera :camera-third-person)
|
||||
(wsd:send *client* (com.inuoe.jzon:stringify (list (camera3d-target camera) username :red :move)))
|
||||
|
||||
(when (is-key-down 87)
|
||||
(wsd:send *client* (com.inuoe.jzon:stringify (list :move (camera3d-target camera)))))
|
||||
(when (is-key-down 65)
|
||||
(wsd:send *client* (com.inuoe.jzon:stringify (list :move (camera3d-target camera)))))
|
||||
(when (is-key-down 83)
|
||||
(wsd:send *client* (com.inuoe.jzon:stringify (list :move (camera3d-target camera)))))
|
||||
(when (is-key-down 68)
|
||||
(wsd:send *client* (com.inuoe.jzon:stringify (list :move (camera3d-target camera)))))
|
||||
|
||||
(setf cube-screen-pos (get-world-to-screen (v+ (camera3d-target camera) (vec 0 1.0 0)) camera))
|
||||
(with-drawing
|
||||
(clear-background :raywhite)
|
||||
|
@ -41,9 +51,7 @@
|
|||
(draw-cube-wires (camera3d-target camera) 1.0 1.0 1.0 :maroon)
|
||||
(draw-grid 20 1.0))
|
||||
(draw-text username (- (floor (vx cube-screen-pos)) (floor (measure-text username 20) 2))
|
||||
(floor (vy cube-screen-pos) ) 20 :black)))))
|
||||
(wsd:close-connection *client*))
|
||||
(floor (vy cube-screen-pos) ) 20 :black))))
|
||||
(wsd:send *client* (com.inuoe.jzon:stringify (list :logout username))))
|
||||
|
||||
(bt:make-thread 'game-loop)
|
||||
|
||||
(bt:run-in-new-thread (bt:get-thread 'game-loop))
|
||||
(wsd:close-connection *client*)
|
||||
|
|
|
@ -14,9 +14,12 @@
|
|||
(format nil "user-~a" (random 100000))))
|
||||
|
||||
(defun broadcast-to-room (connection message)
|
||||
(let ((message (format nil "~a: ~a"
|
||||
(gethash connection *connections*)
|
||||
(let ((message (format nil "~a"
|
||||
;(gethash connection *connections*)
|
||||
message)))
|
||||
|
||||
(format t "~A~%" (com.inuoe.jzon:parse message))
|
||||
|
||||
(loop :for con :being :the :hash-key :of *connections* :do
|
||||
(websocket-driver:send con message))))
|
||||
|
||||
|
@ -40,6 +43,10 @@
|
|||
(lambda (&key code reason)
|
||||
(declare (ignore code reason))
|
||||
(handle-close-connection ws)))
|
||||
(websocket-driver:on :error ws
|
||||
(lambda (error)
|
||||
(format t "Got an error: ~S~%" error)))
|
||||
|
||||
(lambda (responder)
|
||||
(declare (ignore responder))
|
||||
(websocket-driver:start-connection ws))))
|
||||
|
|
Loading…
Reference in New Issue