This commit is contained in:
2024-04-16 23:03:54 +08:00
commit 54580cc1b2
723 changed files with 103745 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import { _decorator, Component, Tween, tween } from 'cc'
const { ccclass, property } = _decorator
import { FishPathInfo } from '../../script/game/config/FishPathInfo'
import FishManager from '../../script/game/manager/FishManager'
import { FishInfo } from '../../script/game/config/FishInfo'
@ccclass('FishBase')
export default class FishBase extends Component {
public fishInfo: FishInfo
public fishType: number = 1
public blood: number = 1
public fishPathInfo: FishPathInfo
public isDead: boolean
onLoad() {}
start() {}
public playDeadMv() {
this.isDead = true
this.scheduleOnce(() => {
FishManager.instance.killFish(this)
}, 1.5)
tween(this.node)
.repeatForever(tween().by(0.6, { angle: -360 }))
.start()
}
onDisable() {
//this.node.stopAllActions();
Tween.stopAllByTarget(this.node)
this.unscheduleAllCallbacks()
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ce1d849d-a18c-4132-807c-2cf4d6e9bea5",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,85 @@
import {
_decorator,
Component,
Vec2,
Node,
Vec3,
error,
Collider2D,
Contact2DType,
IPhysics2DContact,
} from 'cc'
const { ccclass, property } = _decorator
import FishBase from './FishBase'
import FishNetManager from '../../script/game/manager/FishNetManager'
import BulletManager from '../../script/game/manager/BulletManager'
@ccclass('FishBulletBase')
export default class FishBulletBase extends Component {
public bulletType: number = 0
public targetP: Vec2
public _cacheVec2: Vec2 = new Vec2()
public _cacheVec3: Vec3 = new Vec3()
private _collider: Collider2D
onLoad() {
this._collider = this.getComponent(Collider2D)
this._collider.sensor = true
//this._collider.on(Contact2DType.PRE_SOLVE, this.onBeginContact, this);
// PhysicsSystem2D.instance.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
start() {}
onEnable() {
this._collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this)
//this._collider.on(Contact2DType.END_CONTACT, this.onBeginContact, this);
}
onDisable() {
this._collider.off(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this)
//this._collider.off(Contact2DType.END_CONTACT, this.onBeginContact, this);
}
onBeginContact(
selfCollider: Collider2D,
other: Collider2D,
contact: IPhysics2DContact | null
) {
// 只在两个碰撞体开始接触时被调用一次
if (other) {
let fish: FishBase = other.getComponent(FishBase)
if (fish && !fish.isDead) {
this.node.getPosition(this._cacheVec3)
this._cacheVec2.x = this._cacheVec3.x
this._cacheVec2.y = this._cacheVec3.y
FishNetManager.instance.addFishNet(this.bulletType, this._cacheVec2)
BulletManager.instance.killBullet(this)
fish.blood -= this.bulletType + 1
// fish.blood -= 100
if (fish.blood <= 0) {
fish.playDeadMv()
}
}
}
}
//v2.4代码
onCollisionEnter(other: Node, self: Node) {
error('onCollisionEnter=FishBulletBase=', other, self)
if (other) {
let fish: FishBase = other.getComponent(FishBase)
if (fish && !fish.isDead) {
this.node.getPosition(this._cacheVec3)
this._cacheVec2.x = this._cacheVec3.x
this._cacheVec2.y = this._cacheVec3.y
FishNetManager.instance.addFishNet(this.bulletType, this._cacheVec2)
BulletManager.instance.killBullet(this)
fish.blood -= this.bulletType + 1
// fish.blood -= 100
if (fish.blood <= 0) {
fish.playDeadMv()
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "80535cc5-82f1-4c39-a482-415d3c126891",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,162 @@
import {
_decorator,
Component,
CCInteger,
CCFloat,
Vec2,
Animation,
Vec3,
} from 'cc'
const { ccclass, property } = _decorator
import FishBase from './FishBase'
import MathUtils from '../../script/engine/utils/MathUtils'
import { Logger } from '../../script/engine/utils/Logger'
import TimeHelper from '../../script/game/utils/TimeHelper'
@ccclass('FishMover')
export default class FishMover extends Component {
// //鱼类型
@property({ type: CCInteger })
public fishType: number = 1
// //鱼移动速度
@property({ type: CCFloat })
public speed: number = 3
// //下个位置移动点
private targetMoveIndex: number = 0
// //鱼移动位置
public movePList: Array<Vec2> = []
// //贝萨尔曲线
public bezierPList: Array<Vec2> = []
public isMoving: boolean = false
private minSpeed: number = 0.1
private moveCount: number = 1
private totalTimes: number = 60 * 2
private _vec3Cahce: Vec3 = new Vec3()
public startMove() {
this.targetMoveIndex = 0
this.isMoving = true
//this.node.getComponent(Animation).play()//v3 当前帧 不能播放
TimeHelper.exeNextFrame(this.node, () =>
this.node.getComponent(Animation).play()
)
}
update(dt) {
// this.moveFish();
this.checkMoveBezier()
}
private checkMoveBezier() {
if (this.isMoving && !this.getComponent(FishBase).isDead) {
this.moveCount++
if (this.moveCount >= this.totalTimes) {
this.moveCount = this.totalTimes
}
this.moveBezier()
}
}
public moveBezier() {
// [warn] [[-632,-230],[-444,-117],[-264,-242]]
// let p0: cc.Vec2 = cc.v2(-632, -230)
// let p1: cc.Vec2 = cc.v2(-444, -117)
// let p2: cc.Vec2 = cc.v2(-264, -242)
if (this.bezierPList.length > this.targetMoveIndex + 2) {
let p0: Vec2 = this.bezierPList[this.targetMoveIndex]
let p1: Vec2 = this.bezierPList[this.targetMoveIndex + 1]
let p2: Vec2 = this.bezierPList[this.targetMoveIndex + 2]
let t: number = this.moveCount / this.totalTimes
let mx: number =
Math.pow(1 - t, 2) * p0.x +
2 * t * (1 - t) * p1.x +
Math.pow(t, 2) * p2.x
let my: number =
Math.pow(1 - t, 2) * p0.y +
2 * t * (1 - t) * p1.y +
Math.pow(t, 2) * p2.y
this.node.getPosition(this._vec3Cahce)
let rad: number = MathUtils.p2pRad(
new Vec2(this._vec3Cahce.x, this._vec3Cahce.y),
new Vec2(mx, my)
)
let rot111: number = MathUtils.radiansToDegrees(rad)
let rot: number = MathUtils.rotation2Fish(rot111)
if (this.fishType == 7 || this.fishType == 27 || this.fishType == 29) {
if (rot > 90 || rot < -90) {
this.node.getScale(this._vec3Cahce)
if (this._vec3Cahce.x > 0) {
this._vec3Cahce.x = -1 * this._vec3Cahce.x
this.node.setScale(this._vec3Cahce)
}
} else {
this.node.getScale(this._vec3Cahce)
if (this._vec3Cahce.x < 0) {
this._vec3Cahce.x = -1 * this._vec3Cahce.x
this.node.setScale(this._vec3Cahce)
}
}
} else if (
this.fishType == 9 ||
this.fishType == 10 ||
this.fishType == 21 ||
this.fishType == 28
) {
} else {
// this.node.rotation = rot; //过时
this.node.angle = -rot
}
// Logger.log("moveBezier====", rad, rot111, this.fishType, rot)
let moveTimes: number = Math.round(this.speed / this.minSpeed)
for (let i = 0; i < moveTimes; i++) {
let speedX: number = this.minSpeed * Math.cos(rad)
let speedY: number = this.minSpeed * Math.sin(rad)
this.node.getPosition(this._vec3Cahce)
this._vec3Cahce.x += speedX
this._vec3Cahce.y += speedY
this.node.setPosition(this._vec3Cahce)
if (
MathUtils.distance(this._vec3Cahce.x, this._vec3Cahce.y, mx, my) <=
this.minSpeed
) {
this.node.setPosition(mx, my)
break
}
if (
MathUtils.distance(
this._vec3Cahce.x,
this._vec3Cahce.y,
p2.x,
p2.y
) <=
this.minSpeed * 2
) {
this.node.setPosition(p2.x, p2.y)
this.targetMoveIndex += 2
this.moveCount = 0
break
}
}
} else {
this.isMoving = false
}
}
onDisable() {
this.isMoving = false
}
public exportBezierConfig() {
Logger.warn('exportBezierConfig=')
let tempConfig: Array<Array<number>> = []
for (let i = 0; i < this.bezierPList.length; i++) {
tempConfig[i] = []
tempConfig[i].push(Math.floor(this.bezierPList[i].x))
tempConfig[i].push(Math.floor(this.bezierPList[i].y))
}
Logger.warn('fishtype', this.fishType)
Logger.warn('speed', this.speed)
Logger.warn('scale', this.node.scale)
Logger.warn(JSON.stringify(tempConfig))
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "bcf7f0c8-2438-4a9d-ac46-3e36b66274a3",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,27 @@
import { _decorator, Component, Tween, tween, Vec3, Vec2 } from 'cc'
const { ccclass, property } = _decorator
import FishNetManager from '../../script/game/manager/FishNetManager'
@ccclass('FishNetBase')
export default class FishNetBase extends Component {
public netType: number = 0
private tween: Tween<any>
private static vec3: Vec3 = new Vec3(2, 2, 1)
public playMv() {
this.node.setScale(Vec3.ZERO)
this.tween = tween(this.node)
.to(0.2, { scale: FishNetBase.vec3 })
.delay(0.3)
.call(() => {
FishNetManager.instance.destroyFishNet(this)
})
.start()
}
onDestroy() {
if (this.tween) {
this.tween.stop()
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "f6fc67f9-e173-4b95-a947-653698fe49b6",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,67 @@
import { _decorator, Slider, Node, Canvas, instantiate, director } from 'cc'
const { ccclass, property } = _decorator
import EventManager from '../../script/engine/utils/EventManager'
import DialogBase from '../../script/engine/uicomponent/DialogBase'
import MusicPrefab from '../../script/engine/uicomponent/MusicPrefab'
import SoundPrefab from '../../script/engine/uicomponent/SoundPrefab'
import PrefabLoader from '../../script/engine/utils/PrefabLoader'
import { GameConfig } from '../../script/game/config/GameConfig'
@ccclass('FishSetting')
export default class FishSetting extends DialogBase {
@property({ type: Slider })
private musicSlider: Slider | null = null
@property({ type: Slider })
private soundSlider: Slider | null = null
onLoadMe() {
EventManager.instance.addSliderEvent(
this.node,
this.musicSlider.node,
'onMusicSlider',
0
)
EventManager.instance.addSliderEvent(
this.node,
this.soundSlider.node,
'onSoundSlider',
0
)
this.refresh()
}
private onMusicSlider(slider: Slider, customEventData) {
let percent: number = Number(slider.progress.toFixed(3))
// let maxMoney: number = Math.max(UserInfoModel.userScore - 10, 0)
// this.nowExchangeNum = Math.floor(maxMoney * this.nowPercent);
// this.refresh();
MusicPrefab.changeVolumn(percent)
this.refresh()
}
private onSoundSlider(slider: Slider, customEventData) {
let percent: number = Number(slider.progress.toFixed(3))
SoundPrefab.changeVolumn(percent)
this.refresh()
}
private refresh() {
this.musicSlider.progress = MusicPrefab.musicVolumn
this.soundSlider.progress = SoundPrefab.soundVolumn
}
public static show(parentNode: Node = null) {
PrefabLoader.loadPrefab(
GameConfig.GameName + '/' + 'game/dialog/FishSetting',
(loadedResource) => {
if (!parentNode) {
parentNode = DialogBase.GetRootCanvas()
}
let node: Node = instantiate(loadedResource)
parentNode.addChild(node)
node.setPosition(0, 0)
}
)
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ce79e4dd-1fe1-45fd-b29c-fc8f0773bfa1",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,106 @@
import {
_decorator,
Component,
Label,
Animation,
Node,
Vec2,
Tween,
tween,
Vec3,
} from 'cc'
const { ccclass, property } = _decorator
import FishSetting from './FishSetting'
import FishManager from '../../script/game/manager/FishManager'
import CannonManager from '../../script/game/manager/CannonManager'
@ccclass('FishUI')
export default class FishUI extends Component {
public static instance: FishUI = null
@property({ type: Label })
private dzScore: Label | null = null
@property({ type: Label })
private jfScore: Label | null = null
@property({ type: Animation })
private clickEffect: Animation | null = null
@property({ type: Node })
private waveEffect: Node | null = null
// 豆子
public dz_score: number = 100
// 积分
public jf_score: number = 0
private _vec3Cache: Vec3
onLoad() {
FishUI.instance = this
this._vec3Cache = new Vec3()
this.clickEffect.node.active = false
this.waveEffect.active = false
this.dzScore = this.node
.getChildByName('dzScore')
.getComponent(Label) as Label
this.jfScore = this.node
.getChildByName('jfScore')
.getComponent(Label) as Label
}
start() {
this.refreshScore()
// setTimeout(()=>{
// this.playWaveEffect();
// }, 5000)
}
public playClickEffect(p: Vec2) {
this._vec3Cache.x = p.x
this._vec3Cache.y = p.y
this._vec3Cache.z = 0
this.clickEffect.node.setPosition(this._vec3Cache)
this.clickEffect.node.active = true
this.clickEffect.play()
}
public playWaveEffect() {
this.waveEffect.active = true
this.waveEffect.setPosition(1292.703, 0)
FishManager.instance.playFishMap()
tween(this.waveEffect)
.to(2, { position: new Vec3(-1319.969, 0, 0) })
.call(() => {
this.waveEffect.active = false
FishManager.instance.startFishMap()
})
.start()
}
private onClickPre() {
if (CannonManager.instance.cannonType > 1) {
CannonManager.instance.cannonType--
CannonManager.instance.refreshCannon()
}
}
private onClickNext() {
if (CannonManager.instance.cannonType < 7) {
CannonManager.instance.cannonType++
CannonManager.instance.refreshCannon()
}
}
public refreshScore() {
this.dzScore.string = this.dz_score + ''
this.jfScore.string = this.jf_score + ''
}
private onClickSetting() {
FishSetting.show()
}
onDestroy() {
FishUI.instance = null
this.unscheduleAllCallbacks()
Tween.stopAllByTarget(this.node)
//this.node.stopAllActions();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "4760473c-e783-4c94-8bdb-f5b91f23034a",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,90 @@
import {
_decorator,
ScrollView,
Prefab,
Node,
instantiate,
Label,
Vec3,
Animation,
} from 'cc'
const { ccclass, property } = _decorator
import FishBase from './FishBase'
import DialogBase from '../../script/engine/uicomponent/DialogBase'
import { FishConfig } from '../../script/game/config/FishConfig'
import { FishInfo } from '../../script/game/config/FishInfo'
import FishManager from '../../script/game/manager/FishManager'
import PrefabLoader from '../../script/engine/utils/PrefabLoader'
import { GameConfig } from '../../script/game/config/GameConfig'
import TimeHelper from '../../script/game/utils/TimeHelper'
@ccclass('FishWiki')
export default class FishWiki extends DialogBase {
@property({ type: ScrollView })
private scrollView: ScrollView | null = null
@property({ type: Prefab })
private wikiItemPrefab: Prefab | null = null
private _vec3Cache: Vec3
onLoadMe() {
this._vec3Cache = new Vec3(1, 1, 1)
this.init()
}
private init() {
this.scrollView.content.removeAllChildren()
this.initOne(0)
}
private initOne(index: number) {
if (index < FishConfig.config.length) {
let itemNode: Node = instantiate(this.wikiItemPrefab)
this.scrollView.content.addChild(itemNode)
let fishInfo: FishInfo = FishConfig.config[index]
let txtName: Label = itemNode
.getChildByName('txtName')
.getComponent(Label)
txtName.string = fishInfo.name
let txtLife: Label = itemNode
.getChildByName('txtLife')
.getComponent(Label)
txtLife.string = 'life:' + fishInfo.blood + ''
let view: Node = itemNode.getChildByName('view')
view.removeAllChildren()
let fish: FishBase = FishManager.instance.createFishByType(
fishInfo.fishType
)
view.addChild(fish.node)
fish.node.setPosition(0, 0)
//缩放有bug
//Vec3.multiplyScalar(this._vec3Cache, this._vec3Cache, fishInfo.wikiScale);
//fish.node.setScale(this._vec3Cache);
//fish.node.getComponent(Animation).play(); //v3 当前帧 不能播放
TimeHelper.exeNextFrame(this.node, () =>
fish.node.getComponent(Animation).play()
)
this.scheduleOnce(() => {
this.initOne(index + 1)
}, 0.05)
}
}
public static show(parentNode: Node = null) {
PrefabLoader.loadPrefab(
GameConfig.GameName + '/' + 'game/dialog/FishWiki',
(loadedResource) => {
if (!parentNode) {
parentNode = DialogBase.GetRootCanvas()
}
let node: Node = instantiate(loadedResource)
parentNode.addChild(node)
node.setPosition(0, 0)
}
)
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "1d85a467-57af-40ac-9d0b-4f12b38a9ea5",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}