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
528e7534
Commit
528e7534
authored
Nov 22, 2024
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
b2d1c691
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
MainGame.ts
assets/Scripts/Scenes/MainGame/MainGame.ts
+2
-1
Snake.ts
assets/Scripts/Scenes/MainGame/Snake.ts
+8
-3
No files found.
assets/Scripts/Scenes/MainGame/MainGame.ts
View file @
528e7534
...
@@ -123,11 +123,12 @@ export class MainGame extends Scene {
...
@@ -123,11 +123,12 @@ export class MainGame extends Scene {
wallRight
.
getComponent
(
UITransform
).
height
=
Global
.
MAP_HEIGHT
;
wallRight
.
getComponent
(
UITransform
).
height
=
Global
.
MAP_HEIGHT
;
this
.
player
.
init
({
this
.
player
.
init
({
// initEnergy: 100
// initEnergy: 100
00
});
});
// 初始化食物和NPC
// 初始化食物和NPC
this
.
fondManger
.
init
(
this
.
maxFood
);
this
.
fondManger
.
init
(
this
.
maxFood
);
// this.fondManger.init(2000);
this
.
initAnimal
(
this
.
maxAnimal
);
this
.
initAnimal
(
this
.
maxAnimal
);
// this.initAnimal(1);
// this.initAnimal(1);
...
...
assets/Scripts/Scenes/MainGame/Snake.ts
View file @
528e7534
...
@@ -92,7 +92,6 @@ export class Snake extends Component {
...
@@ -92,7 +92,6 @@ export class Snake extends Component {
const
hw
=
this
.
imgHead
.
originalSize
.
width
;
const
hw
=
this
.
imgHead
.
originalSize
.
width
;
const
bw
=
this
.
imgBody1
.
originalSize
.
width
;
const
bw
=
this
.
imgBody1
.
originalSize
.
width
;
// this.head.getComponent(UITransform).anchorX = (bw / 2) / hw;
this
.
head
.
getComponent
(
UITransform
).
anchorX
=
(
bw
/
2
)
/
hw
;
this
.
head
.
getComponent
(
UITransform
).
anchorX
=
(
bw
/
2
)
/
hw
;
...
@@ -177,9 +176,11 @@ export class Snake extends Component {
...
@@ -177,9 +176,11 @@ export class Snake extends Component {
// 能量与成长
// 能量与成长
lastRemaining
=
0
;
lastRemaining
=
0
;
private
addEnergy
(
value
:
number
)
{
private
addEnergy
(
value
:
number
)
{
console
.
log
(
this
.
energy
,
value
);
this
.
energy
+=
value
;
this
.
energy
+=
value
;
const
growthThreshold
=
Math
.
floor
(
4
*
this
.
scale
);
const
growthThreshold
=
Math
.
floor
(
4
*
this
.
scale
);
value
+=
this
.
lastRemaining
;
value
+=
this
.
lastRemaining
;
while
(
value
>=
growthThreshold
)
{
while
(
value
>=
growthThreshold
)
{
...
@@ -190,6 +191,8 @@ export class Snake extends Component {
...
@@ -190,6 +191,8 @@ export class Snake extends Component {
}
}
}
}
console
.
log
(
this
.
energy
,
this
.
scale
,
this
.
energy
/
this
.
bodyArr
.
length
);
this
.
lastRemaining
=
value
;
this
.
lastRemaining
=
value
;
// this.speed = 600 * this.scale;
// this.speed = 600 * this.scale;
...
@@ -309,8 +312,10 @@ export class Snake extends Component {
...
@@ -309,8 +312,10 @@ 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
.
y
<=
-
mapHalfHeight
||
newHeadPos
.
y
>=
mapHalfHeight
||
newHeadPos
.
x
>=
mapHalfWidth
||
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