
1赞
大佬们给的建议 
还行,发现一个bug 带血条的怪物,默认没血
这个是boss血条忘记初始化了,下个版本修正,感谢 
哈哈,找到一个bug ,伤害数值精度有问题
啥问题 
攻击精度确实有问题,我给它取个整 
你这个游戏通关给的金币太黑了吧,都不够用 
偷偷告诉你个外挂,点击设置界面里面的设置题标连续点击5次可以无限加金币 
无敌了又有点无聊了 
啊,这。。。。。
给点技术说明大家学习,
用引擎的刚体碰撞还是自己计算碰撞?
对象池?
丢斧头是手动算移动坐标?
说一些开发的坑给大家学习学习
其实没多少技术在里面的,我整理一波看看吧 
怪物用的碰撞逻辑如下,其实主要还是用到cocos自带的碰撞系统,只要分好组基本不会太卡!碰撞检测也比较呆,只是检测移动的方向有没有碰撞,有的话就停止移动。代码我就不一一介绍了,有兴趣的小伙伴可以自己看一下,技能方面比较简单就不介绍了 ,就是自己计算运动轨迹然后让物体运动就行了
update(dt) {
if (GameData.isPause != this.isPause) {
this.isPause = GameData.isPause
if (this.isPause) {
this.enemyAnim.pause()
} else {
this.enemyAnim.resume()
}
}
if (GameData.isPause) return
if (!this.target) return;
if (this._isDie) return;
let playerWorldPos = this.target.node.convertToWorldSpaceAR(cc.Vec2.ZERO)
let targetPos: cc.Vec2 = this.node.parent.convertToNodeSpaceAR(playerWorldPos);
let bulletPos: cc.Vec2 = this.node.getPosition();
let normalizeVec: cc.Vec2 = targetPos.subtract(bulletPos).normalize();
let isLeft = normalizeVec.x < 0
if (this.isLeft != isLeft) {
this.isLeft = isLeft
this._setDis()
}
if ((normalizeVec.x > 0 && !this._isRight) || (normalizeVec.x < 0 && !this._isLeft)) {
this.node.x += normalizeVec.x * this.moveSpeed * dt;
}
if ((normalizeVec.y > 0 && !this._isTop) || (normalizeVec.y < 0 && !this._isDown)) {
this.node.y += normalizeVec.y * this.moveSpeed * dt;
}
if (GameData.distance(this.node.convertToWorldSpaceAR(cc.Vec2.ZERO), playerWorldPos) >= 3000) {
this._isDie = true
EnemyCtrl.getInstance().destroyEnemy(this)
this.sendEvent(GameEvent.PustEnemyNode, this)
}
if (this._isRight) {
this._rightCD -= dt
if (this._rightCD < 0) {
this._isRight = false
}
}
if (this._isLeft) {
this._leftCD -= dt
if (this._leftCD < 0) {
this._isLeft = false
}
}
if (this._isTop) {
this._topCD -= dt
if (this._topCD < 0) {
this._isTop = false
}
}
if (this._isDown) {
this._downCD -= dt
if (this._downCD < 0) {
this._isDown = false
}
}
}
onCollisionStay(other, self) {
if (GameData.isPause) return
if (this._isDie) return
let player: PlayerBase = other.node.getComponent(PlayerBase)
if (player && this._isCanAttack) {
this._isCanAttack = false
player.hit(this._enemyInfo.attackNum)
this.scheduleOnce(() => {
this._isCanAttack = true
}, this._enemyInfo.attackInterval)
}
let enemy: Enemy = other.node.getComponent(Enemy)
if (enemy) {
let targetPos = this.target.node.convertToWorldSpaceAR(cc.v2(0, 0))
let myPos = this.node.convertToWorldSpaceAR(cc.v2(0, 0))
let otherPos = enemy.node.convertToWorldSpaceAR(cc.v2(0, 0))
let myDis = GameData.distance(myPos, targetPos)
let otherDis = GameData.distance(otherPos, targetPos)
if (otherDis < myDis) {
if (Math.abs(myPos.x - otherPos.x) > Math.abs(myPos.y - otherPos.y)) {
//碰撞物在左右边
if (myPos.x - otherPos.x < 0) {
//在右边
this._isRight = true
this._rightCD = this._pengCD
} else {
//在左边
this._isLeft = true
this._leftCD = this._pengCD
}
} else {
//碰撞物在上下边
if (myPos.y - otherPos.y < 0) {
//在上边
this._isTop = true
this._topCD = this._pengCD
} else {
//在下边
this._isDown = true
this._downCD = this._pengCD
}
}
}
}
}
点赞!加油!
