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
76cc6857
Commit
76cc6857
authored
Nov 21, 2024
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
24b4bd2f
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
120 additions
and
19 deletions
+120
-19
MainGame.scene
assets/Bundles/MainGame/MainGame.scene
+3
-3
MainGame.ts
assets/Scripts/Scenes/MainGame/MainGame.ts
+1
-1
Snake.ts
assets/Scripts/Scenes/MainGame/Snake.ts
+16
-15
utils.meta
assets/Scripts/Scenes/MainGame/utils.meta
+9
-0
uitl.ts
assets/Scripts/Scenes/MainGame/utils/uitl.ts
+0
-0
uitl.ts.meta
assets/Scripts/Scenes/MainGame/utils/uitl.ts.meta
+0
-0
CoroutineRunner.ts
assets/Scripts/Utils/CoroutineRunner.ts
+82
-0
CoroutineRunner.ts.meta
assets/Scripts/Utils/CoroutineRunner.ts.meta
+9
-0
No files found.
assets/Bundles/MainGame/MainGame.scene
View file @
76cc6857
...
@@ -190,7 +190,7 @@
...
@@ -190,7 +190,7 @@
"_priority": 40000,
"_priority": 40000,
"_fov": 45,
"_fov": 45,
"_fovAxis": 0,
"_fovAxis": 0,
"_orthoHeight":
857.2908366533865
,
"_orthoHeight":
695.1569767441861
,
"_near": 0,
"_near": 0,
"_far": 2000,
"_far": 2000,
"_color": {
"_color": {
...
@@ -1534,7 +1534,7 @@
...
@@ -1534,7 +1534,7 @@
"_priority": 50000,
"_priority": 50000,
"_fov": 45,
"_fov": 45,
"_fovAxis": 0,
"_fovAxis": 0,
"_orthoHeight":
857.2908366533865
,
"_orthoHeight":
695.1569767441861
,
"_near": 1,
"_near": 1,
"_far": 2000,
"_far": 2000,
"_color": {
"_color": {
...
@@ -2241,7 +2241,7 @@
...
@@ -2241,7 +2241,7 @@
"__uuid__": "f7e4cff9-e50b-4028-b58e-f258871093ca",
"__uuid__": "f7e4cff9-e50b-4028-b58e-f258871093ca",
"__expectedType__": "cc.Prefab"
"__expectedType__": "cc.Prefab"
},
},
"maxFood":
2
00,
"maxFood":
3
00,
"maxAnimal": 20,
"maxAnimal": 20,
"joystick": {
"joystick": {
"__id__": 38
"__id__": 38
...
...
assets/Scripts/Scenes/MainGame/MainGame.ts
View file @
76cc6857
...
@@ -37,7 +37,7 @@ export class MainGame extends Scene {
...
@@ -37,7 +37,7 @@ export class MainGame extends Scene {
displayName
:
"最多食物"
,
displayName
:
"最多食物"
,
tooltip
:
"地图上随机产生食物,如果超过当前值不在产生。"
tooltip
:
"地图上随机产生食物,如果超过当前值不在产生。"
})
})
maxFood
:
number
=
2
00
;
maxFood
:
number
=
3
00
;
@
property
({
@
property
({
displayName
:
"NPC数量"
,
displayName
:
"NPC数量"
,
...
...
assets/Scripts/Scenes/MainGame/Snake.ts
View file @
76cc6857
...
@@ -17,7 +17,7 @@ import {
...
@@ -17,7 +17,7 @@ import {
import
{
FoodType
}
from
"./Common/Enums"
;
import
{
FoodType
}
from
"./Common/Enums"
;
import
{
Global
}
from
"./Global"
;
import
{
Global
}
from
"./Global"
;
import
{
PoolManager
}
from
"./Manager/PoolManager"
;
import
{
PoolManager
}
from
"./Manager/PoolManager"
;
import
{
isIntersect
,
loadSkin
}
from
"./uitl"
;
import
{
isIntersect
,
loadSkin
}
from
"./u
tils/u
itl"
;
import
{
MainGame
}
from
"./MainGame"
;
import
{
MainGame
}
from
"./MainGame"
;
import
{
executePreFrame
,
getItemGenerator
}
from
"../../Utils/ExecutePreFrame"
;
import
{
executePreFrame
,
getItemGenerator
}
from
"../../Utils/ExecutePreFrame"
;
...
@@ -101,7 +101,7 @@ export class Snake extends Component {
...
@@ -101,7 +101,7 @@ export class Snake extends Component {
// 设置身体部分的贴图
// 设置身体部分的贴图
body
.
getComponent
(
Sprite
).
spriteFrame
=
i
%
2
==
0
?
this
.
imgBody1
:
this
.
imgBody2
;
body
.
getComponent
(
Sprite
).
spriteFrame
=
i
%
2
==
0
?
this
.
imgBody1
:
this
.
imgBody2
;
body
.
active
=
false
;
//
body.active = false;
this
.
bodyArr
.
push
(
body
);
this
.
bodyArr
.
push
(
body
);
}
}
...
@@ -189,12 +189,12 @@ export class Snake extends Component {
...
@@ -189,12 +189,12 @@ export class Snake extends Component {
newBody
.
getComponent
(
Sprite
).
spriteFrame
=
len
%
2
==
0
?
this
.
imgBody1
:
this
.
imgBody2
;
newBody
.
getComponent
(
Sprite
).
spriteFrame
=
len
%
2
==
0
?
this
.
imgBody1
:
this
.
imgBody2
;
newBody
.
getComponent
(
Collider2D
).
tag
=
this
.
tag
;
newBody
.
getComponent
(
Collider2D
).
tag
=
this
.
tag
;
newBody
.
active
=
isIntersect
(
//
newBody.active = isIntersect(
newBody
.
getPosition
(),
//
newBody.getPosition(),
this
.
head
.
getPosition
(),
//
this.head.getPosition(),
this
.
vw
,
//
this.vw,
this
.
vh
//
this.vh
);
//
);
this
.
bodyArr
.
splice
(
len
,
0
,
newBody
);
this
.
bodyArr
.
splice
(
len
,
0
,
newBody
);
}
}
...
@@ -206,7 +206,7 @@ export class Snake extends Component {
...
@@ -206,7 +206,7 @@ export class Snake extends Component {
isFast
=
false
;
isFast
=
false
;
private
positions
:
Vec3
[]
=
[];
// 存储历史位置点
private
positions
:
Vec3
[]
=
[];
// 存储历史位置点
private
readonly
HISTORY_LENGTH
=
100
;
// 增加历史点数量
private
readonly
HISTORY_LENGTH
=
100
;
// 增加历史点数量
private
readonly
SEGMENT_SPACING
=
5
;
// 增加节点间距
private
readonly
SEGMENT_SPACING
=
8
;
// 增加节点间距
moveTime
=
1
/
60
;
moveTime
=
1
/
60
;
totalTime
=
0
;
totalTime
=
0
;
...
@@ -271,12 +271,12 @@ export class Snake extends Component {
...
@@ -271,12 +271,12 @@ export class Snake extends Component {
body
.
setScale
(
this
.
scale
,
this
.
scale
);
body
.
setScale
(
this
.
scale
,
this
.
scale
);
body
.
setSiblingIndex
(
this
.
bodyArr
.
length
-
i
);
body
.
setSiblingIndex
(
this
.
bodyArr
.
length
-
i
);
body
.
active
=
isIntersect
(
//
body.active = isIntersect(
targetPos
,
//
targetPos,
this
.
head
.
getPosition
(),
//
this.head.getPosition(),
this
.
vw
,
//
this.vw,
this
.
vh
//
this.vh
);
//
);
}
}
}
}
...
@@ -302,6 +302,7 @@ export class Snake extends Component {
...
@@ -302,6 +302,7 @@ export class Snake extends Component {
this
.
isLife
=
false
;
this
.
isLife
=
false
;
this
.
node
.
active
=
false
;
this
.
node
.
active
=
false
;
console
.
log
(
MainGame
.
ins
.
animalNode
.
children
.
length
)
this
.
initFond
(
this
.
bodyArr
.
length
);
this
.
initFond
(
this
.
bodyArr
.
length
);
...
...
assets/Scripts/Scenes/MainGame/utils.meta
0 → 100644
View file @
76cc6857
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a23ad008-035e-4d4c-8b0a-ae8d587e1321",
"files": [],
"subMetas": {},
"userData": {}
}
assets/Scripts/Scenes/MainGame/uitl.ts
→
assets/Scripts/Scenes/MainGame/u
tils/u
itl.ts
View file @
76cc6857
File moved
assets/Scripts/Scenes/MainGame/uitl.ts.meta
→
assets/Scripts/Scenes/MainGame/u
tils/u
itl.ts.meta
View file @
76cc6857
File moved
assets/Scripts/Utils/CoroutineRunner.ts
0 → 100644
View file @
76cc6857
function
*
waitSeconds
(
duration
:
number
)
{
let
start
=
Date
.
now
();
while
(
duration
>
0
)
{
const
current
=
Date
.
now
();
const
dt
=
current
-
start
;
start
=
current
;
duration
-=
dt
;
yield
;
}
}
export
class
CoroutineRunner
{
private
generatorStacks
:
any
[];
private
removeQueue
:
Set
<
any
>
;
private
addQueue
:
any
[];
constructor
()
{
this
.
generatorStacks
=
[];
this
.
addQueue
=
[];
this
.
removeQueue
=
new
Set
();
}
isBusy
()
{
return
this
.
addQueue
.
length
+
this
.
generatorStacks
.
length
>
0
;
}
add
(
generator
:
Generator
,
delay
=
0
)
{
const
genStack
=
[
generator
];
if
(
delay
)
{
genStack
.
push
(
waitSeconds
(
delay
));
}
this
.
addQueue
.
push
(
genStack
);
}
remove
(
generator
:
Generator
)
{
this
.
removeQueue
.
add
(
generator
);
}
update
()
{
this
.
_addQueued
();
this
.
_removeQueued
();
for
(
const
genStack
of
this
.
generatorStacks
)
{
const
main
=
genStack
[
0
];
// Handle if one coroutine removes another
if
(
this
.
removeQueue
.
has
(
main
))
{
continue
;
}
while
(
genStack
.
length
)
{
const
topGen
=
genStack
[
genStack
.
length
-
1
];
const
{
value
,
done
}
=
topGen
.
next
();
if
(
done
)
{
if
(
genStack
.
length
===
1
)
{
this
.
removeQueue
.
add
(
topGen
);
break
;
}
genStack
.
pop
();
}
else
if
(
value
)
{
genStack
.
push
(
value
);
}
else
{
break
;
}
}
}
this
.
_removeQueued
();
}
_addQueued
()
{
if
(
this
.
addQueue
.
length
)
{
this
.
generatorStacks
.
splice
(
this
.
generatorStacks
.
length
,
0
,
...
this
.
addQueue
);
this
.
addQueue
=
[];
}
}
_removeQueued
()
{
if
(
this
.
removeQueue
.
size
)
{
this
.
generatorStacks
=
this
.
generatorStacks
.
filter
(
genStack
=>
!
this
.
removeQueue
.
has
(
genStack
[
0
]));
this
.
removeQueue
.
clear
();
}
}
}
\ No newline at end of file
assets/Scripts/Utils/CoroutineRunner.ts.meta
0 → 100644
View file @
76cc6857
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "142ccfd9-e442-4f29-9e74-88e23bb5f86f",
"files": [],
"subMetas": {},
"userData": {}
}
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