课程演示
游戏体验
课程链接
开发背景
游戏介绍
- 引擎版本:Cocos Creator 3.6.1
- 编程语言:TypeScript
水果消消乐是一款经典三消游戏,玩法简单有趣,类似火爆全网的羊了个羊。
底部出现三个相同的水果,即可消除。
移出道具:移出三个水果并把它们堆放在旁边
撤回道具:撤回上一次点击水果并把它放到原位置
洗牌道具:随机打乱未使用的所有水果。
判定过关:把所有水果都消除完,即过关。
判定失败:底部水果数量超过7个(包含7个),即失败。
关卡编辑
微信广告集成
接入了微信流量主的Banner广告、插屏广告、激励视频广告还有微信分享等
在代码中简单修改广告id即可
this.idBannerAD = 'xxxxxx'//banner广告位id
this.idChaPingAD = 'xxxxxx'//插屏广告位id
this.idJiLiShiPinAD = 'xxxxxx'//激励视频广告位id
主要代码介绍
- 判断块与块之间叠加显示
let children = this.parentBlocks.children
for (let i = 0; i < children.length; i++) {
let ts_block_1 = children[i].getComponent(block)
let rect_1 = ts_block_1.getBoundingBox_pz()
ts_block_1.setTouch(true)
for (let j = i+1; j < children.length; j++) {
let ts_block_2 = children[j].getComponent(block)
let rect_2 = ts_block_2.getBoundingBox_pz()
if (rect_1.intersects(rect_2)) {
ts_block_1.setTouch(false)
break
}
}
}
- 判断是否可消除
let ts_block = node_block.getComponent(block)
ts_block.isMoving = false
let num_di_block = ts_block.numDi
let children = this.parentBlocksDi.children
let arr_blockType = []
for (let i = 0; i < children.length; i++) {
let ts_block_2 = children[i].getComponent(block)
if (ts_block.blockType == ts_block_2.blockType && ts_block_2.isXiaoChu == false) {
arr_blockType.push(children[i])
}
}
let is_xiaoChu = false
if (arr_blockType.length == 3) {
for (let i = arr_blockType.length-1; i >= 0; i--) {
arr_blockType[i].getComponent(block).isXiaoChu = true
tween(arr_blockType[i])
.delay(0.05)
.to(0.08,{scale:new Vec3(0,0,)})
.removeSelf()
.start()
//arr_blockType[i].removeFromParent()
is_xiaoChu = true
}
}
- 判定游戏失败
let num_xiaoChu_geShu = 0
let children_2 = this.parentBlocksDi.children
for (let i = 0; i < children_2.length; i++) {
let ts_block = children_2[i].getComponent(block)
if (ts_block.isXiaoChu) {
num_xiaoChu_geShu++
}
}
if (children_2.length - num_xiaoChu_geShu >= 7) {
this.gameType = -1
this.audioSource.playOneShot(this.arrAudio[2],1)
console.log('游戏失败');
}
- 判定游戏通关
let children_1 = this.parentBlocks.children标签:微信,ts,length,小游戏,let,复刻,blockType,children,block From: https://blog.51cto.com/u_10537721/5787653
if(children_1.length == 0){
this.gameType = 1
this.audioSource.playOneShot(this.arrAudio[3],1)
console.log('游戏通关');
this.numLevel++
this.scheduleOnce(function(){
this.init()
},1)
}