-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathon-collision.lisp
executable file
·246 lines (219 loc) · 7.6 KB
/
on-collision.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
;;; Copyright 2009-2011 Christoph Senjak
(in-package :uxul-world)
(defmethod on-collision ((obj T) (obj2 T) collision)
"Per default do not react on objects at all. Warn only."
(format t "Warning: On-Collision is not overridden for some object
it is called for. Classes of Arguments: ~A ~A~%"
(class-name (class-of obj))
(class-name (class-of obj))))
;; Player colliding with other objects
(defmethod on-collision
((moving-rectangle player)
(standing-rectangle stone)
(collision collision))
(if (eql (direction collision) :DOWN)
;; "bottom" - allow jumping again
(setf (mayjump moving-rectangle) T)
;; "ceiling" - dont allow continuing jump
(if (eql (direction collision) :UP)
(setf (maycontjump moving-rectangle) nil))
)
(collide-blocks moving-rectangle standing-rectangle collision))
(defmethod on-collision
((moving-rectangle player)
(standing-rectangle door)
(collision collision))
(cond ((find-if #'(lambda (x) (string= x (dungeon standing-rectangle))) (keys moving-rectangle))
(setf (keys moving-rectangle) (delete (dungeon standing-rectangle) (keys moving-rectangle) :count 1))
(setf (visible standing-rectangle) nil)
(setf (active standing-rectangle) nil)
(setf (colliding standing-rectangle) nil))
((eql (direction collision) :DOWN)
;; "bottom" - allow jumping again
(setf (mayjump moving-rectangle) T))
;; "ceiling" - dont allow continuing jump
((eql (direction collision) :UP)
(setf (maycontjump moving-rectangle) nil)))
(collide-blocks moving-rectangle standing-rectangle collision))
(defmethod on-collision
((moving-rectangle player)
(standing-rectangle teleporter)
(collision collision))
;; make rectangle active to check for overlapping
(setf (active standing-rectangle) T)
;; walk through
(setf (colliding standing-rectangle) nil)
(move-about moving-rectangle (desired-movement collision))
(setf (colliding standing-rectangle) t))
(defmethod on-collision
((moving-rectangle player)
(standing-rectangle tulip)
(collision collision))
(setf (visible standing-rectangle) nil)
(setf (active standing-rectangle) nil)
(setf (colliding standing-rectangle) nil)
(if (< (power moving-rectangle) 10)
(incf (power moving-rectangle)))
(incf (tulips moving-rectangle)))
(defmethod on-collision
((moving-rectangle player)
(standing-rectangle bottom)
(collision collision))
(if (eql (direction collision) :DOWN)
(call-next-method)
;; else
(progn
(setf (colliding standing-rectangle) nil)
(move-about moving-rectangle (desired-movement collision))
(setf (colliding standing-rectangle) t))))
(defmethod on-collision
((moving-rectangle player)
(standing-rectangle moving-enemy)
(collision collision))
(collide-blocks moving-rectangle
standing-rectangle
collision)
(setf (bounced moving-rectangle) T)
(setf (mayjump moving-rectangle) T)
(setf (autojump moving-rectangle) 5)
(player-hits-enemy moving-rectangle
standing-rectangle
collision)
(setf (colliding standing-rectangle) nil)
(move-about moving-rectangle (desired-movement collision))
(setf (colliding standing-rectangle) t)
)
(defmethod on-collision
((moving-rectangle player)
(standing-rectangle standing-enemy)
(collision collision))
(collide-blocks moving-rectangle
standing-rectangle
collision)
(player-hits-enemy moving-rectangle
standing-rectangle
collision))
(defmethod on-collision
((moving-rectangle player)
(standing-rectangle standing-item)
(collision collision))
(collide-blocks moving-rectangle
standing-rectangle
collision)
(item-catch standing-rectangle moving-rectangle))
(defmethod on-collision
((moving-rectangle player)
(standing-rectangle moving-item)
(collision collision))
(collide-blocks moving-rectangle
standing-rectangle
collision)
(item-catch standing-rectangle moving-rectangle))
;; moving-item colliding with other objects
(defmethod on-collision
((moving-rectangle moving-item)
(standing-rectangle player)
(collision collision))
(collide-blocks moving-rectangle
standing-rectangle
collision)
(item-catch moving-rectangle standing-rectangle))
(defmethod on-collision
((moving-rectangle moving-item)
(standing-rectangle bottom)
(collision collision))
(if (eql (direction collision) :DOWN)
(call-next-method)
;; else
(progn
(setf (colliding standing-rectangle) nil)
(move-about moving-rectangle (desired-movement collision))
(setf (colliding standing-rectangle) t))))
(defmethod on-collision
((moving-rectangle moving-item)
(standing-rectangle stone)
(collision collision))
(collide-blocks moving-rectangle standing-rectangle collision))
;; simple-enemy special methods
(defmethod on-collision ((m simple-enemy) (s stone) (c collision))
(cond ((eql (direction c) :left)
(setf (direction m) :right))
((eql (direction c) :right)
(setf (direction m) :left)))
(collide-blocks m s c))
;; burning-marshmallow special methods
(defmethod on-collision ((m burning-marshmallow) (s stone) (c collision))
(cond
((eql (direction c) :LEFT)
(setf (horizontal-direction m) :RIGHT))
((eql (direction c) :RIGHT)
(setf (horizontal-direction m) :LEFT))
((eql (direction c) :UP)
(setf (vertical-direction m) :DOWN))
((eql (direction c) :DOWN)
(setf (vertical-direction m) :UP))
(T ;; diagonal
(setf (horizontal-direction m)
(if (eql (horizontal-direction m) :LEFT) :RIGHT :LEFT))
(setf (vertical-direction m)
(if (eql (vertical-direction m) :UP) :DOWN :UP))))
(set-burning-marshmallow-animation m))
(defmethod on-collision
((moving-rectangle burning-marshmallow)
(standing-rectangle bottom)
(collision collision))
(if (eql (direction collision) :DOWN)
(call-next-method)
;; else
(progn
(setf (colliding standing-rectangle) nil)
(move-about moving-rectangle (desired-movement collision))
(setf (colliding standing-rectangle) t))))
(defmethod on-collision
((moving-rectangle burning-marshmallow)
(standing-rectangle player)
(collision collision))
(enemy-hits-player moving-rectangle
standing-rectangle
collision)
(setf (colliding standing-rectangle) nil)
(move-about moving-rectangle (desired-movement collision))
(setf (colliding standing-rectangle) t))
(defmethod on-collision
((moving-rectangle player)
(standing-rectangle burning-marshmallow)
(collision collision))
(enemy-hits-player standing-rectangle
moving-rectangle
collision)
(setf (colliding standing-rectangle) nil)
(move-about moving-rectangle (desired-movement collision))
(setf (colliding standing-rectangle) t))
;; moving-enemy colliding with other objects
(defmethod on-collision ((m moving-enemy) (s stone) (c collision))
(collide-blocks m s c))
(defmethod on-collision
((moving-rectangle moving-enemy)
(standing-rectangle bottom)
(collision collision))
(if (eql (direction collision) :DOWN)
(call-next-method)
;; else
(progn
(setf (colliding standing-rectangle) nil)
(move-about moving-rectangle (desired-movement collision))
(setf (colliding standing-rectangle) t))))
(defmethod on-collision
((moving-rectangle moving-enemy)
(standing-rectangle player)
(collision collision))
(collide-blocks moving-rectangle
standing-rectangle
collision)
(enemy-hits-player moving-rectangle
standing-rectangle
collision)
(setf (colliding standing-rectangle) nil)
(move-about moving-rectangle (desired-movement collision))
(setf (colliding standing-rectangle) t)
)