Commit 66b48421 authored by haiyoucuv's avatar haiyoucuv

init

parent d2bdaab7
......@@ -9,10 +9,10 @@ import {
PhysicsGroup,
Vec2,
IVec2Like,
v2,
v2, CircleCollider2D, NodeEventType,
} from "cc";
import { Snake } from "./Snake";
import { DirectionType } from "./Common/Enums";
import { DirectionType, EPropType } from "./Common/Enums";
import { Global } from "./Global";
import { MainGame } from "./MainGame";
import { FoodManger } from "./Manager/FoodManger";
......@@ -91,18 +91,42 @@ export class AISnake extends Snake {
onEnable() {
super.onEnable();
const eye = this.head.getChildByName("范围").getComponent(Collider2D);
const eye = this.head.getChildByName("范围").getComponent(CircleCollider2D);
eye.radius = 200;
eye.on(Contact2DType.BEGIN_CONTACT, this.onBeginEye, this);
// eye.on(Contact2DType.END_CONTACT, this.onEndEye, this);
}
foodList = [];
bodyList = [];
onBeginEye(selfCollider: Collider2D, otherCollider: Collider2D) {
if (otherCollider.group === PhysicsGroup["Body"] && otherCollider.tag != this.tag) {
const { group, tag, node } = otherCollider;
// if (group == PhysicsGroup["Prop"] && tag == EPropType.FOOD) {
// this.foodList.push(otherCollider.node);
// } else if (group == PhysicsGroup["Body"] && otherCollider.tag != this.tag) {
// this.bodyList.push(otherCollider.node);
// }
// console.log(otherCollider.group);
if (group === PhysicsGroup["Body"] && tag != this.tag) {
// 碰到其他蛇身
this.head.angle += 180;
// this.isFast = true;
this.setState(AIState.ESCAPING, otherCollider.node?.parent?.getComponent(Snake));
this.setState(AIState.ESCAPING, node?.parent?.getComponent(Snake));
}
}
onEndEye(selfCollider: Collider2D, otherCollider: Collider2D) {
const { group, tag } = otherCollider;
if (group == PhysicsGroup["Prop"] && tag == EPropType.FOOD) {
this.foodList.slice(this.foodList.indexOf(otherCollider.node), 1);
} else if (group == PhysicsGroup["Body"] && otherCollider.tag != this.tag) {
this.bodyList.slice(this.bodyList.indexOf(otherCollider.node), 1);
}
console.log(this.foodList, this.bodyList);
}
death() {
......
This diff is collapsed.
......@@ -224,8 +224,8 @@ export class MainGame extends Scene {
FoodManger.ins.init(300);
// 初始化NPC
this.initAnimal(20);
// this.initAnimal(1);
// this.initAnimal(20);
this.initAnimal(1);
PreCd.ins.node.active = true;
......
......@@ -184,7 +184,7 @@
"_priority": 65535,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 897.0108303249098,
"_orthoHeight": 406,
"_near": 1,
"_far": 2000,
"_color": {
......
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