BlueGit

timfa frameworkv3

Files

frameworkv3 / framework / engine / objectComponents / transform.js

transform.js

big refactor
timfa Tim · pushed by timfa · 4 years ago
c94b8e9a History
transform.js 1.2 KiB Download Raw
1class Transform
2{
3 position = null;
4 scale = null;
5 rotation = 0;
6 gameObject = null;
7
8 velocity = null;
9 angularVelocity = 0;
10
11 get size()
12 {
13 return new vector(
14 this.scale.x * this.gameObject.renderer.sprite.width,
15 this.scale.y * this.gameObject.renderer.sprite.height);
16 }
17
18 constructor(gameObject, x, y, w, h, r)
19 {
20 this.gameObject = gameObject;
21 this.position = new vector(x, y);
22 this.scale = new vector(w, h);
23 this.rotation = r;
24
25 this.velocity = new vector(0, 0)
26 }
27
28 pointTowards(point)
29 {
30 var delta = point.subtract(this.position);
31
32 this.rotation = delta.toAngle();
33 }
34
35 left()
36 {
37 return this.g_dir(0);
38 }
39
40 right()
41 {
42 return this.g_dir(180);
43 }
44
45 forward()
46 {
47 return this.g_dir(90);
48 }
49
50 back()
51 {
52 return this.g_dir(270);
53 }
54
55 g_dir(offset)
56 {
57 var myAngleInRadians = (this.rotation + offset) * (Math.PI / 180);
58
59 return angleVector = new vector( -Math.cos(myAngleInRadians), -Math.sin(myAngleInRadians) );
60 }
61}