BlueGit

blue-star speeltuin

Files

speeltuin / src / objects / frog.js

frog.js

raycast testin
timfa Tim · pushed by timfa · 4 years ago
33f8925f History
frog.js 1.7 KiB Download Raw
1class Frog extends GameObject {
2
3 speed = 200;
4
5 facing =
6 {
7 left: 1,
8 right: 2
9 };
10
11 currentFacing = this.facing.right;
12 idle = true;
13
14 constructor(x,y,sprite,layer)
15 {
16 super(x,y,sprite,layer);
17 this.collider.enabled = true;
18 }
19
20 update(deltaTime)
21 {
22 super.update(deltaTime);
23 this.idle = true;
24
25 if(! (GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft)))
26 {
27 if(GameInput.isHeld(GameInput.keys.ArrowRight))
28 {
29 this.arrowCounter++;
30 this.transform.position.x += this.speed * deltaTime;
31
32 if(this.currentFacing != this.facing.right)
33 {
34 this.renderer.mirrorX = !this.renderer.mirrorX;
35 this.currentFacing = this.facing.right;
36 }
37
38 CookieManager.setCookie("arrow", "right");
39 this.idle = false;
40 this.renderer.setAnimation("walk", 0, .2);
41 }
42
43 if(GameInput.isHeld(GameInput.keys.ArrowLeft))
44 {
45 this.arrowCounter++;
46 this.transform.position.x -= this.speed * deltaTime;
47
48 if(this.currentFacing != this.facing.left)
49 {
50
51 this.renderer.mirrorX = !this.renderer.mirrorX;
52 this.currentFacing = this.facing.left;
53 }
54
55 CookieManager.setCookie("arrow", "left")
56 this.idle = false;
57 this.renderer.setAnimation("walk", 0, .2);
58 }
59 }
60
61 if(this.idle)
62 {
63 this.renderer.setAnimationCycleSpeed(-1);
64 }
65 }
66}