Guest User

Kirby Super Star (J) HUD (written by ユウ, some additions by gocha)

a guest
Dec 15th, 2010
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.62 KB | None | 0 0
  1. -- スプライト情報を表示
  2.  
  3. require("sdx_common")
  4.  
  5. function DrawSpriteRect(x, y, color)
  6.     gui.rect(x - 12, y - 12, x + 11, y + 11, color, color)
  7. end
  8.  
  9. pad, pad_prev = {}
  10. input_devs, input_devs_prev = {}, {}
  11.  
  12. disp_index = 0
  13. disp_onlyone = false
  14. accel = 1
  15.  
  16. yact_index = 0
  17. yact_move  = 1
  18. yact_max   = 2
  19. Y_action = yact_index
  20.  
  21. MouseActionStat = {
  22.     SelectedSprite = -1
  23. }
  24.  
  25. -- 全スプライトの情報を表示 ----------------------------------------------------
  26. function DispAllInfo()
  27.     local cx, cy = GetCameraPos()
  28.     local count = 0
  29.    
  30.     for i = 0, Sprite.Index.max, 1 do
  31.         if Sprite.Exists(i) and (not disp_onlyone or i == disp_index) then
  32.             count = count + 1
  33.             local x, y = Sprite.GetPos(i)
  34.             x = x - cx
  35.             y = y - cy
  36.             DrawSpriteRect(x, y, "#ff000080")
  37.            
  38.             gui.text(x-12, y-12, i)
  39.             gui.text(x-12, y-4,  string.format("%04X", Sprite.GetNumber(i)))
  40.             gui.text(x-12, y+4,  string.format("%06X", Sprite.GetProgramAddress(i)))
  41.         end
  42.     end
  43. end
  44.  
  45. -- 操作方法を表示 --------------------------------------------------------------
  46. function DispHowto()
  47.     local disp_x = 0
  48.     gui.text(disp_x, statusbar_top, "Hold L + R")
  49.    
  50.     if     Y_action == yact_index then gui.text(disp_x, statusbar_top+7, "Y:index")
  51.     elseif Y_action == yact_move  then gui.text(disp_x, statusbar_top+7, "Y:move")
  52.     elseif Y_action == yact_map   then gui.text(disp_x, statusbar_top+7, "Y:map")
  53.     end
  54.    
  55.     gui.text(disp_x, statusbar_top+14, "B:"..accel)
  56.    
  57.     if disp_onlyone
  58.     then gui.text(disp_x, statusbar_top+21, "X:one")
  59.     else gui.text(disp_x, statusbar_top+21, "X:all")
  60.     end
  61.    
  62.     gui.text(disp_x, statusbar_top+28, "A:retry")
  63.    
  64.     gui.text(disp_x, statusbar_top+42, string.format("camera:%d, %d", GetCameraPos()))
  65. end
  66.  
  67. --
  68. function DispUnnamedValue(x, y, adr)
  69.     gui.text(x, y, string.format("$%04X : %04X", adr, memory.readword(adr + disp_index * 2)))
  70. end
  71.  
  72. -- 個別情報を表示 --------------------------------------------------------------
  73. function DispPersonalInfo()
  74.     local disp_x, disp_x2, disp_x3 = 60, 140, 200
  75.     local disp_y = statusbar_top + 2
  76.    
  77.     gui.text(disp_x, statusbar_top, "index : "..disp_index)
  78.    
  79.     if Sprite.Exists(disp_index)
  80.     then gui.text(disp_x, statusbar_top+7, "exist : true")
  81.     else gui.text(disp_x, statusbar_top+7, "exist : false")
  82.     end
  83.    
  84.     gui.text(disp_x, statusbar_top+14, string.format("num : %04X-%04X", Sprite.GetNumber(disp_index)))
  85.    
  86.     gui.text(disp_x, statusbar_top+21, string.format("pos : %d, %d", Sprite.GetPos(disp_index)))
  87.    
  88.     gui.text(disp_x, statusbar_top+28, string.format("program : %06X", Sprite.GetProgramAddress(disp_index)))
  89.     gui.text(disp_x, statusbar_top+35, string.format("            %04X", memory.readword(0x7032 + disp_index *2)))
  90.     gui.text(disp_x, statusbar_top+42, string.format("any : %06X", Sprite.GetAnyAddress(disp_index)))
  91.    
  92.    
  93.     DispUnnamedValue(disp_x2, disp_y,    0x6630)
  94.     DispUnnamedValue(disp_x2, disp_y+7,  0x66AA)
  95.     DispUnnamedValue(disp_x2, disp_y+14, 0x6724)
  96.     DispUnnamedValue(disp_x2, disp_y+21, 0x679E)
  97.     DispUnnamedValue(disp_x2, disp_y+28, 0x6818)
  98.     DispUnnamedValue(disp_x2, disp_y+35, 0x6DD0)
  99.     DispUnnamedValue(disp_x2, disp_y+42, 0x6E4A)
  100.    
  101.     DispUnnamedValue(disp_x3, disp_y,    0x6F3E)
  102.     DispUnnamedValue(disp_x3, disp_y+7,  0x6FB8)
  103.     DispUnnamedValue(disp_x3, disp_y+14, 0x70AC)
  104.     DispUnnamedValue(disp_x3, disp_y+21, 0x7126)
  105.     DispUnnamedValue(disp_x3, disp_y+28, 0x71A0)
  106.     DispUnnamedValue(disp_x3, disp_y+35, 0x721A)
  107.     DispUnnamedValue(disp_x3, disp_y+42, 0x7294)
  108. end
  109.  
  110.  
  111. -- フレーム前の処理(キー入力に応じて表示を変更) --------------------------------
  112. function FrameBefore()
  113.     pad_prev = pad
  114.     input_devs_prev = input_devs
  115.  
  116.     pad = joypad.get(1)
  117.     input_devs = input.get()
  118.    
  119.     -- マウスイベント処理
  120.     if input_devs.leftclick then
  121.         if not input_devs_prev.leftclick then
  122.             -- 左クリックでスプライトを選択
  123.             MouseActionStat.SelectedSprite = Sprite.Find(input_devs.xmouse, input_devs.ymouse)
  124.             if MouseActionStat.SelectedSprite ~= -1 then
  125.                 disp_index = MouseActionStat.SelectedSprite
  126.             end
  127.         else
  128.             -- ドラッグで選択スプライト移動
  129.             local index = MouseActionStat.SelectedSprite
  130.             if Sprite.Exists(index) then
  131.                 local cameraX, cameraY = GetCameraPos()
  132.                 local worldX, worldY = input_devs.xmouse + cameraX, input_devs.ymouse + cameraY
  133.                 Sprite.SetPos(disp_index, worldX, worldY)
  134.             end
  135.         end
  136.     else
  137.         if input_devs_prev.leftclick then
  138.             -- 慣性つきで投げられるとたのしい!
  139.         end
  140.         MouseActionStat.SelectedSprite = -1
  141.     end
  142.    
  143.     if not pad.L or not pad.R then return end
  144.    
  145.     if pad.Y and not pad_prev.Y
  146.     then Y_action = Y_action + 1
  147.         if Y_action >= yact_max then Y_action = yact_index end
  148.     end
  149.    
  150.     if pad.B and not pad_prev.B
  151.     then accel = accel + 1
  152.         if accel > 16 then accel = 1 end
  153.     end
  154.    
  155.     if pad.X and not pad_prev.X then disp_onlyone = not disp_onlyone end
  156.    
  157.     if pad.A and not pad_prev.A then SetMapReloadFlag() end
  158.    
  159.     if Y_action == yact_index then
  160.         -- 対象スプライトを変更
  161.         if     pad.right and not pad_prev.right then disp_index = disp_index + 1
  162.         elseif pad.left  and not pad_prev.left  then disp_index = disp_index - 1
  163.         elseif pad.down  and not pad_prev.down  then disp_index = disp_index + 10
  164.         elseif pad.up    and not pad_prev.up    then disp_index = disp_index - 10
  165.         end
  166.        
  167.         if disp_index < 0 then disp_index = 0
  168.         elseif disp_index > Sprite.Index.max then disp_index = Sprite.Index.max
  169.         end
  170.     elseif Y_action == yact_move then
  171.         -- 対象スプライトを移動
  172.         local x, y = Sprite.GetPos(disp_index)
  173.                
  174.         if     pad.right then x = x + accel
  175.         elseif pad.left  then x = x - accel
  176.         end
  177.        
  178.         if     pad.down  then y = y + accel
  179.         elseif pad.up    then y = y - accel
  180.         end
  181.        
  182.         Sprite.SetPos(disp_index, x, y)
  183.     end
  184.    
  185.     pad_prev = pad
  186.     indevs_prev = indevs
  187. end
  188.  
  189. -- フレーム後の処理(キー入力の無効化) ------------------------------------------
  190. function FrameAfter()
  191.     if not pad.L or not pad.R then return end
  192.    
  193.     -- ソフトリセット可能にする
  194.     if not pad.start or not pad.select then
  195.         pad.L      = false
  196.         pad.R      = false
  197.         pad.start  = false
  198.         pad.select = false
  199.     end
  200.    
  201.     pad.up     = false
  202.     pad.down   = false
  203.     pad.right  = false
  204.     pad.left   = false
  205.     pad.A      = false
  206.     pad.X      = false
  207.     pad.Y      = false
  208.     pad.B      = false
  209.    
  210.     joypad.set(1, pad)
  211. end
  212.  
  213. -- 描画処理 --------------------------------------------------------------------
  214. gui.register(function()
  215.     DispAllInfo()
  216.     HideStatusbar()
  217.     DispHowto()
  218.     DispPersonalInfo()
  219. end)
  220.  
  221. -- メインループ ----------------------------------------------------------------
  222.  
  223. emu.registerbefore(FrameBefore)
  224. emu.registerafter(FrameAfter)
Add Comment
Please, Sign In to add comment