You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.6 KiB

(in-package :pong.game)
(defclass action ()
((timestamp :initarg :timestamp
:initform (/ (get-internal-real-time) internal-time-units-per-second)
:reader action-timestamp)
(paddle :initarg :paddle :initform nil :reader paddle)))
(defgeneric apply-action (action game))
(defclass start-down-action (action) ())
(defclass stop-down-action (action) ())
(defclass start-up-action (action) ())
(defclass stop-up-action (action) ())
(cpk:defencoding action timestamp paddle)
(cpk:defencoding start-down-action timestamp paddle)
(cpk:defencoding stop-down-action timestamp paddle)
(cpk:defencoding start-up-action timestamp paddle)
(cpk:defencoding stop-up-action timestamp paddle)
(defun get-paddle (paddle state)
(case paddle
(:left (state-left-paddle state))
(:right (state-right-paddle state))) )
(defmethod apply-action ((action start-down-action) (game game))
(let* ((state (game-state game))
(paddle (get-paddle (paddle action) state)))
(incf (paddle-vy paddle) +paddle-speed+)))
(defmethod apply-action ((action stop-down-action) (game game))
(let* ((state (game-state game))
(paddle (get-paddle (paddle action) state)))
(decf (paddle-vy paddle) +paddle-speed+)))
(defmethod apply-action ((action start-up-action) (game game))
(let* ((state (game-state game))
(paddle (get-paddle (paddle action) state)))
(decf (paddle-vy paddle) +paddle-speed+)))
(defmethod apply-action ((action stop-up-action) (game game))
(let* ((state (game-state game))
(paddle (get-paddle (paddle action) state)))
(incf (paddle-vy paddle) +paddle-speed+)))