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
0487e174
Commit
0487e174
authored
Nov 25, 2024
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
c0b3fa4a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
+15
-4
Player.ts
assets/Scripts/Scenes/MainGame/Player.ts
+9
-2
Snake.ts
assets/Scripts/Scenes/MainGame/Snake.ts
+6
-2
No files found.
assets/Scripts/Scenes/MainGame/Player.ts
View file @
0487e174
...
...
@@ -19,19 +19,26 @@ export class Player extends Snake {
@
property
(
FastBtn
)
fastBtn
:
FastBtn
=
null
;
get
length
():
number
{
return
super
.
length
;
}
set
length
(
value
:
number
)
{
super
.
length
=
value
;
this
.
updateLength
(
value
);
}
onLoad
()
{
super
.
onLoad
();
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
)
{
...
...
assets/Scripts/Scenes/MainGame/Snake.ts
View file @
0487e174
...
...
@@ -64,6 +64,7 @@ export class Snake extends Component {
get
length
()
{
return
this
.
_length
;
}
set
length
(
value
:
number
)
{
this
.
_length
=
value
;
this
.
node
.
emit
(
"updateLength"
,
value
);
...
...
@@ -88,7 +89,6 @@ export class Snake extends Component {
this
.
energy
=
0
;
this
.
bodyArr
=
[];
this
.
scale
=
scale
;
// this.speed = this.speed * scale;
this
.
tag
=
Snake
.
tag
++
;
// 设置头部
...
...
@@ -101,7 +101,6 @@ export class Snake extends Component {
const
bw
=
this
.
imgBody1
.
originalSize
.
width
;
this
.
head
.
getComponent
(
UITransform
).
anchorX
=
(
bw
/
2
)
/
hw
;
// 创建尾巴节点
const
tile
=
bodyPool
.
get
()
||
instantiate
(
this
.
bodyPrefab
);
tile
.
angle
=
angle
;
...
...
@@ -122,6 +121,8 @@ export class Snake extends Component {
this
.
node
.
addChild
(
tile
);
this
.
bodyArr
.
push
(
tile
);
this
.
length
=
2
;
// 创建身体节点
this
.
addEnergy
(
initEnergy
);
...
...
@@ -204,6 +205,9 @@ export class Snake extends Component {
// 蛇身体生长
private
grow
()
{
this
.
length
+=
1
;
let
len
=
this
.
bodyArr
.
length
;
if
(
this
.
imgTail
)
len
-=
1
;
...
...
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