
PICO-8でブロック崩しを作ろう(ブロックパターンの実装
縦横に並べているだけだったブロックを自由な位置に配置できるようにします。
_init()

_init()にグローバル変数levelを定義します。
パターンの意味は次のようになります。
B:ブロック
X:空白
/:改行(ブロック・空白の合計が11個を超えた場合も改行)
1〜9:直前のB or Xを数値分横に並べる。
※ブロックが5個連続で並び空白が6個並んでるのが1段目でその下に空白が5個、ブロックが6個並ぶ2段目がきます。
buildbricks()

単純に縦横にブロックを並べていた関数buildbricks()を書き換えて、引数lvlで与えられた文字列を元にブロックを配置するようにします。
lvlに入ってる文字列を1文字ずつ取り出して、その文字によってブロックの配置位置を決める処理です。
startgame()

startgame()で先ほど書き換えたbuildbricks()を実行します。
じゃーーん!

こんなパターンも・・・
