BlueGit

blue-star speeltuin

Files

speeltuin / src / objects / arrow.js

arrow.js

cookie test
timfa Tim · pushed by timfa · 4 years ago
caf93735 History
arrow.js 1.3 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 CookieManager.setCookie("arrow", "right")
26 }
27
28 if(GameInput.isHeld(GameInput.keys.ArrowLeft))
29 {
30 this.transform.position.x -= this.speed * deltaTime;
31 CookieManager.setCookie("arrow", "left")
32 }
33
34 if(GameInput.isHeld(GameInput.keys.ArrowUp))
35 {
36 this.transform.position.y -= this.speed * deltaTime;
37 CookieManager.setCookie("arrow", "up")
38 }
39
40 if(GameInput.isHeld(GameInput.keys.ArrowDown))
41 {
42 this.transform.position.y += this.speed * deltaTime;
43 CookieManager.setCookie("arrow", "down")
44 }
45
46 if(oldPos.distanceTo(this.transform.position) > 1)
47 {
48 this.transform.pointTowards(oldPos)
49 this.transform.rotation += 180;
50 }
51 }
52}