-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathge2d.js
More file actions
55 lines (46 loc) · 1.45 KB
/
ge2d.js
File metadata and controls
55 lines (46 loc) · 1.45 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
class Game{
constructor(id){
self.canvas = document.getElementById(id);
self.ctx = canvas.getContext("2d");
self.height = self.canvas.height;
self.width = self.canvas.width;
self.click = false;
self.canvas.addEventListener("mousemove", function(e){
self.pointer_x = e.clientX;
self.pointer_y = e.clientY;
});
self.canvas.onclick = function(){
self.click = true;
};
}
background_color(color) {
self.bg_color = color;
self.ctx.fillStyle = self.bg_color;
self.ctx.fillRect(0, 0, self.width, self.height);
}
clear(){
self.ctx.beginPath();
self.ctx.fillStyle = self.bg_color;
self.ctx.fillRect(0, 0, self.width, self.height);
self.ctx.arc(self.width/2, self.height/2, self.width*2, 0, 2*Math.PI, false);
self.ctx.fillStyle = self.bg_color;
self.ctx.fill();
}
circle(x, y, radius, color){
self.ctx.beginPath();
self.ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
self.ctx.fillStyle = color;
self.ctx.fill();
}
pointer(reset=false){
var d = {x: self.pointer_x,
y: self.pointer_y,
click: self.click}
if(reset){self.click=false;};
return d
}
rect(x1, y1, x2, y2, color){
self.ctx.fillStyle = color;
self.ctx.fillRect(x1, y1, x2, y2);
}
}