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

制作一款打飞机游戏58:子弹模式组合

今天我们将继续深入探讨子弹模式系统,并在我们的模式编辑器上做一些收尾工作。

子弹模式系统的乐趣

首先,我想说,这个子弹模式系统真的非常有趣。看着屏幕上不断喷射的子弹,感觉真是太棒了!

合并修饰符

今天,我想添加一个合并修饰符。这个修饰符允许我们将多个子弹模式合并在一起,同时发射。这样,在BOSS战中,我们就可以一次性发射多种不同的子弹,而不是分别发射。我相信这将是一个非常有用的功能。

我将为这个合并修饰符创建一个菜单,并设置五个插槽来组合不同的子弹模式。如果将来需要更多插槽,我们可以随时增加。

实现合并修饰符

现在,让我们来实现这个合并修饰符。我们将遍历所有插槽,如果插槽中的值不为零,就生成对应的子弹模式,并将所有子弹添加到返回数组中。这样,我们就可以在屏幕上看到合并后的子弹效果了。

角度指示器

接下来,我想添加一个角度指示器。当敌人发射子弹时,角度指示器将显示子弹的发射角度,以避免混淆。我们将使用一个简单的公式来计算角度,并绘制一条线来表示子弹的发射方向。

测试新功能

在将新功能添加到游戏中之前,我想先做一个测试运行。在上一期的Doggy Zone中,我给大家布置了一个任务,那就是复制Loki Striker在《Steel Surge》中展示的一个美丽子弹模式。现在,我想亲自尝试一下,看看我们的系统是否足够灵活,能够创造出这样的模式。

创建新子弹模式

通过不断尝试和调整参数,我成功创建了一个类似Loki Striker展示的子弹模式。这个模式由两个螺旋子弹模式叠加而成,每个螺旋由三个子弹组成,部分子弹速度较快,部分较慢。看起来非常酷炫!

pico-8 cartridge // http://www.pico-8.com
version 41
__lua__
-- todo
------------------
-- bring it into the game
-- bring it into brainedit-- shift?-- assumptions
------------------
-- bullets don't change direction
-- bullets don't change speedfunction _init()--- customize here ---#include shmup_pats.txtfile="shmup_pats.txt"arrname="pats"data=pats#include shmup_myspr.txt#include shmup_anilib.txt----------------------debug={}msg={}_drw=draw_pats_upd=update_patsmenuitem(1,"export",export)reload(0x0,0x0,0x2000,"cowshmup.p8")curx=1cury=1scrolly=0scrollx=0scroll=0pspr={x=64,y=110}enspr={x=64,y=64,bulq={}}buls={} poke(0x5f2d, 1)selpat=1fireang=-99
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()domouse()mscroll=stat(36)scroll+=0.2scroll=scroll%16_upd()
endfunction dokeys()if stat(30) thenkey=stat(31)if key=="p" thenpoke(0x5f30,1)endelsekey=nilendendfunction domouse()local oldmousex=mousexlocal oldmousey=mouseymousex=stat(32)mousey=stat(33)mousemove=falseif mousex!=oldmousex or oldmousey!=mousey thenmousemove=trueendif stat(34)==0 thenclkwait=falseendclkl=falseclkr=falseif not clkwait thenif stat(34)==1 thenclkl=trueclkwait=trueelseif stat(34)==2 thenclkr=trueclkwait=true  endendend
-->8
--drawfunction draw_pats()cls(13)if flr(scroll)%2==0 thenfillp(0b0000111100001111.1)elsefillp(0b1111000011110000.1)endfor i=0,7 doline(i*16,0,i*16,128,5)endfillp(▥)for i=-1,7 doline(0,i*16+scroll,128,i*16+scroll,5)endfillp()--enemyline(enspr.x-2,enspr.y-2,enspr.x+2,enspr.y+2,5)line(enspr.x-2,enspr.y+2,enspr.x+2,enspr.y-2,5)local myang=0if fireang==-99 thenmyang=atan2(pspr.y-enspr.y,pspr.x-enspr.x)endline(enspr.x+sin(myang)*8,enspr.y+cos(myang)*8,enspr.x+sin(myang)*12,enspr.y+cos(myang)*12,5)--playercirc(pspr.x,pspr.y,3,5)for s in all(buls) dodrawobj(s) enddrawmenu()bgprint(#buls,3,120,5)endfunction draw_table()cls(2)--spr(0,0,0,16,16)drawmemnu()
endfunction drawmenu()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 menui thenfor i=1,#menui dofor j=1,#menui[i] dolocal mymnui=menui[i][j]local c=mymnui.c or 13if i==cury and j==curx thenc=7if _upd==upd_type thenc=0endend bgprint(mymnui.w,mymnui.x,mymnui.y,13)   bgprint(mymnui.txt,mymnui.x,mymnui.y,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)end
end-->8
--updatefunction update_pats()if key=="1" thenif fireang==-99 thenfireang=0elsefireang=-99endendrefresh_pats()enspr.x=mousexenspr.y=mouseyif clkl and selpat<=#pats thenpatshoot(enspr,selpat,fireang)enddobulq(enspr)dobuls(buls)if btnp(⬆️) thencury-=1endif btnp(⬇️) thencury+=1endcury=mid(1,cury,#menu)if cury==1 thencurx=1if btnp(⬅️) thenselpat-=1endif btnp(➡️) thenselpat+=1endselpat=mid(1,selpat,#pats+1)elseif cury==2 thencurx=1elseif cury==#menu thencurx=1elsecurx=2endif btnp(❎) thenlocal mymnu=menu[cury][curx]if mymnu.cmd=="patedit" then_upd=upd_typetypetxt=tostr(mymnu.txt)typecur=#typetxt+1callback=enter_patreturnelseif mymnu.cmd=="newpat" thenadd(pats,newpat("base"))returnelseif mymnu.cmd=="delpat" thendeli(pats,selpat)add(msg,{txt="pat deleted!",t=120})endendendfunction 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+1callback=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-- enterpoke(0x5f30,1)callback()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 spacejam(n)local ret=""for i=1,n doret..=" "endreturn ret
endfunction split2d(s)local arr=split(s,"|",false)for k, v in pairs(arr) doarr[k] = split(v)endreturn arr
endfunction mysgn(v) return v==0 and 0 or sgn(v)
endfunction rndrange(low,high)return flr(rnd(high+1-low)+low)
endfunction mspr(si,sx,sy)local _x,_y,_w,_h,_ox,_oy,_fx,_nx=unpack(myspr[si])sspr(_x,_y,_w,_h,sx-_ox,sy-_oy,_w,_h,_fx==1)if _fx==2 thensspr(_x,_y,_w,_h,sx-_ox+_w,sy-_oy,_w,_h,true)endif _nx thenmspr(_nx,sx,sy)end
endfunction cyc(age,arr,anis)local anis=anis or 1return arr[(age\anis-1)%#arr+1]
endfunction drawobj(obj)mspr(cyc(obj.age,obj.ani,obj.anis),obj.x,obj.y)--★if coldebug and obj.col thenmsprc(obj.col,obj.x,obj.y)end
endfunction copylist(org)local ret={}for k, v in pairs(org) doret[k]=vendreturn 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)add(msg,{txt="exported!",t=120})--debug[1]="exported!"
end
-->8
--uifunction refresh_pats()menu={}if selpat>#pats thenadd(menu,{{txt="< new pat ",w="          ",cmd="newpat",x=4,y=4,c=13  }})return endlocal mypat=pats[selpat]add(menu,{{txt="< pat "..selpat.." >",w="    ",cmd="pat",x=4,y=4,c=13  }})add(menu,{{txt=mypat[1],w="    ",cmd="patedit",cmdy=selpat,cmdx=1,x=4,y=12,c=13  }})local mycap={}if mypat[1]=="base" thenmycap={"spd :","ani :","anis:","col :" }elseif mypat[1]=="some" thenmycap={"src :","perc:"} elseif mypat[1]=="sprd" thenmycap={"src :","from:","to  :","ang :","spd :","time:","mirr:"}  elseif mypat[1]=="brst" thenmycap={"src :","num :","ang :","spd :","time:"}elseif mypat[1]=="comb" thenmycap={"src1:","src2:","src3:","src4:","src5:"} elsefor i=2,#mypat doadd(mycap,"p"..i..":")endendfor i=2,#mypat doadd(menu,{{txt=mycap[i-1],w="     ",cmd="",cmdy=selpat,cmdx=i,x=4,y=6+i*7,c=13  },{txt=mypat[i],w=spacejam(#tostr(mypat[i])),cmd="patedit",cmdy=selpat,cmdx=i,x=24,y=6+i*7,c=13  }}) endadd(menu,{{txt="delete",w="      ",cmd="delpat",cmdy=selpat,x=4,y=6+#mypat*7+9,c=13  }})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 newpat(typ)if typ=="base" thenreturn {"base",1,11,3,40} elseif typ=="some" thenreturn {"some",1,0.5}elseif typ=="sprd" thenreturn {"sprd",1,1,1,0.1,0,0,0}elseif typ=="brst" thenreturn {"brst",1,1,0.5,0,5}elseif typ=="comb" thenreturn {"comb",1,0,0,0,0}elsereturn {typ} endendfunction enter_pat()local mymnu=menu[cury][curx]local typeval=typetxtif mymnu.cmdx==1 then--tricky!!if data[mymnu.cmdy][mymnu.cmdx]!=typetxt and typetxt!="" thendata[mymnu.cmdy]=newpat(typetxt)   endelsetypeval=tonum(typeval)if typeval==nil thentypeval=0enddata[mymnu.cmdy][mymnu.cmdx]=tonum(typeval)end_upd=update_pats
endfunction enter_table()local mymnu=menu[cury][curx]local typeval=typetxtif typeval==nil or typeval=="" 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=0end   data[mymnu.cmdy][mymnu.cmdx]=typeval_upd=update_table
end
-->8
--patsfunction dobuls(arr)for s in all(arr) dos.age+=1s.x+=s.sxs.y+=s.syif s.y<-16 or s.y>130 thendel(arr,s)endend
endfunction patshoot(en,pat,pang)if pang==-99 thenpang=atan2(pspr.y-en.y,pspr.x-en.x)endlocal mybuls=makepat(pat,pang)for b in all(mybuls) doadd(en.bulq,b)end
endfunction dobulq(en)for b in all(en.bulq) doif b.wait<=0 thenb.x+=en.xb.y+=en.yb.sx=sin(b.ang)*b.spdb.sy=cos(b.ang)*b.spdadd(buls,b)del(en.bulq,b)elseb.wait-=1endend
endfunction makepat(pat,pang)local mypat,ret=pats[pat],{}local patype,p2,p3,p4,p5,p6,p7,p8=unpack(mypat)if patype=="base" thenadd(ret,{age=0,x=0,y=0,ang=pang,spd=p2,ani=anilib[p3],anis=p4,col=p5,wait=0})elseif patype=="some" thenif rnd()<p3 thenret=makepat(p3,pang)endelseif patype=="sprd" thenfor i=p3-1,p4-1 dofor p in all(makepat(p2,pang)) dop.spd+=i*p6p.wait+=i*p7add(ret,p)if i>0 and p8>0 thenlocal copyp=copylist(p)copyp.ang+=i*-p5add(ret,copyp)endp.ang+=i*p5endendelseif patype=="brst" thenfor i=1,p3 dolocal rndw,rnds=flr(rnd(p6)),rnd(p5)for p in all(makepat(p2,pang+spread(p4))) dop.wait+=rndwp.spd+=rndsadd(ret,p)endendelseif patype=="comb" thenfor i=2,5 doif mypat[i]>0 thenfor p in all(makepat(mypat[i],pang)) doadd(ret,p)endendendendreturn ret
endfunction spread(val)return (rnd(2)-1)*val
end__gfx__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__
0000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

http://www.xdnf.cn/news/9214.html

相关文章:

  • 低空经济数据湖架构设计方案
  • 在springboot,禁止查询数据库种的某字段
  • 【linux篇】动静态库和自动化构建的“神之一手”:make、Makefile
  • AtCoder 第407场初级竞赛 A~E题解
  • java helloWord java程序运行机制 用idea创建一个java项目 标识符 关键字 数据类型 字节
  • 服务器中分布式存储数据技术都包含哪些内容?
  • maven 最短路径依赖优先
  • Qt QPaintEvent绘图事件painter使用指南
  • Qt函数setText设置中文导致乱码/程序崩溃/报错:常量中有换行符
  • html css js网页制作成品——HTML+CSS+js醇香咖啡屋网页设计(5页)附源码
  • 大模型应用开发第三讲:大模型是Agent的“大脑”,提供通用推理能力(如GPT-4、Claude 3)
  • inviteflood:基于 UDP 的 SIP/SDP 洪水攻击工具!全参数详细教程!Kali Linux教程!
  • 从零实现本地语音识别(FunASR)
  • 在AIX环境下修改oracle 11g rac的IP地址
  • 使用requestAnimationFrame编写动画效果或者处理大量数据
  • 时序数据库IoTDB安装学习经验分享
  • 第三届全国先进技术成果转化大会成功举办 中科亿海微携品亮相
  • 【premiere教程】【01】【跑个流程】
  • 【android bluetooth 协议分析 02】【bluetooth hal 层详解 6】【高通蓝牙hal主要流程介绍-下】
  • Java 基础全面解析
  • Kettle 远程mysql 表导入到 hadoop hive
  • WPF【11_7】WPF实战-重构与美化(ViewModel的嵌套与分解、海量数据不要Join)
  • OpenCV CUDA模块图像处理------颜色空间处理之GPU 上对两张带有 Alpha 通道的图像进行合成操作函数alphaComp()
  • 【洛谷P9303题解】AC代码- [CCC 2023 J5] CCC Word Hunt
  • ubuntu22.04 安装 SecureCRT8.7.3
  • 没有经验能考OCP认证吗?
  • 视频逐帧提取图片的工具
  • 拆解汽车HMI设计:如何用3D可视化提升驾驶安全感?
  • RagFlow参数配置测试
  • 2025.5.27学习日记 linux三剑客 sed与正则表达式