Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
L4R1_game
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
L4R1_game
Commits
5e1bcabf
Commit
5e1bcabf
authored
Oct 11, 2026
by
liwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 鸭子朝向不再读空路点
鸭子 2 只有 7 个路点,按下标计算朝向前先确认坐标存在。 Co-authored-by:
Cursor
<
cursoragent@cursor.com
>
parent
f3e932be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
16 deletions
+38
-16
L4R1_game.ts
assets/L4R1_game/scene/L4R1_game.ts
+38
-16
No files found.
assets/L4R1_game/scene/L4R1_game.ts
View file @
5e1bcabf
...
...
@@ -93,19 +93,40 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
duck2Moving
()
}
duck1Moving
()
{
this
.
duck1
.
position
=
this
.
duck1PosList
[
this
.
_duck1Now
];
pickNextDuckIndex
(
list
,
current
)
{
const
count
=
list
?
list
.
length
:
0
;
if
(
count
<=
1
)
{
return
0
;
}
let
next
=
current
;
for
(
let
i
=
0
;
i
<
8
&&
next
===
current
;
i
++
)
{
next
=
Math
.
floor
(
Math
.
random
()
*
count
);
}
return
next
;
}
cc
.
tween
(
this
.
duck1
).
to
(
10
,
{
x
:
this
.
duck1PosList
[
this
.
_duck1To
].
x
,
y
:
this
.
duck1PosList
[
this
.
_duck1To
].
y
}).
call
(()
=>
{
faceDuck
(
duck
,
fromPos
,
toPos
)
{
if
(
!
duck
||
!
fromPos
||
!
toPos
)
{
return
;
}
duck
.
angle
=
30
-
180
/
Math
.
PI
*
cc
.
v2
(
toPos
.
x
-
fromPos
.
x
,
toPos
.
y
-
fromPos
.
y
).
angle
(
cc
.
v2
(
0
,
1
));
console
.
log
(
duck
.
angle
);
}
this
.
_duck1Now
=
this
.
_duck1To
;
duck1Moving
()
{
const
nowPos
=
this
.
duck1PosList
[
this
.
_duck1Now
];
const
toPos
=
this
.
duck1PosList
[
this
.
_duck1To
];
if
(
!
nowPos
||
!
toPos
)
{
return
;
}
this
.
duck1
.
position
=
nowPos
;
this
.
_duck1To
=
Math
.
floor
(
Math
.
random
()
*
8
);
cc
.
tween
(
this
.
duck1
).
to
(
10
,
{
x
:
toPos
.
x
,
y
:
toPos
.
y
}).
call
(()
=>
{
this
.
_duck1Now
=
this
.
_duck1To
;
this
.
_duck1To
=
this
.
pickNextDuckIndex
(
this
.
duck1PosList
,
this
.
_duck1Now
);
if
(
this
.
_duck1To
!=
this
.
_duck1Now
)
{
this
.
duck1
.
angle
=
30
-
180
/
Math
.
PI
*
cc
.
v2
(
this
.
duck1PosList
[
this
.
_duck1To
].
x
-
this
.
duck1PosList
[
this
.
_duck1Now
].
x
,
this
.
duck1PosList
[
this
.
_duck1To
].
y
-
this
.
duck1PosList
[
this
.
_duck1Now
].
y
).
angle
(
cc
.
v2
(
0
,
1
))
console
.
log
(
this
.
duck1
.
angle
);
this
.
faceDuck
(
this
.
duck1
,
this
.
duck1PosList
[
this
.
_duck1Now
],
this
.
duck1PosList
[
this
.
_duck1To
]);
}
this
.
duck1Moving
();
...
...
@@ -115,18 +136,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
duck2Moving
()
{
this
.
duck2
.
position
=
this
.
duck2PosList
[
this
.
_duck2Now
];
const
nowPos
=
this
.
duck2PosList
[
this
.
_duck2Now
];
const
toPos
=
this
.
duck2PosList
[
this
.
_duck2To
];
if
(
!
nowPos
||
!
toPos
)
{
return
;
}
this
.
duck2
.
position
=
nowPos
;
cc
.
tween
(
this
.
duck2
).
to
(
10
,
{
x
:
t
his
.
duck2PosList
[
this
.
_duck2To
].
x
,
y
:
this
.
duck2PosList
[
this
.
_duck2To
]
.
y
}).
call
(()
=>
{
cc
.
tween
(
this
.
duck2
).
to
(
10
,
{
x
:
t
oPos
.
x
,
y
:
toPos
.
y
}).
call
(()
=>
{
this
.
_duck2Now
=
this
.
_duck2To
;
this
.
_duck2To
=
Math
.
floor
(
Math
.
random
()
*
8
);
this
.
_duck2To
=
this
.
pickNextDuckIndex
(
this
.
duck2PosList
,
this
.
_duck2Now
);
if
(
this
.
_duck2To
!=
this
.
_duck2Now
)
{
this
.
duck2
.
angle
=
30
-
180
/
Math
.
PI
*
cc
.
v2
(
this
.
duck2PosList
[
this
.
_duck2To
].
x
-
this
.
duck2PosList
[
this
.
_duck2Now
].
x
,
this
.
duck2PosList
[
this
.
_duck2To
].
y
-
this
.
duck2PosList
[
this
.
_duck2Now
].
y
).
angle
(
cc
.
v2
(
0
,
1
))
console
.
log
(
this
.
duck2
.
angle
);
this
.
faceDuck
(
this
.
duck2
,
this
.
duck2PosList
[
this
.
_duck2Now
],
this
.
duck2PosList
[
this
.
_duck2To
]);
}
this
.
duck2Moving
();
...
...
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