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.4 KiB
49 lines
1.4 KiB
;;;; break.lisp
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;; This file should be the only one that manages program state.
|
|
;;;
|
|
(in-package #:break)
|
|
|
|
(defparameter *entities* nil)
|
|
(defparameter *pad* nil)
|
|
(defparameter *balls* nil)
|
|
(defparameter *tiles* nil)
|
|
|
|
(defparameter *internal-size* (v! 320 240))
|
|
(defparameter *projection-matrix* (rtg-math.projection:orthographic-v2 *internal-size* 1.0 100.0))
|
|
(defparameter *viewport* (make-viewport))
|
|
|
|
(defun update-entities ()
|
|
(let ((ents (cons *pad* (concatenate 'list *balls* *tiles* *entities*))))
|
|
(map nil #'update ents)))
|
|
|
|
(defun window-size-callback (size &rest ignored)
|
|
(declare (ignore ignored))
|
|
(setf (viewport-dimensions (current-viewport))
|
|
(list (aref size 0) (aref size 1)))
|
|
(setf *projection-matrix* (update-matrix size)))
|
|
|
|
(defun step-game ()
|
|
(with-viewport *viewport*
|
|
(labels ((draw-ent (ent)
|
|
(draw-entity ent *projection-matrix*)))
|
|
(step-host)
|
|
(update-repl-link)
|
|
(clear)
|
|
(update-entities)
|
|
(draw-entity *pad* *projection-matrix*)
|
|
(map nil #'draw-ent *balls*)
|
|
(map nil #'draw-ent *tiles*)
|
|
(map nil #'draw-ent *entities*)
|
|
(swap))))
|
|
|
|
(let ((running nil))
|
|
(defun run-loop ()
|
|
(setf running t)
|
|
(whilst-listening-to
|
|
((#'window-size-callback (window 0) :size))
|
|
(loop :while (and running (not (shutting-down-p))) :do
|
|
(continuable (step-game)))))
|
|
(defun stop-loop ()
|
|
(setf running nil)))
|