almost drawing engine. at least no syntax errors...
This commit is contained in:
parent
3a3c66bba5
commit
bfda5bc4df
25
engine.lisp
25
engine.lisp
|
@ -2,26 +2,31 @@
|
||||||
|
|
||||||
(defclass engine-object (game-object)
|
(defclass engine-object (game-object)
|
||||||
((start-time :initarg :start-time :accessor start-time :initform 0)
|
((start-time :initarg :start-time :accessor start-time :initform 0)
|
||||||
|
;; time till fully active
|
||||||
(activation-time :initarg :activation-time :accessor activation-time :initform 0)))
|
(activation-time :initarg :activation-time :accessor activation-time :initform 0)))
|
||||||
|
|
||||||
|
|
||||||
|
(defmethod activate ((object engine-object) start-time)
|
||||||
|
(setf (start-time object) start-time))
|
||||||
|
|
||||||
(defclass engine-model (model)
|
(defclass engine-model (model)
|
||||||
((template-vertices :initarg :template-vertices :accessor template-vertices :initform nil)
|
((template-vertices :initarg :template-vertices :accessor template-vertices :initform nil)
|
||||||
(template-colors :initarg :template-colors :accessor template-colors :initform nil)))
|
(template-colors :initarg :template-colors :accessor template-colors :initform nil)))
|
||||||
|
|
||||||
(defun generate-step-2d-array (2darr time)
|
(defun generate-step-2d-array (2darr time)
|
||||||
(let ((len-arr (length 2darr))
|
(let ((len-arr (length 2darr))
|
||||||
(len-row (length (aref 2darr 0))))
|
(len-row (length (first 2darr))))
|
||||||
(make-2d-array len-arr len-row
|
(make-2d-array len-arr len-row
|
||||||
(loop for i from 0 to len-arr collecting
|
(loop for row in 2darr collecting
|
||||||
(loop for j from 0 to len-row collecting
|
(loop for item in row collecting
|
||||||
(let ((item (aref (aref 2darr i) j)))
|
;(let ((item (aref (aref 2darr i) j)))
|
||||||
(if (listp item)
|
(if (listp item)
|
||||||
(converge (first item) (second item) (third item) time)
|
(converge (first item) (second item) (third item) time)
|
||||||
item)))))))
|
item))))))
|
||||||
|
|
||||||
; take 2 seconds to fully fire
|
; take 2 seconds to fully fire
|
||||||
(defmethod regen-model ((model engine-model) time)
|
(defmethod regen-model ((model engine-model) time)
|
||||||
|
(format t "REGNE MODEL~%")
|
||||||
(setf (vertices model) (generate-step-2d-array (template-vertices model) time))
|
(setf (vertices model) (generate-step-2d-array (template-vertices model) time))
|
||||||
(setf (colors model) (generate-step-2d-array (template-colors model) time)))
|
(setf (colors model) (generate-step-2d-array (template-colors model) time)))
|
||||||
|
|
||||||
|
@ -38,9 +43,9 @@
|
||||||
((0 255 2) (0 255 2) (64 255 2))))
|
((0 255 2) (0 255 2) (64 255 2))))
|
||||||
|
|
||||||
|
|
||||||
(defmethod draw ((model engine-model) time)
|
(defmethod draw ((object engine-object) time)
|
||||||
(if (and (generated-model model) (< (- time (start-time model)) (activation-time model)))
|
(if (< (- time (start-time object)) (activation-time object))
|
||||||
(regen-model model time))
|
(regen-model (model object) time))
|
||||||
(call-next-method))
|
(call-next-method))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,8 @@
|
||||||
|
|
||||||
(defun thruster-on (key)
|
(defun thruster-on (key)
|
||||||
(case key
|
(case key
|
||||||
; ((:sdl-key-w) ; + z
|
((:sdl-key-w) ; + z
|
||||||
|
(activate-attachment *self* :thruster (wall-time)))
|
||||||
; (progn
|
; (progn
|
||||||
;(setf (aref (acceleration (motion *self*)) 2) (- *acceleration*))
|
;(setf (aref (acceleration (motion *self*)) 2) (- *acceleration*))
|
||||||
;(engine-start (engine *self*) (wall-time))))
|
;(engine-start (engine *self*) (wall-time))))
|
||||||
|
@ -167,7 +168,8 @@
|
||||||
|
|
||||||
(defun thruster-off (key)
|
(defun thruster-off (key)
|
||||||
(case key
|
(case key
|
||||||
;((:sdl-key-w) ; + z
|
((:sdl-key-w) ; + z
|
||||||
|
(deactivate-attachment *self* :thruster))
|
||||||
; (progn
|
; (progn
|
||||||
; (setf (aref (acceleration (motion *self*)) 2) 0)
|
; (setf (aref (acceleration (motion *self*)) 2) 0)
|
||||||
; (engine-stop (engine *self*))))
|
; (engine-stop (engine *self*))))
|
||||||
|
@ -256,13 +258,12 @@
|
||||||
:attachments
|
:attachments
|
||||||
(list :thruster
|
(list :thruster
|
||||||
(make-instance 'engine-object
|
(make-instance 'engine-object
|
||||||
|
:activation-time 2
|
||||||
:model (make-instance 'engine-model
|
:model (make-instance 'engine-model
|
||||||
:template-vertices *thruster-vertices*
|
:template-vertices *thruster-vertices*
|
||||||
:template-colors *thruster-colors*)
|
:template-colors *thruster-colors*)
|
||||||
:body (make-instance 'body
|
:body (make-instance 'body
|
||||||
:coords (vector 0 0 3)))))))
|
:coords (vector 0 0 3))))))
|
||||||
|
|
||||||
|
|
||||||
;:engines (list :engines (list :thrust
|
;:engines (list :engines (list :thrust
|
||||||
; (make-instance 'engine-object
|
; (make-instance 'engine-object
|
||||||
; :motion (make-instance 'motion :coords (vector 0 0.5 3.0))
|
; :motion (make-instance 'motion :coords (vector 0 0.5 3.0))
|
||||||
|
|
15
objects.lisp
15
objects.lisp
|
@ -12,10 +12,19 @@
|
||||||
;(defmethod coords ((object game-object))
|
;(defmethod coords ((object game-object))
|
||||||
; (coords (body object)))
|
; (coords (body object)))
|
||||||
|
|
||||||
(defmethod activate ((object game-object) sym start-time)
|
(defgeneric activate (object start-time))
|
||||||
|
(defgeneric activate-attachment (object sym start-time))
|
||||||
|
|
||||||
|
(defgeneric deactivate (object))
|
||||||
|
(defgeneric deactivate-attachment (object sym))
|
||||||
|
|
||||||
|
(defmethod activate-attachment ((object game-object) sym start-time)
|
||||||
(push sym (active-attachments object))
|
(push sym (active-attachments object))
|
||||||
(activate (getf (attachments object) sym) start-time))
|
(activate (getf (attachments object) sym) start-time))
|
||||||
|
|
||||||
|
(defmethod deactivate-attachment ((object game-object) sym)
|
||||||
|
(setf (active-attachments object) (remove sym (active-attachments object))))
|
||||||
|
|
||||||
(defmethod draw :before ((object game-object) time)
|
(defmethod draw :before ((object game-object) time)
|
||||||
(gl:push-matrix)
|
(gl:push-matrix)
|
||||||
(gl:translate (aref (coords (body object)) 0) (aref (coords (body object)) 1) (aref (coords (body object)) 2))
|
(gl:translate (aref (coords (body object)) 0) (aref (coords (body object)) 1) (aref (coords (body object)) 2))
|
||||||
|
@ -27,4 +36,6 @@
|
||||||
(gl:pop-matrix))
|
(gl:pop-matrix))
|
||||||
|
|
||||||
(defmethod draw ((object game-object) time)
|
(defmethod draw ((object game-object) time)
|
||||||
(draw (model object) time))
|
(draw (model object) time)
|
||||||
|
(loop for a in (active-attachments object) do
|
||||||
|
(draw (getf (attachments object) a) time)))
|
||||||
|
|
Loading…
Reference in New Issue