Commit 0487e174 authored by haiyoucuv's avatar haiyoucuv

init

parent c0b3fa4a
......@@ -19,19 +19,26 @@ export class Player extends Snake {
@property(FastBtn)
fastBtn: FastBtn = null;
get length(): number {
return super.length;
}
set length(value: number) {
super.length = value;
this.updateLength(value);
}
onLoad() {
super.onLoad();
input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
input.on(Input.EventType.KEY_UP, this.onKeyUp, this);
this.fastBtn.node.on("fast", this.onFast, this);
this.node.on("updateLength", this.updateLength, this);
}
onDestroy() {
input.off(Input.EventType.KEY_DOWN, this.onKeyDown, this);
input.off(Input.EventType.KEY_UP, this.onKeyUp, this);
this.fastBtn.node.off("fast", this.onFast, this);
this.node.off("updateLength", this.updateLength, this);
}
onFast(isFast: boolean) {
......
......@@ -64,6 +64,7 @@ export class Snake extends Component {
get length() {
return this._length;
}
set length(value: number) {
this._length = value;
this.node.emit("updateLength", value);
......@@ -88,7 +89,6 @@ export class Snake extends Component {
this.energy = 0;
this.bodyArr = [];
this.scale = scale;
// this.speed = this.speed * scale;
this.tag = Snake.tag++;
// 设置头部
......@@ -101,7 +101,6 @@ export class Snake extends Component {
const bw = this.imgBody1.originalSize.width;
this.head.getComponent(UITransform).anchorX = (bw / 2) / hw;
// 创建尾巴节点
const tile = bodyPool.get() || instantiate(this.bodyPrefab);
tile.angle = angle;
......@@ -122,6 +121,8 @@ export class Snake extends Component {
this.node.addChild(tile);
this.bodyArr.push(tile);
this.length = 2;
// 创建身体节点
this.addEnergy(initEnergy);
......@@ -204,6 +205,9 @@ export class Snake extends Component {
// 蛇身体生长
private grow() {
this.length += 1;
let len = this.bodyArr.length;
if (this.imgTail) len -= 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment