Commit 4af542f5 by Mike Zhu

fix conflict in Stores

parents 81da815d ee5f3c96
class Guy extends egret.Sprite {
public constructor() {
super()
this.init()
}
private avatar = new egret.Bitmap()
private imageLoader = new egret.ImageLoader()
private init() {
this.avatar.width = 72
this.avatar.height = 72
this.imageLoader.addEventListener(egret.Event.COMPLETE,this.loadCompleteHandler,this)
this.imageLoader.load("http://www.insajderi.com/wp-content/uploads/2018/01/asdja.jpg")
this.addChild(this.avatar)
}
private loadCompleteHandler() {
let texture = new egret.Texture()
texture._setBitmapData(this.imageLoader.data)
this.avatar.texture = texture
}
private step = 72
public applyDelta(delta){
this.x += this.step * delta.x
this.y += this.step * delta.y
if(this.x <= 0){
this.x = 0
}
if(this.y <= 0){
this.y = 0
}
if(this.y >= 72*9){
this.y = 72*9
}
if(this.x >= 72*13){
this.x = 72*13
}
}
}
\ No newline at end of file
const gridWidth = 72
const gridHeight = 72
const gridsInX = 14
const gridsInY = 10
class Map extends egret.Sprite {
private grids:any = []
public constructor() {
super();
this.init()
}
// 初始化(给开始按钮绑定点击事件)
private init() {
console.log('Map.init')
for (let i = 0; i < gridsInY; i++) {
this.grids.push([])
for (let j = 0; j < gridsInX; j++) {
const grid = new MapGrid()
grid.x = j * gridWidth
grid.y = i * gridHeight
this.grids[i].push(grid)
this.addChild(grid)
}
}
if (Store.isCatcher()) {
const mask = new egret.Shape()
mask.x = 100
mask.y = 100
mask.graphics.lineStyle( 10, 0x00ff00 );
mask.graphics.beginFill( 0xff0000, 1);
mask.graphics.drawCircle( 0, 0, 50 );
mask.graphics.endFill();
mask.touchEnabled = false
this.mask = mask
}
// put display object to this scene
}
public release() {
// 移除事件
}
}
\ No newline at end of file
class MapGrid extends egret.Sprite {
private bg:egret.Bitmap = new egret.Bitmap()
public constructor() {
super();
this.init()
}
// 初始化(给开始按钮绑定点击事件)
private init() {
console.log('Map.init')
this.bg.texture = RES.getRes('grid_jpg')
this.addChild(this.bg)
this.bg.touchEnabled = true
this.bg.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchTap, this)
}
private onTouchTap() {
console.log(this, this.parent)
if (Store.isCatcher()) {
console.log(this, this.parent)
// const map = SceneManager.getInstance().gameScene.map
}
}
public release() {
// 移除事件
}
}
\ No newline at end of file
let _state: any = {} let _state: any = {
role: null,
cid: null,
roomId: null,
}
class Store { class Store {
static getState() { static getState() {
return _state return _state
} }
static onMessage(message) { static onMessage(message) {
const { payload } = message
switch (message.type) { switch (message.type) {
case 'start': case 'game_ready':
const { cid, room_id, payload: { role } } = payload
_state = { _state = {
..._state,
cid,
role,
roomId: room_id,
} }
break; break;
case 'setUserInfo': case 'setUserInfo':
...@@ -18,4 +28,9 @@ class Store { ...@@ -18,4 +28,9 @@ class Store {
} }
return _state return _state
} }
static isCatcher() {
return true
return _state.role === 'ghost'
}
} }
\ No newline at end of file
class GameScene extends egret.Sprite { class GameScene extends egret.Sprite {
private controller: egret.Sprite private controller: egret.Sprite
public map
public constructor() { public constructor() {
super(); super();
this.init() this.init()
} }
private pointtt = new egret.Shape() private me = new Guy()
// 初始化(给开始按钮绑定点击事件) // 初始化(给开始按钮绑定点击事件)
private init() { private init() {
...@@ -15,17 +15,14 @@ class GameScene extends egret.Sprite { ...@@ -15,17 +15,14 @@ class GameScene extends egret.Sprite {
this.controller = new Controller() this.controller = new Controller()
this.addChild(this.controller) this.addChild(this.controller)
this.controller.addEventListener("position_change", this.onPositionChange, this) this.controller.addEventListener("position_change", this.onPositionChange, this)
this.map = new Map()
this.pointtt.graphics.beginFill(0xFF0000, 1) this.addChild(this.map)
this.pointtt.graphics.drawCircle(667, 375, 15) this.addChild(this.me)
this.pointtt.graphics.endFill()
this.addChild(this.pointtt)
} }
private step = 72
private onPositionChange(delta){ private onPositionChange(delta){
this.pointtt.x += this.step * delta.data.x this.me.applyDelta(delta.data)
this.pointtt.y += this.step * delta.data.y
} }
public release() { public release() {
......
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