0.0.9 • Published 3 years ago
gm-game-melon v0.0.9
gm-game-melon
合成大西瓜
安装
npm install gm-game-melon
使用
必须开启 "enableSkia": "true"
- json
{
"usingComponents": {
"game-melon": "gm-game-melon/melon"
}
}
- js
Page({
data: {
gameshow: true,
gameSource: {
gravityX: 0,//x轴重力(小于0:x轴偏左)
gravityY: 100,//y轴重力(小于0:Y轴偏上)
fixDef: {
density: 0.000000001,//密度
friction: 1.0,//摩擦力(0-1)0:没有摩擦力
restitution: 0.2,//0.2;//回复力(0-1)0:不会反弹
fixedRotation: true,//是否禁止刚体旋转 true:允许旋转
},
hechengInterval: 500,//两个合成间隔时间 (毫秒)
world: [
// { src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01EkAhl51FJvdGaiIy3_!!1080040467.png", direction: "bottom", width: 750, height: 10 },
// { src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01EkAhl51FJvdGaiIy3_!!1080040467.png", direction: "top", width: 750, height: 10 },
// { src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01RVyIAg1FJvd81pxEe_!!1080040467.png", direction: "left", width: 8, height: 1716 },
// { src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01RVyIAg1FJvd81pxEe_!!1080040467.png", direction: "right", width: 8, height: 1716 }
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN011tf1yN1FJvbf2Giw2_!!1080040467.png", direction: "bottom", show: true, width: 750, height: 10 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN011tf1yN1FJvbf2Giw2_!!1080040467.png", direction: "top", show: true, width: 750, height: 10 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01289gtt1FJvbbeuLLr_!!1080040467.png", direction: "left", show: true, width: 8, height: 1716 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01289gtt1FJvbbeuLLr_!!1080040467.png", direction: "right", show: true, width: 8, height: 1716 }
],
paddingLeft: 50,
paddingRight: 50,
curDefIdx: 0,//最大顶部默认球下标,相对imgArr数组
maxDefIdx: 3,//最大顶部默认球下标
defCenterY: 200,//顶部生成元素Y轴中心坐标,默认Y轴中心点
alignType: "bottom",//相对defCenterY位置对其方式 默认center:中心点对其 top:顶部对齐 bottom:底部对齐
lifeLine: 400,//生命线,超过了就结束游戏
warnHeight: 100,//危险区域,距离结束线距离,在此范围内,就回调危险提示方法
imgArr: [
//球形
// { type: 0, shape: "circle", val: 5, src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01UL03sF1FJvd8YzHiG_!!1080040467.png", width: 750, height: 50, scoreImg: { src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01SJk6cq1FJvdDwlMQr_!!1080040467.png", width: 57, height: 29 } },
{ type: 0, shape: "circle", val: 5, src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01xlMYpZ1FJvdDoaMjf_!!1080040467.png", audioName: "default", width: 41, height: 41, scoreImg: { src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01SJk6cq1FJvdDwlMQr_!!1080040467.png", width: 57, height: 29, centerX: true, y: 500, showTime: 1000 } },
{ type: 1, shape: "circle", val: 10, src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01YgLY2Q1FJvdCwQITP_!!1080040467.png", audioName: "default", width: 67, height: 67, scoreImg: { src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01mzt20k1FJvdETTEDf_!!1080040467.png", width: 89, height: 29, centerX: true, y: 500, showTime: 1000 } },
{ type: 2, shape: "circle", val: 15, src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01D83Syx1FJvdDobuLO_!!1080040467.png", audioName: "default", width: 104, height: 104, scoreImg: { src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01Mj0EIq1FJvd85DyGd_!!1080040467.png", width: 89, height: 29, centerX: true, y: 500, showTime: 1000 } },
{ type: 3, shape: "circle", val: 20, src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01FbABGP1FJvd8h2RVa_!!1080040467.png", audioName: "default", width: 138, height: 138, scoreImg: { src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01k61HUv1FJvdAxyfM3_!!1080040467.png", width: 89, height: 29, centerX: true, y: 500, showTime: 1000 } },
{ type: 4, shape: "circle", val: 25, src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01zOo7So1FJvd8wZchf_!!1080040467.png", audioName: "default", width: 189, height: 189, scoreImg: { src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01inRqdi1FJvd5kAIkM_!!1080040467.png", width: 89, height: 29, centerX: true, y: 500, showTime: 1000 } },
{ type: 5, shape: "circle", val: 30, src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01Oh77NE1FJvdCwQlaJ_!!1080040467.png", audioName: "default", width: 236, height: 236, scoreImg: { src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01n7CzQz1FJvd3rabsk_!!1080040467.png", width: 89, height: 29, centerX: true, y: 500, showTime: 1000 } },
{ type: 6, shape: "circle", val: 100, src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01gpvchE1FJvd8h2iAf_!!1080040467.png", audioName: "default", width: 292, height: 293, scoreImg: { src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01tnc6gS1FJvdETDmkK_!!1080040467.png", width: 171, height: 49, centerX: true, y: 500, showTime: 1000 } },
{ type: 7, shape: "circle", val: 0, src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01AHBy5i1FJvcyyWdLu_!!1080040467.png", width: 360, height: 361, centerX: true, y: 500, showTime: 1000 },
],
audioObj: {
default: { audioSrc: "http://isv-vod.alibabausercontent.com/RGjZJMdpNgKGVQeEyw8/6cnFJEwIj5AGWCcBlTf?auth_key=1616480580-0-0-d0561ac34c6e55e1502b94b0bf20216f&w=0&h=0&e=sd&t=212b035516162213804197727e85ac" },//默认音效
},
},
},
onLoad() {
},
onRef(game) {
this.gameComponent = game;
},
/**游戏初始化完成*/
onInitDone() {
console.log("initDone...")
my.alert({
content: "游戏初始化完成"
})
},
/**游戏开始 */
beginFun() {
if (!!this.gameComponent) {
this.gameComponent.start();
}
},
resetFun() {
if (!!this.gameComponent) {
this.gameComponent.reset();
}
},
drupFun() {
if (!!this.gameComponent) {
this.gameComponent.drup();
}
},
onDrupCallBack(img) {
// 敲除元素成功后回调
my.alert({ content: "敲除成功" })
},
refreshFun() {
// 刷新即将掉落的元素
if (!!this.gameComponent) {
this.gameComponent.refreshFun();
}
},
onRefreshCallBack() {
// 刷新回调函数
my.alert({ content: "刷新成功" })
},
onWarnCallBack() {
// 进入危险区域回调方法
my.alert({ content: "危险了,快使用道具解除危险" })
},
/**游戏结束 */
onFinish(item) {
// item.totalScore 总分数
// item.maxObj 最大合成对象 对应imgArr里面的元素
let type;
try {
type = item.maxObj.type;
} catch (e) { }
my.alert({
content: "游戏结束:" + item.totalScore + "maxType:" + type
})
},
/**游戏切换 */
switchFun() {
this.setData({ gameshow: !this.data.gameshow });
},
onUpdate(item) {
/* my.alert({
content: item.totalScore
}); */
// totalScore:总分数
// item.img:消除图片对象 对应imgArr里面元素
this.setData({
totalScore: item.totalScore,
img: item.img,
})
},
});
- xaml
<!--
onInitDone:游戏组件初始化完成
onUpdate:游戏合成回调
onFinish:游戏结束回调
onDrupCallBack:敲除技能回调
onRefreshCallBack:刷新技能回调
onWarnCallBack:进入危险区域回调
-->
<gm-game-melon gameSource="{{gameSource}}" onInitDone="onInitDone" onUpdate="onUpdate" onFinish="onFinish" onDrupCallBack="onDrupCallBack" onRefreshCallBack="onRefreshCallBack" onWarnCallBack="onWarnCallBack" onRef="onRef" />