-
Notifications
You must be signed in to change notification settings - Fork 0
/
ray.js
67 lines (41 loc) · 1.46 KB
/
ray.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
//var explosionPoint = {x: 0, y: 0};
rayArmed = true;
canvas.addEventListener('click', function(evt) {
if (rayArmed){
var mousePos = getMousePos(canvas, evt);
var xDif = mousePos.x - pC.x;
var yDif = mousePos.y - pC.y;
var slope = yDif/xDif;
var whichSide;
if (mousePos.x >= pC.x) { whichSide = 1} else {whichSide = -1};
var targetPoint = {
x: canvas.width/2 + whichSide*112000,
y: canvas.height/2 + 112000*whichSide*slope}
ray = [ pC.x, pC.y, targetPoint.x, targetPoint.y ]
//if the beam doesn't hit anything in between, then:
//ok, search all the damn objects to see if they intersect;
ray = searchForHits(ray, platforms);
// ray = [ pC.x, pC.y, targetPoint.x, targetPoint.y ]
//explosionPoint = targetPoint;
renderRayNext = true;
}
}, false);
var renderRay = function(ray){
var explosionPoint = {x: 0, y: 0};
var exP = renderPoint(ray[2], ray[3])
explosionPoint.x = exP[0];
explosionPoint.y = exP[1];
context.beginPath();
context.moveTo(canvas.width/2, canvas.height/2)
context.lineTo( explosionPoint.x, explosionPoint.y );
context.lineWidth = 2*zoomFactor+ 1;
context.strokeStyle = 'orange';
context.stroke();
context.beginPath();
context.arc(explosionPoint[0], explosionPoint[1], 25, 0, (2 * Math.PI), false);
context.fillStyle = 'red';
context.fill();
context.lineWidth = 0;
context.strokeStyle = 'black'
context.stroke();
}