こちらにはタイル背景に登場する関数群が使用されています。
(06 - Map.lua)
01:SCREEN_BOTTOM = 0 02:SCREEN_TOP = 1 03: 04:BGTopText = Screen.LoadTextBG() 05:Screen.Initialize( SCREEN_TOP, BGTopText ) 06: 07:BGTopText:PrintXY( 0, 0, "Press A to change corner tiles" ) 08:BGTopText:PrintXY( 0, 1, "Use d-pad to scroll map" ) 09:BGTopText:PrintXY( 0, 3, "Press START to exit" ) 10: 11:BGBottomMap = Screen.LoadTileBG() 12: 13:BGBottomMap:LoadPalette( "map_examplescrn.bmp.pal" ) 14: 15:BGBottomMap:LoadTiles( "map_examplescrn.raw", 256 ) 16: 17:BGBottomMap:LoadMap( "map_examplescrn.map", ( 320 / 8 ), ( 240 / 8 ) ) 18: 19:Screen.Initialize( SCREEN_BOTTOM, BGBottomMap ) 20: 21:nX = 0 22:nY = 0 23:nTile = 0 24:while true do 25: if Pads.Left() then 26: nX = math.max( nX-1, 0 ) 27: end 28: if Pads.Right() then 29: nX = math.min( nX+1, 320-256) 30: end 31: if Pads.Up() then 32: nY = math.max( nY-1, 0 ) 33: end 34: if Pads.Down() then 35: nY = math.min( nY+1, 240-192 ) 36: end 37: 38: if Pads.A() then 39: nTile = math.mod( ( nTile + 1 ), 10 ) 40: BGBottomMap:SetMapTile( 0, 0, nTile ) 41: BGBottomMap:SetMapTile( 39, 0, nTile ) 42: BGBottomMap:SetMapTile( 0, 29, nTile ) 43: BGBottomMap:SetMapTile( 39, 29, nTile ) 44: end 45: 46: if Pads.Start() then 47: break 48: end 49: 50: BGBottomMap:ScrollXY( nX, nY ) 51: Screen.WaitForVBL() 52:end
プログラムの解説
01:SCREEN_BOTTOM = 0 02:SCREEN_TOP = 1
いつもの画面番号指定
04:BGTopText = Screen.LoadTextBG() 05:Screen.Initialize( SCREEN_TOP, BGTopText )
上画面はテキストで初期化
07:BGTopText:PrintXY( 0, 0, "Press A to change corner tiles" ) 08:BGTopText:PrintXY( 0, 1, "Use d-pad to scroll map" ) 09:BGTopText:PrintXY( 0, 3, "Press START to exit" )
Aボタンで角のタイルを変更
十字キーでマップがスクロール
STARTボタンで終了
11:BGBottomMap = Screen.LoadTileBG()
タイル背景を読み込む
13:BGBottomMap:LoadPalette( "map_examplescrn.bmp.pal" )
タイル用のパレット読み込み
15:BGBottomMap:LoadTiles( "map_examplescrn.raw", 256 )
タイルチップ読み込み。画像モードは256色
17:BGBottomMap:LoadMap( "map_examplescrn.map", ( 320 / 8 ), ( 240 / 8 ) )
画像サイズが320×240、実際のタイル数はそれぞれ8で割った数字になる
19:Screen.Initialize( SCREEN_BOTTOM, BGBottomMap )
タイル背景で初期化
21:nX = 0 22:nY = 0 23:nTile = 0
変数の初期化
24:while true do
52行目までループ
25: if Pads.Left() then 26: nX = math.max( nX-1, 0 ) 27: end 28: if Pads.Right() then 29: nX = math.min( nX+1, 320-256) 30: end 31: if Pads.Up() then 32: nY = math.max( nY-1, 0 ) 33: end 34: if Pads.Down() then 35: nY = math.min( nY+1, 240-192 ) 36: end
十字キーが押された時の処理
math関数を使用して画面の範囲外を参照しないように固定
38: if Pads.A() then 39: nTile = math.mod( ( nTile + 1 ), 10 ) 40: BGBottomMap:SetMapTile( 0, 0, nTile ) 41: BGBottomMap:SetMapTile( 39, 0, nTile ) 42: BGBottomMap:SetMapTile( 0, 29, nTile ) 43: BGBottomMap:SetMapTile( 39, 29, nTile ) 44: end
Aボタンが押されたら角のタイルを変更する
Xは0から始まって39まで(320÷8)、Yは同様に29まで(240÷8)
46: if Pads.Start() then 47: break 48: end
STARTボタンで終了
50: BGBottomMap:ScrollXY( nX, nY )
マップをスクロール
51: Screen.WaitForVBL()
いつものFPS固定
52:end
24行目のループ終端