OSDN Git Service

6d3aa66016f441614fccd37b55a1fcc0fa3380a4
[rulp/rulp.git] / layers / planes.lisp
1 ;;;; Ru*** roLeplay Playground virtual tabletop
2 ;;;; Copyright (C) 2022  Zull
3 ;;;;
4 ;;;; This program is free software: you can redistribute it and/or modify
5 ;;;; it under the terms of the GNU General Public License as published by
6 ;;;; the Free Software Foundation, either version 3 of the License, or
7 ;;;; (at your option) any later version.
8 ;;;;
9 ;;;; This program is distributed in the hope that it will be useful,
10 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ;;;; GNU General Public License for more details.
13 ;;;;
14 ;;;; You should have received a copy of the GNU General Public License
15 ;;;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17 (in-package :rulp.layers)
18
19 (defgeneric bounce (v p)
20   (:documentation "Given a point v and a plane p this generic check if
21 the point collide with some wall or it is out of bound and return t
22 when it is, nil otherwise"))
23
24 (defun lex< (a b)
25   "lexycal-graphical orders between a and b, returns t if a < b, otherwise returns nil"
26   (declare (list a b)
27            (optimize (speed 3)))
28   (if (eql (car a) (car b))
29       (< (cdr a) (cdr b))
30       (< (car a) (car B))))
31
32 (defclass plane ()
33   ((collision-list :accessor collision-list
34                    :initarg :collision-list
35                    :initform nil
36                    :type list
37                    :documentation "an ordered list of collision, use when entities do stuff")
38    (entities-list :accessor entities-list
39                   :initarg :entities-list
40                   :initform nil
41                   :type list
42                   :documentation "the entities contained into the plane")
43    (width :accessor width
44           :initarg :width
45           :initform 0
46           :type number
47           :documentation "the width of the plane, when 0 or negative it uses the texture width")
48    (height :accessor height
49            :initarg :height
50            :initform 0
51            :type number
52            :documentation "the height of the plane, when 0 or negative it uses the texture height")
53    (background :accessor background
54                :initarg :background
55                :initform ""
56                :type string
57                :documentation "the path for the construction, that can be a image or something else")
58    (span :accessor grid-dimension
59          :initarg :grid-dimension
60          :documentation "the dimension of the standard grid, this will be replaced with a function"
61          :initform 70)))
62
63 ;; grid logic, to be placed in the correct package (and file
64 (defmethod bounce (v (p plane))
65   "rapidly check if the given point is in the collision list"
66   (member v (collision-list p)))
67
68 ;; the name is intended to be temporary
69 (defmethod display ((p plane))
70   (render (get-screen (background p)) 0 0 (width p) (height p)))
71
72 (defmethod width ((s plane))
73   (if (= (slot-value s 'width) 0)
74       (width (get-screen (background s)))
75       (slot-value s 'width)))
76
77 (defmethod height ((s plane))
78   (if (= (slot-value s 'height) 0)
79       (height (get-screen (background s)))
80       (slot-value s 'height)))
81
82 ;; temporary, they are used somewhere on view for the evenience the
83 ;; plane was moved (now the plane doesn't consider coordinates)
84 (defmethod x ((s plane))
85   0)
86
87 (defmethod y ((s plane))
88   0)