BlueGit

blue-star speeltuin

chao behaviour start

timfa Tim · pushed by timfa

Authored 2022-10-19 · 4 years ago

Hash
0b47e9e95b23c739fc5c38be783778a79e37d7fe
Parent
638fdaba
4 files changed +42 −0
build/images/ball.png added Binary file +0 −0

The contents of this binary file are not shown.

build/images/gems.png added Binary file +0 −0

The contents of this binary file are not shown.

src/chaoBehaviour/chaoBehaviour.js added +18 −0
@@ -0,0 +1,18 @@
1 class ChaoBehaviour
2 {
3 constructor()
4 {
5 Chao.Instance.registerBehaviour(this);
6 }
7
8 startBehaviour()
9 {
10 //override this to allow the Chao to start this behaviour
11 }
12
13 endBehaviour()
14 {
15 //make sure to call this so the Chao knows it can queue up another thing.
16 Chao.Instance.behaviourCompleted();
17 }
18 }
@@ -0,0 +1,18 @@
1class ChaoBehaviour
2{
3 constructor()
4 {
5 Chao.Instance.registerBehaviour(this);
6 }
7
8 startBehaviour()
9 {
10 //override this to allow the Chao to start this behaviour
11 }
12
13 endBehaviour()
14 {
15 //make sure to call this so the Chao knows it can queue up another thing.
16 Chao.Instance.behaviourCompleted();
17 }
18}
src/objects/chao.js +24 −0
@@ -1,12 +1,36 @@
1 1 class Chao extends GameObject
2 2 {
3 3 speed = 40;
4 scenePadding = 50;
5 targetDestination = null;
6 busyWithBehaviour = false;
7
8 minTimeBetweenBehaviour = 3; //in seconds
9 maxTimeBetweenbehaviour = 10; // in seconds
10 behaviourTimer = 10;
11
12 behaviourList = [];
13
14 static Instance;
4 15
5 16 constructor(x, y, sprite, layer)
6 17 {
7 18 super(x, y, sprite, layer);
8 19 this.wasHeld = {}
9 20 this.collider.enabled = true;
21 Chao.Instance = this;
22 }
23
24 registerBehaviour(behaviour)
25 {
26 this.behaviourList.push(behaviour);
27 }
28
29 behaviourCompleted()
30 {
31 this.busyWithBehaviour = false;
32 }
33
10 34 addedToScene()
11 35 {
12 36 this.renderer.sprite = this.scene.game.chaoImages.random();
@@ -1,12 +1,36 @@
1class Chao extends GameObject
1class Chao extends GameObject
2{
2{
3 speed = 40;
3 speed = 40;
4 scenePadding = 50;
5 targetDestination = null;
6 busyWithBehaviour = false;
7
8 minTimeBetweenBehaviour = 3; //in seconds
9 maxTimeBetweenbehaviour = 10; // in seconds
10 behaviourTimer = 10;
11
12 behaviourList = [];
13
14 static Instance;
4
15
5 constructor(x, y, sprite, layer)
16 constructor(x, y, sprite, layer)
6 {
17 {
7 super(x, y, sprite, layer);
18 super(x, y, sprite, layer);
8 this.wasHeld = {}
19 this.wasHeld = {}
9 this.collider.enabled = true;
20 this.collider.enabled = true;
21 Chao.Instance = this;
22 }
23
24 registerBehaviour(behaviour)
25 {
26 this.behaviourList.push(behaviour);
27 }
28
29 behaviourCompleted()
30 {
31 this.busyWithBehaviour = false;
32 }
33
10 addedToScene()
34 addedToScene()
11 {
35 {
12 this.renderer.sprite = this.scene.game.chaoImages.random();
36 this.renderer.sprite = this.scene.game.chaoImages.random();