This commit is contained in:
2024-10-05 04:22:34 +08:00
parent 5993f231fd
commit 30911fcf5c
298 changed files with 28632 additions and 28632 deletions

View File

@@ -1,12 +1,12 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "37ac4184-546f-4fa8-9030-da49dbe4219c",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "37ac4184-546f-4fa8-9030-da49dbe4219c",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -1,6 +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'),
}
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'),
}

View File

@@ -1,9 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "f01978bd-5d14-49a6-bea7-4b7ad0c82b7b",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "f01978bd-5d14-49a6-bea7-4b7ad0c82b7b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,86 +1,86 @@
import { FishInfo } from './FishInfo'
import config from './Config'
export class FishConfig {
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++) {
const fishInfo: FishInfo = this.config[i]
if (fishInfo.fishType === fishType) return fishInfo
}
}
}
import { FishInfo } from './FishInfo'
import config from './Config'
export class FishConfig {
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++) {
const fishInfo: FishInfo = this.config[i]
if (fishInfo.fishType === fishType) return fishInfo
}
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c7516237-7eb2-4767-8cc7-7ce0b2d5484e",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c7516237-7eb2-4767-8cc7-7ce0b2d5484e",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,18 +1,18 @@
export class FishInfo {
public fishType: number
public name: string
public blood: number
// public wikiScale: number
constructor(
fishType: number,
name: string,
blood: number,
// wikiScale: number,
) {
this.fishType = fishType
this.name = name
this.blood = blood
// this.wikiScale = wikiScale
}
}
export class FishInfo {
public fishType: number
public name: string
public blood: number
// public wikiScale: number
constructor(
fishType: number,
name: string,
blood: number,
// wikiScale: number,
) {
this.fishType = fishType
this.name = name
this.blood = blood
// this.wikiScale = wikiScale
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "03f14923-6d67-4d91-97ad-a81bf4f1551f",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "03f14923-6d67-4d91-97ad-a81bf4f1551f",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,11 +1,11 @@
import { FishMapInfo } from './FishMapInfo'
export class FishMap {
public mapId: number
public fishMapInfoList: Array<FishMapInfo>
constructor(mapId: number, list: Array<FishMapInfo>) {
this.mapId = mapId
this.fishMapInfoList = list
}
}
import { FishMapInfo } from './FishMapInfo'
export class FishMap {
public mapId: number
public fishMapInfoList: Array<FishMapInfo>
constructor(mapId: number, list: Array<FishMapInfo>) {
this.mapId = mapId
this.fishMapInfoList = list
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "f84ce3e3-8c47-43ff-a6f4-7cda4c320fcf",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "f84ce3e3-8c47-43ff-a6f4-7cda4c320fcf",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,15 +1,15 @@
export class FishMapInfo {
public fishType: number
public scale: number
public side: number // 1: -1:
public x: number
public y: number
constructor(fishType: number, scale: number, side: number, x: number, y: number) {
this.fishType = fishType
this.scale = scale
this.side = side
this.x = x
this.y = y
}
}
export class FishMapInfo {
public fishType: number
public scale: number
public side: number // 1: -1:
public x: number
public y: number
constructor(fishType: number, scale: number, side: number, x: number, y: number) {
this.fishType = fishType
this.scale = scale
this.side = side
this.x = x
this.y = y
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5f3df30a-4677-4f9c-97a9-e80fcb5b8295",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5f3df30a-4677-4f9c-97a9-e80fcb5b8295",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "704e17b3-0f7b-478a-8ad1-1cb2f5d89a8f",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "704e17b3-0f7b-478a-8ad1-1cb2f5d89a8f",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,11 +1,11 @@
import { Vec2 } from 'cc'
export class FishPathInfo {
public pathId: string
public path: Array<Vec2> = []
constructor(pathId: string, path: Array<Vec2>) {
this.pathId = pathId
this.path = path
}
}
import { Vec2 } from 'cc'
export class FishPathInfo {
public pathId: string
public path: Array<Vec2> = []
constructor(pathId: string, path: Array<Vec2>) {
this.pathId = pathId
this.path = path
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "01cc78a7-9862-45b4-ad09-ebb92c01de58",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "01cc78a7-9862-45b4-ad09-ebb92c01de58",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,3 +1,3 @@
export class GameConfig {
public static GameName: string = 'FishSingle'
}
export class GameConfig {
public static GameName: string = 'FishSingle'
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "8b274344-0b4c-4ac5-a289-2f8cd7a5596b",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "8b274344-0b4c-4ac5-a289-2f8cd7a5596b",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,12 +1,12 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "1e8eeb35-adbc-485b-879b-bf95de554cfd",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "1e8eeb35-adbc-485b-879b-bf95de554cfd",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -1,156 +1,156 @@
import {
Component,
EventTouch,
Node,
NodePool,
Prefab,
UITransform,
Vec2,
Vec3,
_decorator,
instantiate,
sys,
} from 'cc'
import FishBulletBase from '../../../fish/script/FishBulletBase'
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
private _vec3Cache: Vec3
private _vec2Cache: Vec2
private _fireTime: number = 0
private _fireTimeNew: number
onLoad() {
this._vec3Cache = new Vec3()
this._vec2Cache = new Vec2()
BulletManager.instance = this
this.node.on(Node.EventType.TOUCH_START, this.onShootBullet, this)
}
start() {}
update() {
this.checkMoveBullet()
}
// 检测子弹是否移动完成
private checkMoveBullet() {
for (let i = this.bulletList.length - 1; i >= 0; i--) {
const bullet: FishBulletBase = this.bulletList[i]
const isMoving: boolean = MoveHelper.moveNode(
bullet.node,
this.bulletMoveSpeed,
bullet.targetP.x,
bullet.targetP.y,
)
if (!isMoving) {
bullet.node.getPosition(this._vec3Cache)
this._vec2Cache.x = this._vec3Cache.x
this._vec2Cache.y = this._vec3Cache.y
FishNetManager.instance.addFishNet(bullet.bulletType, this._vec2Cache)
this.bulletList.splice(i, 1)
this.destroyBullet(bullet)
}
}
}
// 发射炮弹
private onShootBullet(event: EventTouch) {
// TOUCH_START 在Editor上连续触发2次导致发2次炮弹bug
if (sys.platform === 'EDITOR_PAGE') {
this._fireTimeNew = new Date().getTime()
if (this._fireTimeNew - this._fireTime < 15000) return
this._fireTime = this._fireTimeNew
}
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)
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()
this._vec3Cache = CannonManager.instance.getCannonPosition()
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())
this._vec3Cache.x = 1
this._vec3Cache.y = 1
this._vec3Cache.y = 1
Vec3.multiplyScalar(this._vec3Cache, this._vec3Cache, 2)
bullet.node.setScale(this._vec3Cache)
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) {
bulletNode = this.bulletPool[bulletType].get()
} else {
bulletNode = instantiate(this.bulletPrefabList[bulletType])
}
bulletNode.getComponent(FishBulletBase).bulletType = bulletType
return bulletNode.getComponent(FishBulletBase)
}
public killBullet(bullet: FishBulletBase) {
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') {
bullet.node.destroy()
return
}
if (!this.bulletPool[bullet.bulletType]) this.bulletPool[bullet.bulletType] = new NodePool()
this.bulletPool[bullet.bulletType].put(bullet.node)
}
onDestroy() {
BulletManager.instance = null
}
}
import {
Component,
EventTouch,
Node,
NodePool,
Prefab,
UITransform,
Vec2,
Vec3,
_decorator,
instantiate,
sys,
} from 'cc'
import FishBulletBase from '../../../fish/script/FishBulletBase'
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
private _vec3Cache: Vec3
private _vec2Cache: Vec2
private _fireTime: number = 0
private _fireTimeNew: number
onLoad() {
this._vec3Cache = new Vec3()
this._vec2Cache = new Vec2()
BulletManager.instance = this
this.node.on(Node.EventType.TOUCH_START, this.onShootBullet, this)
}
start() {}
update() {
this.checkMoveBullet()
}
// 检测子弹是否移动完成
private checkMoveBullet() {
for (let i = this.bulletList.length - 1; i >= 0; i--) {
const bullet: FishBulletBase = this.bulletList[i]
const isMoving: boolean = MoveHelper.moveNode(
bullet.node,
this.bulletMoveSpeed,
bullet.targetP.x,
bullet.targetP.y,
)
if (!isMoving) {
bullet.node.getPosition(this._vec3Cache)
this._vec2Cache.x = this._vec3Cache.x
this._vec2Cache.y = this._vec3Cache.y
FishNetManager.instance.addFishNet(bullet.bulletType, this._vec2Cache)
this.bulletList.splice(i, 1)
this.destroyBullet(bullet)
}
}
}
// 发射炮弹
private onShootBullet(event: EventTouch) {
// TOUCH_START 在Editor上连续触发2次导致发2次炮弹bug
if (sys.platform === 'EDITOR_PAGE') {
this._fireTimeNew = new Date().getTime()
if (this._fireTimeNew - this._fireTime < 15000) return
this._fireTime = this._fireTimeNew
}
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)
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()
this._vec3Cache = CannonManager.instance.getCannonPosition()
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())
this._vec3Cache.x = 1
this._vec3Cache.y = 1
this._vec3Cache.y = 1
Vec3.multiplyScalar(this._vec3Cache, this._vec3Cache, 2)
bullet.node.setScale(this._vec3Cache)
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) {
bulletNode = this.bulletPool[bulletType].get()
} else {
bulletNode = instantiate(this.bulletPrefabList[bulletType])
}
bulletNode.getComponent(FishBulletBase).bulletType = bulletType
return bulletNode.getComponent(FishBulletBase)
}
public killBullet(bullet: FishBulletBase) {
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') {
bullet.node.destroy()
return
}
if (!this.bulletPool[bullet.bulletType]) this.bulletPool[bullet.bulletType] = new NodePool()
this.bulletPool[bullet.bulletType].put(bullet.node)
}
onDestroy() {
BulletManager.instance = null
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "bd065d0b-0b60-4981-aea0-75d2f209b7ea",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "bd065d0b-0b60-4981-aea0-75d2f209b7ea",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,72 +1,72 @@
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
onLoad() {
this._vec3Cache = new Vec3()
CannonManager.instance = this
this.node.parent.on(Node.EventType.MOUSE_MOVE, this.onMeMove.bind(this))
this.refreshCannon()
}
// 炮塔移动
private onMeMove(event: EventMouse) {
this.rotateCannon(event.getUILocation())
}
// 炮塔旋转
public rotateCannon(uilocation: Vec2) {
const location = uilocation
this._vec3Cache.x = location.x
this._vec3Cache.y = location.y
this._vec3Cache.z = 0
const tran = this.node.getComponent(UITransform)
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
const localTouch: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
this.view.getPosition(this._vec3Cache)
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]
}
// 获取炮塔位置
public getCannonPosition() {
return this.view.getPosition()
}
onDestroy() {
CannonManager.instance = null
}
}
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
onLoad() {
this._vec3Cache = new Vec3()
CannonManager.instance = this
this.node.parent.on(Node.EventType.MOUSE_MOVE, this.onMeMove.bind(this))
this.refreshCannon()
}
// 炮塔移动
private onMeMove(event: EventMouse) {
this.rotateCannon(event.getUILocation())
}
// 炮塔旋转
public rotateCannon(uilocation: Vec2) {
const location = uilocation
this._vec3Cache.x = location.x
this._vec3Cache.y = location.y
this._vec3Cache.z = 0
const tran = this.node.getComponent(UITransform)
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
const localTouch: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
this.view.getPosition(this._vec3Cache)
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]
}
// 获取炮塔位置
public getCannonPosition() {
return this.view.getPosition()
}
onDestroy() {
CannonManager.instance = null
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "d03d3fa0-9f23-4106-be05-9d106bd8f8c8",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "d03d3fa0-9f23-4106-be05-9d106bd8f8c8",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,272 +1,272 @@
import {
Animation,
Component,
Node,
NodePool,
Prefab,
Tween,
Vec2,
Vec3,
_decorator,
game,
instantiate,
tween,
} from 'cc'
import FishBase from '../../../fish/script/FishBase'
import FishMover from '../../../fish/script/FishMover'
import FishUI from '../../../fish/script/FishUI'
import { Logger } from '../../engine/utils/Logger'
import RandomUtil from '../../engine/utils/RandomUtil'
import { FishConfig } from '../config/FishConfig'
import { FishInfo } from '../config/FishInfo'
import { FishMap } from '../config/FishMap'
import { FishMapInfo } from '../config/FishMapInfo'
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: 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 _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)
}
start() {
// this.randomFish()
}
update() {
// this.checkRandomFish()
this.checkFishMoveEnd()
// this.checkFishMap()
}
private checkFishMap() {
if (!this.isFishMap) {
if (this.mapCount > 0) {
this.mapCount--
if (this.mapCount <= 0) FishUI.instance.playWaveEffect()
}
}
}
// 检测是否随机鱼
private checkRandomFish() {
if (!this.isFishMap) {
if (this.nextRandomFishTime > 0) {
this.nextRandomFishTime--
// if (this.nextRandomFishTime === 0) this.randomFish()
}
}
}
// 检测鱼是否移动结束
private checkFishMoveEnd() {
this.fishList.forEach(async (item: FishBase, key: string) => {
if (this.isFishMap) {
// 鱼阵回收
if (item.isDead === 2) {
item.node.getPosition(this._fishPosCache)
this._fishPosCache.x -= 2
item.node.setPosition(this._fishPosCache)
if (this._fishPosCache.x <= -screen.width / 2) {
// 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 (!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.size <= 0) {
this.isFishMap = false
// this.randomFish()
}
}
/**
* 原:本地随机生成鱼
* 新:服务端生成鱼
*/
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.fishList.set(fish.fishId, fish)
// this.fishContainer.addChild(fish.node)
this.fishContainer.addChild(this.fishList.get(fish.fishId).node)
}
}
// 创建鱼类
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])
}
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).fishId = data.fishId
fishNode.getComponent(FishBase).isDead = 2
return fishNode.getComponent(FishBase)
}
// 销毁鱼类
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) {
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[f.fishType - 1].put(f.node)
this.fishList.delete(f.fishId)
}
public playFishMap() {
this.isFishMap = true
this.fishList.forEach((fish: FishBase, key: string) => {
this.destroyFish(fish)
})
}
public startFishMap() {
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++) {
const fishMapInfo: FishMapInfo = fishMapInfoList[i]
// 暂时屏蔽
// @ts-ignore
const fish: FishBase = this.createFishByType(fishMapInfo.fishType)
fish.node.angle = 0
this.fishContainer.addChild(fish.node)
fish.node.setPosition(fishMapInfo.x + screen.width, fishMapInfo.y)
this.fishList.set(fish.fishId, fish)
}
}
onDestroy() {
FishManager.instance = null
WsManager.instance.off(100)
}
protected onDisable(): void {}
}
import {
Animation,
Component,
Node,
NodePool,
Prefab,
Tween,
Vec2,
Vec3,
_decorator,
game,
instantiate,
tween,
} from 'cc'
import FishBase from '../../../fish/script/FishBase'
import FishMover from '../../../fish/script/FishMover'
import FishUI from '../../../fish/script/FishUI'
import { Logger } from '../../engine/utils/Logger'
import RandomUtil from '../../engine/utils/RandomUtil'
import { FishConfig } from '../config/FishConfig'
import { FishInfo } from '../config/FishInfo'
import { FishMap } from '../config/FishMap'
import { FishMapInfo } from '../config/FishMapInfo'
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: 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 _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)
}
start() {
// this.randomFish()
}
update() {
// this.checkRandomFish()
this.checkFishMoveEnd()
// this.checkFishMap()
}
private checkFishMap() {
if (!this.isFishMap) {
if (this.mapCount > 0) {
this.mapCount--
if (this.mapCount <= 0) FishUI.instance.playWaveEffect()
}
}
}
// 检测是否随机鱼
private checkRandomFish() {
if (!this.isFishMap) {
if (this.nextRandomFishTime > 0) {
this.nextRandomFishTime--
// if (this.nextRandomFishTime === 0) this.randomFish()
}
}
}
// 检测鱼是否移动结束
private checkFishMoveEnd() {
this.fishList.forEach(async (item: FishBase, key: string) => {
if (this.isFishMap) {
// 鱼阵回收
if (item.isDead === 2) {
item.node.getPosition(this._fishPosCache)
this._fishPosCache.x -= 2
item.node.setPosition(this._fishPosCache)
if (this._fishPosCache.x <= -screen.width / 2) {
// 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 (!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.size <= 0) {
this.isFishMap = false
// this.randomFish()
}
}
/**
* 原:本地随机生成鱼
* 新:服务端生成鱼
*/
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.fishList.set(fish.fishId, fish)
// this.fishContainer.addChild(fish.node)
this.fishContainer.addChild(this.fishList.get(fish.fishId).node)
}
}
// 创建鱼类
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])
}
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).fishId = data.fishId
fishNode.getComponent(FishBase).isDead = 2
return fishNode.getComponent(FishBase)
}
// 销毁鱼类
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) {
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[f.fishType - 1].put(f.node)
this.fishList.delete(f.fishId)
}
public playFishMap() {
this.isFishMap = true
this.fishList.forEach((fish: FishBase, key: string) => {
this.destroyFish(fish)
})
}
public startFishMap() {
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++) {
const fishMapInfo: FishMapInfo = fishMapInfoList[i]
// 暂时屏蔽
// @ts-ignore
const fish: FishBase = this.createFishByType(fishMapInfo.fishType)
fish.node.angle = 0
this.fishContainer.addChild(fish.node)
fish.node.setPosition(fishMapInfo.x + screen.width, fishMapInfo.y)
this.fishList.set(fish.fishId, fish)
}
}
onDestroy() {
FishManager.instance = null
WsManager.instance.off(100)
}
protected onDisable(): void {}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b20609a9-5a1b-4119-9fb1-399b45155aab",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b20609a9-5a1b-4119-9fb1-399b45155aab",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,53 +1,53 @@
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) {
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) {
fishNetNode = this.fishNetPool[netType].get()
} 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)
}
onDestroy() {
FishNetManager.instance = null
}
}
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) {
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) {
fishNetNode = this.fishNetPool[netType].get()
} 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)
}
onDestroy() {
FishNetManager.instance = null
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "fec491b0-4f6f-4a17-928d-a4ee3c2bb567",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "fec491b0-4f6f-4a17-928d-a4ee3c2bb567",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,54 +1,54 @@
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
@ccclass('ScoreManager')
export default class ScoreManager extends Component {
public static instance: ScoreManager = null
@property({ type: Prefab })
private scrorePrefab: Prefab | null = null
private scorePool: NodePool
onLoad() {
ScoreManager.instance = this
this.scorePool = new NodePool()
}
// 添加积分
public addScore(score: number, p: Vec2) {
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()
})
}
// 创建积分
private createScore(score: number): ScorePrefab {
let scoreNode: Node
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() {}
onDestroy() {
ScoreManager.instance = null
}
}
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
@ccclass('ScoreManager')
export default class ScoreManager extends Component {
public static instance: ScoreManager = null
@property({ type: Prefab })
private scrorePrefab: Prefab | null = null
private scorePool: NodePool
onLoad() {
ScoreManager.instance = this
this.scorePool = new NodePool()
}
// 添加积分
public addScore(score: number, p: Vec2) {
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()
})
}
// 创建积分
private createScore(score: number): ScorePrefab {
let scoreNode: Node
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() {}
onDestroy() {
ScoreManager.instance = null
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ff2defbe-9c85-4632-b16a-021567da1bdd",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ff2defbe-9c85-4632-b16a-021567da1bdd",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,137 +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
}
}
}
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
}
}
}

View File

@@ -1,9 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "44f1bff8-2972-4ae5-8f53-e0daaa97b92e",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "44f1bff8-2972-4ae5-8f53-e0daaa97b92e",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,12 +1,12 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a52a8a98-fc73-4bb3-9081-157a181af0a9",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a52a8a98-fc73-4bb3-9081-157a181af0a9",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -1,36 +1,36 @@
import { Component, Node, Prefab, _decorator, instantiate } from 'cc'
import PrefabLoader from '../../engine/utils/PrefabLoader'
import { GameConfig } from '../config/GameConfig'
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()
},
)
})
}
public static clear() {
ResourcePrefab.instance = null
ResourcePrefab.prefab = null
}
public static getScorePrefab() {
return ResourcePrefab.instance.getComponent(ResourcePrefab).scorePrefab
}
}
import { Component, Node, Prefab, _decorator, instantiate } from 'cc'
import PrefabLoader from '../../engine/utils/PrefabLoader'
import { GameConfig } from '../config/GameConfig'
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()
},
)
})
}
public static clear() {
ResourcePrefab.instance = null
ResourcePrefab.prefab = null
}
public static getScorePrefab() {
return ResourcePrefab.instance.getComponent(ResourcePrefab).scorePrefab
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "e0c999fe-5635-4caa-8c3b-d16793848320",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "e0c999fe-5635-4caa-8c3b-d16793848320",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,27 +1,27 @@
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}`
}
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)
}
}
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}`
}
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)
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "465f63cc-b6fe-4ea9-9a10-79254fbe67cc",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "465f63cc-b6fe-4ea9-9a10-79254fbe67cc",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,50 +1,50 @@
import { Component, Material, Node, Prefab, _decorator, instantiate } from 'cc'
import PrefabLoader from '../../engine/utils/PrefabLoader'
import { GameConfig } from '../config/GameConfig'
const { ccclass, property } = _decorator
@ccclass('ShaderMaterialPrefab')
export default class ShaderMaterialPrefab extends Component {
public static instance: Node
@property({ type: Material })
public default: Material | null = null
@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`,
(loadedResource: Prefab) => {
ShaderMaterialPrefab.instance = instantiate(loadedResource)
resolve()
},
)
})
}
}
import { Component, Material, Node, Prefab, _decorator, instantiate } from 'cc'
import PrefabLoader from '../../engine/utils/PrefabLoader'
import { GameConfig } from '../config/GameConfig'
const { ccclass, property } = _decorator
@ccclass('ShaderMaterialPrefab')
export default class ShaderMaterialPrefab extends Component {
public static instance: Node
@property({ type: Material })
public default: Material | null = null
@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`,
(loadedResource: Prefab) => {
ShaderMaterialPrefab.instance = instantiate(loadedResource)
resolve()
},
)
})
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "7c56c670-6b06-4cf1-a606-7af6226a3cb6",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "7c56c670-6b06-4cf1-a606-7af6226a3cb6",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,12 +1,12 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "8041396e-ebea-4101-a42b-e0eee5b71be2",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "8041396e-ebea-4101-a42b-e0eee5b71be2",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -1,111 +1,111 @@
import {
Component,
Game,
Node,
Prefab,
Sprite,
Tween,
Vec3,
_decorator,
director,
game,
instantiate,
} from 'cc'
import FishMover from '../../../fish/script/FishMover'
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 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()
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() {
const textureMgr: TextureMgr = this.bg.getComponent(TextureMgr)
this.bg.spriteFrame =
textureMgr.Spriteset[RandomUtil.nextInt(0, textureMgr.Spriteset.length - 1)]
}
private initShowNode() {
if (this.showNode) {
this.showNode.destroy()
this.showNode = null
}
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))
this.node.addChild(this.showNode)
}
private testPathPlay() {
this.initShowNode()
const pathInfo: FishPathInfo = FishPathConfig.getPathInfo(3)
Logger.log('testPathPlay=pathInfo=', pathInfo)
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
this.showNode.getComponent(FishMover).startMove()
}
private onClickWiki() {
FishWiki.show()
}
private showMsg(res: any) {
Logger.log('showMsg=res=', res)
CommonTips.showMsg(res.msg)
}
onDestroyMe() {
this.unscheduleAllCallbacks()
// this.node.stopAllActions();
Tween.stopAllByTarget(this.node)
}
onHide() {
director.pause()
}
onAppShow() {
director.resume()
}
}
import {
Component,
Game,
Node,
Prefab,
Sprite,
Tween,
Vec3,
_decorator,
director,
game,
instantiate,
} from 'cc'
import FishMover from '../../../fish/script/FishMover'
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 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()
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() {
const textureMgr: TextureMgr = this.bg.getComponent(TextureMgr)
this.bg.spriteFrame =
textureMgr.Spriteset[RandomUtil.nextInt(0, textureMgr.Spriteset.length - 1)]
}
private initShowNode() {
if (this.showNode) {
this.showNode.destroy()
this.showNode = null
}
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))
this.node.addChild(this.showNode)
}
private testPathPlay() {
this.initShowNode()
const pathInfo: FishPathInfo = FishPathConfig.getPathInfo(3)
Logger.log('testPathPlay=pathInfo=', pathInfo)
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
this.showNode.getComponent(FishMover).startMove()
}
private onClickWiki() {
FishWiki.show()
}
private showMsg(res: any) {
Logger.log('showMsg=res=', res)
CommonTips.showMsg(res.msg)
}
onDestroyMe() {
this.unscheduleAllCallbacks()
// this.node.stopAllActions();
Tween.stopAllByTarget(this.node)
}
onHide() {
director.pause()
}
onAppShow() {
director.resume()
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ebb8d437-f642-4a91-9a2c-6d9b8743d7d7",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ebb8d437-f642-4a91-9a2c-6d9b8743d7d7",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,137 +1,137 @@
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'
import EventManager, { HaoEvent } from '../../engine/utils/EventManager'
import HotUpdate from '../../engine/utils/HotUpdate'
import { Logger } from '../../engine/utils/Logger'
import VersionManager from '../../engine/utils/VersionManager'
import ResourcePreload from '../utils/ResourcePreload'
import SceneManager from './SceneManager'
import { FishConfig } from '../config/FishConfig'
@ccclass('LoadingScene')
export default class LoadingScene extends Component {
public static scriptName: string = 'LoadingScene'
@property({ type: Node })
private progressNode: Node | null = null
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_ALREADY_UP_TO_DATE,
this.onUpdateFinish,
this,
)
if (sys.isNative && VersionManager.instance.isOpenHotUpdate) {
this.checkUpdate()
} else {
this.preLoadRes()
}
}
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;
//if(collisionManager){
//collisionManager.enabled = true;
// collisionManager.enabledDebugDraw = true;
// collisionManager.enabledDrawBoundingBox = true;
//}
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)
}
}
private checkUpdate() {
Logger.log(this, 'checkUpdate====')
VersionManager.instance.checkUpdate(0)
}
private onNeedUpdate(event: HaoEvent, key: string) {
Logger.log(this, 'onNeedUpdate=====', key, VersionManager.Config_Key)
if (key == VersionManager.Config_Key[0]) {
VersionManager.instance.startUpdate(0)
}
}
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)
}
}
private onUpdateFail(event, key: string) {
if (key == VersionManager.Config_Key[0]) {
Logger.warn(this, '热更新失败========')
CommonTips.showMsg('热更新失败')
ResourcePreload.instance.restartGame()
}
}
private onUpdateFinish(event, key: string, needRestart: boolean) {
Logger.log(this, 'onUpdateFinish========')
if (key == VersionManager.Config_Key[0] && !needRestart) {
this.preLoadRes()
}
}
private async preLoadRes() {
ResourcePreload.instance.preLoad(() => {
this.startGame()
}, this.progressNode.getComponent(Progress))
}
private startGame() {
Logger.info(this, 'startGame')
SceneManager.instance.sceneSwitch('FishGameScene', true)
}
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)
}
}
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'
import EventManager, { HaoEvent } from '../../engine/utils/EventManager'
import HotUpdate from '../../engine/utils/HotUpdate'
import { Logger } from '../../engine/utils/Logger'
import VersionManager from '../../engine/utils/VersionManager'
import ResourcePreload from '../utils/ResourcePreload'
import SceneManager from './SceneManager'
import { FishConfig } from '../config/FishConfig'
@ccclass('LoadingScene')
export default class LoadingScene extends Component {
public static scriptName: string = 'LoadingScene'
@property({ type: Node })
private progressNode: Node | null = null
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_ALREADY_UP_TO_DATE,
this.onUpdateFinish,
this,
)
if (sys.isNative && VersionManager.instance.isOpenHotUpdate) {
this.checkUpdate()
} else {
this.preLoadRes()
}
}
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;
//if(collisionManager){
//collisionManager.enabled = true;
// collisionManager.enabledDebugDraw = true;
// collisionManager.enabledDrawBoundingBox = true;
//}
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)
}
}
private checkUpdate() {
Logger.log(this, 'checkUpdate====')
VersionManager.instance.checkUpdate(0)
}
private onNeedUpdate(event: HaoEvent, key: string) {
Logger.log(this, 'onNeedUpdate=====', key, VersionManager.Config_Key)
if (key == VersionManager.Config_Key[0]) {
VersionManager.instance.startUpdate(0)
}
}
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)
}
}
private onUpdateFail(event, key: string) {
if (key == VersionManager.Config_Key[0]) {
Logger.warn(this, '热更新失败========')
CommonTips.showMsg('热更新失败')
ResourcePreload.instance.restartGame()
}
}
private onUpdateFinish(event, key: string, needRestart: boolean) {
Logger.log(this, 'onUpdateFinish========')
if (key == VersionManager.Config_Key[0] && !needRestart) {
this.preLoadRes()
}
}
private async preLoadRes() {
ResourcePreload.instance.preLoad(() => {
this.startGame()
}, this.progressNode.getComponent(Progress))
}
private startGame() {
Logger.info(this, 'startGame')
SceneManager.instance.sceneSwitch('FishGameScene', true)
}
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)
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ba786f67-34b5-4fa6-abc5-69a3ef70bfd3",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ba786f67-34b5-4fa6-abc5-69a3ef70bfd3",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,73 +1,73 @@
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()
private loadingSceneName: string
public currentSceneName: string
public initFullScreenPrefab(isShow: boolean = false) {
if (sys.isBrowser && !sys.isMobile) {
if (isShow) {
// FullscreenPrefab.show();
} else {
// FullscreenPrefab.close();
}
}
}
public async sceneSwitch(name: string, showProgress: boolean = false) {
if (this.loadingSceneName === name) return
Logger.log(this, 'sceneSwitch==', name)
if (sys.isBrowser) {
// showProgress = true;
}
this.initFullScreenPrefab(false)
this.loadingSceneName = name
if (showProgress) {
await LoadingScenePrefab.show()
director.preloadScene(
name,
(completedCount: number, totalCount: number, item: any) => {
LoadingScenePrefab.updateLoading(completedCount, totalCount)
},
(error: Error, asset: SceneAsset) => {
if (error) {
Logger.warn(this, 'preloadScene=error', error.message)
CommonTips.showMsg('加载场景失败')
} else {
// director.getScene().destroy();//director.getScene().cleanup();
director.loadScene(name, this.loadSceneOK.bind(this))
}
},
)
} else {
// director.getScene().destroy();//director.getScene().cleanup();
director.loadScene(name, this.loadSceneOK.bind(this))
}
}
private loadSceneOK() {
LoadingScenePrefab.close()
this.initFullScreenPrefab(true)
this.currentSceneName = this.loadingSceneName
this.loadingSceneName = ''
Logger.log(this, 'scene load ok=', this.currentSceneName)
EventManager.instance.dispatchEvent(CommonEvent.Event_Scene_Switch)
}
public preloadScene(
sceneName: string,
onProgressCallback: any = null,
onLoadedCallback: any = null,
) {
director.preloadScene(sceneName, onProgressCallback, onLoadedCallback)
}
}
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()
private loadingSceneName: string
public currentSceneName: string
public initFullScreenPrefab(isShow: boolean = false) {
if (sys.isBrowser && !sys.isMobile) {
if (isShow) {
// FullscreenPrefab.show();
} else {
// FullscreenPrefab.close();
}
}
}
public async sceneSwitch(name: string, showProgress: boolean = false) {
if (this.loadingSceneName === name) return
Logger.log(this, 'sceneSwitch==', name)
if (sys.isBrowser) {
// showProgress = true;
}
this.initFullScreenPrefab(false)
this.loadingSceneName = name
if (showProgress) {
await LoadingScenePrefab.show()
director.preloadScene(
name,
(completedCount: number, totalCount: number, item: any) => {
LoadingScenePrefab.updateLoading(completedCount, totalCount)
},
(error: Error, asset: SceneAsset) => {
if (error) {
Logger.warn(this, 'preloadScene=error', error.message)
CommonTips.showMsg('加载场景失败')
} else {
// director.getScene().destroy();//director.getScene().cleanup();
director.loadScene(name, this.loadSceneOK.bind(this))
}
},
)
} else {
// director.getScene().destroy();//director.getScene().cleanup();
director.loadScene(name, this.loadSceneOK.bind(this))
}
}
private loadSceneOK() {
LoadingScenePrefab.close()
this.initFullScreenPrefab(true)
this.currentSceneName = this.loadingSceneName
this.loadingSceneName = ''
Logger.log(this, 'scene load ok=', this.currentSceneName)
EventManager.instance.dispatchEvent(CommonEvent.Event_Scene_Switch)
}
public preloadScene(
sceneName: string,
onProgressCallback: any = null,
onLoadedCallback: any = null,
) {
director.preloadScene(sceneName, onProgressCallback, onLoadedCallback)
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b636d5b8-723e-4576-861b-5cfc3151e46a",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b636d5b8-723e-4576-861b-5cfc3151e46a",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,12 +1,12 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "2a75ef29-1cd1-446e-95df-61bd54c8c217",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "2a75ef29-1cd1-446e-95df-61bd54c8c217",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -1,183 +1,183 @@
import { Component, Vec2, _decorator } from 'cc'
const { ccclass, property } = _decorator
export enum AstarGridType {
Hider = 0, // 不能走
Normal = 1, // 能走
End = 2, // 终点
}
@ccclass('Astar')
export class AstarGrid {
public x: number = 0
public y: number = 0
public f: number = 0
public g: number = 0
public h: number = 0
public type: number = 0
public parent: AstarGrid = null
}
export class Astar extends Component {
public mapW: number = 24 // 横向格子数量
public mapH: number = 13 // 纵向格子数量
public is8dir: boolean = false // 是否8方向寻路 //4方向:代表只能走上下左右 8方向:代表可以走上下左右,左上,右上,左下,右下
private openList: Array<AstarGrid> = []
private closeList: Array<AstarGrid> = []
private path: Array<AstarGrid> = []
private gridsList: Array<Array<AstarGrid>> = []
onLoad() {}
/**
* @param mapW 宽格子数
* @param mapH 高格子数
* @param is8dir 是8方向(上,下,左,右,左上,右上,左下,右下)寻路还是4方向(上,下,左,右)
*/
public init(mapW: number, mapH: number, is8dir: boolean = false) {
this.mapW = mapW
this.mapH = mapH
this.is8dir = is8dir
this.initMap()
}
/**
* 初始化map的格子
*/
private initMap() {
this.openList = []
this.closeList = []
this.path = []
// 初始化格子二维数组
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)
}
/**
* 创建一个格子到地图
* @param x
* @param y
* @param type
*/
private addGrid(x: number, y: number, type: number = AstarGridType.Hider) {
const grid = new AstarGrid()
grid.x = x
grid.y = y
grid.type = type
this.gridsList[x][y] = grid
}
/**
* 设置格子类型
* @param x
* @param y
* @param type
*/
public setGridType(x: number, y: number, type: number) {
const curGrid: AstarGrid = this.gridsList[x][y]
curGrid.type = type
}
/**
* 开始搜索路径
* @param startPos
* @param endPos
* @param callback
*/
public findPath(startPos: Vec2, endPos: Vec2, callback: Function = null) {
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) {
// 每次都取出f值最小的节点进行查找
curGrid = this.openList[0]
if (curGrid.type === AstarGridType.End) {
// Logger.log(this,"find path success.");
this.generatePath(curGrid)
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) {
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.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
)
continue
} else {
// 四方形行走
if (Math.abs(i) === Math.abs(j)) continue
}
// 计算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)
// 更新f值
this.gridsList[col][row].f = this.gridsList[col][row].g + this.gridsList[col][row].h
// 如果不在开放列表里则添加到开放列表里
if (!this.openList.includes(this.gridsList[col][row]))
this.openList.push(this.gridsList[col][row])
// // 重新按照f值排序升序排列)
}
}
}
}
// 遍历完四周节点后把当前节点加入关闭列表
this.closeList.push(curGrid)
// 从开放列表把当前节点移除
this.openList.splice(this.openList.indexOf(curGrid), 1)
if (this.openList.length <= 0) {
// Logger.log(this,"find path failed.");
this.path = []
if (callback) callback(this.path)
break
}
// 重新按照f值排序升序排列)
this.openList.sort((x, y) => {
return x.f - y.f
})
}
}
/**
* 生成路径
* @param grid
*/
private generatePath(grid: AstarGrid) {
this.path.push(grid)
while (grid.parent) {
grid = grid.parent
this.path.push(grid)
}
return this.path
}
onDestroy() {}
}
import { Component, Vec2, _decorator } from 'cc'
const { ccclass, property } = _decorator
export enum AstarGridType {
Hider = 0, // 不能走
Normal = 1, // 能走
End = 2, // 终点
}
@ccclass('Astar')
export class AstarGrid {
public x: number = 0
public y: number = 0
public f: number = 0
public g: number = 0
public h: number = 0
public type: number = 0
public parent: AstarGrid = null
}
export class Astar extends Component {
public mapW: number = 24 // 横向格子数量
public mapH: number = 13 // 纵向格子数量
public is8dir: boolean = false // 是否8方向寻路 //4方向:代表只能走上下左右 8方向:代表可以走上下左右,左上,右上,左下,右下
private openList: Array<AstarGrid> = []
private closeList: Array<AstarGrid> = []
private path: Array<AstarGrid> = []
private gridsList: Array<Array<AstarGrid>> = []
onLoad() {}
/**
* @param mapW 宽格子数
* @param mapH 高格子数
* @param is8dir 是8方向(上,下,左,右,左上,右上,左下,右下)寻路还是4方向(上,下,左,右)
*/
public init(mapW: number, mapH: number, is8dir: boolean = false) {
this.mapW = mapW
this.mapH = mapH
this.is8dir = is8dir
this.initMap()
}
/**
* 初始化map的格子
*/
private initMap() {
this.openList = []
this.closeList = []
this.path = []
// 初始化格子二维数组
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)
}
/**
* 创建一个格子到地图
* @param x
* @param y
* @param type
*/
private addGrid(x: number, y: number, type: number = AstarGridType.Hider) {
const grid = new AstarGrid()
grid.x = x
grid.y = y
grid.type = type
this.gridsList[x][y] = grid
}
/**
* 设置格子类型
* @param x
* @param y
* @param type
*/
public setGridType(x: number, y: number, type: number) {
const curGrid: AstarGrid = this.gridsList[x][y]
curGrid.type = type
}
/**
* 开始搜索路径
* @param startPos
* @param endPos
* @param callback
*/
public findPath(startPos: Vec2, endPos: Vec2, callback: Function = null) {
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) {
// 每次都取出f值最小的节点进行查找
curGrid = this.openList[0]
if (curGrid.type === AstarGridType.End) {
// Logger.log(this,"find path success.");
this.generatePath(curGrid)
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) {
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.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
)
continue
} else {
// 四方形行走
if (Math.abs(i) === Math.abs(j)) continue
}
// 计算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)
// 更新f值
this.gridsList[col][row].f = this.gridsList[col][row].g + this.gridsList[col][row].h
// 如果不在开放列表里则添加到开放列表里
if (!this.openList.includes(this.gridsList[col][row]))
this.openList.push(this.gridsList[col][row])
// // 重新按照f值排序升序排列)
}
}
}
}
// 遍历完四周节点后把当前节点加入关闭列表
this.closeList.push(curGrid)
// 从开放列表把当前节点移除
this.openList.splice(this.openList.indexOf(curGrid), 1)
if (this.openList.length <= 0) {
// Logger.log(this,"find path failed.");
this.path = []
if (callback) callback(this.path)
break
}
// 重新按照f值排序升序排列)
this.openList.sort((x, y) => {
return x.f - y.f
})
}
}
/**
* 生成路径
* @param grid
*/
private generatePath(grid: AstarGrid) {
this.path.push(grid)
while (grid.parent) {
grid = grid.parent
this.path.push(grid)
}
return this.path
}
onDestroy() {}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "2e03a7ea-58a9-4bbb-9dcc-660b093ea918",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "2e03a7ea-58a9-4bbb-9dcc-660b093ea918",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,12 +1,12 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "67ea5a4d-4210-4fdb-af71-bba5c66b368b",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "67ea5a4d-4210-4fdb-af71-bba5c66b368b",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -1,18 +1,18 @@
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() {
const randomIndex: number = RandomUtil.nextInt(1, 3)
MusicPrefab.play(`background_${randomIndex}`)
}
public static playFishDead(fishType: number) {
SoundPrefab.play(`deadfish_${fishType}`)
}
public static playFire() {
SoundPrefab.play('fire')
}
}
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() {
const randomIndex: number = RandomUtil.nextInt(1, 3)
MusicPrefab.play(`background_${randomIndex}`)
}
public static playFishDead(fishType: number) {
SoundPrefab.play(`deadfish_${fishType}`)
}
public static playFire() {
SoundPrefab.play('fire')
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5515ff19-e57f-4594-99b0-2e5439136f41",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5515ff19-e57f-4594-99b0-2e5439136f41",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,64 +1,64 @@
import { error, game } from 'cc'
import DarkLayer from '../../engine/uicomponent/DarkLayer'
import LoadingPrefab from '../../engine/uicomponent/LoadingPrefab'
import LoadingScenePrefab from '../../engine/uicomponent/LoadingScenePrefab'
import MusicPrefab from '../../engine/uicomponent/MusicPrefab'
import Progress from '../../engine/uicomponent/Progress'
import SoundPrefab from '../../engine/uicomponent/SoundPrefab'
import ResourcePrefab from '../prefab/ResourcePrefab'
import ShaderMaterialPrefab from '../prefab/ShaderMaterialPrefab'
export default class ResourcePreload {
public static instance: ResourcePreload = new ResourcePreload()
private isPreloaded: boolean = false
private totalNum: number = 6
private nowIndex: number = 0
private progress: Progress
public async preLoad(callback: Function, progress: Progress) {
if (this.isPreloaded) {
callback()
return
}
this.isPreloaded = true
this.progress = progress
if (this.progress)
progress.updateProgress(this.nowIndex, this.totalNum)
await LoadingPrefab.preLoad() // 1
this.finishOneItemLoad()
await DarkLayer.preLoad() // 2
this.finishOneItemLoad()
await MusicPrefab.preLoad() // 3
this.finishOneItemLoad()
await SoundPrefab.preLoad() // 4
this.finishOneItemLoad()
await ResourcePrefab.preLoad() // 5
this.finishOneItemLoad()
await ShaderMaterialPrefab.preLoad() // 6
this.finishOneItemLoad() //
callback()
}
private finishOneItemLoad() {
this.nowIndex++
if (this.progress)
this.progress.updateProgress(this.nowIndex, this.totalNum)
}
public restartGame() {
this.isPreloaded = false
// GameSocket.getInstance().closeSocket(false);
LoadingScenePrefab.clear()
LoadingPrefab.clear()
error('需要获取游戏里所有的AudioSource停止音乐')
// audioEngine.stopAll();
// VersionManager.instance.releaseAll();
MusicPrefab.destory()
SoundPrefab.destory()
ResourcePrefab.clear()
game.restart()
}
}
import { error, game } from 'cc'
import DarkLayer from '../../engine/uicomponent/DarkLayer'
import LoadingPrefab from '../../engine/uicomponent/LoadingPrefab'
import LoadingScenePrefab from '../../engine/uicomponent/LoadingScenePrefab'
import MusicPrefab from '../../engine/uicomponent/MusicPrefab'
import Progress from '../../engine/uicomponent/Progress'
import SoundPrefab from '../../engine/uicomponent/SoundPrefab'
import ResourcePrefab from '../prefab/ResourcePrefab'
import ShaderMaterialPrefab from '../prefab/ShaderMaterialPrefab'
export default class ResourcePreload {
public static instance: ResourcePreload = new ResourcePreload()
private isPreloaded: boolean = false
private totalNum: number = 6
private nowIndex: number = 0
private progress: Progress
public async preLoad(callback: Function, progress: Progress) {
if (this.isPreloaded) {
callback()
return
}
this.isPreloaded = true
this.progress = progress
if (this.progress)
progress.updateProgress(this.nowIndex, this.totalNum)
await LoadingPrefab.preLoad() // 1
this.finishOneItemLoad()
await DarkLayer.preLoad() // 2
this.finishOneItemLoad()
await MusicPrefab.preLoad() // 3
this.finishOneItemLoad()
await SoundPrefab.preLoad() // 4
this.finishOneItemLoad()
await ResourcePrefab.preLoad() // 5
this.finishOneItemLoad()
await ShaderMaterialPrefab.preLoad() // 6
this.finishOneItemLoad() //
callback()
}
private finishOneItemLoad() {
this.nowIndex++
if (this.progress)
this.progress.updateProgress(this.nowIndex, this.totalNum)
}
public restartGame() {
this.isPreloaded = false
// GameSocket.getInstance().closeSocket(false);
LoadingScenePrefab.clear()
LoadingPrefab.clear()
error('需要获取游戏里所有的AudioSource停止音乐')
// audioEngine.stopAll();
// VersionManager.instance.releaseAll();
MusicPrefab.destory()
SoundPrefab.destory()
ResourcePrefab.clear()
game.restart()
}
}

View File

@@ -1,11 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c49b722e-acd3-4d0f-9685-b773d596a5b3",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c49b722e-acd3-4d0f-9685-b773d596a5b3",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -1,7 +1,7 @@
import { Node, tween } from 'cc'
export default class TimeHelper {
public static exeNextFrame(node: Node, callback: Function) {
tween(node).delay(0.02).call(callback).start()
}
}
import { Node, tween } from 'cc'
export default class TimeHelper {
public static exeNextFrame(node: Node, callback: Function) {
tween(node).delay(0.02).call(callback).start()
}
}

View File

@@ -1,9 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "11277eab-4376-4199-9255-4d5c9d2b9e7e",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "11277eab-4376-4199-9255-4d5c9d2b9e7e",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,16 +1,16 @@
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
}
}
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
}
}

View File

@@ -1,9 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "e0962cbd-f5bd-4c15-b6d8-c403d02a854f",
"files": [],
"subMetas": {},
"userData": {}
}
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "e0962cbd-f5bd-4c15-b6d8-c403d02a854f",
"files": [],
"subMetas": {},
"userData": {}
}