|
@@ -1,4 +1,6 @@
|
|
|
import { Scene } from 'phaser'
|
|
import { Scene } from 'phaser'
|
|
|
|
|
+import { fetchChatRoles } from '@/api'
|
|
|
|
|
+import { emitter } from '@/plugins'
|
|
|
|
|
|
|
|
enum Direction {
|
|
enum Direction {
|
|
|
LEFT = 'l',
|
|
LEFT = 'l',
|
|
@@ -17,6 +19,7 @@ interface Person {
|
|
|
wait: boolean
|
|
wait: boolean
|
|
|
sprite: null | any
|
|
sprite: null | any
|
|
|
paths: Array<Path>
|
|
paths: Array<Path>
|
|
|
|
|
+ chatRole?: null | any
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getRandom(num = 1) {
|
|
function getRandom(num = 1) {
|
|
@@ -148,6 +151,90 @@ export default class PlayScene2 extends Scene {
|
|
|
this.map.createLayer('dress', [Atlas], 0, 0)
|
|
this.map.createLayer('dress', [Atlas], 0, 0)
|
|
|
this.map.createLayer('sign', [Atlas], 0, 0)
|
|
this.map.createLayer('sign', [Atlas], 0, 0)
|
|
|
|
|
|
|
|
|
|
+ // console.log(this.personInfo)
|
|
|
|
|
+
|
|
|
|
|
+ const width = (Math.floor(window.innerHeight / 100) - 6) * 50 + 2270
|
|
|
|
|
+ this.cameras.main.setBounds(0, 0, width, 1024)
|
|
|
|
|
+ this.cameras.main.fadeIn(1000)
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ this.cameras.main.pan(650, 512, 300)
|
|
|
|
|
+ this.personInfo = {}
|
|
|
|
|
+
|
|
|
|
|
+ fetchChatRoles(20).then((res: any) => {
|
|
|
|
|
+ console.log(res)
|
|
|
|
|
+ res.forEach((item: any) => {
|
|
|
|
|
+ this.personInfo[item.playerName] = <Person>{
|
|
|
|
|
+ wait: false,
|
|
|
|
|
+ sprite: null,
|
|
|
|
|
+ paths: [],
|
|
|
|
|
+ chatRole: item
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ this.setPerson()
|
|
|
|
|
+ })
|
|
|
|
|
+ }, 1000)
|
|
|
|
|
+
|
|
|
|
|
+ // this.cameras.main.fadeIn(1000)
|
|
|
|
|
+
|
|
|
|
|
+ // this.cameras.main.once('camerapancomplete', (camera: any) => {
|
|
|
|
|
+ // camera.pan(620, 512)
|
|
|
|
|
+ // })
|
|
|
|
|
+
|
|
|
|
|
+ const cam = this.cameras.main
|
|
|
|
|
+ this.input.on('pointermove', (p: any) => {
|
|
|
|
|
+ if (!p.isDown) return
|
|
|
|
|
+
|
|
|
|
|
+ cam.scrollX -= (p.x - p.prevPosition.x) / cam.zoom
|
|
|
|
|
+ // if (cam.scrollX < -220) {
|
|
|
|
|
+ // cam.scrollX = -220
|
|
|
|
|
+ // }
|
|
|
|
|
+ // if (cam.scrollX > 1290) {
|
|
|
|
|
+ // cam.scrollX = 1290
|
|
|
|
|
+ // }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ update() {
|
|
|
|
|
+ Object.keys(this.personInfo).forEach((key: string) => {
|
|
|
|
|
+ const info = this.personInfo[key]
|
|
|
|
|
+ if (info.sprite) {
|
|
|
|
|
+ if (!info.wait) {
|
|
|
|
|
+ switch (info.direction) {
|
|
|
|
|
+ case 'l':
|
|
|
|
|
+ info.sprite.x -= 1
|
|
|
|
|
+ break
|
|
|
|
|
+ case 'r':
|
|
|
|
|
+ info.sprite.x += 1
|
|
|
|
|
+ break
|
|
|
|
|
+ case 'u':
|
|
|
|
|
+ info.sprite.y -= 1
|
|
|
|
|
+ break
|
|
|
|
|
+ case 'd':
|
|
|
|
|
+ info.sprite.y += 1
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ const walkName = {
|
|
|
|
|
+ [Direction.LEFT]: key + '-left-walk',
|
|
|
|
|
+ [Direction.RIGHT]: key + '-right-walk',
|
|
|
|
|
+ [Direction.UP]: key + '-up-walk',
|
|
|
|
|
+ [Direction.DOWN]: key + '-down-walk'
|
|
|
|
|
+ }
|
|
|
|
|
+ const x = info.sprite.x
|
|
|
|
|
+ const y = info.sprite.y
|
|
|
|
|
+ info.paths.forEach((path: Path) => {
|
|
|
|
|
+ if (x === path.postion.x && y === path.postion.y) {
|
|
|
|
|
+ const direction = path.directions[getRandom(path.directions.length)]
|
|
|
|
|
+ info.sprite.play(walkName[direction], true)
|
|
|
|
|
+ info.direction = direction
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ setPerson() {
|
|
|
Object.keys(this.personInfo).forEach((key: string, index: number) => {
|
|
Object.keys(this.personInfo).forEach((key: string, index: number) => {
|
|
|
this.personInfo[key].paths = [...this.map.objects][index].objects.map((obj: any) => {
|
|
this.personInfo[key].paths = [...this.map.objects][index].objects.map((obj: any) => {
|
|
|
return {
|
|
return {
|
|
@@ -159,9 +246,6 @@ export default class PlayScene2 extends Scene {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
- console.log(this.personInfo)
|
|
|
|
|
-
|
|
|
|
|
const anims = this.anims
|
|
const anims = this.anims
|
|
|
Object.keys(this.personInfo).forEach((key: string) => {
|
|
Object.keys(this.personInfo).forEach((key: string) => {
|
|
|
const left_walk_name = key + '-left-walk'
|
|
const left_walk_name = key + '-left-walk'
|
|
@@ -247,59 +331,9 @@ export default class PlayScene2 extends Scene {
|
|
|
info.wait = false
|
|
info.wait = false
|
|
|
info.sprite.play(info.sprite.anims.currentAnim.key)
|
|
info.sprite.play(info.sprite.anims.currentAnim.key)
|
|
|
}, 1000)
|
|
}, 1000)
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- this.cameras.main.setBounds(0, 0, 512 * 5, 1024)
|
|
|
|
|
-
|
|
|
|
|
- const cam = this.cameras.main
|
|
|
|
|
- this.input.on('pointermove', (p: any) => {
|
|
|
|
|
- if (!p.isDown) return
|
|
|
|
|
-
|
|
|
|
|
- cam.scrollX -= (p.x - p.prevPosition.x) / cam.zoom
|
|
|
|
|
- // if (cam.scrollX < -220) {
|
|
|
|
|
- // cam.scrollX = -220
|
|
|
|
|
- // }
|
|
|
|
|
- // if (cam.scrollX > 1290) {
|
|
|
|
|
- // cam.scrollX = 1290
|
|
|
|
|
- // }
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- update() {
|
|
|
|
|
- Object.keys(this.personInfo).forEach((key: string) => {
|
|
|
|
|
- const info = this.personInfo[key]
|
|
|
|
|
- if (!info.wait) {
|
|
|
|
|
- switch (info.direction) {
|
|
|
|
|
- case 'l':
|
|
|
|
|
- info.sprite.x -= 1
|
|
|
|
|
- break
|
|
|
|
|
- case 'r':
|
|
|
|
|
- info.sprite.x += 1
|
|
|
|
|
- break
|
|
|
|
|
- case 'u':
|
|
|
|
|
- info.sprite.y -= 1
|
|
|
|
|
- break
|
|
|
|
|
- case 'd':
|
|
|
|
|
- info.sprite.y += 1
|
|
|
|
|
- break
|
|
|
|
|
- }
|
|
|
|
|
- const walkName = {
|
|
|
|
|
- [Direction.LEFT]: key + '-left-walk',
|
|
|
|
|
- [Direction.RIGHT]: key + '-right-walk',
|
|
|
|
|
- [Direction.UP]: key + '-up-walk',
|
|
|
|
|
- [Direction.DOWN]: key + '-down-walk'
|
|
|
|
|
- }
|
|
|
|
|
- const x = info.sprite.x
|
|
|
|
|
- const y = info.sprite.y
|
|
|
|
|
- info.paths.forEach((path: Path) => {
|
|
|
|
|
- if (x === path.postion.x && y === path.postion.y) {
|
|
|
|
|
- const direction = path.directions[getRandom(path.directions.length)]
|
|
|
|
|
- info.sprite.play(walkName[direction], true)
|
|
|
|
|
- info.direction = direction
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ emitter.emit('chooseRole', info.chatRole)
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|