-
Notifications
You must be signed in to change notification settings - Fork 0
/
leveltemplate.js
53 lines (45 loc) · 1.41 KB
/
leveltemplate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import VirtualJoystick from "./VirtualJoystick.js";
import VirtualJoystickGraphic from "./VirtualJoystick.js";
export default class Level6Scene extends Phaser.Scene {
constructor() {
super({ key: "Level6Scene" });
}
preload() {
this.load.image("jet1", "assets/images/planes/jet1.png");
this.load.image("jet2", "assets/images/planes/jet2.png");
}
create() {
console.log("Level6Scene create start");
this.plane = this.add.sprite(
this.scale.width * 0.1,
this.scale.height / 2,
"jet1"
);
this.plane.setScale(0.5);
this.joystick = new VirtualJoystickGraphic(this, 100, 500);
console.log("Level6Scene create end");
}
update() {
if (this.joystick && this.joystick.dragging) {
const deltaX = this.joystick.stickCircle.x - this.joystick.x;
const deltaY = this.joystick.stickCircle.y - this.joystick.y;
this.plane.x += deltaX * 0.1;
this.plane.y += deltaY * 0.1;
if (deltaY !== 0) {
if (!this.changeTimer) this.changeTimer = this.time.now;
if (this.time.now - this.changeTimer > 1000) {
this.plane.setTexture("jet2");
this.plane.setScale(0.25);
}
} else {
this.changeTimer = null;
this.plane.setTexture("jet1");
this.plane.setScale(0.2);
}
} else {
this.changeTimer = null;
this.plane.setTexture("jet1");
this.plane.setScale(0.2);
}
}
}