
- 状态机:为了实现游戏的不同状态(如启动屏幕和游戏运行状态),我们引入了状态机。通过动态地切换
draw
和update
函数,我们能够根据游戏当前的状态来执行不同的操作。 - 启动屏幕:制作了一个简单的启动屏幕,当玩家按下按钮时,游戏会从启动屏幕切换到实际运行状态。
- 清除屏幕:移除了每次绘制前的清屏操作,因为我们总是将整个地图绘制到屏幕上,所以不需要清屏来查看各图层之间的空隙。
- 爆炸效果:对爆炸效果进行了微调,使其看起来更加自然和不可预测。通过使用
R&D range
函数,我们为爆炸的偏移量添加了随机性。
function _init()t=0debug={}butarr=split("1,2,3,1,4,6,7,4,5,9,8,5,1,2,3,1")dirx=split("0,-1,1, 0,0, -0.7, 0.7,0.7,-0.7")diry=split("0, 0,0,-1,1, -0.7,-0.7,0.7,0.7")--★shiparr=split("65,67,69,71,73")flamearr=split("76,77,78,77")mapsegs=split("3,3,3,3,3,2,1,0,1,7,6,5,10,4,11,6,11,11,5,9,10,8,1,0,15,14,1,13,12,19,19,18,17,16,18,17,16,17,16,19,22,21,20,27,26,25,23,24,3,3")_upd=upd_menu_drw=drw_menu
endfunction startgame()px,py=64,64spd=1.4lastdir=0shipspr=0scroll=0xscroll=0mapsegi=0cursegs={}boss=falseparts={}shots={}shotwait=0muzz={}_upd=upd_game_drw=drw_game
endfunction _draw()_drw()--★cursor(4,4)color(7)for txt in all(debug) doprint(txt)end
endfunction _update60()t+=1_upd()
end-->8
--drawfunction drw_game()for seg in all(cursegs) domap(seg.x,seg.y,xscroll,scroll-seg.o,18,8)endfor p in all(parts) doif p.wait==nil thenp.draw(p)endendfor s in all(shots) do spr(s.sani[flr(s.si)],s.x,s.y,1,s.sh)endfor m in all(muzz) do spr(m.sani[flr(m.si)],px+m.x,py+m.y,2,2)end--shipspr(shiparr[flr(shipspr*2.4+3.5)],px,py,2,2)local fframe=flamearr[t\3%4+1]spr(fframe,px+6,py+15)spr(fframe,px+3,py+15)debug[1]=scroll
endfunction drw_menu()map(19,8)
end