Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Game server and client
- Loading branch information
Showing
11 changed files
with
283 additions
and
180 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(in-package :mortar-combat) | ||
|
||
|
||
(defevent player-added-event () | ||
(player)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(in-package :mortar-combat) | ||
|
||
|
||
(defclass game-client (connector) () | ||
(:default-initargs :host "localhost" :port 8222)) | ||
|
||
|
||
(defun make-game-client () | ||
(make-instance 'game-client)) | ||
|
||
|
||
(defun register-player (client name) | ||
(run (-> (client :command :register-player | ||
:name name) | ||
()))) | ||
|
||
|
||
(defun send-player-info (client name player) | ||
(let ((pos (position-of player)) | ||
(rot (rotation-of player))) | ||
(run (-> (client :command :player-info | ||
:name name | ||
:position (list (x pos) (y pos)) | ||
:rotation (list (x rot) (y rot))) | ||
())))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(in-package :mortar-combat) | ||
|
||
|
||
(defclass game-server (connector) | ||
((players :initform (make-hash-table :test 'equal))) | ||
(:default-initargs :host "localhost" :port 8222)) | ||
|
||
|
||
(defun make-game-server () | ||
(make-instance 'game-server)) | ||
|
||
|
||
(defmethod process-command ((command (eql :register-player)) message) | ||
(with-slots (players) *connector* | ||
(with-message (name) message | ||
(with-instance-lock-held (*connector*) | ||
(let ((player (make-instance 'player))) | ||
(setf (gethash name players) player) | ||
(post (make-player-added-event player) (events)))))) | ||
nil) | ||
|
||
|
||
(defmethod process-command ((command (eql :player-info)) message) | ||
(with-slots (players) *connector* | ||
(with-message (name position rotation) message | ||
(with-instance-lock-held (*connector*) | ||
(when-let ((player (gethash name players))) | ||
(setf (position-of player) (sequence->vec2 position) | ||
(rotation-of player) (sequence->vec2 rotation)))))) | ||
nil) |
Oops, something went wrong.