update
This commit is contained in:
6
assets/FishSingle/script/game/config/Config.ts
Normal file
6
assets/FishSingle/script/game/config/Config.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { DEV } from 'cc/env'
|
||||
|
||||
export default {
|
||||
url: () => (DEV ? 'https://fish.wanzhuanyongcheng.cn' : 'https://fish.jdt168.com'),
|
||||
wsUrl: () => (DEV ? 'fish.wanzhuanyongcheng.cn' : 'fish.jdt168.com'),
|
||||
}
|
||||
@@ -2,10 +2,8 @@
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "71a46444-1a80-435f-b02e-0fe6acf71155",
|
||||
"uuid": "f01978bd-5d14-49a6-bea7-4b7ad0c82b7b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,44 +1,86 @@
|
||||
import { FishInfo } from './FishInfo'
|
||||
|
||||
import config from './Config'
|
||||
export class FishConfig {
|
||||
public static readonly config: ReadonlyArray<FishInfo> = [
|
||||
new FishInfo(1, '蝴蝶鱼', 2, 2),
|
||||
new FishInfo(2, '鲶鱼', 2, 1),
|
||||
new FishInfo(3, '狮子鱼', 2, 2),
|
||||
new FishInfo(4, '条纹鱼', 2, 2),
|
||||
new FishInfo(5, '沙丁鱼', 2, 2),
|
||||
new FishInfo(6, '石斑鱼', 2, 2),
|
||||
new FishInfo(7, '河豚', 3, 1.2),
|
||||
new FishInfo(8, '海螺', 3, 2),
|
||||
new FishInfo(9, '接吻鱼', 3, 1.2),
|
||||
new FishInfo(10, '海姆', 4, 1),
|
||||
new FishInfo(11, '绿鳍鱼', 4, 1.2),
|
||||
new FishInfo(12, '鲎', 4, 1.2),
|
||||
new FishInfo(13, '魔鬼鱼', 5, 0.6),
|
||||
new FishInfo(14, '小海龟', 5, 2),
|
||||
new FishInfo(15, '锤头鲨', 6, 0.5),
|
||||
new FishInfo(16, '金枪鱼', 6, 0.5),
|
||||
new FishInfo(17, '大三元', 6, 0.5),
|
||||
new FishInfo(18, '黄金鲎', 6, 1.2),
|
||||
new FishInfo(19, '大四喜', 7, 0.5),
|
||||
new FishInfo(20, '黄金锤头鲨', 7, 0.5),
|
||||
new FishInfo(21, '金海姆', 7, 0.6),
|
||||
new FishInfo(22, '五福临门', 8, 0.4),
|
||||
new FishInfo(23, '金海龟', 8, 0.7),
|
||||
new FishInfo(24, '金鲨', 8, 0.5),
|
||||
new FishInfo(25, '蓝鲨', 8, 0.5),
|
||||
new FishInfo(26, '美人鱼', 14, 0.4),
|
||||
new FishInfo(27, '金龙', 14, 0.3),
|
||||
new FishInfo(28, '章鱼', 10, 0.5),
|
||||
new FishInfo(29, '电鳗鱼', 3, 0.8)
|
||||
public static config: Array<FishInfo> = [
|
||||
// new FishInfo(1, '蝴蝶鱼', 2, 2),
|
||||
// new FishInfo(2, '鲶鱼', 2, 1),
|
||||
// new FishInfo(3, '狮子鱼', 2, 2),
|
||||
// new FishInfo(4, '条纹鱼', 2, 2),
|
||||
// new FishInfo(5, '沙丁鱼', 2, 2),
|
||||
// new FishInfo(6, '石斑鱼', 2, 2),
|
||||
// new FishInfo(7, '河豚', 3, 1.2),
|
||||
// new FishInfo(8, '海螺', 3, 2),
|
||||
// new FishInfo(9, '接吻鱼', 3, 1.2),
|
||||
// new FishInfo(10, '海姆', 4, 1),
|
||||
// new FishInfo(11, '绿鳍鱼', 4, 1.2),
|
||||
// new FishInfo(12, '鲎', 4, 1.2),
|
||||
// new FishInfo(13, '魔鬼鱼', 5, 0.6),
|
||||
// new FishInfo(14, '小海龟', 5, 2),
|
||||
// new FishInfo(15, '锤头鲨', 6, 0.5),
|
||||
// new FishInfo(16, '金枪鱼', 6, 0.5),
|
||||
// new FishInfo(17, '大三元', 6, 0.5),
|
||||
// new FishInfo(18, '黄金鲎', 6, 1.2),
|
||||
// new FishInfo(19, '大四喜', 7, 0.5),
|
||||
// new FishInfo(20, '黄金锤头鲨', 7, 0.5),
|
||||
// new FishInfo(21, '金海姆', 7, 0.6),
|
||||
// new FishInfo(22, '五福临门', 8, 0.4),
|
||||
// new FishInfo(23, '金海龟', 8, 0.7),
|
||||
// new FishInfo(24, '金鲨', 8, 0.5),
|
||||
// new FishInfo(25, '蓝鲨', 8, 0.5),
|
||||
// new FishInfo(26, '美人鱼', 14, 0.4),
|
||||
// new FishInfo(27, '金龙', 14, 0.3),
|
||||
// new FishInfo(28, '章鱼', 10, 0.5),
|
||||
// new FishInfo(29, '电鳗鱼', 3, 0.8),
|
||||
// new FishInfo(1, '蝴蝶鱼'),
|
||||
// new FishInfo(2, '鲶鱼'),
|
||||
// new FishInfo(3, '狮子鱼'),
|
||||
// new FishInfo(4, '条纹鱼'),
|
||||
// new FishInfo(5, '沙丁鱼'),
|
||||
// new FishInfo(6, '石斑鱼'),
|
||||
// new FishInfo(7, '河豚'),
|
||||
// new FishInfo(8, '海螺'),
|
||||
// new FishInfo(9, '接吻鱼'),
|
||||
// new FishInfo(10, '海姆'),
|
||||
// new FishInfo(11, '绿鳍鱼'),
|
||||
// new FishInfo(12, '鲎'),
|
||||
// new FishInfo(13, '魔鬼鱼'),
|
||||
// new FishInfo(14, '小海龟'),
|
||||
// new FishInfo(15, '锤头鲨'),
|
||||
// new FishInfo(16, '金枪鱼'),
|
||||
// new FishInfo(17, '大三元'),
|
||||
// new FishInfo(18, '黄金鲎'),
|
||||
// new FishInfo(19, '大四喜'),
|
||||
// new FishInfo(20, '黄金锤头鲨'),
|
||||
// new FishInfo(21, '金海姆'),
|
||||
// new FishInfo(22, '五福临门'),
|
||||
// new FishInfo(23, '金海龟'),
|
||||
// new FishInfo(24, '金鲨'),
|
||||
// new FishInfo(25, '蓝鲨'),
|
||||
// new FishInfo(26, '美人鱼'),
|
||||
// new FishInfo(27, '金龙'),
|
||||
// new FishInfo(28, '章鱼'),
|
||||
// new FishInfo(29, '电鳗鱼'),
|
||||
]
|
||||
|
||||
public static async init() {
|
||||
this.config = []
|
||||
return new Promise<boolean>((resolve) => {
|
||||
fetch(`${config.url()}/fish/list`)
|
||||
.then((response) => response.text())
|
||||
.then((response) => {
|
||||
const { data: res } = JSON.parse(response)
|
||||
res.data.forEach((item) => {
|
||||
this.config.push(new FishInfo(item.ID, item.name, item.health))
|
||||
})
|
||||
resolve(true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public static getFishInfoByType(fishType: number) {
|
||||
for (let i = 0; i < this.config.length; i++) {
|
||||
let fishInfo: FishInfo = this.config[i]
|
||||
if (fishInfo.fishType == fishType) {
|
||||
return fishInfo
|
||||
}
|
||||
const fishInfo: FishInfo = this.config[i]
|
||||
if (fishInfo.fishType === fishType) return fishInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,17 @@ export class FishInfo {
|
||||
public fishType: number
|
||||
public name: string
|
||||
public blood: number
|
||||
public wikiScale: number
|
||||
// public wikiScale: number
|
||||
|
||||
constructor(
|
||||
fishType: number,
|
||||
name: string,
|
||||
blood: number,
|
||||
wikiScale: number
|
||||
// wikiScale: number,
|
||||
) {
|
||||
this.fishType = fishType
|
||||
this.name = name
|
||||
this.blood = blood
|
||||
this.wikiScale = wikiScale
|
||||
// this.wikiScale = wikiScale
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
export class FishMapInfo {
|
||||
public fishType: number
|
||||
public scale: number
|
||||
public side: number //1: -1:
|
||||
public side: number // 1: -1:
|
||||
public x: number
|
||||
public y: number
|
||||
|
||||
constructor(
|
||||
fishType: number,
|
||||
scale: number,
|
||||
side: number,
|
||||
x: number,
|
||||
y: number
|
||||
) {
|
||||
constructor(fishType: number, scale: number, side: number, x: number, y: number) {
|
||||
this.fishType = fishType
|
||||
this.scale = scale
|
||||
this.side = side
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Vec2 } from 'cc'
|
||||
import { FishPathInfo } from './FishPathInfo'
|
||||
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
import { FishMapInfo } from './FishMapInfo'
|
||||
|
||||
import { FishMap } from './FishMap'
|
||||
import { FishMapInfo } from './FishMapInfo'
|
||||
import { FishPathInfo } from './FishPathInfo'
|
||||
|
||||
export class FishPathConfig {
|
||||
private static mapConfig: Array<Array<Array<number>>> = [
|
||||
@@ -90,7 +92,7 @@ export class FishPathConfig {
|
||||
[1, 1, 1, 754, -7],
|
||||
[1, 1, 1, 671, 26],
|
||||
[1, 1, 1, 630, 59],
|
||||
[1, 1, 1, 584, 80]
|
||||
[1, 1, 1, 584, 80],
|
||||
],
|
||||
[
|
||||
[2, 1, 1, -784, 353],
|
||||
@@ -135,7 +137,7 @@ export class FishPathConfig {
|
||||
[3, 1, 1, 523, -253],
|
||||
[3, 1, 1, 172, 128],
|
||||
[3, 1, 1, -357, 30],
|
||||
[3, 1, 1, 582, 23]
|
||||
[3, 1, 1, 582, 23],
|
||||
],
|
||||
[
|
||||
[5, 1, 1, -888, 405],
|
||||
@@ -191,7 +193,7 @@ export class FishPathConfig {
|
||||
[7, 1, 1, 340, -259],
|
||||
[7, 1, 1, 485, -254],
|
||||
[7, 1, 1, 622, -254],
|
||||
[7, 1, 1, 816, -251]
|
||||
[7, 1, 1, 816, -251],
|
||||
],
|
||||
[
|
||||
[9, 1, 1, -513, 150],
|
||||
@@ -222,7 +224,7 @@ export class FishPathConfig {
|
||||
[9, 1, 1, 865, 195],
|
||||
[9, 1, 1, 665, 207],
|
||||
[17, 1, 1, -461, 2],
|
||||
[17, 1, 1, 515, -49]
|
||||
[17, 1, 1, 515, -49],
|
||||
],
|
||||
[
|
||||
[19, 1, 1, -785, 31],
|
||||
@@ -234,7 +236,7 @@ export class FishPathConfig {
|
||||
[20, 1, 1, 425, -301],
|
||||
[20, 1, 1, 537, 265],
|
||||
[20, 1, 1, -604, 317],
|
||||
[20, 1, 1, -634, -285]
|
||||
[20, 1, 1, -634, -285],
|
||||
],
|
||||
[
|
||||
[21, 1, 1, -757, 94],
|
||||
@@ -245,12 +247,12 @@ export class FishPathConfig {
|
||||
[21, 1, 1, -437, 300],
|
||||
[21, 1, 1, -434, -155],
|
||||
[21, 1, 1, 314, -154],
|
||||
[21, 1, 1, 435, 249]
|
||||
[21, 1, 1, 435, 249],
|
||||
],
|
||||
[
|
||||
[22, 1, 1, -548, 65],
|
||||
[22, 1, 1, 747, 61],
|
||||
[22, 1, 1, 95, 63]
|
||||
[22, 1, 1, 95, 63],
|
||||
],
|
||||
[
|
||||
[23, 1, 1, -431, 384],
|
||||
@@ -262,7 +264,7 @@ export class FishPathConfig {
|
||||
[23, 1, 1, 1025, 60],
|
||||
[23, 1, 1, 677, -247],
|
||||
[23, 1, 1, 104, 390],
|
||||
[23, 1, 1, 84, -265]
|
||||
[23, 1, 1, 84, -265],
|
||||
],
|
||||
[
|
||||
[24, 1, 1, -429, 353],
|
||||
@@ -271,7 +273,7 @@ export class FishPathConfig {
|
||||
[24, 1, 1, -27, 35],
|
||||
[24, 1, 1, 563, 39],
|
||||
[24, 1, 1, -268, -245],
|
||||
[24, 1, 1, 172, -260]
|
||||
[24, 1, 1, 172, -260],
|
||||
],
|
||||
[
|
||||
[25, 1, 1, -595, 276],
|
||||
@@ -279,27 +281,27 @@ export class FishPathConfig {
|
||||
[25, 1, 1, -192, -64],
|
||||
[25, 1, 1, 464, -46],
|
||||
[25, 1, 1, 191, -280],
|
||||
[25, 1, 1, 884, -319]
|
||||
[25, 1, 1, 884, -319],
|
||||
],
|
||||
[
|
||||
[26, 1, 1, -681, 441],
|
||||
[26, 1, 1, 685, 426],
|
||||
[26, 1, 1, -46, 140],
|
||||
[26, 1, 1, -494, -207],
|
||||
[26, 1, 1, 497, -238]
|
||||
[26, 1, 1, 497, -238],
|
||||
],
|
||||
[
|
||||
[27, 1, 1, -431, 345],
|
||||
[27, 1, 1, 569, 311],
|
||||
[27, 1, 1, 112, -12],
|
||||
[27, 1, 1, -298, -271],
|
||||
[27, 1, 1, 678, -244]
|
||||
[27, 1, 1, 678, -244],
|
||||
],
|
||||
[
|
||||
[28, 1, 1, -454, 8],
|
||||
[28, 1, 1, 597, 1],
|
||||
[28, 1, 1, 46, 431],
|
||||
[28, 1, 1, 44, -227]
|
||||
[28, 1, 1, 44, -227],
|
||||
],
|
||||
[
|
||||
[2, 1, 1, -557, 409],
|
||||
@@ -345,9 +347,10 @@ export class FishPathConfig {
|
||||
[5, 1, 1, 407, -178],
|
||||
[5, 1, 1, 297, 8],
|
||||
[5, 1, 1, 625, 48],
|
||||
[5, 1, 1, 379, 92]
|
||||
]
|
||||
[5, 1, 1, 379, 92],
|
||||
],
|
||||
]
|
||||
|
||||
private static formatMapConfig: Array<FishMap> = []
|
||||
private static config: Array<Array<Array<number>>> = [
|
||||
// 左边开始
|
||||
@@ -368,7 +371,7 @@ export class FishPathConfig {
|
||||
[627, -511],
|
||||
[762, -578],
|
||||
[885, -667],
|
||||
[1068, -773]
|
||||
[1068, -773],
|
||||
],
|
||||
[
|
||||
[-1295, 534],
|
||||
@@ -385,7 +388,7 @@ export class FishPathConfig {
|
||||
[753, 233],
|
||||
[936, 279],
|
||||
[1182, 350],
|
||||
[1314, 418]
|
||||
[1314, 418],
|
||||
],
|
||||
[
|
||||
[-1295, 534],
|
||||
@@ -402,7 +405,7 @@ export class FishPathConfig {
|
||||
[827, -42],
|
||||
[1020, -131],
|
||||
[1189, -170],
|
||||
[1309, -198]
|
||||
[1309, -198],
|
||||
],
|
||||
[
|
||||
[-1295, 534],
|
||||
@@ -419,7 +422,7 @@ export class FishPathConfig {
|
||||
[835, 88],
|
||||
[1013, -2],
|
||||
[1212, -99],
|
||||
[1309, -198]
|
||||
[1309, -198],
|
||||
],
|
||||
[
|
||||
[-1275, -118],
|
||||
@@ -436,7 +439,7 @@ export class FishPathConfig {
|
||||
[772, 391],
|
||||
[887, 426],
|
||||
[1066, 513],
|
||||
[1164, 710]
|
||||
[1164, 710],
|
||||
],
|
||||
[
|
||||
[-1299, -618],
|
||||
@@ -453,7 +456,7 @@ export class FishPathConfig {
|
||||
[904, 176],
|
||||
[1090, 273],
|
||||
[1208, 355],
|
||||
[1308, 435]
|
||||
[1308, 435],
|
||||
],
|
||||
[
|
||||
[-1275, -118],
|
||||
@@ -470,7 +473,7 @@ export class FishPathConfig {
|
||||
[784, 266],
|
||||
[935, 228],
|
||||
[1157, 174],
|
||||
[1329, 163]
|
||||
[1329, 163],
|
||||
],
|
||||
[
|
||||
[-1288, -220],
|
||||
@@ -487,7 +490,7 @@ export class FishPathConfig {
|
||||
[851, 203],
|
||||
[1050, 141],
|
||||
[1255, 58],
|
||||
[1326, 20]
|
||||
[1326, 20],
|
||||
],
|
||||
[
|
||||
[-1288, -220],
|
||||
@@ -504,7 +507,7 @@ export class FishPathConfig {
|
||||
[993, -283],
|
||||
[1090, -319],
|
||||
[1242, -341],
|
||||
[1329, -396]
|
||||
[1329, -396],
|
||||
],
|
||||
[
|
||||
[-1288, -220],
|
||||
@@ -521,7 +524,7 @@ export class FishPathConfig {
|
||||
[1011, -407],
|
||||
[1095, -418],
|
||||
[1238, -539],
|
||||
[1317, -663]
|
||||
[1317, -663],
|
||||
],
|
||||
[
|
||||
[-1314, -508],
|
||||
@@ -540,7 +543,7 @@ export class FishPathConfig {
|
||||
[1093, 280],
|
||||
[1026, 371],
|
||||
[868, 631],
|
||||
[648, 787]
|
||||
[648, 787],
|
||||
],
|
||||
[
|
||||
[-1314, -508],
|
||||
@@ -559,7 +562,7 @@ export class FishPathConfig {
|
||||
[1093, 280],
|
||||
[1026, 371],
|
||||
[868, 631],
|
||||
[648, 787]
|
||||
[648, 787],
|
||||
],
|
||||
[
|
||||
[-1314, -508],
|
||||
@@ -576,9 +579,9 @@ export class FishPathConfig {
|
||||
[872, -200],
|
||||
[1060, -391],
|
||||
[1150, -492],
|
||||
[1301, -461]
|
||||
[1301, -461],
|
||||
],
|
||||
//右边开始
|
||||
// 右边开始
|
||||
[
|
||||
[1286, -293],
|
||||
[1149, -184],
|
||||
@@ -588,7 +591,7 @@ export class FishPathConfig {
|
||||
[476, 57],
|
||||
[467, 300],
|
||||
[408, 500],
|
||||
[405, 701]
|
||||
[405, 701],
|
||||
],
|
||||
[
|
||||
[1345, 34],
|
||||
@@ -599,7 +602,7 @@ export class FishPathConfig {
|
||||
[267, -29],
|
||||
[66, -79],
|
||||
[-219, -287],
|
||||
[-271, -693]
|
||||
[-271, -693],
|
||||
],
|
||||
[
|
||||
[1345, 34],
|
||||
@@ -614,7 +617,7 @@ export class FishPathConfig {
|
||||
[-725, -92],
|
||||
[-963, -68],
|
||||
[-1169, -46],
|
||||
[-1325, -40]
|
||||
[-1325, -40],
|
||||
],
|
||||
[
|
||||
[1345, 34],
|
||||
@@ -629,7 +632,7 @@ export class FishPathConfig {
|
||||
[-719, -199],
|
||||
[-981, -264],
|
||||
[-1180, -291],
|
||||
[-1320, -367]
|
||||
[-1320, -367],
|
||||
],
|
||||
[
|
||||
[1345, 34],
|
||||
@@ -644,7 +647,7 @@ export class FishPathConfig {
|
||||
[-707, -320],
|
||||
[-961, -408],
|
||||
[-1160, -449],
|
||||
[-1309, -524]
|
||||
[-1309, -524],
|
||||
],
|
||||
[
|
||||
[1345, 34],
|
||||
@@ -659,7 +662,7 @@ export class FishPathConfig {
|
||||
[-596, -448],
|
||||
[-847, -604],
|
||||
[-1019, -589],
|
||||
[-1241, -695]
|
||||
[-1241, -695],
|
||||
],
|
||||
[
|
||||
[1345, 34],
|
||||
@@ -674,7 +677,7 @@ export class FishPathConfig {
|
||||
[-898, 66],
|
||||
[-1070, 219],
|
||||
[-1181, 292],
|
||||
[-1289, 558]
|
||||
[-1289, 558],
|
||||
],
|
||||
[
|
||||
[1345, 34],
|
||||
@@ -689,7 +692,7 @@ export class FishPathConfig {
|
||||
[-806, 84],
|
||||
[-905, 246],
|
||||
[-1008, 375],
|
||||
[-1021, 750]
|
||||
[-1021, 750],
|
||||
],
|
||||
[
|
||||
[1297, 542],
|
||||
@@ -704,7 +707,7 @@ export class FishPathConfig {
|
||||
[-806, 84],
|
||||
[-905, 246],
|
||||
[-1008, 375],
|
||||
[-1021, 750]
|
||||
[-1021, 750],
|
||||
],
|
||||
[
|
||||
[1297, 542],
|
||||
@@ -719,7 +722,7 @@ export class FishPathConfig {
|
||||
[-806, 84],
|
||||
[-927, 189],
|
||||
[-1073, 291],
|
||||
[-1318, 474]
|
||||
[-1318, 474],
|
||||
],
|
||||
[
|
||||
[1297, 542],
|
||||
@@ -734,7 +737,7 @@ export class FishPathConfig {
|
||||
[-775, -77],
|
||||
[-923, -28],
|
||||
[-1133, -46],
|
||||
[-1294, -10]
|
||||
[-1294, -10],
|
||||
],
|
||||
[
|
||||
[1297, 542],
|
||||
@@ -749,7 +752,7 @@ export class FishPathConfig {
|
||||
[-616, -254],
|
||||
[-854, -240],
|
||||
[-1115, -272],
|
||||
[-1312, -336]
|
||||
[-1312, -336],
|
||||
],
|
||||
[
|
||||
[1297, 542],
|
||||
@@ -764,7 +767,7 @@ export class FishPathConfig {
|
||||
[-562, -321],
|
||||
[-647, -446],
|
||||
[-930, -540],
|
||||
[-1073, -726]
|
||||
[-1073, -726],
|
||||
],
|
||||
[
|
||||
[1293, -558],
|
||||
@@ -779,7 +782,7 @@ export class FishPathConfig {
|
||||
[-562, -321],
|
||||
[-647, -446],
|
||||
[-930, -540],
|
||||
[-1073, -726]
|
||||
[-1073, -726],
|
||||
],
|
||||
[
|
||||
[1293, -558],
|
||||
@@ -794,7 +797,7 @@ export class FishPathConfig {
|
||||
[-568, -262],
|
||||
[-857, -301],
|
||||
[-1055, -406],
|
||||
[-1353, -380]
|
||||
[-1353, -380],
|
||||
],
|
||||
[
|
||||
[1293, -558],
|
||||
@@ -809,7 +812,7 @@ export class FishPathConfig {
|
||||
[-590, -195],
|
||||
[-905, -120],
|
||||
[-1100, -72],
|
||||
[-1300, 225]
|
||||
[-1300, 225],
|
||||
],
|
||||
[
|
||||
[1293, -558],
|
||||
@@ -824,7 +827,7 @@ export class FishPathConfig {
|
||||
[-633, -130],
|
||||
[-917, 33],
|
||||
[-1079, 184],
|
||||
[-1220, 412]
|
||||
[-1220, 412],
|
||||
],
|
||||
[
|
||||
[1293, -558],
|
||||
@@ -839,9 +842,9 @@ export class FishPathConfig {
|
||||
[-602, -25],
|
||||
[-857, 181],
|
||||
[-921, 416],
|
||||
[-909, 805]
|
||||
[-909, 805],
|
||||
],
|
||||
//下往上
|
||||
// 下往上
|
||||
[
|
||||
[-279, -786],
|
||||
[-92, -667],
|
||||
@@ -855,7 +858,7 @@ export class FishPathConfig {
|
||||
[-602, -25],
|
||||
[-857, 181],
|
||||
[-921, 416],
|
||||
[-909, 805]
|
||||
[-909, 805],
|
||||
],
|
||||
[
|
||||
[-279, -786],
|
||||
@@ -870,7 +873,7 @@ export class FishPathConfig {
|
||||
[-362, 152],
|
||||
[-543, 358],
|
||||
[-721, 502],
|
||||
[-401, 770]
|
||||
[-401, 770],
|
||||
],
|
||||
[
|
||||
[-279, -786],
|
||||
@@ -885,7 +888,7 @@ export class FishPathConfig {
|
||||
[60, 214],
|
||||
[-85, 418],
|
||||
[-140, 630],
|
||||
[-401, 770]
|
||||
[-401, 770],
|
||||
],
|
||||
[
|
||||
[-279, -786],
|
||||
@@ -900,7 +903,7 @@ export class FishPathConfig {
|
||||
[253, 319],
|
||||
[330, 465],
|
||||
[544, 684],
|
||||
[858, 803]
|
||||
[858, 803],
|
||||
],
|
||||
[
|
||||
[841, -837],
|
||||
@@ -915,9 +918,10 @@ export class FishPathConfig {
|
||||
[253, 319],
|
||||
[330, 465],
|
||||
[544, 684],
|
||||
[858, 803]
|
||||
]
|
||||
[858, 803],
|
||||
],
|
||||
]
|
||||
|
||||
private static formatConfig: Array<FishPathInfo> = []
|
||||
|
||||
public static init() {
|
||||
@@ -928,70 +932,60 @@ export class FishPathConfig {
|
||||
private static initMapConfig() {
|
||||
this.formatMapConfig = []
|
||||
for (let i = 0; i < this.mapConfig.length; i++) {
|
||||
let arr: Array<Array<number>> = this.mapConfig[i]
|
||||
let fishMapInfoList: Array<FishMapInfo> = []
|
||||
const arr: Array<Array<number>> = this.mapConfig[i]
|
||||
const fishMapInfoList: Array<FishMapInfo> = []
|
||||
for (let j = 0; j < arr.length; j++) {
|
||||
let temp: Array<number> = arr[j]
|
||||
let fishMapInfo: FishMapInfo = new FishMapInfo(
|
||||
const temp: Array<number> = arr[j]
|
||||
const fishMapInfo: FishMapInfo = new FishMapInfo(
|
||||
temp[0],
|
||||
temp[1],
|
||||
temp[2],
|
||||
temp[3],
|
||||
temp[4]
|
||||
temp[4],
|
||||
)
|
||||
fishMapInfoList.push(fishMapInfo)
|
||||
}
|
||||
let fishMap: FishMap = new FishMap(i, fishMapInfoList)
|
||||
const fishMap: FishMap = new FishMap(i, fishMapInfoList)
|
||||
this.formatMapConfig.push(fishMap)
|
||||
// console.log('this.formatMapConfig ', this.formatMapConfig)
|
||||
}
|
||||
}
|
||||
|
||||
public static randomFishMap() {
|
||||
let randomIndex: number = RandomUtil.nextInt(
|
||||
0,
|
||||
this.formatMapConfig.length - 1
|
||||
)
|
||||
let map: FishMap = this.formatMapConfig[randomIndex]
|
||||
return map
|
||||
const randomIndex: number = RandomUtil.nextInt(0, this.formatMapConfig.length - 1)
|
||||
return this.formatMapConfig[randomIndex]
|
||||
}
|
||||
|
||||
private static initNormalConfig() {
|
||||
this.formatConfig = []
|
||||
let pathId: number = 1
|
||||
for (let i = 0; i < this.config.length; i++) {
|
||||
let path: Array<Vec2> = []
|
||||
let flipXPath: Array<Vec2> = []
|
||||
let flipYPath: Array<Vec2> = []
|
||||
const path: Array<Vec2> = []
|
||||
const flipXPath: Array<Vec2> = []
|
||||
const flipYPath: Array<Vec2> = []
|
||||
for (let j = 0; j < this.config[i].length; j++) {
|
||||
let p: Vec2 = new Vec2(this.config[i][j][0], this.config[i][j][1])
|
||||
const p: Vec2 = new Vec2(this.config[i][j][0], this.config[i][j][1])
|
||||
path.push(p)
|
||||
let flipXP: Vec2 = new Vec2(-p.x, p.y)
|
||||
let flipYP: Vec2 = new Vec2(p.x, -p.y)
|
||||
const flipXP: Vec2 = new Vec2(-p.x, p.y)
|
||||
const flipYP: Vec2 = new Vec2(p.x, -p.y)
|
||||
flipXPath.push(flipXP)
|
||||
flipYPath.push(flipYP)
|
||||
}
|
||||
this.formatConfig.push(new FishPathInfo(pathId++, path))
|
||||
this.formatConfig.push(new FishPathInfo(pathId++, flipXPath))
|
||||
this.formatConfig.push(new FishPathInfo(pathId++, flipYPath))
|
||||
this.formatConfig.push(new FishPathInfo(pathId, path))
|
||||
this.formatConfig.push(new FishPathInfo(pathId, flipXPath))
|
||||
this.formatConfig.push(new FishPathInfo(pathId, flipYPath))
|
||||
}
|
||||
}
|
||||
|
||||
public static getPathInfo(pathId: number) {
|
||||
for (let i = 0; i < this.formatConfig.length; i++) {
|
||||
let pathInfo: FishPathInfo = this.formatConfig[i]
|
||||
if (pathInfo.pathId == pathId) {
|
||||
return pathInfo
|
||||
}
|
||||
const pathInfo: FishPathInfo = this.formatConfig[i]
|
||||
if (pathInfo.pathId === pathId) return pathInfo
|
||||
}
|
||||
}
|
||||
|
||||
public static randomPathInfo() {
|
||||
let randomIndex: number = RandomUtil.nextInt(
|
||||
0,
|
||||
this.formatConfig.length - 1
|
||||
)
|
||||
// let randomIndex: number = 0
|
||||
let pathInfo: FishPathInfo = this.formatConfig[randomIndex]
|
||||
return pathInfo
|
||||
const randomIndex: number = RandomUtil.nextInt(0, this.formatConfig.length - 1)
|
||||
return this.formatConfig[randomIndex]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Vec2 } from 'cc'
|
||||
|
||||
export class FishPathInfo {
|
||||
public pathId: number
|
||||
public pathId: string
|
||||
public path: Array<Vec2> = []
|
||||
|
||||
constructor(pathId: number, path: Array<Vec2>) {
|
||||
constructor(pathId: string, path: Array<Vec2>) {
|
||||
this.pathId = pathId
|
||||
this.path = path
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export default class GameEvent {
|
||||
}
|
||||
@@ -1,32 +1,39 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
EventTouch,
|
||||
instantiate,
|
||||
Node,
|
||||
NodePool,
|
||||
Prefab,
|
||||
sys,
|
||||
UITransform,
|
||||
Vec2,
|
||||
Vec3
|
||||
Vec3,
|
||||
_decorator,
|
||||
instantiate,
|
||||
sys,
|
||||
} from 'cc'
|
||||
|
||||
import FishBulletBase from '../../../fish/script/FishBulletBase'
|
||||
import MathUtils from '../../engine/utils/MathUtils'
|
||||
import CannonManager from './CannonManager'
|
||||
import { MoveHelper } from '../../engine/utils/MoveHelper'
|
||||
import FishNetManager from './FishNetManager'
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import MathUtils from '../../engine/utils/MathUtils'
|
||||
|
||||
import { MoveHelper } from '../../engine/utils/MoveHelper'
|
||||
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
|
||||
import CannonManager from './CannonManager'
|
||||
import FishNetManager from './FishNetManager'
|
||||
import WsManager from './WsManager'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
// 子弹管理类
|
||||
@ccclass('BulletManager')
|
||||
export default class BulletManager extends Component {
|
||||
public static instance: BulletManager = null
|
||||
@property({ type: [Prefab] })
|
||||
private bulletPrefabList: Prefab[] | [] = []
|
||||
|
||||
private bulletPool: Array<NodePool> = []
|
||||
private bulletList: Array<FishBulletBase> = []
|
||||
private bulletMoveSpeed: number = 30
|
||||
@@ -40,24 +47,23 @@ export default class BulletManager extends Component {
|
||||
this._vec2Cache = new Vec2()
|
||||
BulletManager.instance = this
|
||||
this.node.on(Node.EventType.TOUCH_START, this.onShootBullet, this)
|
||||
// this.node.on(Node.EventType.TOUCH_MOVE, this.onShootBullet, this)
|
||||
}
|
||||
|
||||
start() {
|
||||
}
|
||||
start() {}
|
||||
|
||||
update() {
|
||||
this.checkMoveBullet()
|
||||
}
|
||||
|
||||
// 检测子弹是否移动完成
|
||||
private checkMoveBullet() {
|
||||
for (let i = this.bulletList.length - 1; i >= 0; i--) {
|
||||
let bullet: FishBulletBase = this.bulletList[i]
|
||||
let isMoving: boolean = MoveHelper.moveNode(
|
||||
const bullet: FishBulletBase = this.bulletList[i]
|
||||
const isMoving: boolean = MoveHelper.moveNode(
|
||||
bullet.node,
|
||||
this.bulletMoveSpeed,
|
||||
bullet.targetP.x,
|
||||
bullet.targetP.y
|
||||
bullet.targetP.y,
|
||||
)
|
||||
if (!isMoving) {
|
||||
bullet.node.getPosition(this._vec3Cache)
|
||||
@@ -70,38 +76,31 @@ export default class BulletManager extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
// 发射炮弹
|
||||
private onShootBullet(event: EventTouch) {
|
||||
//TOUCH_START 在Editor上,连续触发2次,导致发2次炮弹bug
|
||||
if (sys.platform == 'EDITOR_PAGE') {
|
||||
// TOUCH_START 在Editor上,连续触发2次,导致发2次炮弹bug
|
||||
if (sys.platform === 'EDITOR_PAGE') {
|
||||
this._fireTimeNew = new Date().getTime()
|
||||
if (this._fireTimeNew - this._fireTime < 100) {
|
||||
return
|
||||
}
|
||||
if (this._fireTimeNew - this._fireTime < 15000) return
|
||||
this._fireTime = this._fireTimeNew
|
||||
}
|
||||
|
||||
let tran = this.node.getComponent(UITransform)
|
||||
let location = event.getUILocation()
|
||||
const tran = this.node.getComponent(UITransform)
|
||||
const location = event.getUILocation()
|
||||
this._vec3Cache.x = location.x
|
||||
this._vec3Cache.y = location.y
|
||||
this._vec3Cache.z = 0
|
||||
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
|
||||
let localP: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
|
||||
const localP: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
|
||||
FishUI.instance.playClickEffect(localP)
|
||||
// 子弹发射
|
||||
if (FishUI.instance.dz_score >= CannonManager.instance.cannonType) {
|
||||
FishUI.instance.dz_score -= CannonManager.instance.cannonType
|
||||
FishUI.instance.refreshScore()
|
||||
// FishUI.instance.refreshScore()
|
||||
this._vec3Cache = CannonManager.instance.getCannonPosition()
|
||||
|
||||
let rad: number = MathUtils.p2pRad(
|
||||
new Vec2(this._vec3Cache.x, this._vec3Cache.y),
|
||||
localP
|
||||
)
|
||||
let rot: number = MathUtils.radiansToDegrees(rad)
|
||||
let bullet: FishBulletBase = this.createBullet(
|
||||
CannonManager.instance.cannonType - 1
|
||||
)
|
||||
const rad: number = MathUtils.p2pRad(new Vec2(this._vec3Cache.x, this._vec3Cache.y), localP)
|
||||
const rot: number = MathUtils.radiansToDegrees(rad)
|
||||
const bullet: FishBulletBase = this.createBullet(CannonManager.instance.cannonType - 1)
|
||||
bullet.targetP = localP
|
||||
this.node.addChild(bullet.node)
|
||||
bullet.node.setPosition(CannonManager.instance.getCannonPosition())
|
||||
@@ -113,14 +112,14 @@ export default class BulletManager extends Component {
|
||||
bullet.node.angle = rot
|
||||
this.bulletList.push(bullet)
|
||||
GameMusicHelper.playFire()
|
||||
|
||||
//旋转炮台
|
||||
// 旋转炮台
|
||||
CannonManager.instance.rotateCannon(location)
|
||||
} else {
|
||||
CommonTips.showMsg('豆子不足!')
|
||||
}
|
||||
}
|
||||
|
||||
// 创建子弹
|
||||
private createBullet(bulletType: number) {
|
||||
let bulletNode: Node
|
||||
if (this.bulletPool[bulletType] && this.bulletPool[bulletType].size() > 0) {
|
||||
@@ -133,23 +132,21 @@ export default class BulletManager extends Component {
|
||||
}
|
||||
|
||||
public killBullet(bullet: FishBulletBase) {
|
||||
let index: number = this.bulletList.indexOf(bullet)
|
||||
const index: number = this.bulletList.indexOf(bullet)
|
||||
if (index >= 0) {
|
||||
this.bulletList.splice(index, 1)
|
||||
this.destroyBullet(bullet)
|
||||
}
|
||||
}
|
||||
|
||||
// 销毁子弹
|
||||
private destroyBullet(bullet: FishBulletBase) {
|
||||
//临时代码,因为回收在内存卡顿。后面在优化 2023-2-10
|
||||
if (sys.platform == 'EDITOR_PAGE') {
|
||||
// 临时代码,因为回收在内存卡顿。后面在优化 2023-2-10
|
||||
if (sys.platform === 'EDITOR_PAGE') {
|
||||
bullet.node.destroy()
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.bulletPool[bullet.bulletType]) {
|
||||
this.bulletPool[bullet.bulletType] = new NodePool()
|
||||
}
|
||||
if (!this.bulletPool[bullet.bulletType]) this.bulletPool[bullet.bulletType] = new NodePool()
|
||||
this.bulletPool[bullet.bulletType].put(bullet.node)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,29 @@
|
||||
import { _decorator, Component, EventMouse, Node, Sprite, SpriteFrame, UITransform, Vec2, Vec3 } from 'cc'
|
||||
import {
|
||||
Component,
|
||||
EventMouse,
|
||||
Node,
|
||||
Sprite,
|
||||
SpriteFrame,
|
||||
UITransform,
|
||||
Vec2,
|
||||
Vec3,
|
||||
_decorator,
|
||||
} from 'cc'
|
||||
|
||||
import MathUtils from '../../engine/utils/MathUtils'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
// 炮塔管理类
|
||||
@ccclass('CannonManager')
|
||||
export default class CannonManager extends Component {
|
||||
public static instance: CannonManager = null
|
||||
@property({ type: Node })
|
||||
private view: Node | null = null
|
||||
|
||||
@property({ type: [SpriteFrame] })
|
||||
private cannonSpriteFrame: Array<SpriteFrame> | [] = []
|
||||
|
||||
// 炮塔倍数
|
||||
public cannonType: number = 1
|
||||
private _vec3Cache: Vec3
|
||||
@@ -21,33 +35,33 @@ export default class CannonManager extends Component {
|
||||
this.refreshCannon()
|
||||
}
|
||||
|
||||
// 炮塔移动
|
||||
private onMeMove(event: EventMouse) {
|
||||
this.rotateCannon(event.getUILocation())
|
||||
}
|
||||
|
||||
// 炮塔旋转
|
||||
public rotateCannon(uilocation: Vec2) {
|
||||
let location = uilocation
|
||||
const location = uilocation
|
||||
this._vec3Cache.x = location.x
|
||||
this._vec3Cache.y = location.y
|
||||
this._vec3Cache.z = 0
|
||||
let tran = this.node.getComponent(UITransform)
|
||||
const tran = this.node.getComponent(UITransform)
|
||||
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
|
||||
|
||||
let localTouch: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
|
||||
const localTouch: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
|
||||
this.view.getPosition(this._vec3Cache)
|
||||
let rad: number = MathUtils.p2pRad(
|
||||
new Vec2(this._vec3Cache.x, this._vec3Cache.y),
|
||||
localTouch
|
||||
)
|
||||
let rot: number = MathUtils.radiansToDegrees(rad)
|
||||
const rad: number = MathUtils.p2pRad(new Vec2(this._vec3Cache.x, this._vec3Cache.y), localTouch)
|
||||
const rot: number = MathUtils.radiansToDegrees(rad)
|
||||
this.view.angle = rot - 90
|
||||
}
|
||||
|
||||
// 刷新炮塔
|
||||
public refreshCannon() {
|
||||
this.view.getComponent(Sprite).spriteFrame =
|
||||
this.cannonSpriteFrame[this.cannonType - 1]
|
||||
this.view.getComponent(Sprite).spriteFrame = this.cannonSpriteFrame[this.cannonType - 1]
|
||||
}
|
||||
|
||||
// 获取炮塔位置
|
||||
public getCannonPosition() {
|
||||
return this.view.getPosition()
|
||||
}
|
||||
|
||||
@@ -1,210 +1,272 @@
|
||||
import { _decorator, Animation, Component, game, instantiate, Node, NodePool, Prefab, Vec2, Vec3 } from 'cc'
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
import {
|
||||
Animation,
|
||||
Component,
|
||||
Node,
|
||||
NodePool,
|
||||
Prefab,
|
||||
Tween,
|
||||
Vec2,
|
||||
Vec3,
|
||||
_decorator,
|
||||
game,
|
||||
instantiate,
|
||||
tween,
|
||||
} from 'cc'
|
||||
|
||||
import FishBase from '../../../fish/script/FishBase'
|
||||
import { FishPathConfig } from '../config/FishPathConfig'
|
||||
import FishMover from '../../../fish/script/FishMover'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import { FishInfo } from '../config/FishInfo'
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
import { FishConfig } from '../config/FishConfig'
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
import ScoreManager from './ScoreManager'
|
||||
import { FishInfo } from '../config/FishInfo'
|
||||
import { FishMap } from '../config/FishMap'
|
||||
import { FishMapInfo } from '../config/FishMapInfo'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import { FishPathConfig } from '../config/FishPathConfig'
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
|
||||
import TimeHelper from '../utils/TimeHelper'
|
||||
|
||||
import ScoreManager from './ScoreManager'
|
||||
import WsManager from './WsManager'
|
||||
import { FishPathInfo } from '../config/FishPathInfo'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
interface dataType {
|
||||
fisn: Array<FishType>
|
||||
}
|
||||
|
||||
interface FishType {
|
||||
fishId: string
|
||||
fishInfo: FishInfo
|
||||
fishType: string
|
||||
isDead: number
|
||||
fishPathInfo: Array<fishPathInfoType>
|
||||
}
|
||||
|
||||
interface fishPathInfoType {
|
||||
pathId: string
|
||||
path: Array<PathPoint>
|
||||
}
|
||||
|
||||
interface PathPoint {
|
||||
x: number
|
||||
y: number
|
||||
}
|
||||
|
||||
// 鱼管理类
|
||||
@ccclass('FishManager')
|
||||
export default class FishManager extends Component {
|
||||
public static instance: FishManager = null
|
||||
@property({ type: Node })
|
||||
private fishContainer: Node | null = null
|
||||
|
||||
@property({ type: [Prefab] })
|
||||
public fishPrefabList: Array<Prefab> = []
|
||||
|
||||
private fishPool: Array<NodePool> = []
|
||||
private fishList: Array<FishBase> = []
|
||||
private fishList: Map<string, FishBase> = new Map()
|
||||
private nextRandomFishTime: number = 0
|
||||
private minRandomTime: number = 2 * (game.frameRate as number)
|
||||
private maxRandomTime: number = 5 * (game.frameRate as number)
|
||||
private isFishMap: boolean = false
|
||||
private mapCount: number = 0
|
||||
private minMapCount: number = 30 * (game.frameRate as number)
|
||||
private maxMapCount: number = 60 * (game.frameRate as number)
|
||||
// // private minMapCount: number = 2 * cc.game.getFrameRate();
|
||||
// // private maxMapCount: number = 5 * cc.game.getFrameRate();
|
||||
|
||||
private _fishPosCache: Vec3
|
||||
|
||||
onLoad() {
|
||||
WsManager.instance.on(100, this.randomFish, this)
|
||||
FishManager.instance = this
|
||||
this._fishPosCache = new Vec3()
|
||||
Logger.log(
|
||||
'maxRandomTime=',
|
||||
this.minRandomTime,
|
||||
this.maxRandomTime,
|
||||
game.frameRate
|
||||
)
|
||||
Logger.log('maxRandomTime=', this.minRandomTime, this.maxRandomTime, game.frameRate)
|
||||
}
|
||||
|
||||
start() {
|
||||
this.randomFish()
|
||||
// this.randomFish()
|
||||
}
|
||||
|
||||
update() {
|
||||
this.checkRandomFish()
|
||||
// this.checkRandomFish()
|
||||
this.checkFishMoveEnd()
|
||||
this.checkFishMap()
|
||||
// this.checkFishMap()
|
||||
}
|
||||
|
||||
private checkFishMap() {
|
||||
if (!this.isFishMap) {
|
||||
if (this.mapCount > 0) {
|
||||
this.mapCount--
|
||||
if (this.mapCount <= 0) {
|
||||
FishUI.instance.playWaveEffect()
|
||||
}
|
||||
if (this.mapCount <= 0) FishUI.instance.playWaveEffect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检测是否随机鱼
|
||||
private checkRandomFish() {
|
||||
if (!this.isFishMap) {
|
||||
if (this.nextRandomFishTime > 0) {
|
||||
this.nextRandomFishTime--
|
||||
if (this.nextRandomFishTime == 0) {
|
||||
this.randomFish()
|
||||
}
|
||||
// if (this.nextRandomFishTime === 0) this.randomFish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检测鱼是否移动结束
|
||||
private checkFishMoveEnd() {
|
||||
for (let i = this.fishList.length - 1; i >= 0; i--) {
|
||||
let fish: FishBase = this.fishList[i]
|
||||
this.fishList.forEach(async (item: FishBase, key: string) => {
|
||||
if (this.isFishMap) {
|
||||
if (!fish.isDead) {
|
||||
fish.node.getPosition(this._fishPosCache)
|
||||
// 鱼阵回收
|
||||
if (item.isDead === 2) {
|
||||
item.node.getPosition(this._fishPosCache)
|
||||
this._fishPosCache.x -= 2
|
||||
fish.node.setPosition(this._fishPosCache)
|
||||
item.node.setPosition(this._fishPosCache)
|
||||
if (this._fishPosCache.x <= -screen.width / 2) {
|
||||
//winSize.width
|
||||
this.destroyFish(fish)
|
||||
this.fishList.splice(i, 1)
|
||||
// winSize.width
|
||||
await WsManager.instance.onSend({
|
||||
type: 102,
|
||||
fish_id: item.fishId,
|
||||
})
|
||||
// this.fishList.splice(index, 1)
|
||||
this.destroyFish(item)
|
||||
// this.fishList.delete(item.fishId)
|
||||
this.checkEndFishMap()
|
||||
}
|
||||
}
|
||||
} else if (!fish.getComponent(FishMover).isMoving) {
|
||||
this.destroyFish(fish)
|
||||
this.fishList.splice(i, 1)
|
||||
} else if (!item.getComponent(FishMover).isMoving) {
|
||||
// 普通鱼回收
|
||||
await WsManager.instance.onSend({
|
||||
type: 102,
|
||||
fish_id: item.fishId,
|
||||
})
|
||||
// this.fishList.splice(index, 1)
|
||||
this.destroyFish(item)
|
||||
// this.fishList.delete(item.fishId)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private checkEndFishMap() {
|
||||
Logger.log('checkEndFishMap==', this.isFishMap, this.fishList)
|
||||
if (this.isFishMap && this.fishList.length <= 0) {
|
||||
// Logger.log('checkEndFishMap==', this.isFishMap, this.fishList)
|
||||
if (this.isFishMap && this.fishList.size <= 0) {
|
||||
this.isFishMap = false
|
||||
this.randomFish()
|
||||
// this.randomFish()
|
||||
}
|
||||
}
|
||||
|
||||
private randomFish() {
|
||||
if (this.isFishMap) return
|
||||
let randomNum: number = RandomUtil.nextInt(1, 10)
|
||||
// let randomNum: number = RandomUtil.nextInt(1, 1);
|
||||
for (let i = 0; i < randomNum; i++) {
|
||||
let fishType: number = RandomUtil.nextInt(1, 29)
|
||||
// let fishType: number = RandomUtil.nextInt(1, 1);
|
||||
let fish: FishBase = this.createFishByType(fishType)
|
||||
fish.fishPathInfo = FishPathConfig.randomPathInfo()
|
||||
/**
|
||||
* 原:本地随机生成鱼
|
||||
* 新:服务端生成鱼
|
||||
*/
|
||||
private async randomFish(data: dataType) {
|
||||
const arr = data.fisn
|
||||
const paths: Array<FishPathInfo> = []
|
||||
if (!Array.isArray(arr) || this.isFishMap) return
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const fish: FishBase = this.createFishByType(arr[i])
|
||||
for (let k = 0; k < arr[i].fishPathInfo.length; k++) {
|
||||
const path: Array<Vec2> = []
|
||||
|
||||
for (let j = 0; j < arr[i].fishPathInfo[k].path.length; j++) {
|
||||
const p: Vec2 = new Vec2(
|
||||
arr[i].fishPathInfo[k].path[j].x,
|
||||
arr[i].fishPathInfo[k].path[j].y,
|
||||
)
|
||||
path.push(p)
|
||||
}
|
||||
paths.push(new FishPathInfo(arr[i].fishPathInfo[k].pathId, path))
|
||||
}
|
||||
fish.fishPathInfo = paths[0]
|
||||
this._fishPosCache.z = 0
|
||||
this._fishPosCache.x = fish.fishPathInfo.path[0].x
|
||||
this._fishPosCache.y = fish.fishPathInfo.path[0].y
|
||||
fish.node.setPosition(this._fishPosCache)
|
||||
fish.getComponent(FishMover).bezierPList = fish.fishPathInfo.path
|
||||
fish.getComponent(FishMover).startMove()
|
||||
this.fishList.push(fish)
|
||||
this.fishContainer.addChild(fish.node)
|
||||
}
|
||||
Logger.log('checkFishMoveEnd=randomFish=', this.fishList)
|
||||
this.nextRandomFishTime = RandomUtil.nextInt(
|
||||
this.minRandomTime,
|
||||
this.maxRandomTime
|
||||
)
|
||||
if (this.mapCount <= 0) {
|
||||
this.mapCount = RandomUtil.nextInt(this.minMapCount, this.maxMapCount)
|
||||
// this.fishList.push(fish)
|
||||
this.fishList.set(fish.fishId, fish)
|
||||
// this.fishContainer.addChild(fish.node)
|
||||
this.fishContainer.addChild(this.fishList.get(fish.fishId).node)
|
||||
}
|
||||
}
|
||||
|
||||
public createFishByType(fishType: number): FishBase {
|
||||
// 创建鱼类
|
||||
public createFishByType(data: FishType | any): FishBase {
|
||||
let fishNode: Node
|
||||
const fishType: number = Number(data.fishType)
|
||||
if (this.fishPool[fishType - 1] && this.fishPool[fishType - 1].size() > 0) {
|
||||
fishNode = this.fishPool[fishType - 1].get()
|
||||
} else {
|
||||
fishNode = instantiate(this.fishPrefabList[fishType - 1])
|
||||
}
|
||||
//fishNode.getComponent(Animation).play() //v3 当前帧 不能播放
|
||||
TimeHelper.exeNextFrame(fishNode, () =>
|
||||
fishNode.getComponent(Animation).play()
|
||||
)
|
||||
let fishInfo: FishInfo = FishConfig.getFishInfoByType(fishType)
|
||||
TimeHelper.exeNextFrame(fishNode, () => fishNode.getComponent(Animation).play())
|
||||
const fishInfo: FishInfo = FishConfig.getFishInfoByType(fishType)
|
||||
fishNode.getComponent(FishBase).fishInfo = fishInfo
|
||||
fishNode.getComponent(FishBase).fishType = fishType
|
||||
fishNode.getComponent(FishBase).blood = fishInfo.blood
|
||||
fishNode.getComponent(FishBase).isDead = false
|
||||
fishNode.getComponent(FishBase).fishId = data.fishId
|
||||
fishNode.getComponent(FishBase).isDead = 2
|
||||
return fishNode.getComponent(FishBase)
|
||||
}
|
||||
|
||||
public killFish(fish: FishBase) {
|
||||
let index: number = this.fishList.indexOf(fish)
|
||||
if (index >= 0) {
|
||||
// console.log("鱼挂了")
|
||||
GameMusicHelper.playFishDead(fish.fishType)
|
||||
fish.node.getPosition(this._fishPosCache)
|
||||
let vec2 = new Vec2(this._fishPosCache.x, this._fishPosCache.y)
|
||||
ScoreManager.instance.addScore(fish.fishInfo.blood, vec2)
|
||||
this.fishList.splice(index, 1)
|
||||
this.destroyFish(fish)
|
||||
this.checkEndFishMap()
|
||||
// 销毁鱼类
|
||||
public killFish(res: any) {
|
||||
const fishCheck = this.fishList.get(res.fish_id)
|
||||
// console.log('正在执行销毁=', fishCheck.fishId, res.fish_id, res.fish_status, fishCheck.isDead)
|
||||
if (fishCheck) {
|
||||
fishCheck.isDead = 1
|
||||
setTimeout(() => {
|
||||
GameMusicHelper.playFishDead(fishCheck.fishType)
|
||||
fishCheck.node.getPosition(this._fishPosCache)
|
||||
const vec2 = new Vec2(this._fishPosCache.x, this._fishPosCache.y)
|
||||
ScoreManager.instance.addScore(Number(res.fish_number), vec2)
|
||||
this.destroyFish(fishCheck)
|
||||
// console.log('killFish=', fishCheck.fishId, fishCheck.fishInfo.name)
|
||||
this.checkEndFishMap()
|
||||
}, 500)
|
||||
tween(fishCheck.node)
|
||||
.repeatForever(tween().by(0.6, { angle: -360 }))
|
||||
.start()
|
||||
|
||||
// this.fishList.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
private destroyFish(fish: FishBase) {
|
||||
if (!this.fishPool[fish.fishType - 1]) {
|
||||
this.fishPool[fish.fishType - 1] = new NodePool()
|
||||
const f = this.fishList.get(fish.fishId)
|
||||
if (!f) return
|
||||
if (!this.fishPool[f.fishType - 1]) {
|
||||
this.fishPool[f.fishType - 1] = new NodePool()
|
||||
}
|
||||
this.fishPool[fish.fishType - 1].put(fish.node)
|
||||
this.fishPool[f.fishType - 1].put(f.node)
|
||||
this.fishList.delete(f.fishId)
|
||||
}
|
||||
|
||||
public playFishMap() {
|
||||
this.isFishMap = true
|
||||
for (let i = this.fishList.length - 1; i >= 0; i--) {
|
||||
let fish: FishBase = this.fishList[i]
|
||||
this.fishList.forEach((fish: FishBase, key: string) => {
|
||||
this.destroyFish(fish)
|
||||
this.fishList.splice(i, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public startFishMap() {
|
||||
// this.playFishMap();
|
||||
// this.fishList = [];
|
||||
|
||||
let map: FishMap = FishPathConfig.randomFishMap()
|
||||
let fishMapInfoList: Array<FishMapInfo> = map.fishMapInfoList
|
||||
const map: FishMap = FishPathConfig.randomFishMap()
|
||||
const fishMapInfoList: Array<FishMapInfo> = map.fishMapInfoList
|
||||
Logger.log('startFishMap==', this.isFishMap, this.fishList, map)
|
||||
for (let i = 0; i < fishMapInfoList.length; i++) {
|
||||
let fishMapInfo: FishMapInfo = fishMapInfoList[i]
|
||||
let fish: FishBase = this.createFishByType(fishMapInfo.fishType)
|
||||
const fishMapInfo: FishMapInfo = fishMapInfoList[i]
|
||||
// 暂时屏蔽
|
||||
// @ts-ignore
|
||||
const fish: FishBase = this.createFishByType(fishMapInfo.fishType)
|
||||
fish.node.angle = 0
|
||||
// fish.node.setScale(fishMapInfo.scale);
|
||||
this.fishContainer.addChild(fish.node)
|
||||
fish.node.setPosition(fishMapInfo.x + screen.width, fishMapInfo.y)
|
||||
this.fishList.push(fish)
|
||||
this.fishList.set(fish.fishId, fish)
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
FishManager.instance = null
|
||||
WsManager.instance.off(100)
|
||||
}
|
||||
|
||||
protected onDisable(): void {}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,31 @@
|
||||
import { _decorator, Component, instantiate, Node, NodePool, Prefab, Vec2, Vec3 } from 'cc'
|
||||
import { Component, Node, NodePool, Prefab, Vec2, Vec3, _decorator, instantiate } from 'cc'
|
||||
|
||||
import FishNetBase from '../../../fish/script/FishNetBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
// 鱼网管理类
|
||||
@ccclass('FishNetManager')
|
||||
export default class FishNetManager extends Component {
|
||||
public static instance: FishNetManager = null
|
||||
@property({ type: [Prefab] })
|
||||
private netPrefabList: Prefab[] | [] = []
|
||||
|
||||
private fishNetPool: Array<NodePool> = []
|
||||
|
||||
onLoad() {
|
||||
FishNetManager.instance = this
|
||||
}
|
||||
|
||||
// 添加鱼网
|
||||
public addFishNet(netType: number, p: Vec2) {
|
||||
let fishNet: FishNetBase = this.createFishNet(netType)
|
||||
const fishNet: FishNetBase = this.createFishNet(netType)
|
||||
this.node.addChild(fishNet.node)
|
||||
fishNet.node.setPosition(new Vec3(p.x, p.y, 0))
|
||||
fishNet.playMv()
|
||||
}
|
||||
|
||||
// 创建鱼网
|
||||
private createFishNet(netType: number) {
|
||||
let fishNetNode: Node
|
||||
if (this.fishNetPool[netType] && this.fishNetPool[netType].size() > 0) {
|
||||
@@ -28,14 +33,17 @@ export default class FishNetManager extends Component {
|
||||
} else {
|
||||
fishNetNode = instantiate(this.netPrefabList[netType])
|
||||
}
|
||||
|
||||
fishNetNode.getComponent(FishNetBase).netType = netType
|
||||
return fishNetNode.getComponent(FishNetBase)
|
||||
}
|
||||
|
||||
// 销毁鱼网
|
||||
public destroyFishNet(fishNet: FishNetBase) {
|
||||
if (!this.fishNetPool[fishNet.netType]) {
|
||||
this.fishNetPool[fishNet.netType] = new NodePool()
|
||||
}
|
||||
|
||||
this.fishNetPool[fishNet.netType].put(fishNet.node)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { _decorator, Component, instantiate, Node, NodePool, Prefab, Vec2, Vec3 } from 'cc'
|
||||
import ScorePrefab from '../prefab/ScorePrefab'
|
||||
import { Component, Node, NodePool, Prefab, Vec2, Vec3, _decorator, instantiate } from 'cc'
|
||||
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import ScorePrefab from '../prefab/ScorePrefab'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@@ -9,6 +10,7 @@ export default class ScoreManager extends Component {
|
||||
public static instance: ScoreManager = null
|
||||
@property({ type: Prefab })
|
||||
private scrorePrefab: Prefab | null = null
|
||||
|
||||
private scorePool: NodePool
|
||||
|
||||
onLoad() {
|
||||
@@ -16,34 +18,35 @@ export default class ScoreManager extends Component {
|
||||
this.scorePool = new NodePool()
|
||||
}
|
||||
|
||||
// 添加积分
|
||||
public addScore(score: number, p: Vec2) {
|
||||
let scorePrefab: ScorePrefab = this.createScore(score)
|
||||
const scorePrefab: ScorePrefab = this.createScore(score)
|
||||
this.node.addChild(scorePrefab.node)
|
||||
scorePrefab.node.setPosition(new Vec3(p.x, p.y, 0))
|
||||
scorePrefab.init(score)
|
||||
scorePrefab.playMoveEffect(new Vec2(-472.398, -547.481), () => {
|
||||
this.destroyScore(scorePrefab)
|
||||
FishUI.instance.jf_score += score
|
||||
FishUI.instance.refreshScore()
|
||||
// 本地不在添加积分
|
||||
// FishUI.instance.jf_score += score
|
||||
// FishUI.instance.refreshScore()
|
||||
})
|
||||
}
|
||||
|
||||
// 创建积分
|
||||
private createScore(score: number): ScorePrefab {
|
||||
let scoreNode: Node
|
||||
if (this.scorePool && this.scorePool.size() > 0) {
|
||||
scoreNode = this.scorePool.get()
|
||||
} else {
|
||||
scoreNode = instantiate(this.scrorePrefab)
|
||||
}
|
||||
if (this.scorePool && this.scorePool.size() > 0) scoreNode = this.scorePool.get()
|
||||
else scoreNode = instantiate(this.scrorePrefab)
|
||||
|
||||
return scoreNode.getComponent(ScorePrefab)
|
||||
}
|
||||
|
||||
// 销毁积分
|
||||
private destroyScore(scorePrefab: ScorePrefab) {
|
||||
this.scorePool.put(scorePrefab.node)
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
}
|
||||
onDisable() {}
|
||||
|
||||
onDestroy() {
|
||||
ScoreManager.instance = null
|
||||
|
||||
137
assets/FishSingle/script/game/manager/WsManager.ts
Normal file
137
assets/FishSingle/script/game/manager/WsManager.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
import { _decorator } from 'cc'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import config from '../config/Config'
|
||||
|
||||
export default class WsManager {
|
||||
private static _instance: WsManager = null
|
||||
uid: string
|
||||
|
||||
message: any
|
||||
|
||||
t_id: any = null
|
||||
|
||||
public static get instance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new WsManager()
|
||||
}
|
||||
return this._instance
|
||||
}
|
||||
|
||||
private _socket: WebSocket | null = null
|
||||
|
||||
protected m_mapCallbackFun: Map<number, Function>
|
||||
|
||||
constructor() {
|
||||
this.m_mapCallbackFun = new Map<number, Function>()
|
||||
}
|
||||
|
||||
public on(msgId: number, cb: Function, target: any) {
|
||||
let callback = cb.bind(target)
|
||||
let fnCallback: Function = this.m_mapCallbackFun.get(msgId)
|
||||
if (fnCallback) {
|
||||
console.error('重复注册消息处理函数! msgId:' + msgId)
|
||||
} else {
|
||||
this.m_mapCallbackFun.set(msgId, callback)
|
||||
}
|
||||
}
|
||||
|
||||
public off(msgId: number) {
|
||||
if (this.m_mapCallbackFun.has(msgId)) {
|
||||
this.m_mapCallbackFun.delete(msgId)
|
||||
}
|
||||
}
|
||||
|
||||
public get(msgId: number) {
|
||||
return this.m_mapCallbackFun.get(msgId)
|
||||
}
|
||||
|
||||
public offAll() {
|
||||
this.m_mapCallbackFun.clear()
|
||||
}
|
||||
|
||||
// 获取url参数
|
||||
public getQueryString(name: string) {
|
||||
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
|
||||
var r = window.location.search.substr(1).match(reg)
|
||||
if (r != null) {
|
||||
return unescape(r[2])
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
public init(): void {
|
||||
this.uid = this.getQueryString('uid')
|
||||
this._socket = new WebSocket(`wss://${config.wsUrl()}/fish/home?uid=${this.uid}`)
|
||||
|
||||
// 添加事件监听器
|
||||
this._socket.onopen = this.onOpen.bind(this)
|
||||
this._socket.onmessage = this.onMessage.bind(this)
|
||||
this._socket.onclose = this.onClose.bind(this)
|
||||
this._socket.onerror = this.onError.bind(this)
|
||||
}
|
||||
|
||||
public onOpen(): void {
|
||||
console.log('WebSocket connection opened.')
|
||||
setInterval(() => {
|
||||
this._socket.send(JSON.stringify('ping'))
|
||||
}, 20000)
|
||||
this.clear()
|
||||
}
|
||||
|
||||
public async onSend(data: any): Promise<void> {
|
||||
if (this._socket && this._socket.readyState === WebSocket.OPEN) {
|
||||
this._socket.send(JSON.stringify(data))
|
||||
} else {
|
||||
console.error('消息发送失败!!!')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理接收到的消息
|
||||
* @param event WebSocket message event
|
||||
*/
|
||||
public onMessage(event: MessageEvent): void {
|
||||
this.message = JSON.parse(event.data)
|
||||
|
||||
if (this.message.code === 200 || this.message.code === 5) {
|
||||
FishUI.instance.refreshScore(this.message)
|
||||
}
|
||||
|
||||
let fnCallback: Function = this.m_mapCallbackFun.get(this.message.code)
|
||||
|
||||
if (fnCallback) {
|
||||
fnCallback(this.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭WebSocket连接
|
||||
*/
|
||||
public onClose(): void {
|
||||
console.log('链接已关闭')
|
||||
CommonTips.showMsg('游戏服务器中断关闭,正在重试')
|
||||
// this.init()
|
||||
if (this._socket) {
|
||||
this._socket.close()
|
||||
this._socket = null
|
||||
}
|
||||
this.t_id = setInterval(() => {
|
||||
WsManager.instance.init()
|
||||
}, 8000)
|
||||
}
|
||||
|
||||
public onError(event: Event): void {
|
||||
CommonTips.showMsg('网络连接失败,正在重试链接游戏服务器')
|
||||
this.t_id = setInterval(() => {
|
||||
WsManager.instance.init()
|
||||
}, 8000)
|
||||
}
|
||||
|
||||
public clear() {
|
||||
if (this.t_id) {
|
||||
clearInterval(this.t_id)
|
||||
this.t_id = null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,8 @@
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "65ad3e01-f8b1-4160-a391-c55d6c8f366f",
|
||||
"uuid": "44f1bff8-2972-4ae5-8f53-e0daaa97b92e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { _decorator, Component, instantiate, Node, Prefab } from 'cc'
|
||||
import { Component, Node, Prefab, _decorator, instantiate } from 'cc'
|
||||
|
||||
import PrefabLoader from '../../engine/utils/PrefabLoader'
|
||||
import { GameConfig } from '../config/GameConfig'
|
||||
|
||||
@@ -6,29 +7,30 @@ const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('ResourcePrefab')
|
||||
export default class ResourcePrefab extends Component {
|
||||
private static prefab: Prefab | null = null
|
||||
public static instance: Node
|
||||
@property({ type: Prefab })
|
||||
private scorePrefab: Prefab | null = null
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
GameConfig.GameName + '/' + 'game/prefab/ResourcePrefab',
|
||||
(loadedResource: Prefab) => {
|
||||
ResourcePrefab.prefab = loadedResource
|
||||
ResourcePrefab.instance = instantiate(loadedResource)
|
||||
resolve()
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
private static prefab: Prefab | null = null
|
||||
public static instance: Node
|
||||
@property({ type: Prefab })
|
||||
private scorePrefab: Prefab | null = null
|
||||
|
||||
public static clear() {
|
||||
ResourcePrefab.instance = null
|
||||
ResourcePrefab.prefab = null
|
||||
}
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/game/prefab/ResourcePrefab`,
|
||||
(loadedResource: Prefab) => {
|
||||
ResourcePrefab.prefab = loadedResource
|
||||
ResourcePrefab.instance = instantiate(loadedResource)
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static getScorePrefab() {
|
||||
return ResourcePrefab.instance.getComponent(ResourcePrefab).scorePrefab
|
||||
}
|
||||
public static clear() {
|
||||
ResourcePrefab.instance = null
|
||||
ResourcePrefab.prefab = null
|
||||
}
|
||||
|
||||
public static getScorePrefab() {
|
||||
return ResourcePrefab.instance.getComponent(ResourcePrefab).scorePrefab
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,27 @@
|
||||
import { _decorator, Component, Label, tween, Tween, Vec2, Vec3 } from 'cc'
|
||||
import { Component, Label, Tween, Vec2, Vec3, _decorator, tween } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('ScorePrefab')
|
||||
export default class ScorePrefab extends Component {
|
||||
@property({ type: Label })
|
||||
private txtScore: Label | null = null
|
||||
public init(score: number) {
|
||||
if (score <= 0) {
|
||||
this.txtScore.string = 'Miss'
|
||||
} else {
|
||||
this.txtScore.string = score + ''
|
||||
}
|
||||
}
|
||||
@property({ type: Label })
|
||||
private txtScore: Label | null = null
|
||||
|
||||
public playMoveEffect(p: Vec2, callback: Function = null) {
|
||||
tween(this.node)
|
||||
.to(0.5, { scale: new Vec3(3, 3, 3), position: new Vec3(p.x, p.y, 0) })
|
||||
.call(() => {
|
||||
if (callback) {
|
||||
callback()
|
||||
}
|
||||
})
|
||||
.start()
|
||||
}
|
||||
public init(score: number) {
|
||||
if (score <= 0) this.txtScore.string = 'Miss'
|
||||
else this.txtScore.string = `${score}`
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
Tween.stopAllByTarget(this.node)
|
||||
}
|
||||
public playMoveEffect(p: Vec2, callback: Function = null) {
|
||||
tween(this.node)
|
||||
.to(0.5, { scale: new Vec3(3, 3, 3), position: new Vec3(p.x, p.y, 0) })
|
||||
.call(() => {
|
||||
if (callback) callback()
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
Tween.stopAllByTarget(this.node)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { _decorator, Component, instantiate, Material, Node, Prefab } from 'cc'
|
||||
import { Component, Material, Node, Prefab, _decorator, instantiate } from 'cc'
|
||||
|
||||
import PrefabLoader from '../../engine/utils/PrefabLoader'
|
||||
import { GameConfig } from '../config/GameConfig'
|
||||
|
||||
@@ -13,29 +14,36 @@ export default class ShaderMaterialPrefab extends Component {
|
||||
|
||||
@property({ type: Material })
|
||||
public grayMaterial: Material | null = null
|
||||
|
||||
@property({ type: Material })
|
||||
public oldPhoto: Material | null = null
|
||||
|
||||
@property({ type: Material })
|
||||
public glowInner: Material | null = null
|
||||
|
||||
@property({ type: Material })
|
||||
public mosaic: Material | null = null
|
||||
|
||||
@property({ type: Material })
|
||||
public roundCornerCrop: Material | null = null
|
||||
|
||||
@property({ type: Material })
|
||||
public flashLight: Material | null = null
|
||||
|
||||
@property({ type: Material })
|
||||
public flag: Material | null = null
|
||||
|
||||
@property({ type: Material })
|
||||
public gaussian: Material | null = null
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
GameConfig.GameName + '/' + 'game/prefab/ShaderMaterialPrefab',
|
||||
`${GameConfig.GameName}/game/prefab/ShaderMaterialPrefab`,
|
||||
(loadedResource: Prefab) => {
|
||||
ShaderMaterialPrefab.instance = instantiate(loadedResource)
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,37 +1,63 @@
|
||||
import { _decorator, instantiate, Node, Prefab, Sprite, Tween, Vec3 } from 'cc'
|
||||
import SceneBase from './SceneBase'
|
||||
import TextureMgr from '../../engine/uicomponent/TextureMgr'
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
import {
|
||||
Component,
|
||||
Game,
|
||||
Node,
|
||||
Prefab,
|
||||
Sprite,
|
||||
Tween,
|
||||
Vec3,
|
||||
_decorator,
|
||||
director,
|
||||
game,
|
||||
instantiate,
|
||||
} from 'cc'
|
||||
|
||||
import FishMover from '../../../fish/script/FishMover'
|
||||
import { FishPathInfo } from '../config/FishPathInfo'
|
||||
import { FishPathConfig } from '../config/FishPathConfig'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import FishWiki from '../../../fish/script/FishWiki'
|
||||
import TextureMgr from '../../engine/uicomponent/TextureMgr'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
import { FishPathConfig } from '../config/FishPathConfig'
|
||||
import { FishPathInfo } from '../config/FishPathInfo'
|
||||
import WsManager from '../manager/WsManager'
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishGameScene')
|
||||
export default class FishGameScene extends SceneBase {
|
||||
export default class FishGameScene extends Component {
|
||||
@property(Sprite)
|
||||
private bg: Sprite | null = null
|
||||
|
||||
@property({ type: [Prefab] })
|
||||
private fishPrefabList: Array<Prefab> | null = []
|
||||
|
||||
private showNode: Node | null = null
|
||||
|
||||
onLoad() {
|
||||
this.onLoadMe()
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.onDestroyMe()
|
||||
}
|
||||
|
||||
onLoadMe() {
|
||||
WsManager.instance.init()
|
||||
GameMusicHelper.playBg()
|
||||
FishPathConfig.init()
|
||||
this.initBg()
|
||||
WsManager.instance.on(400, this.showMsg, this)
|
||||
// FishPathConfig.init()
|
||||
// this.initBg()
|
||||
// this.testPathPlay()
|
||||
game.on(Game.EVENT_HIDE, this.onHide, this)
|
||||
game.on(Game.EVENT_SHOW, this.onAppShow, this)
|
||||
}
|
||||
|
||||
private initBg() {
|
||||
let textureMgr: TextureMgr = this.bg.getComponent(TextureMgr)
|
||||
const textureMgr: TextureMgr = this.bg.getComponent(TextureMgr)
|
||||
this.bg.spriteFrame =
|
||||
textureMgr.Spriteset[
|
||||
RandomUtil.nextInt(0, textureMgr.Spriteset.length - 1)
|
||||
]
|
||||
textureMgr.Spriteset[RandomUtil.nextInt(0, textureMgr.Spriteset.length - 1)]
|
||||
}
|
||||
|
||||
private initShowNode() {
|
||||
@@ -39,10 +65,9 @@ export default class FishGameScene extends SceneBase {
|
||||
this.showNode.destroy()
|
||||
this.showNode = null
|
||||
}
|
||||
let fishType: number = 29
|
||||
if (fishType < 1 || fishType > 29) {
|
||||
return
|
||||
}
|
||||
const fishType: number = 29
|
||||
if (fishType < 1 || fishType > 29) return
|
||||
|
||||
this.showNode = instantiate(this.fishPrefabList[fishType - 1])
|
||||
this.showNode.getComponent(FishMover).speed = 2
|
||||
this.showNode.getComponent(FishMover).node.setScale(new Vec3(2, 2, 1))
|
||||
@@ -51,10 +76,10 @@ export default class FishGameScene extends SceneBase {
|
||||
|
||||
private testPathPlay() {
|
||||
this.initShowNode()
|
||||
let pathInfo: FishPathInfo = FishPathConfig.getPathInfo(3)
|
||||
const pathInfo: FishPathInfo = FishPathConfig.getPathInfo(3)
|
||||
Logger.log('testPathPlay=pathInfo=', pathInfo)
|
||||
let params = pathInfo.path
|
||||
let param0 = params[0]
|
||||
const params = pathInfo.path
|
||||
const param0 = params[0]
|
||||
Logger.log('testPathPlay=11=', param0)
|
||||
this.showNode.setPosition(new Vec3(param0.x, param0.y, 0))
|
||||
this.showNode.getComponent(FishMover).bezierPList = params
|
||||
@@ -65,9 +90,22 @@ export default class FishGameScene extends SceneBase {
|
||||
FishWiki.show()
|
||||
}
|
||||
|
||||
private showMsg(res: any) {
|
||||
Logger.log('showMsg=res=', res)
|
||||
CommonTips.showMsg(res.msg)
|
||||
}
|
||||
|
||||
onDestroyMe() {
|
||||
this.unscheduleAllCallbacks()
|
||||
//this.node.stopAllActions();
|
||||
// this.node.stopAllActions();
|
||||
Tween.stopAllByTarget(this.node)
|
||||
}
|
||||
|
||||
onHide() {
|
||||
director.pause()
|
||||
}
|
||||
|
||||
onAppShow() {
|
||||
director.resume()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
import { _decorator, DynamicAtlasManager, Node, PhysicsSystem2D, profiler, sys } from 'cc'
|
||||
import {
|
||||
_decorator,
|
||||
Node,
|
||||
sys,
|
||||
profiler,
|
||||
DynamicAtlasManager,
|
||||
PhysicsSystem2D,
|
||||
Component,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import MusicConfig from '../../engine/config/MusicConfig'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import Progress from '../../engine/uicomponent/Progress'
|
||||
@@ -7,74 +17,69 @@ import HotUpdate from '../../engine/utils/HotUpdate'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import VersionManager from '../../engine/utils/VersionManager'
|
||||
import ResourcePreload from '../utils/ResourcePreload'
|
||||
import SceneBase from './SceneBase'
|
||||
import SceneManager from './SceneManager'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
import { FishConfig } from '../config/FishConfig'
|
||||
|
||||
@ccclass('LoadingScene')
|
||||
export default class LoadingScene extends SceneBase {
|
||||
export default class LoadingScene extends Component {
|
||||
public static scriptName: string = 'LoadingScene'
|
||||
@property({ type: Node })
|
||||
private progressNode: Node | null = null
|
||||
|
||||
async onLoadMe() {
|
||||
protected onLoad(): void {
|
||||
this.onLoadMe()
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
this.onDestroyMe()
|
||||
}
|
||||
|
||||
onLoadMe() {
|
||||
this.baseInit()
|
||||
EventManager.instance.addListener(
|
||||
HotUpdate.Event_On_NeedUpdate,
|
||||
this.onNeedUpdate,
|
||||
this
|
||||
)
|
||||
EventManager.instance.addListener(
|
||||
HotUpdate.Event_On_Progress,
|
||||
this.onUpdateProgress,
|
||||
this
|
||||
)
|
||||
EventManager.instance.addListener(
|
||||
HotUpdate.Event_On_Fail_Update,
|
||||
this.onUpdateFail,
|
||||
this
|
||||
)
|
||||
EventManager.instance.addListener(
|
||||
HotUpdate.Event_Finish_Update,
|
||||
this.onUpdateFinish,
|
||||
this
|
||||
)
|
||||
EventManager.instance.addListener(HotUpdate.Event_On_NeedUpdate, this.onNeedUpdate, this)
|
||||
EventManager.instance.addListener(HotUpdate.Event_On_Progress, this.onUpdateProgress, this)
|
||||
EventManager.instance.addListener(HotUpdate.Event_On_Fail_Update, this.onUpdateFail, this)
|
||||
EventManager.instance.addListener(HotUpdate.Event_Finish_Update, this.onUpdateFinish, this)
|
||||
EventManager.instance.addListener(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
this.onUpdateFinish,
|
||||
this
|
||||
this,
|
||||
)
|
||||
if (sys.isNative && VersionManager.instance.isOpenHotUpdate) {
|
||||
this.checkUpdate()
|
||||
} else {
|
||||
await this.preLoadRes()
|
||||
this.preLoadRes()
|
||||
}
|
||||
}
|
||||
|
||||
private baseInit() {
|
||||
profiler.hideStats() //showStats
|
||||
//let collisionManager:cc.CollisionManager = director.getCollisionManager();
|
||||
PhysicsSystem2D.instance.enable = true
|
||||
private async baseInit() {
|
||||
try {
|
||||
await FishConfig.init()
|
||||
profiler.hideStats() //showStats
|
||||
//let collisionManager:cc.CollisionManager = director.getCollisionManager();
|
||||
PhysicsSystem2D.instance.enable = true
|
||||
|
||||
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
|
||||
// EPhysics2DDrawFlags.Pair |
|
||||
// EPhysics2DDrawFlags.CenterOfMass |
|
||||
// EPhysics2DDrawFlags.Joint |
|
||||
// EPhysics2DDrawFlags.Shape;
|
||||
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
|
||||
// EPhysics2DDrawFlags.Pair |
|
||||
// EPhysics2DDrawFlags.CenterOfMass |
|
||||
// EPhysics2DDrawFlags.Joint |
|
||||
// EPhysics2DDrawFlags.Shape;
|
||||
|
||||
//if(collisionManager){
|
||||
//collisionManager.enabled = true;
|
||||
// collisionManager.enabledDebugDraw = true;
|
||||
// collisionManager.enabledDrawBoundingBox = true;
|
||||
//}
|
||||
//if(collisionManager){
|
||||
//collisionManager.enabled = true;
|
||||
// collisionManager.enabledDebugDraw = true;
|
||||
// collisionManager.enabledDrawBoundingBox = true;
|
||||
//}
|
||||
|
||||
if (DynamicAtlasManager.instance) {
|
||||
DynamicAtlasManager.instance.enabled = false
|
||||
if (DynamicAtlasManager.instance) {
|
||||
DynamicAtlasManager.instance.enabled = false
|
||||
}
|
||||
MusicConfig.init()
|
||||
// cc.director.getCollisionManager().enabled=true;//这是一个全局属性,开启后就代表碰撞检测组件可以进行检测了
|
||||
// cc.director.getCollisionManager().enabledDebugDraw = true; //绘制碰撞区域
|
||||
} catch (error) {
|
||||
Logger.error(this, error)
|
||||
}
|
||||
MusicConfig.init()
|
||||
// cc.director.getCollisionManager().enabled=true;//这是一个全局属性,开启后就代表碰撞检测组件可以进行检测了
|
||||
// cc.director.getCollisionManager().enabledDebugDraw = true; //绘制碰撞区域
|
||||
}
|
||||
|
||||
private checkUpdate() {
|
||||
@@ -89,13 +94,10 @@ export default class LoadingScene extends SceneBase {
|
||||
}
|
||||
}
|
||||
|
||||
private onUpdateProgress(event: Function, loadedFiles: number, totalFiles: number, key: string) {
|
||||
private onUpdateProgress(event, loadedFiles, totalFiles, key) {
|
||||
if (key == VersionManager.Config_Key[0]) {
|
||||
let msg: string =
|
||||
Math.min(100, (loadedFiles / totalFiles) * 100).toFixed(2) + '%'
|
||||
this.progressNode
|
||||
.getComponent(Progress)
|
||||
.updateProgress(loadedFiles, totalFiles, msg)
|
||||
let msg: string = Math.min(100, (loadedFiles / totalFiles) * 100).toFixed(2) + '%'
|
||||
this.progressNode.getComponent(Progress).updateProgress(loadedFiles, totalFiles, msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,25 +128,10 @@ export default class LoadingScene extends SceneBase {
|
||||
}
|
||||
|
||||
onDestroyMe() {
|
||||
EventManager.instance.removeListener(
|
||||
HotUpdate.Event_On_NeedUpdate,
|
||||
this.onNeedUpdate
|
||||
)
|
||||
EventManager.instance.removeListener(
|
||||
HotUpdate.Event_On_Progress,
|
||||
this.onUpdateProgress
|
||||
)
|
||||
EventManager.instance.removeListener(
|
||||
HotUpdate.Event_On_Fail_Update,
|
||||
this.onUpdateFail
|
||||
)
|
||||
EventManager.instance.removeListener(
|
||||
HotUpdate.Event_Finish_Update,
|
||||
this.onUpdateFinish
|
||||
)
|
||||
EventManager.instance.removeListener(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
this.onUpdateFinish
|
||||
)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_NeedUpdate, this.onNeedUpdate)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_Progress, this.onUpdateProgress)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_Fail_Update, this.onUpdateFail)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_Finish_Update, this.onUpdateFinish)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_ALREADY_UP_TO_DATE, this.onUpdateFinish)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import { _decorator, Component } from 'cc'
|
||||
import AdapterHelper from '../../engine/utils/AdapterHelper'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('SceneBase')
|
||||
export default class SceneBase extends Component {
|
||||
public static scriptName: string = 'SceneBase'
|
||||
|
||||
onLoad() {
|
||||
AdapterHelper.fixApdater()
|
||||
this.onLoadMe()
|
||||
}
|
||||
|
||||
onLoadMe() {
|
||||
}
|
||||
|
||||
start() {
|
||||
this.onStartMe()
|
||||
}
|
||||
|
||||
onStartMe() {
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.onDestroyMe()
|
||||
}
|
||||
|
||||
onDestroyMe() {
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "544253ea-8aa0-4349-9d6c-efb97841d976",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import { director, SceneAsset, sys } from 'cc'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import LoadingScenePrefab from '../../engine/uicomponent/LoadingScenePrefab'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import EventManager from '../../engine/utils/EventManager'
|
||||
import { SceneAsset, director, sys } from 'cc'
|
||||
|
||||
import CommonEvent from '../../engine/config/CommonEvent'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import LoadingScenePrefab from '../../engine/uicomponent/LoadingScenePrefab'
|
||||
import EventManager from '../../engine/utils/EventManager'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
|
||||
export default class SceneManager {
|
||||
public static instance: SceneManager = new SceneManager()
|
||||
@@ -23,7 +24,7 @@ export default class SceneManager {
|
||||
}
|
||||
|
||||
public async sceneSwitch(name: string, showProgress: boolean = false) {
|
||||
if (this.loadingSceneName == name) return
|
||||
if (this.loadingSceneName === name) return
|
||||
Logger.log(this, 'sceneSwitch==', name)
|
||||
if (sys.isBrowser) {
|
||||
// showProgress = true;
|
||||
@@ -42,13 +43,13 @@ export default class SceneManager {
|
||||
Logger.warn(this, 'preloadScene=error', error.message)
|
||||
CommonTips.showMsg('加载场景失败')
|
||||
} else {
|
||||
//director.getScene().destroy();//director.getScene().cleanup();
|
||||
// director.getScene().destroy();//director.getScene().cleanup();
|
||||
director.loadScene(name, this.loadSceneOK.bind(this))
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
} else {
|
||||
//director.getScene().destroy();//director.getScene().cleanup();
|
||||
// director.getScene().destroy();//director.getScene().cleanup();
|
||||
director.loadScene(name, this.loadSceneOK.bind(this))
|
||||
}
|
||||
}
|
||||
@@ -65,7 +66,7 @@ export default class SceneManager {
|
||||
public preloadScene(
|
||||
sceneName: string,
|
||||
onProgressCallback: any = null,
|
||||
onLoadedCallback: any = null
|
||||
onLoadedCallback: any = null,
|
||||
) {
|
||||
director.preloadScene(sceneName, onProgressCallback, onLoadedCallback)
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { _decorator } from 'cc'
|
||||
import SceneBase from './SceneBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('StartScene')
|
||||
export default class StartScene extends SceneBase {
|
||||
public static scriptName: string = 'StartScene'
|
||||
|
||||
onLoadMe() {
|
||||
}
|
||||
|
||||
update() {
|
||||
}
|
||||
|
||||
onDestroyMe() {
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import { _decorator, Component, Vec2 } from 'cc'
|
||||
import { Component, Vec2, _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
export enum AstarGridType {
|
||||
Hider = 0, //不能走
|
||||
Normal = 1, //能走
|
||||
End = 2, //终点
|
||||
Hider = 0, // 不能走
|
||||
Normal = 1, // 能走
|
||||
End = 2, // 终点
|
||||
}
|
||||
|
||||
@ccclass('Astar')
|
||||
@@ -28,8 +28,7 @@ export class Astar extends Component {
|
||||
private path: Array<AstarGrid> = []
|
||||
private gridsList: Array<Array<AstarGrid>> = []
|
||||
|
||||
onLoad() {
|
||||
}
|
||||
onLoad() {}
|
||||
|
||||
/**
|
||||
* @param mapW 宽格子数
|
||||
@@ -51,15 +50,12 @@ export class Astar extends Component {
|
||||
this.closeList = []
|
||||
this.path = []
|
||||
// 初始化格子二维数组
|
||||
this.gridsList = new Array(this.mapW + 1)
|
||||
for (let col = 0; col < this.gridsList.length; col++) {
|
||||
this.gridsList[col] = new Array(this.mapH + 1)
|
||||
}
|
||||
for (let col = 0; col <= this.mapW; col++) {
|
||||
for (let row = 0; row <= this.mapH; row++) {
|
||||
this.addGrid(col, row, AstarGridType.Normal)
|
||||
}
|
||||
}
|
||||
this.gridsList = Array.from({ length: this.mapW + 1 })
|
||||
for (let col = 0; col < this.gridsList.length; col++)
|
||||
this.gridsList[col] = Array.from({ length: this.mapH + 1 })
|
||||
|
||||
for (let col = 0; col <= this.mapW; col++)
|
||||
for (let row = 0; row <= this.mapH; row++) this.addGrid(col, row, AstarGridType.Normal)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +65,7 @@ export class Astar extends Component {
|
||||
* @param type
|
||||
*/
|
||||
private addGrid(x: number, y: number, type: number = AstarGridType.Hider) {
|
||||
let grid = new AstarGrid()
|
||||
const grid = new AstarGrid()
|
||||
grid.x = x
|
||||
grid.y = y
|
||||
grid.type = type
|
||||
@@ -83,7 +79,7 @@ export class Astar extends Component {
|
||||
* @param type
|
||||
*/
|
||||
public setGridType(x: number, y: number, type: number) {
|
||||
let curGrid: AstarGrid = this.gridsList[x][y]
|
||||
const curGrid: AstarGrid = this.gridsList[x][y]
|
||||
curGrid.type = type
|
||||
}
|
||||
|
||||
@@ -94,70 +90,59 @@ export class Astar extends Component {
|
||||
* @param callback
|
||||
*/
|
||||
public findPath(startPos: Vec2, endPos: Vec2, callback: Function = null) {
|
||||
let startGrid = this.gridsList[startPos.x][startPos.y]
|
||||
const startGrid = this.gridsList[startPos.x][startPos.y]
|
||||
this.openList.push(startGrid)
|
||||
let curGrid: AstarGrid = this.openList[0]
|
||||
while (this.openList.length > 0 && curGrid.type != AstarGridType.End) {
|
||||
while (this.openList.length > 0 && curGrid.type !== AstarGridType.End) {
|
||||
// 每次都取出f值最小的节点进行查找
|
||||
curGrid = this.openList[0]
|
||||
if (curGrid.type == AstarGridType.End) {
|
||||
if (curGrid.type === AstarGridType.End) {
|
||||
// Logger.log(this,"find path success.");
|
||||
this.generatePath(curGrid)
|
||||
if (callback) {
|
||||
callback(this.path)
|
||||
}
|
||||
if (callback) callback(this.path)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
for (let i: number = -1; i <= 1; i++) {
|
||||
for (let j: number = -1; j <= 1; j++) {
|
||||
if (i != 0 || j != 0) {
|
||||
let col = curGrid.x + i
|
||||
let row = curGrid.y + j
|
||||
if (i !== 0 || j !== 0) {
|
||||
const col = curGrid.x + i
|
||||
const row = curGrid.y + j
|
||||
if (
|
||||
col >= 0 &&
|
||||
row >= 0 &&
|
||||
col <= this.mapW &&
|
||||
row <= this.mapH &&
|
||||
this.gridsList[col][row].type != AstarGridType.Hider &&
|
||||
this.closeList.indexOf(this.gridsList[col][row]) < 0
|
||||
col >= 0
|
||||
&& row >= 0
|
||||
&& col <= this.mapW
|
||||
&& row <= this.mapH
|
||||
&& this.gridsList[col][row].type !== AstarGridType.Hider
|
||||
&& !this.closeList.includes(this.gridsList[col][row])
|
||||
) {
|
||||
if (this.is8dir) {
|
||||
// 8方向 斜向走动时要考虑相邻的是不是障碍物
|
||||
if (
|
||||
this.gridsList[col - i][row].type == AstarGridType.Hider ||
|
||||
this.gridsList[col][row - j].type == AstarGridType.Hider
|
||||
) {
|
||||
this.gridsList[col - i][row].type === AstarGridType.Hider
|
||||
|| this.gridsList[col][row - j].type === AstarGridType.Hider
|
||||
)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
// 四方形行走
|
||||
if (Math.abs(i) == Math.abs(j)) {
|
||||
continue
|
||||
}
|
||||
if (Math.abs(i) === Math.abs(j)) continue
|
||||
}
|
||||
// 计算g值
|
||||
let g =
|
||||
curGrid.g +
|
||||
Math.floor(Math.sqrt(Math.pow(i * 10, 2)) + Math.pow(j * 10, 2))
|
||||
if (
|
||||
this.gridsList[col][row].g == 0 ||
|
||||
this.gridsList[col][row].g > g
|
||||
) {
|
||||
const g = curGrid.g + Math.floor(Math.sqrt((i * 10) ** 2) + (j * 10) ** 2)
|
||||
if (this.gridsList[col][row].g === 0 || this.gridsList[col][row].g > g) {
|
||||
this.gridsList[col][row].g = g
|
||||
// 更新父节点
|
||||
this.gridsList[col][row].parent = curGrid
|
||||
}
|
||||
// 计算h值 manhattan估算法
|
||||
this.gridsList[col][row].h =
|
||||
Math.abs(endPos.x - col) + Math.abs(endPos.y - row)
|
||||
this.gridsList[col][row].h = Math.abs(endPos.x - col) + Math.abs(endPos.y - row)
|
||||
// 更新f值
|
||||
this.gridsList[col][row].f =
|
||||
this.gridsList[col][row].g + this.gridsList[col][row].h
|
||||
this.gridsList[col][row].f = this.gridsList[col][row].g + this.gridsList[col][row].h
|
||||
// 如果不在开放列表里则添加到开放列表里
|
||||
if (this.openList.indexOf(this.gridsList[col][row]) < 0) {
|
||||
if (!this.openList.includes(this.gridsList[col][row]))
|
||||
this.openList.push(this.gridsList[col][row])
|
||||
}
|
||||
|
||||
// // 重新按照f值排序(升序排列)
|
||||
}
|
||||
}
|
||||
@@ -170,9 +155,8 @@ export class Astar extends Component {
|
||||
if (this.openList.length <= 0) {
|
||||
// Logger.log(this,"find path failed.");
|
||||
this.path = []
|
||||
if (callback) {
|
||||
callback(this.path)
|
||||
}
|
||||
if (callback) callback(this.path)
|
||||
|
||||
break
|
||||
}
|
||||
// 重新按照f值排序(升序排列)
|
||||
@@ -195,6 +179,5 @@ export class Astar extends Component {
|
||||
return this.path
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
}
|
||||
onDestroy() {}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import SoundPrefab from '../../engine/uicomponent/SoundPrefab'
|
||||
import MusicPrefab from '../../engine/uicomponent/MusicPrefab'
|
||||
import SoundPrefab from '../../engine/uicomponent/SoundPrefab'
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
|
||||
export default class GameMusicHelper {
|
||||
public static playBg() {
|
||||
let randomIndex: number = RandomUtil.nextInt(1, 3)
|
||||
MusicPrefab.play('background_' + randomIndex)
|
||||
const randomIndex: number = RandomUtil.nextInt(1, 3)
|
||||
MusicPrefab.play(`background_${randomIndex}`)
|
||||
}
|
||||
|
||||
public static playFishDead(fishType: number) {
|
||||
SoundPrefab.play('deadfish_' + fishType)
|
||||
SoundPrefab.play(`deadfish_${fishType}`)
|
||||
}
|
||||
|
||||
public static playFire() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { error, game } from 'cc'
|
||||
|
||||
import DarkLayer from '../../engine/uicomponent/DarkLayer'
|
||||
import LoadingPrefab from '../../engine/uicomponent/LoadingPrefab'
|
||||
import LoadingScenePrefab from '../../engine/uicomponent/LoadingScenePrefab'
|
||||
@@ -22,29 +23,28 @@ export default class ResourcePreload {
|
||||
}
|
||||
this.isPreloaded = true
|
||||
this.progress = progress
|
||||
if (this.progress) {
|
||||
if (this.progress)
|
||||
progress.updateProgress(this.nowIndex, this.totalNum)
|
||||
}
|
||||
await LoadingPrefab.preLoad() //1
|
||||
|
||||
await LoadingPrefab.preLoad() // 1
|
||||
this.finishOneItemLoad()
|
||||
await DarkLayer.preLoad() //2
|
||||
await DarkLayer.preLoad() // 2
|
||||
this.finishOneItemLoad()
|
||||
await MusicPrefab.preLoad() //3
|
||||
await MusicPrefab.preLoad() // 3
|
||||
this.finishOneItemLoad()
|
||||
await SoundPrefab.preLoad() //4
|
||||
await SoundPrefab.preLoad() // 4
|
||||
this.finishOneItemLoad()
|
||||
await ResourcePrefab.preLoad() //5
|
||||
await ResourcePrefab.preLoad() // 5
|
||||
this.finishOneItemLoad()
|
||||
await ShaderMaterialPrefab.preLoad() //6
|
||||
await ShaderMaterialPrefab.preLoad() // 6
|
||||
this.finishOneItemLoad() //
|
||||
callback()
|
||||
}
|
||||
|
||||
private finishOneItemLoad() {
|
||||
this.nowIndex++
|
||||
if (this.progress) {
|
||||
if (this.progress)
|
||||
this.progress.updateProgress(this.nowIndex, this.totalNum)
|
||||
}
|
||||
}
|
||||
|
||||
public restartGame() {
|
||||
@@ -53,7 +53,7 @@ export default class ResourcePreload {
|
||||
LoadingScenePrefab.clear()
|
||||
LoadingPrefab.clear()
|
||||
error('需要获取游戏里所有的AudioSource停止音乐')
|
||||
//audioEngine.stopAll();
|
||||
// audioEngine.stopAll();
|
||||
|
||||
// VersionManager.instance.releaseAll();
|
||||
MusicPrefab.destory()
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { _decorator, Component } from 'cc'
|
||||
import { Component, _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('UIRoot')
|
||||
export class UIRoot extends Component {
|
||||
public static Instance: UIRoot
|
||||
onLoad() {
|
||||
UIRoot.Instance = this
|
||||
}
|
||||
onDestroy() {
|
||||
UIRoot.Instance = null
|
||||
}
|
||||
public static Instance: UIRoot
|
||||
|
||||
onLoad() {
|
||||
UIRoot.Instance = this
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
UIRoot.Instance = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user