2022-09-20 15:50:01 +00:00
|
|
|
module.export = cc.Class({
|
|
|
|
extends: cc.Component,
|
|
|
|
|
|
|
|
properties: {
|
|
|
|
lastMovedAt: {
|
|
|
|
type: cc.Float,
|
|
|
|
default: 0 // In "GMT milliseconds"
|
2022-11-12 12:34:38 +00:00
|
|
|
}
|
2022-09-20 15:50:01 +00:00
|
|
|
},
|
|
|
|
|
2022-11-20 13:07:45 +00:00
|
|
|
ctor() {
|
|
|
|
this.activeDirection = {
|
2022-09-20 15:50:01 +00:00
|
|
|
dx: 0,
|
|
|
|
dy: 0
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoad() {
|
|
|
|
const self = this;
|
|
|
|
const canvasNode = self.mapNode.parent;
|
2022-09-21 09:22:34 +00:00
|
|
|
self.mapIns = self.mapNode.getComponent("Map");
|
2022-09-20 15:50:01 +00:00
|
|
|
const joystickInputControllerScriptIns = canvasNode.getComponent("TouchEventsManager");
|
|
|
|
self.ctrl = joystickInputControllerScriptIns;
|
|
|
|
},
|
|
|
|
|
2022-11-12 12:34:38 +00:00
|
|
|
update(dt) {},
|
2022-09-20 15:50:01 +00:00
|
|
|
|
2022-11-12 12:34:38 +00:00
|
|
|
lateUpdate(dt) {},
|
2022-09-20 15:50:01 +00:00
|
|
|
|
|
|
|
_generateRandomDirection() {
|
|
|
|
return ALL_DISCRETE_DIRECTIONS_CLOCKWISE[Math.floor(Math.random() * ALL_DISCRETE_DIRECTIONS_CLOCKWISE.length)];
|
|
|
|
},
|
|
|
|
|
|
|
|
updateSpeed(proposedSpeed) {
|
|
|
|
if (0 == proposedSpeed && 0 < this.speed) {
|
2022-11-12 12:34:38 +00:00
|
|
|
this.startFrozenDisplay();
|
|
|
|
}
|
2022-09-20 15:50:01 +00:00
|
|
|
if (0 < proposedSpeed && 0 == this.speed) {
|
2022-11-12 12:34:38 +00:00
|
|
|
this.stopFrozenDisplay();
|
|
|
|
}
|
|
|
|
this.speed = proposedSpeed;
|
2022-09-20 15:50:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
});
|