Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crazyflirt
Project
Overview
Details
Activity
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
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
Shawn Wang
crazyflirt
Commits
65c2ac66
Commit
65c2ac66
authored
May 06, 2018
by
Matt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add hit test
parent
4a2c995a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
5 deletions
+49
-5
Map.ts
fe/src/Map.ts
+46
-4
Store.ts
fe/src/Store.ts
+3
-1
No files found.
fe/src/Map.ts
View file @
65c2ac66
...
@@ -7,6 +7,7 @@ class Map extends egret.Sprite {
...
@@ -7,6 +7,7 @@ class Map extends egret.Sprite {
private
touchArea
:
egret
.
Bitmap
private
touchArea
:
egret
.
Bitmap
public
isShowingTouchArea
public
isShowingTouchArea
private
runnerMap
:
any
=
{}
private
runnerMap
:
any
=
{}
private
runnerList
:
any
=
[]
public
constructor
()
{
public
constructor
()
{
super
();
super
();
this
.
init
()
this
.
init
()
...
@@ -28,10 +29,14 @@ class Map extends egret.Sprite {
...
@@ -28,10 +29,14 @@ class Map extends egret.Sprite {
this
.
touchArea
=
new
egret
.
Bitmap
()
this
.
touchArea
=
new
egret
.
Bitmap
()
this
.
touchArea
.
texture
=
RES
.
getRes
(
'mask_jpg'
)
this
.
touchArea
.
texture
=
RES
.
getRes
(
'mask_jpg'
)
this
.
touchArea
.
alpha
=
0
this
.
touchArea
.
alpha
=
0
this
.
addChild
(
this
.
touchArea
)
this
.
addChild
(
this
.
touchArea
)
Store
.
getState
().
runners
.
forEach
(
runnerData
=>
{
Store
.
getState
().
runners
.
forEach
(
runnerData
=>
{
const
runner
=
new
Runner
(
runnerData
)
const
runner
=
new
Runner
(
runnerData
)
this
.
addChild
(
runner
)
this
.
addChild
(
runner
)
if
(
Store
.
isCatcher
())
{
runner
.
alpha
===
0
}
this
.
runnerMap
[
runnerData
.
t_cid
]
=
runner
this
.
runnerMap
[
runnerData
.
t_cid
]
=
runner
})
})
EventBus
.
addEventListener
(
'moving'
,
(
payload
)
=>
{
EventBus
.
addEventListener
(
'moving'
,
(
payload
)
=>
{
...
@@ -73,23 +78,60 @@ class Map extends egret.Sprite {
...
@@ -73,23 +78,60 @@ class Map extends egret.Sprite {
},
1000
);
},
1000
);
}
}
public
getCatchedRunners
(
x
,
y
)
{
const
catchedRunners
=
[]
Store
.
getState
().
runners
.
forEach
(
runner
=>
{
if
(
runner
.
x
===
x
&&
runner
.
y
===
y
)
{
catchedRunners
.
push
(
runner
)
}
})
return
catchedRunners
}
public
showSurroundedGrids
(
x
,
y
)
{
public
showSurroundedGrids
(
x
,
y
)
{
this
.
isShowingTouchArea
=
true
this
.
isShowingTouchArea
=
true
const
surroundedGrids
=
this
.
getSurroundedGrids
(
x
,
y
)
const
surroundedGrids
=
this
.
getSurroundedGrids
(
x
,
y
)
const
centerGrid
=
surroundedGrids
.
find
(
grid
=>
grid
.
x
===
x
&&
grid
.
y
===
y
)
const
centerGrid
=
surroundedGrids
.
find
(
grid
=>
grid
.
x
===
x
&&
grid
.
y
===
y
)
centerGrid
.
bg
.
texture
=
RES
.
getRes
(
'grid_select_jpg'
)
centerGrid
.
bg
.
texture
=
RES
.
getRes
(
'grid_select_jpg'
)
surroundedGrids
.
forEach
(
grid
=>
{
const
runners
=
Store
.
getState
().
runners
grid
.
alpha
=
1
})
this
.
touchArea
.
alpha
=
1
this
.
touchArea
.
alpha
=
1
this
.
touchArea
.
x
=
x
-
2
*
gridWidth
this
.
touchArea
.
x
=
x
-
2
*
gridWidth
this
.
touchArea
.
y
=
y
-
2
*
gridHeight
this
.
touchArea
.
y
=
y
-
2
*
gridHeight
surroundedGrids
.
forEach
(
grid
=>
{
grid
.
alpha
=
1
})
runners
.
forEach
(
runner
=>
{
if
(
this
.
touchArea
.
hitTestPoint
(
runner
.
x
,
runner
.
y
))
{
runner
.
alpha
=
1
}
})
this
.
getCatchedRunners
().
forEach
(
runner
=>
{
platform
.
sendSocketMessage
({
data
:
JSON
.
stringify
({
type
:
'catch'
,
room_id
:
'default_room'
,
cid
:
Store
.
getState
().
cid
,
payload
:
{
mark
:
runner
.
mark
,
x
,
y
,
t_cid
:
runner
.
t_cid
}
}),
})
if
(
Store
.
isMe
(
runner
.
t_cid
))
{
SoundManager
.
getInstance
().
playCatched
()
}
})
setTimeout
(()
=>
{
setTimeout
(()
=>
{
centerGrid
.
bg
.
texture
=
RES
.
getRes
(
'grid_jpg'
)
centerGrid
.
bg
.
texture
=
RES
.
getRes
(
'grid_jpg'
)
surroundedGrids
.
forEach
(
grid
=>
{
surroundedGrids
.
forEach
(
grid
=>
{
grid
.
alpha
=
0
grid
.
alpha
=
0
})
})
runners
.
forEach
(
runner
=>
{
alpha
=
0
})
this
.
touchArea
.
alpha
=
0
this
.
touchArea
.
alpha
=
0
this
.
isShowingTouchArea
=
false
this
.
isShowingTouchArea
=
false
},
1000
);
},
1000
);
...
...
fe/src/Store.ts
View file @
65c2ac66
...
@@ -51,11 +51,13 @@ class Store {
...
@@ -51,11 +51,13 @@ class Store {
static
getMyInfo
()
{
static
getMyInfo
()
{
return
_state
.
userInfo
return
_state
.
userInfo
}
}
static
isMe
(
cid
)
{
return
cid
===
_state
.
cid
}
static
getMyPosition
static
getMyPosition
static
isCatcher
()
{
static
isCatcher
()
{
console
.
log
(
'isCatcher_____'
,
_state
.
runners
,
_state
.
cid
)
return
!
_state
.
runners
.
some
(
runner
=>
runner
.
t_cid
===
_state
.
cid
)
return
!
_state
.
runners
.
some
(
runner
=>
runner
.
t_cid
===
_state
.
cid
)
}
}
}
}
...
...
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