Commit c0b3fa4a authored by haiyoucuv's avatar haiyoucuv

init

parent 528e7534
This diff is collapsed.
{
"ver": "1.0.1",
"importer": "ttf-font",
"imported": true,
"uuid": "2c64cd9b-a68c-4de0-b137-694dc03e1edf",
"files": [
".json",
"CKTKingkongNum.ttf"
],
"subMetas": {},
"userData": {}
}
......@@ -67,12 +67,24 @@ export class MainGame extends Scene {
@property(Node)
animalNode: Node = null;
@property(Label)
private LTips: Label = null;
@property(Camera)
camera: Camera = null;
@property({ type: Label, group: "UI" }) killTxt: Label = null;
@property({ type: Label, group: "UI" }) lengthTxt: Label = null;
private _killNum = 0;
set killNum(n: number) {
this._killNum = n;
this.killTxt.string = `${this._killNum}名`;
}
get killNum() {
return this._killNum;
}
private state: GameState = GameState.READY;
private rebirthSum: number = 0;
......@@ -148,9 +160,6 @@ export class MainGame extends Scene {
update(dt: number) {
if (this.state == GameState.READY) return;
// 更新UI提示
this.LTips.string = `长度:${this.player.getSnakeLen()}, 四叉树节点个数:${QuadTreeNode.caches.length}`;
this.player.onUpdate(dt);
// 更新相机位置
......
......@@ -6,6 +6,7 @@ import { Snake } from "./Snake";
import { Joystick } from "./Components/Joystick";
import { FastBtn } from "./Components/FastBtn";
import { Events, GameState } from "./Common/Enums";
import { MainGame } from "./MainGame";
const { ccclass, property } = _decorator;
......@@ -23,18 +24,24 @@ export class Player extends Snake {
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) {
this.isFast = isFast;
}
updateLength(length: number) {
MainGame.ins.lengthTxt.string = `${length}`;
}
death() {
super.death();
......
......@@ -58,10 +58,17 @@ export class Snake extends Component {
protected tag: number = 0;
// 位置相关
private vw: number = Global.visibleSize.width / 2 + 100;
private vh: number = Global.visibleSize.height / 2 + 100;
private ready: boolean = false;
private _length: number = 0;
get length() {
return this._length;
}
set length(value: number) {
this._length = value;
this.node.emit("updateLength", value);
}
get radius() {
return this.scale * 29;
}
......@@ -176,7 +183,6 @@ export class Snake extends Component {
// 能量与成长
lastRemaining = 0;
private addEnergy(value: number) {
console.log(this.energy, value);
this.energy += value;
const growthThreshold = Math.floor(4 * this.scale);
......@@ -191,8 +197,6 @@ export class Snake extends Component {
}
}
console.log(this.energy, this.scale, this.energy / this.bodyArr.length);
this.lastRemaining = value;
// this.speed = 600 * this.scale;
......
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