This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.js
82 lines (82 loc) · 2.05 KB
/
es.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
const canvas = document.getElementById("myCanvas");
const c = canvas.getContext("2d");
class Es{
constructor(w=720,h=480){
canvas.width = w;
canvas.height = h;
}
random(max) {
return Math.floor(Math.random() * max);
}
print(said){
alert(said.toString());
}
rect(x,y,w,h,color,opacity = 1){
c.globalAlpha = opacity;
c.fillStyle = color;
c.fillRect(x,y,w,h);
c.globalAlpha = 1;
}
eclipse(x,y,rad,color,opacity =1){
c.globalAlpha = opacity;
c.beginPath();
c.arc(x,y,rad,0,Math.PI *2,);
c.fillStyle = color;
c.fill();
c.globalAlpha = 1;
}
clear(){
c.fillStyle = "white";
c.fillRect(0,0,canvas.width,canvas.height);
}
background(color){
c.fillStyle = color;
c.fillRect(0,0,canvas.width,canvas.height);
}
image(img,x,y,w,h,opacity=1){
c.globalAlpha = opacity;
c.drawImage(img,x,y,w,h);
c.globalAlpha = 1;
}
text(text,x,y,color,opacity=1,size,font){
c.globalAlpha = opacity;
c.fillStyle = color;
c.font = 'bold '+size+'px '+font+'';
c.fillText(text,x,y);
c.globalAlpha = 1;
}
checkCollisions(x,y,width,height,xx,yy,ww,hh){
if(x < xx + ww &&
x + width > xx &&
y < yy + hh &&
y + height > yy){
return true;
}
else{
return false;
}
}
line(x,y,xx,yy,w,color,opacity=1){
c.globalAlpha = opacity;
c.strokeStyle = color;
c.lineWidth = w;
c.beginPath();
c.moveTo(x, y);
c.lineTo(xx,yy);
c.stroke();
c.globalAlpha = 1;
}
getMousePos(canvas, event) {
var rect = canvas.getBoundingClientRect();
return {
x: event.clientX - rect.left,
y: event.clientY - rect.top
};
}
drawHitbox(x,y,w,h){
c.globalAlpha = 0.3;
c.fillStyle = "white";
c.fillRect(x,y,w,h);
c.globalAlpha = 1;
}
}