当前位置: 首页 > news >正文

制作一款打飞机游戏54:子弹编辑UI

今天,我们将继续工作在我们的子弹模式系统上,创建一些简单的子弹,并为其设计用户界面(UI)。

自动保存功能的重要性

首先,我想提一下自动保存功能。这个功能在编辑器中非常重要,因为我们经常犯错,需要频繁地保存进度。我计划在不久的将来实现这个功能,但目前先搁置一下。

编辑器滚动问题

另外,我注意到一个编辑器中的问题:当编辑列表末尾的精灵时,退出编辑模式后,滚动条会停留在列表末尾,这不是我想要的。我想记住退出前的滚动位置,并在返回时恢复它。这个问题我会在未来的某一集中解决。

子弹模式编辑器UI设计

现在,让我们回到子弹模式编辑器。我们可以创建子弹模式,但还需要一个UI来编辑这些模式。

  • 选择模式‌:首先,我们需要一个界面来显示当前选择的模式。当我们点击时,可以更新并射击选定的模式。
  • 创建按钮‌:接下来,我将创建一个按钮,用于显示当前选定模式的编号。
编辑模式属性
  • 基础按钮‌:首先,我创建了一个基础按钮,用于显示当前选定模式的编号。
  • 模式类型按钮‌:然后,我添加了一个按钮来显示模式的类型(例如,“Sal Pat 1”)。
  • 循环显示属性‌:对于每个模式,我们都有一些属性,如角度、速度、动画等。我创建了一个循环来显示这些属性的值,并为它们添加了标签。
编辑属性值

接下来,我们需要能够编辑这些属性值。

  • 光标导航‌:我实现了光标导航功能,使用户可以通过上下键在属性之间移动。
  • 编辑属性‌:当用户按下回车键时,会弹出一个菜单,允许用户编辑当前选定属性的值。
创建和删除模式
  • 创建新模式‌:我还添加了创建新模式的功能。当用户选择了一个不存在的模式编号时,会自动创建一个新的模式。
  • 删除模式‌:同样,我也实现了删除模式的功能。当用户点击删除按钮时,会删除当前选定的模式。
  • 静态与瞄准射击‌:目前所有的射击都是静态的,但未来我们计划实现瞄准射击功能。这将是一个挑战,因为我们需要考虑如何将这些系统整合在一起。
  • 模式修饰符‌:我还提出了一个想法,即创建模式修饰符。例如,一个模式有时不会发射子弹,或者连续发射多次子弹。这些都需要我们进一步思考和实现。
pico-8 cartridge // http://www.pico-8.com
version 41
__lua__
--todo
-- autosave
-- prevent scrolling after exiting to list
-- copy?
-- nudge values
-- direct spritemap selectionfunction _init()--- customize here ---#include shmup_myspr.txt#include shmup_myspr_meta.txtfile="shmup_myspr.txt"filem="shmup_myspr_meta.txt"arrname="myspr"data=mysprreload(0x0,0x0,0x2000,"cowshmup.p8")------------------------[[meta={}for x=1,#data domobj={}mobj[1]="spr "..xmobj[2]=0meta[x]=mobjend]]--debug={}msg={}_drw=draw_list_upd=update_listmenuitem(1,"export",export)curx=1cury=1scrolly=0scrollx=0poke(0x5f2d, 1)
endfunction _draw()_drw()if #msg>0 thenbgprint(msg[1].txt,64-#msg[1].txt*2,80,14)msg[1].t-=1if msg[1].t<=0 thendeli(msg,1)end  end-- debug --cursor(4,4)color(8)for txt in all(debug) doprint(txt)end
endfunction _update60()dokeys()mscroll=stat(36)_upd()
endfunction dokeys()if stat(30) thenkey=stat(31)if key=="p" thenpoke(0x5f30,1)endelsekey=nilendend
-->8
--draw
function draw_edit()-- backgroundfillp(0b11001100001100111100110000110011)rectfill(0,0,127,127,33)fillp(▒)line(63,0,63,127,13)line(0,63,127,63,13)fillp()draw_menu()-- draw spriteif selspr thenif meta[selspr][2]>0 thenwrapmspr(meta[selspr][2],63,63)msprc(selspr,63,63)elsewrapmspr(selspr,63,63)endend-- blinking dotif (time()*2)%1<0.5 thenpset(63,63,rnd({8,13,7,15}))end
endfunction draw_list()fillp(0b11001100001100111100110000110011)rectfill(0,0,127,127,33)fillp(▒)line(63,0,63,127,13)line(0,63,127,63,13)fillp()draw_menu()-- draw spritelocal mymnu=menu[cury][curx]if mymnu and mymnu.cmdy thenif meta[mymnu.cmdy][2]>0 thenwrapmspr(meta[mymnu.cmdy][2],63,63)msprc(mymnu.cmdy,63,63)elsewrapmspr(mymnu.cmdy,63,63)endendif (time()*2)%1<0.5 thenpset(63,63,rnd({8,13,7,15}))end
endfunction draw_table()cls(2)draw_menu()
endfunction draw_menu()--spr(0,0,0,16,16)if menu thenfor i=1,#menu dofor j=1,#menu[i] dolocal mymnu=menu[i][j]local c=mymnu.c or 13if i==cury and j==curx thenc=7if _upd==upd_type thenc=0endendbgprint(mymnu.w,mymnu.x+scrollx,mymnu.y+scrolly,13)   bgprint(mymnu.txt,mymnu.x+scrollx,mymnu.y+scrolly,c) endendendif _upd==upd_type thenlocal mymnu=menu[cury][curx]local txt_bef=sub(typetxt,1,typecur-1)local txt_cur=sub(typetxt,typecur,typecur)local txt_aft=sub(typetxt,typecur+1)txt_cur=txt_cur=="" and " " or txt_cur if (time()*2)%1<0.5 thentxt_cur="\^i"..txt_cur.."\^-i"endlocal txt=txt_bef..txt_cur..txt_aftbgprint(txt,mymnu.x+scrollx,mymnu.y+scrolly,7)endend-->8
--update
function update_edit()refresh_edit()if btnp(⬆️) thencury-=1endif btnp(⬇️) thencury+=1endcury=(cury-1)%#menu+1cury-=mscrollcury=mid(1,cury,#menu)if cury==1 thencurx=1if btnp(⬅️) thenselspr-=1elseif btnp(➡️) thenselspr+=1endselspr=mid(1,selspr,#data)	elseif cury==11 thencurx=1elsecurx=2endif btnp(🅾️) then_drw=draw_list_upd=update_listrefresh_list()cury=selsprcurx=1scrolly=0scrollx=0returnendif btnp(❎) thenlocal mymnu=menu[cury][curx]if mymnu.cmd=="editval" then_upd=upd_typelocal s=tostr(data[mymnu.cmdy][mymnu.cmdx])if s=="[nil]" or s==nil thens=""endtypetxt=stypecur=#typetxt+1typecall=enter_editelseif mymnu.cmd=="editcol" then_upd=upd_typelocal s=tostr(meta[selspr][2])typetxt=stypecur=#typetxt+1typecall=enter_editcolelseif mymnu.cmd=="sprhead" then_upd=upd_typelocal s=tostr(meta[selspr][1])typetxt=stypecur=#typetxt+1typecall=enter_editname elseif mymnu.cmd=="delspr" thendeli(data,selspr)deli(meta,selspr)selspr-=1if selspr==0 thenselspr=1end_drw=draw_list_upd=update_listrefresh_list()cury=selsprcurx=1scrolly=0scrollx=0return   endend
endfunction update_list()refresh_list()if btnp(⬆️) thencury-=1endif btnp(⬇️) thencury+=1endcury=(cury-1)%#menu+1cury-=mscrollcury=mid(1,cury,#menu)curx=1local mymnu=menu[cury][curx]if mymnu.y+scrolly>110 thenscrolly-=4endif mymnu.y+scrolly<10 thenscrolly+=4endscrolly=min(0,scrolly)if mymnu.x+scrollx>110 thenscrollx-=2endif mymnu.x+scrollx<20 thenscrollx+=2endscrollx=min(0,scrollx)if btnp(❎) thenlocal mymnu=menu[cury][curx]if mymnu.cmd=="newline" thenadd(data,{0,0,0,0,0,0})add(meta,{"new",0})elseif mymnu.cmd=="editspr" thenselspr=mymnu.cmdy_upd=update_edit_drw=draw_editscrolly=0scrollx=0refresh_edit()cury=1endend
endfunction update_table()refresh_table()if btnp(⬆️) thencury-=1endif btnp(⬇️) thencury+=1endcury=(cury-1)%#menu+1cury-=mscrollcury=mid(1,cury,#menu)if btnp(⬅️) thencurx-=1endif btnp(➡️) thencurx+=1endif cury<#menu thencurx=(curx-2)%(#menu[cury]-1)+2elsecurx=1endlocal mymnu=menu[cury][curx]if mymnu.y+scrolly>110 thenscrolly-=4endif mymnu.y+scrolly<10 thenscrolly+=4endscrolly=min(0,scrolly)if mymnu.x+scrollx>110 thenscrollx-=2endif mymnu.x+scrollx<20 thenscrollx+=2endscrollx=min(0,scrollx)if btnp(❎) thenlocal mymnu=menu[cury][curx]if mymnu.cmd=="edit" then_upd=upd_typetypetxt=tostr(mymnu.txt)typecur=#typetxt+1typecall=enter_tableelseif mymnu.cmd=="newline" thenadd(data,{0})  elseif mymnu.cmd=="newcell" thenadd(data[mymnu.cmdy],0)endend
endfunction upd_type()if key thenif key=="\r" then-- enter   poke(0x5f30,1)typecall()returnelseif key=="\b" then--backspaceif typecur>1 thenif typecur>#typetxt thentypetxt=sub(typetxt,1,#typetxt-1)elselocal txt_bef=sub(typetxt,1,typecur-2)local txt_aft=sub(typetxt,typecur)typetxt=txt_bef..txt_aftendtypecur-=1endelseif typecur>#typetxt thentypetxt..=keyelselocal txt_bef=sub(typetxt,1,typecur-1)local txt_aft=sub(typetxt,typecur)typetxt=txt_bef..key..txt_aftendtypecur+=1endendif btnp(⬅️) thentypecur-=1endif btnp(➡️) thentypecur+=1endtypecur=mid(1,typecur,#typetxt+1)
end
-->8
--toolsfunction bgprint(txt,x,y,c)print("\#0"..txt,x,y,c)
endfunction split2d(s)local arr=split(s,"|",false)for k, v in pairs(arr) doarr[k] = split(v)endreturn arr
endfunction wrapmspr(si,sx,sy)if si==nil thenbgprint("[nil]",sx-5*2+1,sy-2,14)returnendif myspr[si]==nil thenbgprint("["..si.."]",sx-5*2+1,sy-2,14)returnendlocal ms=myspr[si]if ms[8] then--check for loopsif ms[8]==si thenbgprint("[loop]",sx-6*2+1,sy-2,14)returnelseif checkloop(ms,10) thenbgprint("[loop]",sx-6*2+1,sy-2,14)return   endendendmspr(si,sx,sy)
endfunction checkloop(ms,depth)depth-=1if depth<=0 thenreturn trueendif ms==nil thenreturn trueendif ms[8] thenreturn checkloop(myspr[ms[8]],depth)elsereturn falseend
endfunction mspr(si,sx,sy)local ms=myspr[si]sspr(ms[1],ms[2],ms[3],ms[4],sx-ms[5],sy-ms[6],ms[3],ms[4],ms[7]==1)if ms[7]==2 thensspr(ms[1],ms[2],ms[3],ms[4],sx-ms[5]+ms[3],sy-ms[6],ms[3],ms[4],true)endif ms[8] thenmspr(ms[8],sx,sy)end
endfunction msprc(si,sx,sy)local _x,_y,_w,_h,_ox,_oy,_fx,_nx=unpack(myspr[si])if _fx==2 then_w*=2end--sspr(_x,_y,_w,_h,sx-_ox,sy-_oy,_w,_h,_fx==1)rect(sx-_ox,sy-_oy,sx-_ox+_w-1,sy-_oy+_h-1,rnd({8,14,15}))
endfunction spacejam(n)local ret=""for i=1,n doret..=" "endreturn ret
end
-->8
--i/o
function export()local s=arrname.."=split2d\""for i=1,#data doif i>1 thens..="|"endfor j=1,#data[i] doif j>1 thens..=","ends..=data[i][j]endends..="\""printh(s,file,true)local s="meta=split2d\""for i=1,#meta doif i>1 thens..="|"endfor j=1,#meta[i] doif j>1 thens..=","ends..=meta[i][j]endends..="\""printh(s,filem,true)add(msg,{txt="exported!",t=120})--debug[1]="exported!"
end
-->8
--ui
function refresh_edit()menu={}add(menu,{{txt="< "..selspr.." "..meta[selspr][1].." >",w="",cmd="sprhead",x=2,y=2}})local lab={"  x:","  y:","wid:","hgt:"," ox:"," oy:"," fx:","nxt:"}for i=1,8 dolocal s=tostr(data[selspr][i])if s==nil thens="[nil]"endadd(menu,{{txt=lab[i],w="    ",x=2,y=3+i*7},{txt=s,w=spacejam(#s),cmd="editval",cmdy=selspr,cmdx=i,x=2+16,y=3+i*7}}) endlocal coltxt=meta[selspr][2]==0 and "off" or tostr(meta[selspr][2])add(menu,{{txt="col:",w=spacejam(4),x=2,y=4+9*7},{txt=coltxt,w=spacejam(#coltxt),cmd="editcol",cmdy=selspr,x=19,y=4+9*7}})add(menu,{{txt="delete",w="",cmd="delspr",x=2,y=5+10*7}})
endfunction refresh_list()menu={}for i=1,#data dolocal lne={}local linemax=#data[i]if i==cury thenlinemax+=1  endadd(lne,{txt=i.." "..meta[i][1],w="",cmd="editspr",cmdy=i,x=2,y=-4+6*i})add(menu,lne)endadd(menu,{{txt=" + ",w="   ",cmd="newline",x=2,y=-4+6*(#data+1)+2, }})
endfunction refresh_table()menu={}for i=1,#data dolocal lne={}local linemax=#data[i]if i==cury thenlinemax+=1  endadd(lne,{txt=i,w="   ",cmd="",x=4,y=-4+8*i,c=2  })for j=1,linemax doif j==#data[i]+1 thenadd(lne,{txt="+",w=" ",cmd="newcell",cmdy=i,x=-10+14*(j+1),y=-4+8*i, })elseadd(lne,{txt=data[i][j],cmd="edit",cmdx=j,cmdy=i,x=-10+14*(j+1),y=-4+8*i,w="   "})endendadd(menu,lne)endadd(menu,{{txt=" + ",w="   ",cmd="newline",x=4,y=-4+8*(#data+1), }})
endfunction enter_table()local mymnu=menu[cury][curx]local typeval=tonum(typetxt)if typeval==nil thenif mymnu.cmdx==#data[mymnu.cmdy] and typetxt=="" then--delete celldeli(data[mymnu.cmdy],mymnu.cmdx)if mymnu.cmdx==1 thendeli(data,mymnu.cmdy)end_upd=update_tablereturnend  typeval=0enddata[mymnu.cmdy][mymnu.cmdx]=typeval_upd=update_tablerefresh_table()
endfunction enter_edit()local mymnu=menu[cury][curx]local typeval=tonum(typetxt)if mymnu.cmdx==8 thenif typeval!=nil thenif data[mymnu.cmdy][7]==nil thendata[mymnu.cmdy][7]=0endendendif typeval==nil thenif mymnu.cmdx>=7 and mymnu.cmdx==#data[mymnu.cmdy] thendeli(data[mymnu.cmdy],mymnu.cmdx)elsedata[mymnu.cmdy][mymnu.cmdx]=0endelsedata[mymnu.cmdy][mymnu.cmdx]=typevalend _upd=update_editrefresh_edit()
endfunction enter_editcol()local mymnu=menu[cury][curx]local typeval=tonum(typetxt)if typeval==nil or typeval<1 thenmeta[selspr][2]=0elsemeta[selspr][2]=typevalend_upd=update_editrefresh_edit()
endfunction enter_editname()local mymnu=menu[cury][curx]local typeval=filter(tostr(typetxt))if typeval!="" thenmeta[selspr][1]=typevalend_upd=update_editrefresh_edit()
endfunction filter(s)local s2=""for i=1,#s dolocal c=s[i]if c=="," thenc="."elseif c=="|" thenc="/"ends2..=cendreturn s2
end
__gfx__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__
0000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

相关文章:

  • SQLite 创建表
  • Axios中POST、PUT、PATCH用法区别
  • 骰子游戏(2023睿抗省赛)
  • wireshark: Display Filter Reference
  • MqSQL
  • 《黄帝内经》数学建模与形式化表征方式的重构
  • SQL基础概念以及SQL的执行方式
  • AWS中国区中API Gateway中403的AccessDeniedException问题
  • 将MCP(ModelContextProtocol)与Semantic Kernel集成(调用github)
  • FPGA:CLB资源以及Verilog编码面积优化技巧
  • Redis 基础知识详解
  • Axure安装与基础
  • 用 Deepseek 写的 html+js 密码生成器
  • 杰发科技AC7801——PWM获取固定脉冲个数
  • 遨游三防科普:三防平板是什么?有什么特殊功能?
  • 平时使用电脑,如何去维护
  • 便捷的电脑自动关机辅助工具
  • 力扣HOT100之二叉树: 437. 路径总和 III
  • Android Service与BroadcastReceiver深度解析:从零到一的实现与优化
  • PyTorch性能调优实战:从算子优化到分布式训练全攻略
  • 东营可以做网站的公司在哪/线上拓客渠道有哪些
  • 网站建设的看法有哪些/户外广告
  • java 做的网站/网站app开发公司
  • 互联网建设网站/网站建设的一般步骤
  • 韶关哪里做网站最好/百度网盘人工客服电话
  • 海南房产网站建设/百seo排名优化