BlueGit

blue-star speeltuin

Files

speeltuin / src / objects / arrow.js

arrow.js

mousebtns
timfa Tim · pushed by timfa · 4 years ago
95f32ae3 History
arrow.js 1.1 KiB Download Raw
1class Arrow extends GameObject
2{
3 speed = 250;
4
5 constructor(x, y, sprite, layer)
6 {
7 super(x, y, sprite, layer);
8 this.transform.angularVelocity = 40;
9 }
10
11 onClick(btn)
12 {
13 console.log(btn);
14 }
15
16 update(deltaTime)
17 {
18 super.update(deltaTime);
19
20 let oldPos = this.transform.position.getCopy();
21
22 if(GameInput.isHeld(GameInput.keys.ArrowRight))
23 {
24 this.transform.position.x += this.speed * deltaTime;
25 }
26
27 if(GameInput.isHeld(GameInput.keys.ArrowLeft))
28 {
29 this.transform.position.x -= this.speed * deltaTime;
30 }
31
32 if(GameInput.isHeld(GameInput.keys.ArrowUp))
33 {
34 this.transform.position.y -= this.speed * deltaTime;
35 }
36
37 if(GameInput.isHeld(GameInput.keys.ArrowDown))
38 {
39 this.transform.position.y += this.speed * deltaTime;
40 }
41
42 if(oldPos.distanceTo(this.transform.position) > 1)
43 {
44 this.transform.pointTowards(oldPos)
45 this.transform.rotation += 180;
46 }
47 }
48}