欢迎光临散文网 会员登陆 & 注册

6P 无序背包

2023-06-25 17:31 作者:茕今  | 我要投稿

/*无序背包,使用须知: * 1.先自行在ps中p好背包中物品的图片,统一大小,并上传 * 2、建立两个数组 物品 (类型数值); 物品名 (类型字符); * 3.建立一个变量,物品详情(类型数值) *4建立两个UI,一个无序背包,一个物品详情 **///背景底图,自行替换唯一标识await ac.createImage({name: 'image1',index: 0,inlayer: 'window',resId: '$58057502',pos: {x: 640,y: 360,},anchor: {x: 50,y: 50,},opacity:100,scale:100,visible:true,verticalFlip:false,horizontalFlip:false,});//文本样式await ac.createStyle({name:'style15',font:'方正楷体',bold:false,italic:false,fontSize:24,color:'#000000',speed:9,strokeColor:'#000000',shadowColor:'#000000',shadowPos:{x:0,y:0,},});/*=====================排序勿动=======================*/var paixu = [];// 保存ac.arr.exp到新变量paixu中,并为每个元素添加idpaixu = ac.arr.物品.map(function(value, index) {return {id: index, value: value};});// 对paixu中的数据进行从大到小的排序paixu.sort(function(a, b) { return b.value - a.value;});// 去除所有小于0的数据paixu = paixu.filter(function(obj) { return obj.value > 0;});/*=================按钮的图片,按照数组里物品的顺序添加==================*/var tupian = ["","$58060752","$58060749","$58060748","$58060750","$58060747"];//计算滚动视图高度,自行根据情况调整var H = (tupian.length/5+1)*100;//滚动视图await ac.createScrollView({name:'gdst',index:0,inlayer:'window',visible:true,pos:{x:690,y:346,},anchor:{x:50,y:50,},size:{width:1040,height:544,},innerSize:{width:1072,height:H,},horizontalScroll:false,verticalScroll:true,});//按钮y轴位子var Y1;if (tupian.length/5+1<3){ Y1 = 290 + H}else if (tupian.length/5+1>=3&&tupian.length/5+1<5){Y1 = 190 + H}else if (tupian.length/5+1>=4&&tupian.length/5+1<6){Y1 = 90 + H}var Y2 ;if (tupian.length/5+1<3){ Y2 = 190 + H}else if (tupian.length/5+1>=3&&tupian.length/5+1<5){Y2 = 90 + H}//按钮x轴位子,自行更具情况调整var X0 = 70;var X1 = 270;var X2 = 470;var X3 = 670;var X4 = 870;/*----------------------------------按钮1-------------------------------------*/var tu0 = paixu[0].id//按钮图片1await ac.createImage({name: 'wuping00',index: 0,inlayer: 'gdst',resId: tupian[tu0],pos: {x: X0,y: Y1,},anchor: {x: 51,y: 52,},opacity: 100,scale: 100,visible: true,verticalFlip: false,horizontalFlip: false,});//按钮点出事件的函数(勿动)async function wp00() { ac.var.物品详情=paixu[0].id;//点击音效(可自行更改)ac.playAudio({name: 'playAudio8',resId: '$54737155',vol: 80,effect: 'normal',loop: false,});//替换到物品详情的UI(自行更改)await ac.replaceUI({name: 'replaceUI7',uiId: 'b9tcoazz',});}ac.addEventListener({type: ac.EVENT_TYPES.onTouchEnded,listener: wp00,target: 'wuping00',});//物品名+物品数量(自行修改xy轴位置,其他勿动。XY轴位置:pos: {x: X0,y: Y1-50,})await ac.createText({name: 'text00',index: 0,inlayer: 'gdst',visible: true,content: `<tag style=style15>${ac.arr.物品名[tu0]} ${ac.arr.物品[tu0]}</tag>`,pos: {x: X0,y: Y1-50,},size: {width: 170,height: 34,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});/*==============以下部分与按钮1一样,可复制按钮1============ * 具体修改部分看图片=*/var tu01 = paixu[1].id await ac.createImage({name: 'wuping001',index: 0,inlayer: 'gdst',resId: tupian[tu01],pos: {x: X1,y: Y1,},anchor: {x: 51,y: 52,},opacity: 100,scale: 100,visible: true,verticalFlip: false,horizontalFlip: false,});async function wp001() { ac.var.物品详情=paixu[1].id; ac.playAudio({name: 'playAudio8',resId: '$54737155',vol: 80,effect: 'normal',loop: false,}); await ac.delay({time: 200,});await ac.replaceUI({name: 'replaceUI7',uiId: 'b9tcoazz',});}ac.addEventListener({type: ac.EVENT_TYPES.onTouchEnded,listener: wp001,target: 'wuping001',});await ac.createText({name: 'text001',index: 0,inlayer: 'gdst',visible: true,content: `<tag style=style15>${ac.arr.物品名[tu01]} ${ac.arr.物品[tu01]}</tag>`,pos: {x: X1,y: Y1-50,},size: {width: 170,height: 34,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});var tu02 = paixu[2].idawait ac.createImage({name: 'wuping002',index: 0,inlayer: 'gdst',resId: tupian[tu02],pos: {x: X2,y: Y1,},anchor: {x: 51,y: 52,},opacity: 100,scale: 100,visible: true,verticalFlip: false,horizontalFlip: false,});async function wp002() { ac.var.物品详情=paixu[2].id; ac.playAudio({name: 'playAudio8',resId: '$54737155',vol: 80,effect: 'normal',loop: false,});await ac.delay({time: 200,}); await ac.replaceUI({name: 'replaceUI7',uiId: 'b9tcoazz',});}ac.addEventListener({type: ac.EVENT_TYPES.onTouchEnded,listener: wp002,target: 'wuping002',});await ac.createText({name: 'text002',index: 0,inlayer: 'gdst',visible: true,content: `<tag style=style15>${ac.arr.物品名[tu02]} ${ac.arr.物品[tu02]}</tag>`,pos: {x: X2,y: Y1-50,},size: {width: 170,height: 34,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});var tu03 = paixu[3].idawait ac.createImage({name: 'wuping003',index: 0,inlayer: 'gdst',resId: tupian[tu03],pos: {x: X3,y: Y1,},anchor: {x: 51,y: 52,},opacity: 100,scale: 100,visible: true,verticalFlip: false,horizontalFlip: false,});async function wp003() { ac.var.物品详情=paixu[3].id; ac.playAudio({name: 'playAudio8',resId: '$54737155',vol: 80,effect: 'normal',loop: false,});await ac.delay({time: 200,}); await ac.replaceUI({name: 'replaceUI7',uiId: 'b9tcoazz',});}ac.addEventListener({type: ac.EVENT_TYPES.onTouchEnded,listener: wp003,target: 'wuping003',});await ac.createText({name: 'text003',index: 0,inlayer: 'gdst',visible: true,content: `<tag style=style15>${ac.arr.物品名[tu03]} ${ac.arr.物品[tu03]}</tag>`,pos: {x: X3,y: Y1-50,},size: {width: 170,height: 34,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});var tu04 = paixu[4].idawait ac.createImage({name: 'wuping004',index: 0,inlayer: 'gdst',resId: tupian[tu04],pos: {x: X4,y: Y1,},anchor: {x: 51,y: 52,},opacity: 100,scale: 100,visible: true,verticalFlip: false,horizontalFlip: false,});async function wp004() { ac.var.物品详情=paixu[4].id; ac.playAudio({name: 'playAudio8',resId: '$54737155',vol: 80,effect: 'normal',loop: false,});await ac.delay({time: 200,}); await ac.replaceUI({name: 'replaceUI7',uiId: 'b9tcoazz',});}ac.addEventListener({type: ac.EVENT_TYPES.onTouchEnded,listener: wp004,target: 'wuping004',});await ac.createText({name: 'text004',index: 0,inlayer: 'gdst',visible: true,content: `<tag style=style15>${ac.arr.物品名[tu04]} ${ac.arr.物品[tu04]}</tag>`,pos: {x: X4,y: Y1-50,},size: {width: 170,height: 34,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});/*========================以下部分为物品详情的UI=========================*///背景图,自行更改await ac.createImage({name:'image1',index:0,inlayer:'window',resId:'$58057502',pos:{x:640,y:360,},anchor:{x:50,y:50,},opacity:100,scale:100,visible:true,verticalFlip:false,horizontalFlip:false,});await ac.createImage({name:'image2',index:0,inlayer:'window',resId:'$50352556',pos:{x:640,y:360,},anchor:{x:50,y:50,},opacity:100,scale:100,visible:true,verticalFlip:false,horizontalFlip:false,});//返回按钮 自行更改async function fanhui(){await ac.replaceUI({name:'replaceUI5',uiId:'9qtaensq',});}await ac.createOption({name:'fan',index:0,inlayer:'window',visible:true,nResId:'$50154847',sResId:'$50154845',content:``,pos:{x:1220,y:52,},anchor:{x:50,y:50,},onTouchEnded:fanhui,});//图片显示控键 物品名,我写了1~5,按格式自行添加新的物品,位置自行修改await ac.createTextDisplay({name: 'textDisplay6',index: 0,textGroup: [ {text: `${ac.arr.物品名[1]}`,condition: () => ac.var.物品详情 === 1,}, {text: `${ac.arr.物品名[2]}`,condition: () => ac.var.物品详情 === 2,}, {text: `${ac.arr.物品名[3]}`,condition: () => ac.var.物品详情 === 3,}, {text: `${ac.arr.物品名[4]}`,condition: () => ac.var.物品详情 === 4,}, {text: `${ac.arr.物品名[5]}`,condition: () => ac.var.物品详情 === 5,},],pos: {x: 632,y: 507,},size: {width: 266,height: 42,},inlayer: 'window',spacing: 1,anchor: {x: 50,y: 50,},visible: true,direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,});//物品描述,按照格式自行修改内容,其他的勿改var 描述 = ["",   "一颗又大又圆的养仙丹",//物品1描述   "绿油油的平安扣,像你头上的草原一样",//物品2描述   "平安扣同款绿色荷包,你值得拥有!",//物品3描述   "布林布林金光灿灿的梳子,贵就完了。",//物品4描述   "一匹布",//物品5描述];//物品描述的文本框,自行修改位子,其他的勿动await ac.createText({ name: 'xiangq', index: 0, inlayer: 'window', visible: true, content: `${描述[ac.var.物品详情]}`, pos: {  x: 632,  y: 402, }, size: {  width: 432,  height: 140, }, direction: ac.TEXT_DIRECTION_TYPES.horizontal, halign: ac.HALIGN_TYPES.left, valign: ac.VALIGN_TYPES.center, spacing: 1.5, anchor: {  x: 50,  y: 50, },});//文字样式await ac.createStyle({ name: 'style8', font: '思源黑体', bold: false, italic: false, fontSize: 30, color: '#ffffff', speed: 9, strokeColor: '#000000', shadowColor: '#000000', shadowPos: {  x: 0,  y: 0, },});//使用物品/*使用物品的函数*/async function yong() { /*判定物品数量大于等于1*/if(ac.arr.物品[ac.var.物品详情]>=1){ /*当物品数量大于等于1后,开始接下来的运算*/ if(ac.var.物品详情===1)/* 当打开的是物品1的详情页时*/  {ac.arr.物品[1]=ac.arr.物品[1]-1;  /*物品1的数量减一*/   ac.arr.嫔妃容貌[0]=ac.arr.嫔妃容貌[0]+100;  /*物品1的使用效果,自行修改和添加*/  await ac.createText({name: 'text11',index: 0,inlayer: 'window',visible: true,content: `使用成功,容貌+100\n当前容貌:${ac.arr.嫔妃容貌[0]}`,pos: {x: 640,y: 217,},size: {width: 640,height: 76,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});  /*文本框——使用后的提示*/await ac.delay({time: 1000,});ac.remove({name: 'text11',effect: 'fadeout',duration: 1000,canskip: false,});}/*延迟一秒后文本框消失*/} }//使用按钮 await ac.createOption({  name: 'option8',  index: 0,  inlayer: 'window',  visible: true,  nResId: '$436765',  sResId: '$436766',  content: `使用`,  pos: {   x: 646,   y: 123,  },  anchor: {   x: 50,   y: 50,  },  style: 'style8',  clickAudio: {   resId: '$532507',   vol: 80,  },  onTouchEnded: yong, });

6P 无序背包的评论 (共 条)

分享到微博请遵守国家法律