game-music
v0.0.8
Published
``` npm install game-music ```
Downloads
2
Readme
game-music
游戏
安装
npm install game-music
使用
必须开启 "enableSkia": "true"
- json
{
"usingComponents": {
"game": "game-music/index"
}
}
- mini.project.json
{
"node_modules_es6_whitelist": [
"common-game"
]
}
- js
Page({
data: {
gameSource: {
bg: {
src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01QLXmHJ1FJvqJrNhoK_!!1080040467.jpg",
},
baseOps: {
speed: {
min: 5,//初始速度
max: 15,//最大速度
step: 0.01,//每次递增的速度
speedStep: 50,//移动指定距离,速度增加一次
interval: 1,//一次递减多少值
intervalStepH: 50,//移动指定距离递减一次
minIntervalH: 200,//两个物体之间的最小间隔距离
maxIntervalH: 300,//两个物体之间的间隔距离
},//移动速度
firstY: 0,//首次加载游戏第一个元素的底部坐标位置
// tipX: 0.1,//提示分数位置 (默认是在屏幕中间)
tipY: 580,//提示分数位置
tipShowTime: 500,//提示分数显示的时间
},
liveY: 1242,//生命线
showRect: { y: 362, height: 886 },//游戏元素显示区域
items: [
{ "src": "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01tcKrJw1FJvqIgPW6a_!!1080040467.png", tipType: "tip1", val: 10, bound: { left: 0, top: 0, right: 0, bottom: 12 }, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01CRwdXf1FJvqS4AvBA_!!1080040467.png", tipType: "tip1", val: 10, bound: { left: 0, top: 0, right: 0, bottom: 0 }, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01WYCyb01FJvqS48RJA_!!1080040467.png", tipType: "tip1", val: 10, bound: { left: 0, top: 0, right: 0, bottom: 28 }, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN015FzITw1FJvqPhP76p_!!1080040467.png", tipType: "tip1", val: 10, bound: { left: 0, top: 0, right: 0, bottom: 0 }, probability: 1, },
],
missTip: { "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01G4TWSy1FJvqMw8B81_!!1080040467.png" },//未匹配到元素的时候的miss提示
tip1: {
miss: { "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01G4TWSy1FJvqMw8B81_!!1080040467.png", val: 0, min: 0, max: 20 },//0-20%
good: { "src": "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01n5x0PC1FJvqPt2fck_!!1080040467.png", val: 70, min: 20, max: 80 },//20-60%
perfect: { "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN018EEIJY1FJvqPt1b4R_!!1080040467.png", val: 110, min: 80, max: 100 },//90-100%以上
},
btns: [
{
x: 45,
y: 1323,
col: 0,
def: { src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01nXDWyt1FJvqPN1VWC_!!1080040467.png", },
active: { src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01H0AFuC1FJvqRAk6oc_!!1080040467.png" },
},
{
x: 275,
y: 1323,
col: 1,
def: { src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01nXDWyt1FJvqPN1VWC_!!1080040467.png", },
active: { src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01H0AFuC1FJvqRAk6oc_!!1080040467.png" },
},
{
x: 505,
y: 1323,
col: 2,
def: { src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01nXDWyt1FJvqPN1VWC_!!1080040467.png", },
active: { src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01H0AFuC1FJvqRAk6oc_!!1080040467.png" },
},
],
scorePos: {
align: "right",
x: 688,
y: 303,
bg: {
src: "https://img.alicdn.com/imgextra/i4/1080040467/O1CN0128GiUj1FJvqS3CA9E_!!1080040467.png",
x: 506,
y: 290
},
// 分数数字图片 0 - 9
numOffset: -4,//数字两边空白太多,增加偏移量
numArr: [
{ "src": "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01sFpdGm1FJvqJ3Bko2_!!1080040467.png", "val": "0" },
{ "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01SOMSZa1FJvqSQXNa2_!!1080040467.png", "val": "1" },
{ "src": "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01yxhcbN1FJvqEQTe2y_!!1080040467.png", "val": "2" },
{ "src": "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01iuhLpz1FJvqR8Vjpv_!!1080040467.png", "val": "3" },
{ "src": "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01HERASo1FJvqPklxy0_!!1080040467.png", "val": "4" },
{ "src": "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01c7ju151FJvqP5o8MQ_!!1080040467.png", "val": "5" },
{ "src": "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01nn7KPF1FJvqJ3ATp5_!!1080040467.png", "val": "6" },
{ "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01ESMWFp1FJvqRYiSop_!!1080040467.png", "val": "7" },
{ "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01G86LAh1FJvqEQSAZh_!!1080040467.png", "val": "8" },
{ "src": "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01mGpWFB1FJvqP5ofdM_!!1080040467.png", "val": "9" },
],
},
timePos: {
align: "left",
x: 144,
y: 330,
bg: {
full: { src: "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01uzum6Z1FJvqSS1QGr_!!1080040467.png", x: 19, y: 290 },
src: "https://img.alicdn.com/imgextra/i2/1080040467/O1CN01WwHCFE1FJvqMpH0z4_!!1080040467.png",
x: 19,
y: 290
},
time: 30,//倒计时时间
// 时间数字图片 0 - 9
numOffset: -4,//数字两边空白太多,增加偏移量
numArr: [
{ "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01s6HDsz1FJvqMuxH1a_!!1080040467.png", val: 0 },
{ "src": "https://img.alicdn.com/imgextra/i3/1080040467/O1CN0118a2UF1FJvqKqn26o_!!1080040467.png", val: 1 },
{ "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN013lImv51FJvqKGFyzM_!!1080040467.png", val: 2 },
{ "src": "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01GllsVY1FJvqSR9JFN_!!1080040467.png", val: 3 },
{ "src": "https://img.alicdn.com/imgextra/i4/1080040467/O1CN01kKHeTv1FJvqMoFZTc_!!1080040467.png", val: 4 },
{ "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN011LZydS1FJvqNwldhI_!!1080040467.png", val: 5 },
{ "src": "https://img.alicdn.com/imgextra/i4/1080040467/O1CN016p2NvS1FJvqKGEAiT_!!1080040467.png", val: 6 },
{ "src": "https://img.alicdn.com/imgextra/i2/1080040467/O1CN014DvRjb1FJvqR946zP_!!1080040467.png", val: 7 },
{ "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01slZU2D1FJvqPlNI2A_!!1080040467.png", val: 8 },
{ "src": "https://img.alicdn.com/imgextra/i1/1080040467/O1CN01eR5JP41FJvqR93i25_!!1080040467.png", val: 9 },
{ "src": "https://img.alicdn.com/imgextra/i3/1080040467/O1CN01KWe3Yz1FJvqTEelTC_!!1080040467.png", val: "s" },
],
},
}
},
onLoad() {
},
// 组件主动公开方法----------
beginFun() {
// 开始游戏
this.gameComponent.onEvent("start");
},
resetFun(e) {
// 重置游戏
this.gameComponent.onEvent("reset");
},
isShowFun() {
this.setData({
showGame: !this.data.showGame
})
},
// 组件回调方法------------------
onInitDone(obj) {
this.gameComponent = obj.ref;
// my.alert({
// content: "游戏初始化完成"
// })
// 初始化game
this.gameComponent.onEvent("reset");
},
onUpdate(ops) {
// { totalScore: 0, imgObj: { } }
console.log(ops)
},
onGameOver(totalScore) {
console.log("游戏结束:", totalScore)
},
});
- xaml
<view class="pageBox">
<view class="gameBox">
<game gameSource="{{gameSource}}" a:if="{{!showGame}}" onInitDone="onInitDone" onUpdate="onUpdate" onGameOver="onGameOver" />
</view>
<view style="position:absolute;width: 100%;height:1px;left:0;top:1242rpx;background:red;"></view>
<!--<view style="position:absolute;width:192rpx;height: 1500rpx;background:rgba(0,0,0,0.1);left: 280rpx;top:0;"></view> -->
<view onTap="beginFun" style="position:absolute;z-index: 10;bottom: 50px;left: 0px;">开始</view>
<view onTap="resetFun" style="position:absolute;z-index: 10;bottom: 50px;left: 100px;">重置游戏</view>
<view onTap="isShowFun" style="position:absolute;z-index: 10;bottom: 50px;left: 200px;">切换</view>
</view>