Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
LuzhouLaojiaoSnake_250428
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
LuzhouLaojiaoSnake_250428
Commits
66885c92
Commit
66885c92
authored
May 06, 2025
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分数气泡
parent
64d62ee0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
76 deletions
+19
-76
Snake.ts
src/pages/GamePage/Components/Snake.ts
+16
-75
Config.ts
src/pages/GamePage/config/Config.ts
+3
-1
No files found.
src/pages/GamePage/Components/Snake.ts
View file @
66885c92
...
...
@@ -12,20 +12,6 @@ export class Snake extends Container {
bodyScale
:
number
=
1
;
energy
:
number
=
0
;
private
_length
:
number
=
0
;
get
length
()
{
return
this
.
_length
;
}
set
length
(
value
:
number
)
{
this
.
_length
=
value
;
this
.
emit
(
"updateLength"
,
value
);
}
get
radius
()
{
return
this
.
bodyScale
*
46
/
2
;
}
// 位置相关
private
ready
:
boolean
=
false
;
isLife
:
boolean
=
true
;
...
...
@@ -59,10 +45,8 @@ export class Snake extends Container {
this
.
head
.
position
.
set
(
375
,
375
);
this
.
head
.
anchor
.
set
(
0.5
,
0.5
);
this
.
length
=
1
;
// 创建身体节点
this
.
addEnergy
(
50
);
this
.
addEnergy
(
GameConfig
.
initEnergy
);
this
.
isLife
=
true
;
this
.
ready
=
true
;
...
...
@@ -100,45 +84,29 @@ export class Snake extends Container {
this
.
negCollider
.
setScale
(
this
.
bodyScale
,
this
.
bodyScale
);
}
onEnable
()
{
}
onDisable
()
{
}
// 上次生长富余的能量
private
lastRemaining
=
0
;
/**
* 加能量
* 暂定加长/双倍道具卡效果不叠加
*/
addEnergy
(
value
:
number
)
{
this
.
energy
+=
value
const
growthThreshold
=
Math
.
floor
(
12
*
this
.
bodyScale
);
const
{
growthThreshold
}
=
GameConfig
;
this
.
energy
=
Math
.
max
(
this
.
energy
+
value
,
0
);
value
+=
this
.
lastRemaining
;
const
originLen
=
this
.
bodyArr
.
length
;
const
len
=
this
.
energy
/
growthThreshold
>>
0
;
while
(
value
>=
growthThreshold
)
{
value
-=
growthThreshold
;
if
(
this
.
bodyScale
<
3
)
{
this
.
bodyScale
+=
0.01
;
if
(
originLen
<
len
)
{
for
(
let
i
=
originLen
;
i
<
len
;
i
++
)
{
this
.
grow
();
}
this
.
grow
();
}
else
if
(
originLen
>
len
)
{
this
.
bodyArr
.
splice
(
len
,
originLen
-
len
)
.
forEach
((
body
)
=>
{
body
.
removeFromParent
();
});
}
this
.
lastRemaining
=
value
;
// this.speed = 600 * this.scale;
}
/**
* 快速生长
*/
fastGrow
(
energy
:
number
)
{
this
.
addEnergy
(
energy
)
// for (let i = 0; i < time; i++) {
// this.grow();
// }
}
/**
...
...
@@ -146,14 +114,8 @@ export class Snake extends Container {
*/
private
grow
()
{
if
(
this
.
length
>
180
)
{
return
;
}
if
(
!
this
.
isLife
)
return
;
this
.
length
+=
1
;
let
len
=
this
.
bodyArr
.
length
;
const
newBody
=
new
Sprite
(
Assets
.
get
(
"蛇/初级/body0.png"
));
...
...
@@ -161,23 +123,15 @@ export class Snake extends Container {
const
pre
=
this
.
bodyArr
[
len
-
1
]
||
this
.
head
;
newBody
.
angle
=
pre
.
angle
;
newBody
.
position
.
set
(
999999
,
999999
);
newBody
.
position
.
set
(
pre
.
x
,
pre
.
y
);
newBody
.
scale
.
set
(
this
.
bodyScale
,
this
.
bodyScale
);
this
.
addChildAt
(
newBody
,
0
);
newBody
.
anchor
.
set
(
0.5
,
0.5
);
// newBody.active = isIntersect(
// newBody.getPosition(),
// this.head.getPosition(),
// this.vw,
// this.vh
// );
this
.
bodyArr
.
splice
(
len
,
0
,
newBody
);
}
positions
:
PointData
[]
=
[];
// 存储历史位置点
private
readonly
HISTORY_LENGTH
=
10
;
// 增加历史点数量
private
readonly
SEGMENT_SPACING
=
6.3
;
// 增加节点间距
moveTime
=
1
/
60
;
...
...
@@ -251,19 +205,6 @@ export class Snake extends Container {
body
.
scale
.
set
(
this
.
bodyScale
,
this
.
bodyScale
);
}
}
// // 边界检查
// const mapHalfWidth = Global.HALF_MAP_WIDTH;
// const mapHalfHeight = Global.HALF_MAP_HEIGHT;
// if (
// newHeadPos.x < -mapHalfWidth
// || newHeadPos.x > mapHalfWidth
// || newHeadPos.y < -mapHalfHeight
// || newHeadPos.y > mapHalfHeight
// ) {
// this.death();
// }
}
/****************************** 磁铁 ******************************/
...
...
src/pages/GamePage/config/Config.ts
View file @
66885c92
...
...
@@ -25,7 +25,9 @@ export interface EleData {
export
const
GameConfig
=
{
magnetTime
:
10000
,
magnetScale
:
3
,
magnetScale
:
4
,
initEnergy
:
10
,
growthThreshold
:
2
,
}
export
const
EleConfig
:
{
[
key
in
Ele
]:
EleData
}
=
{
...
...
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