Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
ngt7_fish
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
ngt7_fish
Commits
bf2127ca
Commit
bf2127ca
authored
Oct 23, 2022
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
游戏完成
parent
b0d610b9
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
334 additions
and
265 deletions
+334
-265
layout_fish.ts
assets/gofishing/scene/game/layout_fish.ts
+10
-10
gofishing.fire
assets/gofishing/scene/gofishing.fire
+155
-222
gofishing.ts
assets/gofishing/scene/gofishing.ts
+142
-12
Game.ts
assets/gofishing/scene/tool/Game.ts
+27
-21
No files found.
assets/gofishing/scene/game/layout_fish.ts
View file @
bf2127ca
...
...
@@ -34,16 +34,16 @@ export default class NewClass extends cc.Component {
private
fishs
:
cc
.
Node
[];
gameStart
()
{
//游戏开始。允许出鱼
let
page
=
Game
.
getIns
().
getCurrentPage
();
let
list
=
page
.
optionList
.
concat
();
list
=
JSON
.
parse
(
JSON
.
stringify
(
list
));
list
.
sort
((
A
,
B
)
=>
{
return
Math
.
random
()
<
0.5
});
this
.
list
=
list
;
this
.
count
=
0
;
this
.
lastCount
=
null
;
this
.
fishs
=
[];
this
.
viewFishs
=
[];
this
.
touchFishs
=
[];
//
let page = Game.getIns().getCurrentPage();
//
let list = page.optionList.concat();
//
list = JSON.parse(JSON.stringify(list));
//
list.sort((A, B) => { return Math.random() < 0.5 });
//
this.list = list;
//
this.count = 0;
//
this.lastCount = null;
//
this.fishs = [];
//
this.viewFishs = [];
//
this.touchFishs = [];
//根据顺序生成对应的鱼。
//顺序根据时间来进行跳动。当顺序跳动之后,就会产生新的鱼。
}
...
...
assets/gofishing/scene/gofishing.fire
View file @
bf2127ca
This diff is collapsed.
Click to expand it.
assets/gofishing/scene/gofishing.ts
View file @
bf2127ca
import
{
asyncDelay
,
onHomeworkFinish
}
from
"
../script/util
"
;
import
{
MyCocosSceneComponent
}
from
"
../script/MyCocosSceneComponent
"
;
import
Game
,
{
GAME_STATE
}
from
"
./tool/Game
"
;
import
Game
,
{
GAME_STATE
,
Option
}
from
"
./tool/Game
"
;
import
pg
from
"
./tool/pg
"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
...
...
@@ -29,7 +29,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
initView
();
this
.
initEvent
();
this
.
log
(
"
statr!!!!!!!!!!!!!
"
)
this
.
scheduleOnce
(()
=>
{
pg
.
event
.
emit
(
"
game_start
"
)
},
0.5
);
this
.
gameStart
()
}
protected
onDestroy
():
void
{
pg
.
event
.
clear
();
...
...
@@ -43,11 +43,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
_cantouch
=
true
;
}
private
audioId
:
any
;
async
initView
()
{
}
async
initView
()
{
let
boat_left
=
pg
.
view
.
find
(
this
,
'
layout_bottom/boat_left
'
)
let
boat_right
=
pg
.
view
.
find
(
this
,
'
layout_bottom/boat_right
'
)
pg
.
view
.
setString
(
pg
.
view
.
find
(
boat_left
,
'
text
'
),
Game
.
getIns
().
boatLeft
.
text
)
pg
.
view
.
setString
(
pg
.
view
.
find
(
boat_right
,
'
text
'
),
Game
.
getIns
().
boatRight
.
text
)
}
initEvent
()
{
pg
.
event
.
on
(
"
game_start
"
,
()
=>
{
this
.
gameStart
();
})
pg
.
event
.
on
(
"
game_time_over
"
,
()
=>
{
// alert("game_time_over")
//这里的事件会发送的很早。但是我们需要等待动画执行完了之后再开始后续的内容
...
...
@@ -63,16 +65,144 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg
.
audio
.
playLocalAudio
(
cc
.
find
(
`Canvas/res/audio/btn`
));
if
(
this
.
audioId
>
-
1
)
{
cc
.
audioEngine
.
stopAllEffects
();
// pg.audio.stopAudio(this.audioId);
}
Game
.
getIns
().
state
=
GAME_STATE
.
RUNNING
;
//游戏开始小鱼出现等等
if
(
this
.
audioId
>
-
1
&&
Game
.
getIns
().
state
!=
GAME_STATE
.
WAIT
)
{
cc
.
audioEngine
.
stopAllEffects
();
// pg.audio.stopAudio(this.audioId);
this
.
initFishs
();
}
initFishs
()
{
// 出现鱼
let
fishList
=
Game
.
getIns
().
getFishList
();
let
layout_fish
=
pg
.
view
.
find
(
this
,
'
layout_bottom/layout_fish
'
)
let
item
=
pg
.
view
.
find
(
this
,
'
layout_bottom/item
'
)
fishList
.
forEach
((
fish
,
index
)
=>
{
let
node
=
cc
.
instantiate
(
item
);
layout_fish
.
addChild
(
node
);
this
.
updateItem
(
node
,
fish
);
});
}
updateItem
(
item
,
data
:
Option
)
{
item
.
data
=
data
;
console
.
log
(
data
);
let
text
=
pg
.
view
.
find
(
item
,
'
layout_text/text
'
)
pg
.
view
.
setString
(
text
,
data
.
txt
)
let
count
=
data
.
id
%
10
+
1
;
for
(
let
i
=
1
;
i
<=
10
;
i
++
)
{
let
fishNode
=
pg
.
view
.
find
(
item
,
`fish/fish_
${
i
}
`
)
fishNode
.
active
=
i
==
count
}
//左往右
if
(
Math
.
random
()
<
0.5
)
{
item
.
x
=
-
(
1920
/
2
+
Math
.
random
()
*
200
)
item
.
y
=
-
315
-
Math
.
random
()
*
150
;
item
.
scaleX
=
-
1
;
text
.
scaleX
=
-
1
;
cc
.
tween
(
item
).
repeatForever
(
cc
.
tween
().
by
(
7
+
Math
.
random
()
*
8
,
{
x
:
1920
+
400
}).
call
(()
=>
{
item
.
scaleX
=
-
item
.
scaleX
;
text
.
scaleX
=
-
text
.
scaleX
;
}).
by
(
7
+
Math
.
random
()
*
8
,
{
x
:
-
1920
-
400
}).
call
(()
=>
{
item
.
scaleX
=
-
item
.
scaleX
;
text
.
scaleX
=
-
text
.
scaleX
;
})).
start
();
}
else
{
item
.
x
=
1920
/
2
+
Math
.
random
()
*
200
item
.
y
=
-
315
-
Math
.
random
()
*
150
;
item
.
scaleX
=
1
;
text
.
scaleX
=
1
;
cc
.
tween
(
item
).
repeatForever
(
cc
.
tween
().
by
(
7
+
Math
.
random
()
*
8
,
{
x
:
-
1920
-
400
}).
call
(()
=>
{
item
.
scaleX
=
-
item
.
scaleX
;
text
.
scaleX
=
-
text
.
scaleX
;
}).
by
(
7
+
Math
.
random
()
*
8
,
{
x
:
1920
+
400
}).
call
(()
=>
{
item
.
scaleX
=
-
item
.
scaleX
;
text
.
scaleX
=
-
text
.
scaleX
;
})).
start
();
}
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
this
.
onItemTouchStart
,
this
);
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_MOVE
,
this
.
onItemTouchMove
,
this
);
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
this
.
onItemTouchEnd
,
this
);
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
this
.
onItemTouchCancel
,
this
);
}
onTouchItem
(
e
)
{
let
item
=
e
.
target
;
let
data
=
item
.
data
;
item
.
x
=
0
;
item
.
y
=
0
;
cc
.
Tween
.
stopAllByTarget
(
item
);
setTimeout
(()
=>
{
this
.
updateItem
(
item
,
data
);
},
100
);
}
private
setTouchPos
(
e
)
{
let
item
=
e
.
target
;
let
location
=
e
.
getLocation
();
cc
.
Tween
.
stopAllByTarget
(
item
);
let
pos
=
location
.
sub
(
cc
.
v2
(
1920
/
2
,
1080
/
2
));
item
.
x
=
pos
.
x
;
item
.
y
=
pos
.
y
;
}
onItemTouchStart
(
e
)
{
let
target
:
cc
.
Node
=
e
.
target
;
let
data
=
target
.
data
;
if
(
data
.
isChecked
)
return
;
this
.
setTouchPos
(
e
);
}
onItemTouchMove
(
e
)
{
let
target
:
cc
.
Node
=
e
.
target
;
let
data
=
target
.
data
;
if
(
data
.
isChecked
)
return
;
this
.
setTouchPos
(
e
);
}
onItemTouchEnd
(
e
)
{
//
let
target
:
cc
.
Node
=
e
.
target
;
let
data
=
target
.
data
;
if
(
data
.
isChecked
)
return
;
// let rect = cc.rect(target.x, target.y, target.width, target.height);
let
rect
=
cc
.
rect
(
target
.
x
,
target
.
y
,
50
,
50
);
let
boat_left
=
pg
.
view
.
find
(
this
,
'
layout_bottom/boat_left
'
)
let
boat_right
=
pg
.
view
.
find
(
this
,
'
layout_bottom/boat_right
'
)
let
leftRect
=
cc
.
rect
(
boat_left
.
x
-
boat_left
.
width
/
2
,
boat_left
.
y
-
boat_left
.
height
/
2
,
boat_left
.
width
,
boat_left
.
height
);
let
rightRect
=
cc
.
rect
(
boat_right
.
x
-
boat_right
.
width
/
2
,
boat_right
.
y
-
boat_right
.
height
/
2
,
boat_right
.
width
,
boat_right
.
height
);
let
isRight
=
false
;
let
currentRect
=
null
;
if
(
rect
.
intersects
(
leftRect
))
{
isRight
=
!!
Game
.
getIns
().
boatLeft
.
isChild
(
data
);
Game
.
getIns
().
boatLeft
.
setRight
(
data
);
currentRect
=
leftRect
;
}
else
if
(
rect
.
intersects
(
rightRect
))
{
isRight
=
!!
Game
.
getIns
().
boatRight
.
isChild
(
data
);
Game
.
getIns
().
boatRight
.
setRight
(
data
);
currentRect
=
rightRect
;
}
if
(
isRight
)
{
// target
let
item
=
target
;
let
lastArea
=
100
;
if
(
item
.
scaleX
==
-
1
)
{
// 计算当前坐标距离最左侧的距离
let
space
=
currentRect
.
width
-
((
rect
.
x
+
rect
.
width
)
-
currentRect
.
x
)
-
lastArea
/
5
;
let
time
=
space
/
10
;
cc
.
tween
(
item
).
by
(
time
,
{
x
:
space
}).
start
();
}
else
{
// 计算当前坐标距离最左侧的距离
let
space
=
rect
.
x
-
currentRect
.
x
-
lastArea
;
let
time
=
space
/
10
;
cc
.
tween
(
item
).
by
(
time
,
{
x
:
-
space
}).
start
();
}
}
else
{
this
.
updateItem
(
target
,
data
);
}
//判断是否结束了
if
(
Game
.
getIns
().
boatLeft
.
isAllRight
()
&&
Game
.
getIns
().
boatRight
.
isAllRight
())
{
this
.
showGameOver
();
}
}
onItemTouchCancel
()
{
}
private
showGameOver
()
{
let
gameover
=
cc
.
find
(
"
gameover
"
,
this
.
node
);
gameover
.
scale
=
3
;
...
...
assets/gofishing/scene/tool/Game.ts
View file @
bf2127ca
...
...
@@ -41,8 +41,10 @@ export class Item {
private
static
ID
:
number
=
1000
;
public
audio
:
string
;
public
text
:
string
;
public
optionList
;
public
optionList
:
Array
<
Option
>
;
public
rightList
:
Array
<
Option
>
;
constructor
(
data
)
{
this
.
rightList
=
[]
this
.
audio
=
data
.
audio
;
this
.
text
=
data
.
text
;
this
.
optionList
=
data
.
options
.
map
(
o
=>
{
...
...
@@ -55,7 +57,15 @@ export class Item {
for
(
let
i
=
0
;
i
<
this
.
optionList
.
length
;
i
++
)
{
this
.
optionList
[
i
].
count
=
i
;
}
}
isChild
(
data
)
{
return
this
.
optionList
.
find
(
option
=>
option
.
id
==
data
.
id
)
}
setRight
(
data
)
{
this
.
rightList
.
push
(
data
);
}
isAllRight
()
{
return
this
.
optionList
.
length
==
this
.
rightList
.
length
;
}
}
class
Role
{
...
...
@@ -112,8 +122,8 @@ export default class Game {
this
.
data
=
data
.
questions
;
}
public
start
:
boolean
;
p
rivate
boatLeft
:
Item
;
p
rivate
boatRight
:
Item
;
p
ublic
boatLeft
:
Item
;
p
ublic
boatRight
:
Item
;
reset
()
{
this
.
player
.
reset
();
this
.
start
=
true
;
...
...
@@ -122,24 +132,20 @@ export default class Game {
this
.
boatRight
=
new
Item
(
this
.
data
[
1
]);
this
.
state
=
GAME_STATE
.
WAIT
;
}
checkSuccess
(
arr
:
Option
[])
{
let
data
=
this
.
getCurrentPage
();
let
options
=
data
.
optionList
.
concat
();
options
.
sort
((
A
,
B
)
=>
A
.
id
-
B
.
id
)
for
(
let
i
=
0
;
i
<
options
.
length
;
i
++
)
{
if
(
arr
[
i
]
&&
arr
[
i
].
id
!=
options
[
i
].
id
)
{
return
false
;
}
}
return
true
;
getFishList
()
{
return
this
.
boatLeft
.
optionList
.
concat
(
this
.
boatRight
.
optionList
)
}
getCurrentPage
():
Item
{
if
(
!
this
.
lists
)
return
null
;
}
getTotalPageNum
()
{
return
this
.
lists
.
length
;
}
getCurrentPageNum
()
{
checkSuccess
(
arr
:
Option
[])
{
return
false
;
// let data = this.getCurrentPage();
// let options = data.optionList.concat();
// options.sort((A, B) => A.id - B.id)
// for (let i = 0; i < options.length; i++) {
// if (arr[i] && arr[i].id != options[i].id) {
// return false;
// }
// }
// return true;
}
addPage
()
{
}
...
...
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