Advertisement
Guest User

main.lua

a guest
Mar 5th, 2017
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 36.16 KB | None | 0 0
  1.  
  2. setRoundTime(999 * 6)--frames
  3. setLifeMul(1.0)
  4. setTeam1VS2Life(1.0)
  5. setTurnsRecoveryRate(1.0 / 300.0)
  6.  
  7. setZoom(false)
  8. setZoomMin(0.25)
  9. setZoomMax(1.0)
  10. setZoomSpeed(1.0)
  11.  
  12. loadLifebar('data/HyperDBZ_Lifebar/fight.def')
  13. loadDebugFont('data/HyperDBZ_Lifebar/lifebar_font/NAME2.fnt')
  14. setDebugScript('script/debug.lua')
  15.  
  16. aiLevel = 8
  17.  
  18.  
  19. require('script.randomtest')
  20.  
  21. function addWithRefresh(addFn, text)
  22.   local nextRefresh = os.clock() + 0.02
  23.   for i, c
  24.     in ipairs(script.randomtest.strsplit('\n',
  25.                                          text:gsub('^%s*(.-)%s*$', '%1')))
  26.   do
  27.     addFn(c)
  28.     if os.clock() >= nextRefresh then
  29.       refresh()
  30.       nextRefresh = os.clock() + 0.02
  31.     end
  32.   end
  33. end
  34.  
  35. --shuffle by Uradamus
  36. --https://gist.github.com/Uradamus/10323382
  37. function shuffle(tbl)
  38.   size = #tbl
  39.   for i = size, 1, -1 do
  40.     local rand = math.random(size)
  41.     tbl[i], tbl[rand] = tbl[rand], tbl[i]
  42.   end
  43.   return tbl
  44. end
  45.  
  46. orgAddChar = addChar
  47. orgAddStage = addStage
  48.  
  49. function addChar(text)
  50.   addWithRefresh(orgAddChar, text)
  51. end
  52.  
  53. function addStage(text)
  54.   addWithRefresh(orgAddStage, text)
  55. end
  56.  
  57. assert(loadfile('script/select.lua'))()
  58.  
  59.  
  60. math.randomseed(os.time())
  61.  
  62. ------------------------------------------------------------
  63. sysSff = sffNew('script/system.sff')
  64. sysSnd = sndNew('script/system.snd')
  65. jgFnt = fontNew('data/HyperDBZ_Lifebar/lifebar_font/NAME2.fnt')
  66.  
  67. bgm = 'script/MENU.mp3'
  68. vs = 'script/VS.mp3'
  69. playBGM(bgm)
  70.  
  71. ------------------------------------------------------------
  72. function setCommand(c)
  73.   commandAdd(c, 'u', '$U')
  74.   commandAdd(c, 'd', '$D')
  75.   commandAdd(c, 'l', '$B')
  76.   commandAdd(c, 'r', '$F')
  77.   commandAdd(c, 'a', 'a')
  78.   commandAdd(c, 'b', 'b')
  79.   commandAdd(c, 'c', 'c')
  80.   commandAdd(c, 'x', 'x')
  81.   commandAdd(c, 'y', 'y')
  82.   commandAdd(c, 'z', 'z')
  83.   commandAdd(c, 's', 's')
  84.   commandAdd(c, 'holds', '/s')
  85.   commandAdd(c, 'su', '/s, U')
  86.   commandAdd(c, 'sd', '/s, D')
  87. end
  88.  
  89. p1Cmd = commandNew()
  90. setCommand(p1Cmd)
  91.  
  92. p1Cmdd = commandNew()
  93. setCommand(p1Cmdd)
  94.  
  95. p2Cmd = commandNew()
  96. setCommand(p2Cmd)
  97.  
  98. ------------------------------------------------------------
  99. selectColumns = 3
  100. selectRows = 4
  101.  
  102. setRandomSpr(sysSff, 151, 0, 3.0/selectColumns, 3.0/selectColumns)
  103. setSelColRow(selectColumns, selectRows)
  104. setSelCellSize(29*3.0/selectColumns, 29*3.0/selectColumns)
  105. setSelCellScale(3.0/selectColumns, 3.0/selectColumns)
  106.  
  107. function init()
  108.   p1TeamMode = 0
  109.   p1NumTurns  = 2
  110.   p1SelOffset = 0
  111.   p1SelX = 0
  112.   p1SelY = 0
  113.   p1Portrait = nil
  114.  
  115.   p2TeamMode = 0
  116.   p2NumTurns  = 2
  117.   p2SelOffset = 0
  118.   p2SelX = 0
  119.   p2SelY = 0
  120.   p2Portrait = nil
  121.  
  122.   stageNo = 0
  123.   setStage(0)
  124. end
  125.  
  126. init()
  127.  
  128. function noTask()
  129. end
  130.  
  131.  
  132. function animPosDraw(a, x, y)
  133.   animSetPos(a, x, y)
  134.   animDraw(a)
  135. end
  136.  
  137. function textImgPosDraw(ti, x, y)
  138.   textImgSetPos(ti, x, y)
  139.   textImgDraw(ti)
  140. end
  141.  
  142. function createTextImg(font, bank, aline, text, x, y)
  143.   local ti = textImgNew()
  144.   textImgSetFont(ti, font)
  145.   textImgSetBank(ti, bank)
  146.   textImgSetAlign(ti, aline)
  147.   textImgSetText(ti, text)
  148.   textImgSetPos(ti, x, y)
  149.   return ti
  150. end
  151.  
  152. function btnPalNo(cmd)
  153.   local s = 0
  154.   if commandGetState(cmd, 'holds') then s = 6 end
  155.   if commandGetState(cmd, 'a') then return 1 + s end
  156.   if commandGetState(cmd, 'b') then return 2 + s end
  157.   if commandGetState(cmd, 'c') then return 3 + s end
  158.   if commandGetState(cmd, 'x') then return 4 + s end
  159.   if commandGetState(cmd, 'y') then return 5 + s end
  160.   if commandGetState(cmd, 'z') then return 6 + s end
  161.   return 0
  162. end
  163.  
  164. ------------------------------------------------------------
  165. p1SelTmTxt = createTextImg(jgFnt, 0, 1, 'Player 1', 20, 30)
  166. p1SingleTxt = createTextImg(jgFnt, 0, 1, 'Single', 20, 50)
  167. p1SimulTxt = createTextImg(jgFnt, 0, 1, 'Simul', 20, 65)
  168. p1TurnsTxt = createTextImg(jgFnt, 0, 1, 'Turns', 20, 80)
  169. textImgSetScale(p1SelTmTxt, 0.7, 0.5)
  170. textImgSetScale(p1SingleTxt, 0.5, 0.5)
  171. textImgSetScale(p1SimulTxt, 0.5, 0.5)
  172. textImgSetScale(p1TurnsTxt, 0.5, 0.5)
  173.  
  174. p1TmCursor = animNew(sysSff, [[
  175. 180,0, 0,0, -1
  176. ]])
  177.  
  178. p1TmIcon = animNew(sysSff, [[
  179. 181,0, 0,0, -1
  180. ]])
  181.  
  182. function p1TmSub()
  183.   if commandGetState(p1Cmd, 'u') then
  184.     sndPlay(sysSnd, 100, 0)
  185.     p1TeamMode = p1TeamMode - 1
  186.     if p1TeamMode < 0 then p1TeamMode = 2 end
  187.   elseif commandGetState(p1Cmd, 'd') then
  188.     sndPlay(sysSnd, 100, 0)
  189.     p1TeamMode = p1TeamMode + 1
  190.     if p1TeamMode > 2 then p1TeamMode = 0 end
  191.   elseif p1TeamMode == 2 then
  192.     if commandGetState(p1Cmd, 'l') then
  193.       sndPlay(sysSnd, 100, 0)
  194.       p1NumTurns = p1NumTurns - 1
  195.       if p1NumTurns < 1 then p1NumTurns = 1 end
  196.     elseif commandGetState(p1Cmd, 'r') then
  197.       sndPlay(sysSnd, 100, 0)
  198.       p1NumTurns = p1NumTurns + 1
  199.       if p1NumTurns > 4 then p1NumTurns = 4 end
  200.     end
  201.   end
  202.   textImgDraw(p1SelTmTxt)
  203.   textImgDraw(p1SingleTxt)
  204.   textImgDraw(p1SimulTxt)
  205.   textImgDraw(p1TurnsTxt)
  206.   animUpdate(p1TmIcon)
  207.   animPosDraw(p1TmIcon, 80, 66)
  208.   animPosDraw(p1TmIcon, 86, 66)
  209.   for i = 1, p1NumTurns do
  210.     animPosDraw(p1TmIcon, 74 + i*6, 81)
  211.   end
  212.   animUpdate(p1TmCursor)
  213.   animPosDraw(p1TmCursor, 10, 47 + p1TeamMode*15)
  214.   if btnPalNo(p1Cmd) > 0 then
  215.     sndPlay(sysSnd, 100, 1)
  216.     setTeamMode(1, p1TeamMode, p1NumTurns)
  217.     p1Selected = {}
  218.     p1SelEnd = false
  219.     p1Task = p1SelSub
  220.   end
  221. end
  222.  
  223.  
  224. ------------------------------------------------------------
  225. p2SelTmTxt = createTextImg(jgFnt, 0, -1, 'Player 2', 300, 30)
  226. p2SingleTxt = createTextImg(jgFnt, 0, -1, 'Single', 300, 50)
  227. p2SimulTxt = createTextImg(jgFnt, 0, -1, 'Simul', 300, 65)
  228. p2TurnsTxt = createTextImg(jgFnt, 0, -1, 'Turns', 300, 80)
  229. textImgSetScale(p2SelTmTxt, 0.7, 0.5)
  230. textImgSetScale(p2SingleTxt, 0.5, 0.5)
  231. textImgSetScale(p2SimulTxt, 0.5, 0.5)
  232. textImgSetScale(p2TurnsTxt, 0.5, 0.5)
  233.  
  234.  
  235. p2TmCursor = animNew(sysSff, [[
  236. 190,0, 0,0, -1
  237. ]])
  238.  
  239. p2TmIcon = animNew(sysSff, [[
  240. 191,0, 0,0, -1
  241. ]])
  242.  
  243. function p2TmSub()
  244.   if commandGetState(p2Cmd, 'u') then
  245.     sndPlay(sysSnd, 100, 0)
  246.     p2TeamMode = p2TeamMode - 1
  247.     if p2TeamMode < 0 then p2TeamMode = 2 end
  248.   elseif commandGetState(p2Cmd, 'd') then
  249.     sndPlay(sysSnd, 100, 0)
  250.     p2TeamMode = p2TeamMode + 1
  251.     if p2TeamMode > 2 then p2TeamMode = 0 end
  252.   elseif p2TeamMode == 2 then
  253.     if commandGetState(p2Cmd, 'r') then
  254.       sndPlay(sysSnd, 100, 0)
  255.       p2NumTurns = p2NumTurns - 1
  256.       if p2NumTurns < 1 then p2NumTurns = 1 end
  257.     elseif commandGetState(p2Cmd, 'l') then
  258.       sndPlay(sysSnd, 100, 0)
  259.       p2NumTurns = p2NumTurns + 1
  260.       if p2NumTurns > 4 then p2NumTurns = 4 end
  261.     end
  262.   end
  263.   textImgDraw(p2SelTmTxt)
  264.   textImgDraw(p2SingleTxt)
  265.   textImgDraw(p2SimulTxt)
  266.   textImgDraw(p2TurnsTxt)
  267.   animUpdate(p2TmIcon)
  268.   animPosDraw(p2TmIcon, 240, 66)
  269.   animPosDraw(p2TmIcon, 234, 66)
  270.   for i = 1, p2NumTurns do
  271.     animPosDraw(p2TmIcon, 246 - i*6, 81)
  272.   end
  273.   animUpdate(p2TmCursor)
  274.   animPosDraw(p2TmCursor, 310, 47 + p2TeamMode*15)
  275.   if btnPalNo(p2Cmd) > 0 then
  276.     sndPlay(sysSnd, 100, 1)
  277.     setTeamMode(2, p2TeamMode, p2NumTurns)
  278.     p2Selected = {}
  279.     p2SelEnd = false
  280.     p2Task = p2SelSub
  281.   end
  282. end
  283.  
  284.  
  285. ------------------------------------------------------------
  286. p1Cursor = animNew(sysSff, [[
  287. 160,0, 0,0, -1
  288. ]])
  289. animSetScale(p1Cursor, 3.0/selectColumns, 3.0/selectColumns)
  290.  
  291. p1NameTxt = createTextImg(jgFnt, 0, 1, '', 0, 0)
  292. textImgSetScale(p1NameTxt, 0.5, 0.5)
  293.  
  294. function p1DrawSelectName()
  295.   local y = 162
  296.   for i = 1, #p1Selected do
  297.     textImgSetText(p1NameTxt, getCharName(p1Selected[i]))
  298.     textImgPosDraw(p1NameTxt, 10, y)
  299.     y = y + 7
  300.   end
  301.   return y
  302. end
  303.  
  304. function p1SelSub()
  305.   local n = p1SelOffset + p1SelX + selectColumns*p1SelY
  306.   p1Portrait = n
  307.   local y = p1DrawSelectName()
  308.   if not p1SelEnd then
  309.     if commandGetState(p1Cmd, 'su') then
  310.       sndPlay(sysSnd, 100, 0)
  311.       p1SelY = p1SelY - 20
  312.     elseif commandGetState(p1Cmd, 'sd') then
  313.       sndPlay(sysSnd, 100, 0)
  314.       p1SelY = p1SelY + 20
  315.     elseif commandGetState(p1Cmd, 'u') then
  316.       sndPlay(sysSnd, 100, 0)
  317.       p1SelY = p1SelY - 1
  318.     elseif commandGetState(p1Cmd, 'd') then
  319.       sndPlay(sysSnd, 100, 0)
  320.       p1SelY = p1SelY + 1
  321.     elseif commandGetState(p1Cmd, 'l') then
  322.       sndPlay(sysSnd, 100, 0)
  323.       p1SelX = p1SelX - 1
  324.     elseif commandGetState(p1Cmd, 'r') then
  325.       sndPlay(sysSnd, 100, 0)
  326.       p1SelX = p1SelX + 1
  327.     end
  328.     if p1SelY < 0 then
  329.       p1SelY = 0
  330.     elseif p1SelY >= selectRows then
  331.       p1SelOffset = p1SelOffset + selectColumns*(p1SelY - (selectRows - 4))
  332.       p1SelY = selectRows - 1
  333.     end
  334.     if p1SelX < 0 then
  335.       p1SelX = selectColumns - 1
  336.     elseif p1SelX >= selectColumns then
  337.       p1SelX = 0
  338.     end
  339.     animUpdate(p1Cursor)
  340.     animPosDraw(
  341.       p1Cursor, 118 + 29*p1SelX*3.0/selectColumns,
  342.       107 + 29*p1SelY*3.0/selectColumns)
  343.     textImgSetText(p1NameTxt, getCharName(n))
  344.     textImgPosDraw(p1NameTxt, 10, y)
  345.     p1SelectedPal = btnPalNo(p1Cmd)
  346.     local selval = selectChar(1, n, p1SelectedPal)
  347.     if selval > 0 then
  348.       sndPlay(sysSnd, 100, 1)
  349.       p1Selected[#p1Selected+1] = n
  350.     end
  351.     if selval == 2 then
  352.       p1SelEnd = true
  353.       if p2In == 1 then
  354.         p2Task = p2TmSub
  355.         commandBufReset(p2Cmd, p2In)
  356.       end
  357.     end
  358.   end
  359. end
  360.  
  361.  
  362. ------------------------------------------------------------
  363. p2Cursor = animNew(sysSff, [[
  364. 170,0, 0,0, -1
  365. ]])
  366. animSetScale(p2Cursor, 3.0/selectColumns, 3.0/selectColumns)
  367.  
  368. p2NameTxt = createTextImg(jgFnt, 0, -1, '', 0, 0)
  369. textImgSetScale(p2NameTxt, 0.5, 0.5)
  370.  
  371. function p2DrawSelectName()
  372.   local y = 162
  373.   for i = 1, #p2Selected do
  374.     textImgSetText(p2NameTxt, getCharName(p2Selected[i]))
  375.     textImgPosDraw(p2NameTxt, 310, y)
  376.     y = y + 7
  377.   end
  378.   return y
  379. end
  380.  
  381. function p2SelSub()
  382.   local n = p2SelOffset + p2SelX + selectColumns*p2SelY
  383.   p2Portrait = n
  384.   local y = p2DrawSelectName()
  385.   if not p2SelEnd then
  386.     if commandGetState(p2Cmd, 'su') then
  387.       sndPlay(sysSnd, 100, 0)
  388.       p2SelY = p2SelY - 20
  389.     elseif commandGetState(p2Cmd, 'sd') then
  390.       sndPlay(sysSnd, 100, 0)
  391.       p2SelY = p2SelY + 20
  392.     elseif commandGetState(p2Cmd, 'u') then
  393.       sndPlay(sysSnd, 100, 0)
  394.       p2SelY = p2SelY - 1
  395.     elseif commandGetState(p2Cmd, 'd') then
  396.       sndPlay(sysSnd, 100, 0)
  397.       p2SelY = p2SelY + 1
  398.     elseif commandGetState(p2Cmd, 'l') then
  399.       sndPlay(sysSnd, 100, 0)
  400.       p2SelX = p2SelX - 1
  401.     elseif commandGetState(p2Cmd, 'r') then
  402.       sndPlay(sysSnd, 100, 0)
  403.       p2SelX = p2SelX + 1
  404.     end
  405.     if p2SelY < 0 then
  406.       p2SelY = 0
  407.     elseif p2SelY >= selectRows then
  408.       p2SelOffset = p2SelOffset + selectColumns*(p2SelY - (selectRows - 4))
  409.       p2SelY = selectRows - 1
  410.     end
  411.     if p2SelX < 0 then
  412.       p2SelX = selectColumns - 1
  413.     elseif p2SelX >= selectColumns then
  414.       p2SelX = 0
  415.     end
  416.     animUpdate(p2Cursor)
  417.     animPosDraw(
  418.       p2Cursor, 118 + 29*p2SelX*3.0/selectColumns,
  419.       107 + 29*p2SelY*3.0/selectColumns)
  420.     textImgSetText(p2NameTxt, getCharName(n))
  421.     textImgPosDraw(p2NameTxt, 310, y)
  422.     local selval = selectChar(2, n, btnPalNo(p2Cmd))
  423.     if selval > 0 then
  424.       sndPlay(sysSnd, 100, 1)
  425.       p2Selected[#p2Selected+1] = n
  426.     end
  427.     if selval == 2 then
  428.       p2SelEnd = true
  429.       if p1In == 2 then
  430.         p1Task = p1TmSub
  431.         commandBufReset(p1Cmd, p1In)
  432.       end
  433.     end
  434.   end
  435. end
  436.  
  437.  
  438. ------------------------------------------------------------
  439. selStageTxt = createTextImg(jgFnt, 0, 0, '', 160, 237)
  440. textImgSetScale(selStageTxt, 0.5, 0.5)
  441.  
  442. function selStageSub()
  443.   if commandGetState(p1Cmd, 'l') then
  444.     sndPlay(sysSnd, 100, 0)
  445.     stageNo = setStage(stageNo - 1)
  446.   elseif commandGetState(p1Cmd, 'r') then
  447.     sndPlay(sysSnd, 100, 0)
  448.     stageNo = setStage(stageNo + 1)
  449.   elseif commandGetState(p1Cmd, 'u') then
  450.     sndPlay(sysSnd, 100, 0)
  451.     stageNo = setStage(stageNo - 10)
  452.   elseif commandGetState(p1Cmd, 'd') then
  453.     sndPlay(sysSnd, 100, 0)
  454.     stageNo = setStage(stageNo + 10)
  455.   end
  456.   textImgSetText(
  457.     selStageTxt, 'Stage ' .. stageNo .. ': ' .. getStageName(stageNo))
  458.   textImgDraw(selStageTxt)
  459.   if btnPalNo(p1Cmd) > 0 then
  460.     selectStage(stageNo)
  461.     selMode = false
  462.   end
  463. end
  464.  
  465.  
  466. ------------------------------------------------------------
  467. ------------------------------------------------------------
  468. arcadeModeTxt = createTextImg(jgFnt, 0, 1, 'Arcade Battle', 40, 140)
  469. p1VsComTxt = createTextImg(jgFnt, 0, 1, 'Free Battle', 40, 160)
  470. p1VsP2 = createTextImg(jgFnt, 0, 1, 'Vs. Battle', 40, 180)
  471. watchMode = createTextImg(jgFnt, 0, 1, 'Watch Battle', 40, 200)
  472. netplay = createTextImg(jgFnt, 0, 1, 'Network Battle', 180, 140)
  473. portChange = createTextImg(jgFnt, 0, 1, '', 180, 160)
  474. replay = createTextImg(jgFnt, 0, 1, 'Replay Channel', 180, 180)
  475. optionTxt = createTextImg(jgFnt, 0, 1, 'Options', 180, 200)
  476. textImgSetScale(arcadeModeTxt, 0.5, 0.5)
  477. textImgSetScale(p1VsComTxt, 0.5, 0.5)
  478. textImgSetScale(p1VsP2, 0.5, 0.5)
  479. textImgSetScale(watchMode, 0.5, 0.5)
  480. textImgSetScale(netplay, 0.5, 0.5)
  481. textImgSetScale(portChange, 0.5, 0.5)
  482. textImgSetScale(replay, 0.5, 0.5)
  483. textImgSetScale(optionTxt, 0.5, 0.5)
  484.  
  485. connecting = createTextImg(jgFnt, 0, 1, '', 10, 140)
  486. loading = createTextImg(jgFnt, 0, 1, 'Loading...', 100, 210)
  487.  
  488. inputdia = inputDialogNew()
  489.  
  490. function cmddInput()
  491.   commandInput(p1Cmdd, p1In)
  492.   commandInput(p2Cmdd, p2In)
  493. end
  494.  
  495. function cmdInput()
  496.   commandInput(p1Cmd, p1In)
  497.   commandInput(p2Cmd, p2In)
  498. end
  499.  
  500. function versusScreen()
  501.   for i = 1, 300 do
  502.     animDraw(SelBG)
  503.     animDraw(Sky1)
  504.     animDraw(Sky2)
  505.     animDraw(Sky3)
  506.     animDraw(Lightning)
  507.     animDraw(Lightning2)
  508.     animDraw(Rocks)
  509.     animDraw(VS)
  510.     animUpdate(VS)
  511.     local k = 0
  512.     for j = 1, #p1Selected do
  513.       local scl = 10000.0 / (10000.0 - k*i)
  514.       local tmp = i*k / 20
  515.       drawPortrait(p1Selected[j], 18 - tmp, 0 + tmp/3, scl, scl)
  516.       k = k + 48
  517.     end
  518.     k = 0
  519.     for j = 1, #p2Selected do
  520.       local scl = 10000.0 / (10000.0 - k*i)
  521.       local tmp = i*k / 20
  522.       drawPortrait(p2Selected[j], 302 + tmp, 0 + tmp/3, -scl, scl)
  523.       k = k + 48
  524.     end
  525.     p1DrawSelectName()
  526.     p2DrawSelectName()
  527.     textImgDraw(loading)
  528.     refresh()
  529.   end
  530. end
  531.  
  532. function selectScreen()
  533.   while true do
  534.     p1Selected = {}
  535.     p1SelEnd = false
  536.     p1Portrait = nil
  537.  
  538.     p2Selected = {}
  539.     p2SelEnd = false
  540.     p2Portrait = nil
  541.  
  542.    
  543.     p1Task = p1TmSub
  544.     p2Task = noTask
  545.     if gameMode > 1 and gameMode ~= 3 then
  546.       p2Task = p2TmSub
  547.     end
  548.    
  549.  
  550.     refresh()
  551.  
  552.     commandBufReset(p1Cmd, p1In)
  553.     commandBufReset(p1Cmdd, p1In)
  554.     commandBufReset(p2Cmd, p2In)
  555.  
  556.     selMode = true
  557.     selectStart()
  558.  
  559.     ------------------------------------------------------------
  560.     --Main loop
  561.     ------------------------------------------------------------
  562.     while selMode do
  563.       if esc() then return end
  564.       bgSub()
  565.       if p1Portrait then drawPortrait(p1Portrait, 18, 0, 1, 1) end
  566.       if p2Portrait then drawPortrait(p2Portrait, 302, 0, -1, 1) end
  567.       animDraw(Rocks)
  568.       animDraw(BOX)
  569.       drawFace(118, 107, p1SelOffset)
  570.       drawFace(999, 999, p2SelOffset)
  571.       if p1SelEnd and p2SelEnd then selStageSub() end
  572.       p2Task()
  573.       p1Task()
  574.       cmdInput()
  575.       refresh()
  576.     end
  577.    
  578.     versusScreen()
  579.    
  580.     local winner = game()
  581.    
  582.     bgm = 'script/SELECT.mp3'
  583.     playBGM(bgm)
  584.   end
  585. end
  586.  
  587. function congratulationScreen()
  588.  
  589.   local congratulationsTxt = createTextImg(jgFnt, 0, 0, 'Congratulations!', 160, 100)
  590.  
  591.   for i = 1, 400 do
  592.     textImgDraw(congratulationsTxt)
  593.  
  594.     refresh()
  595.   end
  596. end
  597.  
  598. function gameOverScreen()
  599.   local gameOverTxt = createTextImg(jgFnt, 0, 0, 'Game Over', 160, 100)
  600.  
  601.   for i = 1, 400 do
  602.     textImgDraw(gameOverTxt)
  603.  
  604.     refresh()
  605.   end
  606.  
  607. end
  608.  
  609. function continueScreen()
  610.  
  611.   local continueTxt = createTextImg(jgFnt, 0, 0, 'Continue?', 160, 100)
  612.   local yesTxt = createTextImg(jgFnt, 0, 1, 'Yes', 60, 135)
  613.   local noTxt = createTextImg(jgFnt, 0, 1, 'No', 215, 135)
  614.   local cursor = animNew(sysSff, [[
  615.   180,0, 0,0, -1
  616.   ]])
  617.   animSetScale(cursor, 2, 2)
  618.   local selectedOpt = true
  619.  
  620.   while true do
  621.  
  622.     if esc() then
  623.       return false
  624.     end
  625.  
  626.     textImgDraw(continueTxt)
  627.     textImgDraw(yesTxt)
  628.     textImgDraw(noTxt)
  629.  
  630.     if commandGetState(p1Cmd, 'l') then
  631.       selectedOpt = true
  632.     elseif commandGetState(p1Cmd, 'r') then
  633.       selectedOpt = false
  634.     end
  635.  
  636.     local cursorPosX = 0
  637.     if selectedOpt then
  638.       cursorPosX = 55
  639.     else
  640.       cursorPosX = 210
  641.     end
  642.  
  643.     animUpdate(cursor)
  644.     animPosDraw(cursor, cursorPosX, 135)
  645.  
  646.     if btnPalNo(p1Cmd) > 0 then
  647.       return selectedOpt
  648.     end
  649.  
  650.     cmdInput()
  651.     refresh()
  652.   end
  653.  
  654. end
  655.  
  656. function selectArcadeOpponent()
  657.  
  658.   local opponent = opponentsIndex[1]
  659.  
  660.   selectChar(2, opponent, 4)
  661.   p2Selected[1] = opponent
  662.  
  663.   selectStage(1)
  664. end
  665.  
  666. function selectScreenArcade()
  667.  
  668.   opponentsIndex = {
  669.     1, -- satan
  670.     3, -- goku
  671.     4, -- gohan
  672.     5, -- vegeta
  673.     6, -- goku ssj
  674.     7, -- frieza
  675.     8, -- vegeta ssj or whatever
  676.     10 -- babidi
  677.   }
  678.  
  679.   opponentsIndex = shuffle(opponentsIndex)
  680.  
  681.   p1Selected = {}
  682.   p1SelEnd = false
  683.   p1Portrait = nil
  684.  
  685.   while #opponentsIndex > 0 do
  686.     bgm = 'script/SELECT.mp3'
  687.     playBGM(bgm)
  688.  
  689.     p2Selected = {}
  690.     p2SelEnd = false
  691.     p2Portrait = nil
  692.  
  693.     setTeamMode(1, 0, 1)
  694.     setTeamMode(2, 0, 1)
  695.    
  696.     p1Task = p1SelSub
  697.     p2Task = noTask
  698.  
  699.     refresh()
  700.  
  701.     commandBufReset(p1Cmd, p1In)
  702.     commandBufReset(p1Cmdd, p1In)
  703.     commandBufReset(p2Cmd, p2In)
  704.  
  705.     selMode = true
  706.     selectStart()
  707.  
  708.     ------------------------------------------------------------
  709.     --Main loop
  710.     ------------------------------------------------------------
  711.     if p1SelEnd then
  712.       selectChar(1, p1Selected[1], p1SelectedPal)
  713.     end
  714.  
  715.     while not p1SelEnd do
  716.       if esc() then return end
  717.       bgSub()
  718.       if p1Portrait then drawPortrait(p1Portrait, 18, 0, 1, 1) end
  719.       animDraw(Rocks)
  720.       animDraw(BOX)
  721.       drawFace(118, 107, p1SelOffset)
  722.       p1Task()
  723.       cmdInput()
  724.       refresh()
  725.     end
  726.  
  727.     selectArcadeOpponent()
  728.     versusScreen()
  729.  
  730.     local winner = game()
  731.  
  732.     if winner == 1 then
  733.       table.remove(opponentsIndex,1)
  734.      
  735.     elseif winner == 2 then
  736.       local continue = continueScreen()
  737.      
  738.       if continue then
  739.         p1Selected = {}
  740.         p1SelEnd = false
  741.         p1Portrait = nil
  742.       else
  743.         gameOverScreen()
  744.         return
  745.       end
  746.  
  747.     elseif winner == -1 then
  748.       return
  749.     end
  750.  
  751.   end
  752.  
  753.   congratulationScreen()
  754.   return
  755.  
  756. end
  757.  
  758. function drawMainMenuBg()
  759.   animAddPos(Sky1, .125, 0)
  760.   animUpdate(Sky1)
  761.   animDraw(Sky1)
  762.   animAddPos(Sky2, .25, 0)
  763.   animUpdate(Sky2)
  764.   animDraw(Sky2)
  765.   animAddPos(Sky3, .375, 0)
  766.   animUpdate(Sky3)
  767.   animDraw(Sky3)
  768.   animAddPos(Mount, 0, 0)
  769.   animUpdate(Mount)
  770.   animDraw(Mount)
  771.   animAddPos(Grass, 0, 0)
  772.   animUpdate(Grass)
  773.   animDraw(Grass)
  774.   animAddPos(Home, 0, 0)
  775.   animUpdate(Home)
  776.   animDraw(Home)
  777. end
  778.  
  779. function drawMainMenu()
  780.   drawMainMenuBg()
  781.  
  782.   textImgDraw(arcadeModeTxt)
  783.   textImgDraw(p1VsComTxt)
  784.   textImgDraw(p1VsP2)
  785.   textImgDraw(watchMode)
  786.   textImgDraw(netplay)
  787.   textImgDraw(portChange)
  788.   textImgDraw(replay)
  789.   textImgDraw(optionTxt)
  790.   animAddPos(Logo, 0, 0)
  791.   animUpdate(Logo)
  792.   animDraw(Logo)  
  793.   animUpdate(p1TmCursor)
  794.  
  795.   if gameMode <= 3 then
  796.     animPosDraw(p1TmCursor, 37, 140 + (gameMode*20) )
  797.   else
  798.     animPosDraw(p1TmCursor, 177, 140 + ((gameMode-4)*20) )
  799.   end  
  800.  
  801. end
  802.  
  803. function modeArcade()
  804.   setCom(1, 0)
  805.   p2In = 0
  806.  
  807.   selectScreenArcade()
  808. end
  809.  
  810. function modeCpuBattle()
  811.   bgm = 'script/SELECT.mp3'
  812.   playBGM(bgm)
  813.  
  814.   selectScreen()
  815. end
  816.  
  817. function modeFreeBattle()
  818.   setCom(1, 0)
  819.   bgm = 'script/SELECT.mp3'
  820.   playBGM(bgm)
  821.  
  822.   selectScreen()
  823. end
  824.  
  825. function modeVersus()
  826.   p2In = 2
  827.   setCom(1, 0)
  828.   setCom(2, 0)
  829.   bgm = 'script/SELECT.mp3'
  830.   playBGM(bgm)
  831.  
  832.   selectScreen()
  833. end
  834.  
  835. function modeOnline()
  836.   p2In = 2
  837.   setCom(1, 0)
  838.   setCom(2, 0)
  839.   inputDialogPopup(inputdia, 'Input Server')
  840.   while not inputDialogIsDone(inputdia) do
  841.     refresh()
  842.   end
  843.   textImgSetText(
  844.     connecting,
  845.     'Searching...' .. inputDialogGetStr(inputdia)
  846.     .. ' ' .. getListenPort())
  847.   bgm = 'script/NET.mp3'
  848.   playBGM(bgm)
  849.   enterNetPlay(inputDialogGetStr(inputdia))
  850.   while not connected() do
  851.     if esc() then
  852.       return
  853.     end
  854.     animAddPos(Sky1, .125, 0)
  855.     animUpdate(Sky1)
  856.     animDraw(Sky1)
  857.     animAddPos(Sky2, .25, 0)
  858.     animUpdate(Sky2)
  859.     animDraw(Sky2)
  860.     animAddPos(Sky3, .375, 0)
  861.     animUpdate(Sky3)
  862.     animDraw(Sky3)
  863.     animAddPos(DRAGON, 0, 0)
  864.     animUpdate(DRAGON)
  865.     animDraw(DRAGON)
  866.     textImgDraw(connecting)
  867.     refresh()
  868.   end
  869.  
  870.   init()
  871.   synchronize()
  872.   math.randomseed(sszRandom())
  873.  
  874.   selectScreen()
  875. end
  876.  
  877. function modeChangePort()
  878.   inputDialogPopup(inputdia, 'Input Port')
  879.   while not inputDialogIsDone(inputdia) do
  880.     refresh()
  881.   end
  882.   setListenPort(inputDialogGetStr(inputdia))
  883. end
  884.  
  885. function modeReplay()
  886.   p2In = 2
  887.   setCom(1, 0)
  888.   setCom(2, 0)
  889.   bgm = 'script/SELECT.mp3'
  890.   playBGM(bgm)
  891.   enterReplay('replay/netplay.replay')
  892.   init()
  893.   synchronize()
  894.   math.randomseed(sszRandom())
  895. end
  896.  
  897. function modeOption()
  898.   while true do
  899.  
  900.     if esc() then
  901.       return
  902.     end
  903.  
  904.     drawMainMenuBg()
  905.  
  906.     local optionTitleTxt = createTextImg(jgFnt, 0, 1, 'Options', 130, 20)
  907.     local difficultyTxt = createTextImg(jgFnt, 0, 1, 'Difficulty ', 60, 45)
  908.  
  909.     textImgSetText(difficultyTxt, "Difficulty " .. aiLevel)
  910.     textImgSetScale(optionTitleTxt, 0.5, 0.5)
  911.     textImgSetScale(difficultyTxt, 0.5, 0.5)
  912.     textImgDraw(optionTitleTxt)
  913.     textImgDraw(difficultyTxt)
  914.  
  915.     animPosDraw(p1TmCursor, 57, 45)
  916.  
  917.     if commandGetState(p1Cmd, 'l') and aiLevel > 1 then
  918.       aiLevel = aiLevel - 1
  919.     elseif commandGetState(p1Cmd, 'r') and aiLevel < 8 then
  920.       aiLevel = aiLevel + 1
  921.     end
  922.  
  923.     cmdInput()
  924.     refresh()
  925.    
  926.   end
  927. end
  928.  
  929. function changeMode()
  930.   if commandGetState(p1Cmd, 'u') then
  931.     sndPlay(sysSnd, 100, 0)
  932.     gameMode = gameMode - 1
  933.     if gameMode < 0 then
  934.       gameMode = 3
  935.     elseif gameMode == 3 then
  936.       gameMode = 7
  937.     end
  938.   elseif commandGetState(p1Cmd, 'd') then
  939.     sndPlay(sysSnd, 100, 0)
  940.     gameMode = gameMode + 1
  941.     if gameMode == 4 then
  942.       gameMode = 0
  943.     elseif gameMode == 8 then
  944.       gameMode = 4
  945.     end
  946.   elseif commandGetState(p1Cmd, 'l') then
  947.     sndPlay(sysSnd, 100, 0)
  948.     gameMode = gameMode - 4
  949.     if gameMode < 0 then
  950.       gameMode = gameMode + 8
  951.     end
  952.   elseif commandGetState(p1Cmd, 'r') then
  953.     sndPlay(sysSnd, 100, 0)
  954.     gameMode = gameMode + 4
  955.     if gameMode > 7 then
  956.       gameMode = gameMode - 8
  957.     end
  958.   end
  959.   if gameMode < 0 then
  960.     gameMode = 5
  961.   elseif gameMode > 7 then
  962.     gameMode = 0
  963.   end
  964. end
  965.  
  966. function modeSel()
  967.   while true do
  968.     exitNetPlay()
  969.     exitReplay()
  970.  
  971.     gameMode = 0
  972.     p1In = 1
  973.     p2In = 1
  974.  
  975.     for i = 1, 8 do
  976.       setCom(i, aiLevel)
  977.     end
  978.     setAutoLevel(false)
  979.     setMatchNo(1)
  980.     setHomeTeam(1)
  981.     resetRemapInput()
  982.  
  983.     textImgSetText(portChange, 'Port Change(' .. getListenPort() .. ')')
  984.  
  985.     if bgm ~= 'script/MENU.mp3' then
  986.       bgm = 'script/MENU.mp3'
  987.       playBGM(bgm)
  988.     end
  989.  
  990.     refresh()
  991.     commandBufReset(p1Cmd, 1)
  992.     commandBufReset(p1Cmdd, 1)
  993.  
  994.     while btnPalNo(p1Cmd) <= 0 do  
  995.       changeMode()
  996.       drawMainMenu()
  997.       cmdInput()  
  998.       refresh()
  999.     end
  1000.  
  1001.     sndPlay(sysSnd, 100, 1)
  1002.  
  1003.     cancel = false
  1004.  
  1005.     if gameMode == 0 then
  1006.       modeArcade()
  1007.     elseif gameMode == 1 then
  1008.       modeFreeBattle()
  1009.     elseif gameMode == 2 then
  1010.       modeVersus()
  1011.     elseif gameMode == 3 then
  1012.       modeCpuBattle()
  1013.     elseif gameMode == 4 then
  1014.       modeOnline()
  1015.     elseif gameMode == 5 then
  1016.       modeChangePort()
  1017.     elseif gameMode == 6 then
  1018.       modeReplay()
  1019.     elseif gameMode == 7 then
  1020.       modeOption()
  1021.     end
  1022.    
  1023.   end
  1024. end
  1025.  
  1026. modeSel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement