BlueGit

blue-star speeltuin

Files

speeltuin / src / objects / caster.js

caster.js

autoformat all
timfa Tim · pushed by timfa · 4 years ago
53822765 History
caster.js 877 B Download Raw
1class Caster extends GameObject
2{
3 lastResult = {};
4 update (deltaTime)
5 {
6
7 if (!GameInput.mousePosition)
8 return;
9 this.collider.enabled = true;
10 if (this.collider.isInBounds(GameInput.mousePosition))
11 {
12 console.log("hoverin");
13 }
14 }
15
16 draw (context)
17 {
18 if (!GameInput.mousePosition)
19 return;
20
21 super.draw(context);
22 let origin = this.transform.position;
23 let dir = GameInput.mousePosition.subtract(this.transform.position).normalize();
24 let ray = Ray.Cast(this.scene, this.transform.position, dir);
25
26 if (ray)
27 {
28 context.moveTo(this.transform.position.x, this.transform.position.y);
29 context.lineTo(ray.hitPoint.x, ray.hitPoint.y);
30 context.stroke();
31 this.lastResult = ray;
32 }
33 }
34}