/
Phileas_PicturesCollision.js
143 lines (128 loc) · 4.86 KB
/
Phileas_PicturesCollision.js
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
//=============================================================================
// Phileas_PicturesCollision.js
//=============================================================================
// [Update History]
// 2024.March.10 Ver1.0.0 First Release
/*:
* @target MZ
* @plugindesc Picture collision search
* @author Phileas
*
* @command isColliding
* @text Check the collision
* @desc Do the pictures intersect?
*
* @arg firstPictureId
* @text First picture ID
* @type number
*
* @arg secondPictureId
* @text Second picture ID
* @type number
*
* @arg resultSwitchId
* @text Result switch ID
* @type switch
*
* @help
* Allows you to determine if 2 pictures intersect.
* It will help in mini-games and game mechanics based on collisions.
*
* Use the plugin command - "Check the collision".
* Specify the ID of the pictures and the switch to which the result will be set.
*
* You can always write to the author if you need other features or even plugins.
* Boosty: https://boosty.to/phileas
* RPG Maker Web: https://forums.rpgmakerweb.com/index.php?members/phileas.176075/
* RPG Maker Union: https://rpgmakerunion.ru/id/phileas
* Email: olek.olegovich gmail.com
* Telegram: olekolegovich
*
* [License]
* This plugin is released under MIT license.
* http://opensource.org/licenses/mit-license.php
*
* This means that you can freely use the plugin in non-commercial and commercial games and even edit it.
* But be sure to include me in the credits!
*/
/*:ru
* @target MZ
* @plugindesc Поиск коллизии картинок
* @author Phileas
*
* @command isColliding
* @text Проверь коллизию
* @desc Картинки пересекаются?
*
* @arg firstPictureId
* @text ID первой картинки
* @type number
*
* @arg secondPictureId
* @text ID второй картинки
* @type number
*
* @arg resultSwitchId
* @text ID переключателя результата
* @type switch
*
* @help
* Позволяет определить пересекаются ли 2 картинки.
* Это поможет в мини-играх и игровых механиках, основанных на столкновениях.
*
* Используйте команду плагина - "Проверь коллизию".
* Укажите ID картинок и переключатель, в который установится результат.
*
* Вы всегда можете написать автору, если вам нужны другие функции или даже плагины.
* Boosty: https://boosty.to/phileas
* RPG Maker Web: https://forums.rpgmakerweb.com/index.php?members/phileas.176075/
* RPG Maker Union: https://rpgmakerunion.ru/id/phileas
* Email: olek.olegovich gmail.com
* Telegram: olekolegovich
*
* [License]
* Этот плагин распространяется по лицензии MIT.
* http://opensource.org/licenses/mit-license.php
*
* Это означает, что вы можете свободно использовать плагин в некоммерческих и коммерческих играх и даже редактировать его.
* Но обязательно укажите меня в титрах!
*/
(function() {
//--------MY CODE:
var phileasCollisionPictures = {};
PluginManager.registerCommand("Phileas_PicturesCollision", "isColliding", isColliding);
function makeRect(x, y, xx, yy) {
var rect = new Object();
rect.x = x;
rect.y = y;
rect.xx = xx;
rect.yy = yy;
return rect;
}
function isRectColliding(rect1, rect2) {
if (rect1.xx < rect2.x || rect2.xx < rect1.x) {
return false;
}
if (rect1.yy < rect2.y || rect2.yy < rect1.y) {
return false;
}
return true;
}
function isColliding(params) {
const firstPictureId = Number(params["firstPictureId"]);
const secondPictureId = Number(params["secondPictureId"]);
const resultSwitchId = Number(params["resultSwitchId"]);
const firstBounds = phileasCollisionPictures[firstPictureId]._bounds;
const secondBounds = phileasCollisionPictures[secondPictureId]._bounds;
const rect1 = makeRect(firstBounds.minX, firstBounds.minY, firstBounds.maxX, firstBounds.maxY);
const rect2 = makeRect(secondBounds.minX, secondBounds.minY, secondBounds.maxX, secondBounds.maxY);
const result = isRectColliding(rect1, rect2);
$gameSwitches.setValue(resultSwitchId, result);
}
//--------CHANGED CORE:
Origin_SpriteInitialize = Sprite_Picture.prototype.initialize;
Sprite_Picture.prototype.initialize = function(pictureId) {
phileasCollisionPictures[pictureId] = this;
Origin_SpriteInitialize.call(this, pictureId);
};
}());