Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MingSnake_241120
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
SparkProjects
MingSnake_241120
Commits
66b48421
Commit
66b48421
authored
Dec 13, 2024
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
d2bdaab7
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
670 additions
and
9 deletions
+670
-9
AISnake.ts
assets/Scripts/Scenes/MainGame/AISnake.ts
+30
-6
AISnake3.ts
assets/Scripts/Scenes/MainGame/AISnake3.ts
+637
-0
MainGame.ts
assets/Scripts/Scenes/MainGame/MainGame.ts
+2
-2
Start.scene
assets/Start/Start.scene
+1
-1
No files found.
assets/Scripts/Scenes/MainGame/AISnake.ts
View file @
66b48421
...
...
@@ -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
()
{
...
...
assets/Scripts/Scenes/MainGame/AISnake3.ts
0 → 100644
View file @
66b48421
This diff is collapsed.
Click to expand it.
assets/Scripts/Scenes/MainGame/MainGame.ts
View file @
66b48421
...
...
@@ -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;
...
...
assets/Start/Start.scene
View file @
66b48421
...
...
@@ -184,7 +184,7 @@
"_priority": 65535,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight":
897.0108303249098
,
"_orthoHeight":
406
,
"_near": 1,
"_far": 2000,
"_color": {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment