DelayNoMore/frontend/assets/scripts/BaseCharacter.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

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-09-20 15:50:01 +00:00
},
// LIFE-CYCLE CALLBACKS:
start() {
const self = this;
self.activeDirection = {
dx: 0,
dy: 0
};
},
ctor() {},
2022-09-20 15:50:01 +00:00
onLoad() {
const self = this;
const canvasNode = self.mapNode.parent;
self.mapIns = self.mapNode.getComponent("Map");
2022-09-20 15:50:01 +00:00
const joystickInputControllerScriptIns = canvasNode.getComponent("TouchEventsManager");
self.ctrl = joystickInputControllerScriptIns;
},
scheduleNewDirection(newScheduledDirection, forceAnimSwitch) {
if (!newScheduledDirection) {
return;
}
if (forceAnimSwitch || null == this.activeDirection || (newScheduledDirection.dx != this.activeDirection.dx || newScheduledDirection.dy != this.activeDirection.dy)) {
this.activeDirection = newScheduledDirection;
if (this.animComp && this.animComp.node) {
if (0 > newScheduledDirection.dx) {
this.animComp.node.scaleX = (-1.0);
} else if (0 < newScheduledDirection.dx) {
this.animComp.node.scaleX = (1.0);
2022-09-20 15:50:01 +00:00
}
}
}
},
update(dt) {},
2022-09-20 15:50:01 +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) {
this.startFrozenDisplay();
}
2022-09-20 15:50:01 +00:00
if (0 < proposedSpeed && 0 == this.speed) {
this.stopFrozenDisplay();
}
this.speed = proposedSpeed;
2022-09-20 15:50:01 +00:00
},
});