Skip to content

Commit 8b66ac3

Browse files
committed
v1.2.0
- Generic interface collisions - Modified lhc_get_vel_* functions to work outside of collision events.
1 parent ea0f932 commit 8b66ac3

File tree

2 files changed

+101
-12
lines changed

2 files changed

+101
-12
lines changed

LojHadronCollider.yyp

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/LojHadronCollider/LojHadronCollider.gml

+99-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#macro __LHC_VERSION "v1.1.2"
1+
#macro __LHC_VERSION "v1.2.0"
22
#macro __LHC_PREFIX "[Loj Hadron Collider]"
33
#macro __LHC_SOURCE "https://github.com/Lojemiru/Loj-Hadron-Collider"
44
#macro __LHC_EVENT "__lhc_event_"
@@ -52,6 +52,7 @@ function lhc_activate() {
5252
__lhc_interfaces = array_create(0);
5353
__lhc_intLen = 0;
5454
__lhc_list = ds_list_create();
55+
__lhc_meetingList = ds_list_create();
5556
__lhc_axisVel = array_create(__lhc_Axis.LENGTH, 0);
5657
__lhc_active = true;
5758
}
@@ -61,6 +62,7 @@ function lhc_activate() {
6162
function lhc_cleanup() {
6263
__lhc_active = false;
6364
ds_list_destroy(__lhc_list);
65+
ds_list_destroy(__lhc_meetingList);
6466
}
6567

6668
///@func lhc_create_interface(name, [functionName], [...]);
@@ -141,7 +143,7 @@ function lhc_remove(_interface) {
141143
// Copy old array into new array, except for the object we're deleting
142144
repeat (array_length(__lhc_interfaces)) {
143145
if (__lhc_interfaces[i] != _interface) {
144-
newInterfaces[j] = __lhc_interface[i];
146+
newInterfaces[j] = __lhc_interfaces[i];
145147
j++;
146148
}
147149
i++;
@@ -163,19 +165,107 @@ function lhc_replace(_interface, _function) {
163165
variable_instance_set(id, __LHC_EVENT + _interface, _function);
164166
}
165167

168+
169+
///@func lhc_place_meeting(x, y, interface);
170+
///@desc Interface-based place_meeting().
171+
///@param x The x position to check for interfaces.
172+
///@param y The y position to check for interfaces.
173+
///@param interface The interface (or array of interfaces) to check for collisions.
174+
function lhc_place_meeting(_x, _y, _interface) {
175+
instance_place_list(_x, _y, all, __lhc_meetingList, false);
176+
return __lhc_collision_found(__lhc_meetingList, _interface);
177+
}
178+
179+
///@func lhc_position_meeting(x, y, interface);
180+
///@desc Interface-based position_meeting().
181+
///@param x The x position to check for interfaces.
182+
///@param y The y position to check for interfaces.
183+
///@param interface The interface (or array of interfaces) to check for collisions.
184+
function lhc_position_meeting(_x, _y, _interface) {
185+
instance_position_list(_x, _y, all, __lhc_meetingList, false);
186+
return __lhc_collision_found(__lhc_meetingList, _interface);
187+
}
188+
189+
///@func lhc_collision_circle(x, y, rad, interface, [prec] = false, [notme] = true);
190+
///@desc Interface-based collision_circle().
191+
///@param x The x coordinate of the center of the circle to check.
192+
///@param y The y coordinate of the center of the circle to check.
193+
///@param rad The radius (distance in pixels from its center to its edge).
194+
///@param interface The interface (or array of interfaces) to check for collisions.
195+
///@param [prec] Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster). Defaults to false.
196+
///@param [notme] Whether the calling instance, if relevant, should be excluded (true) or not (false). Defaults to true.
197+
function lhc_collision_circle(_x, _y, _r, _interface, _prec = false, _notme = true) {
198+
collision_circle_list(_x, _y, _r, all, _prec, _notme, __lhc_meetingList, false);
199+
return __lhc_collision_found(__lhc_meetingList, _interface);
200+
}
201+
202+
///@func lhc_collision_ellipse(x1, y1, x2, y2, interface, [prec] = false, [notme] = true);
203+
///@desc Interface-based collision_ellipse().
204+
///@param x1 The x coordinate of the left side of the ellipse to check.
205+
///@param y1 The y coordinate of the top side of the ellipse to check.
206+
///@param x2 The x coordinate of the right side of the ellipse to check.
207+
///@param y2 The y coordinate of the bottom side of the ellipse to check.
208+
///@param interface The interface (or array of interfaces) to check for collisions.
209+
///@param [prec] Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster). Defaults to false.
210+
///@param [notme] Whether the calling instance, if relevant, should be excluded (true) or not (false). Defaults to true.
211+
function lhc_collision_ellipse(_x1, _y1, _x2, _y2, _interface, _prec = false, _notme = true) {
212+
collision_ellipse_list(_x1, _y1, _x2, _y2, all, _prec, _notme, __lhc_meetingList, false);
213+
return __lhc_collision_found(__lhc_meetingList, _interface);
214+
}
215+
216+
///@func lhc_collision_line(x1, y1, x2, y2, interface, [prec] = false, [notme] = true);
217+
///@desc Interface-based collision_line().
218+
///@param x1 The x coordinate of the start of the line.
219+
///@param y1 The y coordinate of the start of the line.
220+
///@param x2 The x coordinate of the end of the line.
221+
///@param y2 The y coordinate of the end of the line.
222+
///@param interface The interface (or array of interfaces) to check for collisions.
223+
///@param [prec] Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster). Defaults to false.
224+
///@param [notme] Whether the calling instance, if relevant, should be excluded (true) or not (false). Defaults to true.
225+
function lhc_collision_line(_x1, _y1, _x2, _y2, _interface, _prec = false, _notme = true) {
226+
collision_line_list(_x1, _y1, _x2, _y2, all, _prec, _notme, __lhc_meetingList, false);
227+
return __lhc_collision_found(__lhc_meetingList, _interface);
228+
}
229+
230+
///@func lhc_collision_point(x, y, interface, [prec] = false, [notme] = true);
231+
///@desc Interface-based collision_point().
232+
///@param x The x coordinate of the point to check.
233+
///@param y The y coordinate of the point to check.
234+
///@param interface The interface (or array of interfaces) to check for collisions.
235+
///@param [prec] Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster). Defaults to false.
236+
///@param [notme] Whether the calling instance, if relevant, should be excluded (true) or not (false). Defaults to true.
237+
function lhc_collision_point(_x, _y, _interface, _prec = false, _notme = true) {
238+
collision_point_list(_x, _y, all, _prec, _notme, __lhc_meetingList, false);
239+
return __lhc_collision_found(__lhc_meetingList, _interface);
240+
}
241+
242+
///@func lhc_collision_rectangle(x1, y1, x2, y2, interface, [prec] = false, [notme] = true);
243+
///@desc Interface-based collision_rectangle().
244+
///@param x1 The x coordinate of the left side of the rectangle to check.
245+
///@param y1 The y coordinate of the top side of the rectangle to check.
246+
///@param x2 The x coordinate of the right side of the rectangle to check.
247+
///@param y2 The y coordinate of the bottom side of the rectangle to check.
248+
///@param interface The interface (or array of interfaces) to check for collisions.
249+
///@param [prec] Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster). Defaults to false.
250+
///@param [notme] Whether the calling instance, if relevant, should be excluded (true) or not (false). Defaults to true.
251+
function lhc_collision_rectangle(_x1, _y1, _x2, _y2, _interface, _prec = false, _notme = true) {
252+
collision_rectangle_list(_x1, _y1, _x2, _y2, all, _prec, _notme, __lhc_meetingList, false);
253+
return __lhc_collision_found(__lhc_meetingList, _interface);
254+
}
255+
166256
// Internal. Used to check if we actually need to perform costly substep movement.
167-
function __lhc_collision_found() {
257+
function __lhc_collision_found(_list, _interface = __lhc_interfaces) {
168258
var objRef, i = 0;
169-
repeat (ds_list_size(__lhc_list)) {
170-
objRef = __lhc_list[| i].object_index;
259+
repeat (ds_list_size(_list)) {
260+
objRef = _list[| i].object_index;
171261
// If this object has any of our tags, return true!
172-
if (asset_has_any_tag(objRef, __lhc_interfaces, asset_object)) {
173-
ds_list_clear(__lhc_list);
262+
if (asset_has_any_tag(objRef, _interface, asset_object)) {
263+
ds_list_clear(_list);
174264
return true;
175265
}
176266
++i;
177267
}
178-
ds_list_clear(__lhc_list);
268+
ds_list_clear(_list);
179269
return false;
180270
}
181271

@@ -265,7 +355,7 @@ function lhc_move(_x, _y, _line = false, _prec = false) {
265355
}
266356

267357
// If we've found an instance in our event list...
268-
if (check > 0 && __lhc_collision_found()) {
358+
if (check > 0 && __lhc_collision_found(__lhc_list)) {
269359
var domMult, subMult,
270360
// Copying to a var is faster than repeated global refs.
271361
xRef = global.__lhc_colRefX,
@@ -337,8 +427,6 @@ function lhc_move(_x, _y, _line = false, _prec = false) {
337427
__lhc_collisionDir = __lhc_CollisionDirection.NONE;
338428
__lhc_continue[__lhc_Axis.X] = true;
339429
__lhc_continue[__lhc_Axis.Y] = true;
340-
__lhc_axisVel[__lhc_Axis.X] = 0;
341-
__lhc_axisVel[__lhc_Axis.Y] = 0;
342430
}
343431

344432
///@func lhc_colliding();

0 commit comments

Comments
 (0)