npm install gm-game-shoot
必须开启 "enableSkia": "true"
{
"usingComponents": {
"game-shoot": "gm-game-shoot/shoot"
}
}
Page({
data: {
renderGame: true,
gameSource: {
speedRang: {
x: { min: "0.1", max: "3" },
y: { min: "0.1", max: "3" }
},
noVibrateShort: false,//射击中了是否震动 false:震动 true:不震动
scaleRang: { min: "0.2", max: "0.8" },
energyNum: 4,//可击中元素个数
playerInfo: {
src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01w8HHJe1FJvdT6EFjl_!!1080040467.png",
width: 88,
height: 88,
defX: 750 / 2,
defY: 80
},
energyArr: [
{
src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01UigC8o1FJvdOfmOBX_!!1080040467.png", width: 179, height: 179, probability: 1,
score: [
{
min: 0,//最小百分比
max: 10,//最大百分比
score: 10,//分数
type: "PERFECT",//类型
},
{
min: 10,//最小百分比
max: 70,//最大百分比
score: 6,//分数
type: "AWESOME",//类型
},
{
min: 70,//最小百分比
max: 100,//最大百分比
score: 4,//分数
type: "GOOD",//类型
}
],
activeSpeed: 1,//击中后动画速度
// 击中后动画
activeImg: [
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN013nYGZr1FJvbVknqhW_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01b1Giqv1FJvbT7mDSO_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01kbTi7q1FJvbYxQvfk_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01uNJkpe1FJvbW6T4eb_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01wRnPov1FJvbShYknv_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01C9HMuO1FJvbKbfTnr_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01F3MLkn1FJvbSz7rs6_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01kCsizV1FJvbT7pIm3_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01xc3pKZ1FJvbTwbJ8r_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01SIzGJR1FJvbVkpKCi_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01oziFtx1FJvbQUQuWH_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01GJ31jG1FJvbX2h65s_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01SmQihp1FJvbW6R3xQ_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01myfalX1FJvbKbe0LV_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01Tog8xb1FJvbQz65j8_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN015zybq21FJvbW6TH9O_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN019VDqb91FJvbPJbaCP_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01jHjNCI1FJvbQz3oMQ_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01HaQOQp1FJvbQz4DIP_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01kPgCCM1FJvbV34ciT_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01KE7M7e1FJvbYZ7guv_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01XnI0b41FJvbYZ69HF_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01LQiGzI1FJvbKbd8HT_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01X5LykS1FJvbYxQzrT_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01VCrvhF1FJvbQz4PnE_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01C2fpKr1FJvbSz7GUF_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01uyaCl61FJvbTl5jd8_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN014QPTkf1FJvbVkpOPK_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01eaG2SD1FJvbW6T8r7_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN011delXC1FJvbPJaF3u_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01sBklRX1FJvbV35E9v_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01y75HZD1FJvbPJamLL_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01XEmV3c1FJvbXgrzFd_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01DKOf0g1FJvbYZ79fz_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01C1CeZG1FJvbKbdCSP_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01K7elMs1FJvbW6SflY_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01wGqtGq1FJvbTwcW2P_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01FdV3Cl1FJvbTl8gZb_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01VBL4dI1FJvbT7qynS_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01LpF1nj1FJvbTwZy3r_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01hoMgp91FJvbSz7Sye_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01nnv1VT1FJvbSz7KfC_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01mXgKgN1FJvbQz69vz_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01t1a9DM1FJvbT7pEg1_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01oDLQWc1FJvbSz9gDz_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01ThYl2r1FJvbT7qe10_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01Csfbs11FJvbYxRnly_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01xMpJ5a1FJvbXgsj0t_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01aqYw5n1FJvbKbgDcQ_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01qx3voA1FJvbTl7XvP_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01P9PnMx1FJvbKbgp3C_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01WqSFvu1FJvbV35tlM_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01ObgBCo1FJvbPJaqXp_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN019CfOs71FJvbT7oEIy_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN019p02f51FJvbShbZX0_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN012ZnSdO1FJvbKbgLwv_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01jxcbOt1FJvbYxQraa_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01Uuhj7O1FJvbVksThO_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN018jN2Ry1FJvbVkswo7_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01maIhHj1FJvbVkpf6E_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01Ybm7Bz1FJvbShbyUs_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01dfpG4p1FJvbTl78y3_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01rPvxFk1FJvbQURJXa_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01sa9eyx1FJvbTl7oZf_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01GaNDTs1FJvbYZ6cSf_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01jfY4mw1FJvbShdJh2_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01Kx8Yho1FJvbShdeU6_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01FNPPXX1FJvbSz7COo_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01ZbMfoe1FJvbSz6nS9_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01XU0mfn1FJvbYZ6Pyp_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01FSiZ681FJvbQz5DlQ_!!1080040467.png", width: 630, height: 580 },
{ src: "https://img.alicdn.com/imgextra/i3/1080040467/O1CN010WS1IY1FJvbTl9pJB_!!1080040467.png", width: 630, height: 580 },
]
},
],
barrierNum: 2,//不可击中元素个数
barrierArr: [
{
src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01DRZbyV1FJvdNsmt8f_!!1080040467.png", width: 166, height: 166, probability: 1
},//bound:障碍物触碰的边界 相对障碍物图片边界向指定方向缩进
],
mask: {
src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN018B996m1FJvdJy5Ic5_!!1080040467.png",//遮罩图片
width: 750,
height: 952,
shootR: 45,//可射击半径
y: 952 / 2,//射击点y轴坐标
r: 952 / 2,//遮罩半径
}
},
},
onLoad() {
},
onRef(game) {
this.gameComponent = game;
},
changeFun() {
this.setData({
renderGame: !this.data.renderGame
})
},
overFun() {
this.gameComponent.stop();
},
beginFun() {
this.gameComponent.start();
},
continueFun() {
this.gameComponent.continue();
},
resetFun() {
this.gameComponent.reset();
},
pauseFun() {
this.gameComponent.pause();
},
shootFun() {
this.gameComponent.shoot();
},
onInitDone() {
// my.alert({
// content: "游戏初始化完成"
// })
this.beginFun();
},
onUpdate(item) {
// curScore:当次得分
// totalScore:当局得分
// {curScore,totalScore}
console.log(item)
// my.alert({
// content: item.curScore + "==" + item.totalScore
// })
},
});
<game-shoot
gameSource="{{gameSource}}"
onRef="onRef"
onFinish="onFinish"
onInitDone="onInitDone"
onUpdate="onUpdate"
/>