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
e25b3082
Commit
e25b3082
authored
Dec 12, 2024
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
3cd61290
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
Snake.ts
assets/Scripts/Scenes/MainGame/Snake.ts
+12
-12
No files found.
assets/Scripts/Scenes/MainGame/Snake.ts
View file @
e25b3082
...
@@ -357,7 +357,7 @@ export class Snake extends Component {
...
@@ -357,7 +357,7 @@ export class Snake extends Component {
private
readonly
HISTORY_LENGTH
=
10
;
// 增加历史点数量
private
readonly
HISTORY_LENGTH
=
10
;
// 增加历史点数量
private
readonly
SEGMENT_SPACING
=
6.3
;
// 增加节点间距
private
readonly
SEGMENT_SPACING
=
6.3
;
// 增加节点间距
moveTime
=
1
/
3
0
;
moveTime
=
1
/
6
0
;
totalTime
=
0
;
totalTime
=
0
;
moveScale
=
1
;
moveScale
=
1
;
...
@@ -399,7 +399,7 @@ export class Snake extends Component {
...
@@ -399,7 +399,7 @@ export class Snake extends Component {
this
.
positions
.
unshift
(
newHeadPos
);
this
.
positions
.
unshift
(
newHeadPos
);
// 确保历史位置点足够多,以容纳所有身体节点
// 确保历史位置点足够多,以容纳所有身体节点
const
requiredLength
=
this
.
bodyArr
.
length
*
space
+
1
;
const
requiredLength
=
this
.
bodyArr
.
length
*
space
+
1
;
if
(
this
.
positions
.
length
>
Math
.
max
(
requiredLength
,
this
.
HISTORY_LENGTH
)
)
{
if
(
this
.
positions
.
length
>
requiredLength
)
{
this
.
positions
.
pop
();
this
.
positions
.
pop
();
}
}
...
@@ -436,16 +436,16 @@ export class Snake extends Component {
...
@@ -436,16 +436,16 @@ export class Snake extends Component {
}
}
// 边界检查
// 边界检查
//
const mapHalfWidth = Global.MAP_WIDTH / 2;
const
mapHalfWidth
=
Global
.
MAP_WIDTH
/
2
;
//
const mapHalfHeight = Global.MAP_HEIGHT / 2;
const
mapHalfHeight
=
Global
.
MAP_HEIGHT
/
2
;
//
if (
if
(
//
newHeadPos.x <= -mapHalfWidth
newHeadPos
.
x
<=
-
mapHalfWidth
//
|| newHeadPos.x >= mapHalfWidth
||
newHeadPos
.
x
>=
mapHalfWidth
//
|| newHeadPos.y <= -mapHalfHeight
||
newHeadPos
.
y
<=
-
mapHalfHeight
//
|| newHeadPos.y >= mapHalfHeight
||
newHeadPos
.
y
>=
mapHalfHeight
//
) {
)
{
//
this.death();
this
.
death
();
//
}
}
}
}
...
...
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