Commit 65c2ac66 by Matt

add hit test

parent 4a2c995a
......@@ -7,6 +7,7 @@ class Map extends egret.Sprite {
private touchArea: egret.Bitmap
public isShowingTouchArea
private runnerMap:any = {}
private runnerList:any = []
public constructor() {
super();
this.init()
......@@ -28,10 +29,14 @@ class Map extends egret.Sprite {
this.touchArea = new egret.Bitmap()
this.touchArea.texture = RES.getRes('mask_jpg')
this.touchArea.alpha = 0
this.addChild(this.touchArea)
Store.getState().runners.forEach(runnerData => {
const runner = new Runner(runnerData)
this.addChild(runner)
if (Store.isCatcher()) {
runner.alpha === 0
}
this.runnerMap[runnerData.t_cid] = runner
})
EventBus.addEventListener('moving', (payload) => {
......@@ -73,23 +78,60 @@ class Map extends egret.Sprite {
}, 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) {
this.isShowingTouchArea = true
const surroundedGrids = this.getSurroundedGrids(x, y)
const centerGrid = surroundedGrids.find(grid => grid.x === x && grid.y === y)
centerGrid.bg.texture = RES.getRes('grid_select_jpg')
surroundedGrids.forEach(grid => {
grid.alpha = 1
})
const runners = Store.getState().runners
this.touchArea.alpha = 1
this.touchArea.x = x - 2 * gridWidth
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(() => {
centerGrid.bg.texture = RES.getRes('grid_jpg')
surroundedGrids.forEach(grid => {
grid.alpha = 0
})
runners.forEach(runner => {
alpha = 0
})
this.touchArea.alpha = 0
this.isShowingTouchArea = false
}, 1000);
......
......@@ -51,11 +51,13 @@ class Store {
static getMyInfo() {
return _state.userInfo
}
static isMe(cid) {
return cid === _state.cid
}
static getMyPosition
static isCatcher() {
console.log('isCatcher_____', _state.runners, _state.cid)
return !_state.runners.some(runner => runner.t_cid === _state.cid)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment