Commit 9e4a331a authored by haiyoucuv's avatar haiyoucuv

init

parent 3d1d99b4
This diff is collapsed.
......@@ -6,14 +6,20 @@ const { ccclass, property, executeInEditMode, disallowMultiple, executionOrder }
enum ESkinType {
Sprite,
Label
Label,
Node,
}
Enum(ESkinType);
@ccclass("SkinNode")
class SkinNode {
@property(Node) node: Node = null;
@property({
type: Node,
visible: function (this) {
return this.type != ESkinType.Node;
}
}) node: Node = null;
@property({ type: ESkinType }) type: ESkinType = ESkinType.Sprite;
......@@ -45,6 +51,22 @@ class SkinNode {
return this.type == ESkinType.Sprite;
}
}) skin2: SpriteFrame = null;
@property({
type: Node,
visible: function (this) {
return this.type == ESkinType.Node;
}
}) node1: Node = null;
@property({
type: Node,
visible: function (this) {
return this.type == ESkinType.Node;
}
}) node2: Node = null;
}
......@@ -69,6 +91,9 @@ export class AutoSkin extends Component {
skNode.node.getComponent(Sprite).spriteFrame = skNode.skin1;
} else if (skNode.type == ESkinType.Label && skNode.color1) {
skNode.node.getComponent(Label).color = skNode.color1;
} else if (skNode.type == ESkinType.Node) {
skNode.node1.active = true;
skNode.node2.active = false;
}
});
......@@ -81,6 +106,9 @@ export class AutoSkin extends Component {
skNode.node.getComponent(Sprite).spriteFrame = skNode.skin2;
} else if (skNode.type == ESkinType.Label && skNode.color2) {
skNode.node.getComponent(Label).color = skNode.color2;
} else if (skNode.type == ESkinType.Node) {
skNode.node1.active = false;
skNode.node2.active = true;
}
});
......
......@@ -130,8 +130,8 @@ export class AISnake extends Snake {
// this.setState(AIState.ESCAPING, node?.parent?.getComponent(Snake));
this.scheduleOnce(() => {
this.isTurnBack = false;
}, Math.random() * 0.2);
}, Math.random() * 0.25);
}, Math.random() * 0.1);
}, Math.random() * 0.1);
} else if (group == PhysicsGroup["Wall"]) {
this.head.angle = this.head.angle + 180 + Math.random() * 60 - 30;
this.setState(AIState.WANDERING, null);
......@@ -194,9 +194,9 @@ export class AISnake extends Snake {
if (this.updateTimer >= this.currentUpdateInterval) {
this.updateTimer = 0;
this.updateAIState();
this.executeCurrentState();
}
this.executeCurrentState(dt);
super.onUpdate(dt);
}
......@@ -270,7 +270,7 @@ export class AISnake extends Snake {
}
}
private executeCurrentState(dt: number) {
private executeCurrentState() {
// 执行原有状态逻辑
switch (this.currentState) {
......@@ -507,7 +507,7 @@ export class AISnake extends Snake {
const { HALF_MAP_WIDTH, HALF_MAP_HEIGHT } = Global;
const candidateFoods = foods.filter(food => {
if (!food.isValid || !food.active || !food.getComponent(PropBase).canEaten) return false;
if (!food.isValid || !food.active || !food["canEaten"]) return false;
const foodPos = food.position;
// 使用曼哈顿距离进行快速预筛选
......
......@@ -15,6 +15,7 @@ export class PropBase extends Component {
onLoad() {
this.node.getComponent(Collider2D).tag = this.tag;
this.node["canEaten"] = true;
}
beEaten(target: Snake) {
......@@ -23,6 +24,7 @@ export class PropBase extends Component {
recycle() {
this.canEaten = true;
this.node["canEaten"] = true;
};
}
......
......@@ -300,6 +300,7 @@ export class Snake extends Component {
eatProp(propTs: PropBase) {
propTs.canEaten = false;
propTs.node["canEaten"] = false;
// 食物吃掉的动画
Tween.stopAllByTarget(propTs.node);
tween(propTs.node)
......@@ -370,7 +371,7 @@ export class Snake extends Component {
*/
private grow() {
if (this.length > 1500) {
if (this.length > 1000) {
return;
}
......
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