-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbutton.js
More file actions
63 lines (62 loc) · 1.65 KB
/
button.js
File metadata and controls
63 lines (62 loc) · 1.65 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
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 is ShyGuy. what was the comment above...
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;
}
}
}