Commit 65c2ac66 by Matt

add hit test

parent 4a2c995a
...@@ -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);
......
...@@ -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)
} }
} }
......
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