-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiscellaneous.js
More file actions
313 lines (299 loc) · 7.76 KB
/
miscellaneous.js
File metadata and controls
313 lines (299 loc) · 7.76 KB
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
class button{
constructor(a,b,c,d,e,f,g,h,i2){
this.x=a;
this.y=b;
this.sizeX=c;
this.sizeY=d;
this.size=e;
this.sizev=f;
this.dragv = g;
this.drag = h;
this.clicks = 0;
this.clicked = false;
this.hover = false;
this.last = false;
this.held = false;
this.heldFor = 0;
this.state = false;
//just in case i use a for loop in constructor, generally it won't disturb much if it's below it, but just in case :3
//it doesn't do anything lol, past HF_ang was an idiot
//lmao
this.type = i2;
}
work(){
//this.size-=sin((frameCount-1)/20)/50;
if(rectHit(this.x,this.y,mouseX,mouseY,this.sizeX,this.sizeY,0,0)){
this.sizev=max(0.05,this.sizev);
this.hover = true;
// print("hovering")
}else{
this.hover = false;
}
this.sizev/=this.drag;
this.size=1+(this.size-1)/this.drag;
this.size+=this.sizev;
//this.size+=sin(frameCount/20)/50;
if(rectHit(this.x,this.y,mouseX,mouseY,this.sizeX,this.sizeY,0,0)&&!this.last&&mouseIsPressed){
this.held = true;
this.last = true;
this.clicked = true;
this.clicks++;
this.state=!this.state;
this.sizev=this.sizev+=0.1;
}else{
this.clicked = false;
}
if(!rectHit(this.x,this.y,mouseX,mouseY,this.sizeX,this.sizeY,0,0)||!mouseIsPressed){
this.last = false;
}
if(this.held&&!mouseIsPressed){
this.held = false;
}
if(this.held){
this.held = true;
this.heldFor++;
this.sizev=max(0.08,this.sizev);
}else{
this.held = false;
this.heldFor = 0;
}
}
}
//Skin for Mouse
function mouseSkin(){
if(player1.showable&&idle<=100){
push();
translate(mouser.x,mouser.y);
scale(1/(zoom/100),1/(zoom/100));
translate(-mouser.x,-mouser.y);
translate(mouser.x,mouser.y);
rotate(PI/4)
strokeWeight(3);
noFill();
stroke(255, 153, 28);
if(!mouseIsPressed){
// image(letters[3][1],0,5,120,120);
}else{
// image(letters[3][1],0,5,140,140);
}
// rect(0,0,13,13,4);
rotate(PI/4+frameCount)
fill(255,153,28);
//rect(0,0,1,1,0.5);
pop();
if(keyIsDown(16)&&levelEdit){
push();
translate(mouser.x,mouser.y);
rotate(nextRot*PI/180);
stroke(255)
line(0,-50,0,-40);
strokeWeight(10)
line(0,50,0,40);
pop();
push();
strokeWeight(10)
stroke(0);
fill(255,0,0);
textSize(20)
text(nextRange,mouser.x+25,mouser.y);
text(nextDelay,mouser.x-25,mouser.y);
pop();
}
}
}
//Char Converter
function ischar(x){
var is =0;
var letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
for(var i=0; i<letters.length; i++){
if(x==letters[i]){
is = i
}
}
if(x=="up"){
return 38
}
if(x=="down"){
return 40
}
if(x=="left"){
return 37
}
if(x=="right"){
return 39
}
is+=65;
return is
}
//Char Array Converter
function ischars(x){
var holder = [];
for(var i=0; i<x.length; i++){
holder[i] = ischar(x[i])
}
return holder
}
//Distance Function
function dis(atx1,aty1,atx2,aty2){
//Pythagorean Theorom
//Thanks Pythagorus
return sqrt(pow(atx1-atx2,2)+pow(aty1-aty2,2));
}
//Rectangular Collisions Detection
function rectHit(x,y,x2,y2,xs,ys,xs2,ys2){
return(abs(x-x2)<xs/2+xs2/2&&abs(y-y2)<ys/2+ys2/2);
}
//applies filter to rectanuglar region, not CENTER aligned
function applyFilterToRegion(x, y, w, h, filterType, intensity) {
// Create an offscreen buffer
let pg = createGraphics(w, h);
// Copy the desired region to the buffer
pg.image(get(x, y, w, h), 0, 0);
// Apply the filter to the buffer
pg.filter(filterType, intensity);
// Draw the buffer back to the main canvas
image(pg, x, y);
}
function copyStringToClipboard(str) {
// Replace literal newlines with escaped \n
const escapedStr = str.replace(/\n/g, '\\n');
// Create new element
var el = document.createElement('textarea');
// Set value (string to be copied)
el.value = escapedStr;
// Set non-editable to avoid focus and move outside of view
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
// Select text inside element
el.select();
// Copy text to clipboard
document.execCommand('copy');
// Remove temporary element
document.body.removeChild(el);
console.log("Copied To Clipboard!");
}
function gridCreate(widths, heights) {
var grider = [];
for (var i = 0; i < widths; i++) {
grider[i] = [];
}
for (let i = 0; i < widths; i++) {
for (let u = 0; u < heights; u++) {
grider[i][u] = 0;
}
}
return grider;
}
function rayCast(x1,y1,x2,y2,x3,y3,x4,y4){
if(x2<x1){
//to make sure the first line is in order by x value
return rayCast(x2,y2,x1,y1,x3,y3,x4,y4)
}else if(x4<x3){
//to make sure the second line is in order by x value
return rayCast(x1,y1,x2,y2,x4,y4,x3,y3)
}else{
var x;
var y;
//drawing the lines
// line(x1,y1,x2,y2)
// line(x3,y3,x4,y4)
//checking for straight up
if(x1==x2 && x3==x4){
// return {works:false, x:undefined, y:undefined}
return {works:false, x:undefined, y:undefined}
}else if(x1==x2){
//solve for the y
y=(y3-y4)/(x3-x4)*(x1-x3)+y3
if(y3>y4){
if(y>=y4 && y<=y3 && y>=y1 && y<=y2){
// stroke("black")
//fill("black")
// line(x1,0,x1,400)
// line(0,y,400,y)
// ellipse(x1,y,15)
return {works:true, x:x1, y:y}
}else{
return {works: false, x:x1,y:y}
}
}else{
if(y>=y3 && y<=y4 && y>=y1 && y<=y2){
// stroke("black")
// fill("black")
// line(x1,0,x1,400)
// line(0,y,400,y)
//ellipse(x1,y,15)
return {works:true, x:x1, y:y}
}else{
return {works: false, x:x1,y:y}
}
}
}else if(x3==x4){
//solve for the y
y=(y1-y2)/(x1-x2)*(x3-x1)+y1
if(y1>y2){
if(y>=y2 && y<=y1 && y>=y3 && y<=y4){
// stroke("black")
// fill("black")
// line(x3,0,x3,400)
// line(0,y,400,y)
// ellipse(x3,y,15)
return {works:true, x:x3, y:y}
}else{
return {works: false, x:x3,y:y}
}
}else{
if(y>=y1 && y<=y2 && y>=y3 && y<=y4){
// stroke("black")
// fill("black")
// line(x3,0,x3,400)
// line(0,y,400,y)
//ellipse(x3,y,15)
return {works:true, x:x3, y:y}
}else{
return {works: false, x:x3,y:y}
}
}
}else{
//checking if the slope is the same
if(((y1-y2)*(x3-x4)-(y3-y4)*(x1-x2))==0){
return {works:false, x:undefined, y:undefined}
}else{
//finding x using system of equations
x=((y3-y1)*(x1-x2)*(x3-x4)+x1*(y1-y2)*(x3-x4)-x3*(y3-y4)*(x1-x2))/((y1-y2)*(x3-x4)-(y3-y4)*(x1-x2))
//solving for y
y=(y1-y2)/(x1-x2)*(x-x1)+y1
//making sure the point is on both lines
if(x>=x1 && x<=x2 && x>=x3 && x<=x4){
//stroke("black")
// fill("black")
// line(x,0,x,400)
// line(0,y,400,y)
//ellipse(x,y,15)
return {works:true, x:x, y:y}
}else{
return {works:false, x:x, y:y}
}
}
}
}
return {works:false, x:undefined, y:undefined}
}
function arrays2DEqual(arr1, arr2) {
if (arr1.length !== arr2.length) return false; // Different row count
for (let i = 0; i < arr1.length; i++) {
if (arr1[i].length !== arr2[i].length) return false; // Different column count
for (let j = 0; j < arr1[i].length; j++) {
if (arr1[i][j] !== arr2[i][j]) return false; // Any mismatch
}
}
return true; // All elements match
}
function arrays2DGet2(arr1,x,y){
let builder = [
[arr1[x][y],arr1[x][y+1]],
[arr1[x+1][y],arr1[x+1][y+1]]
];
return builder;
}