home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Magicquest773184292002.psc / modMap.bas < prev    next >
Encoding:
BASIC Source File  |  2002-04-29  |  19.6 KB  |  901 lines

  1. Attribute VB_Name = "modMap"
  2. Option Explicit
  3.  
  4. Declare Function GetTickCount Lib "kernel32" () As Long
  5.  
  6. Public Const TileWidth = 18
  7. Public Const TileHeight = 18
  8.  
  9. Enum nDir
  10. up = 0
  11. down = 2
  12. Left = 3
  13. Right = 1
  14. End Enum
  15.  
  16. Enum nAI_kinds
  17. Still = 0
  18. Pace = 1
  19. Spin = 2
  20. Random = 3
  21. End Enum
  22.  
  23. Type PackItem
  24. Caption As String
  25. Value As Long
  26. FuncID As String 'the function is preforms (ie magic dust = +10 magic, or candy = +5 health)
  27. Act As Long
  28. End Type
  29.  
  30. Type Pack
  31. Item(1 To 20) As PackItem
  32.  
  33. mDust As Long
  34. money As Long
  35. End Type
  36.  
  37. Type BattleInfo
  38. Health As Long
  39. Attack As Long
  40. Defense As Long
  41. MaxHealth As Long
  42. Level As Long
  43.  
  44. Exp As Long
  45. TExp As Long
  46. End Type
  47.  
  48. Type Player
  49. X As Long
  50. Y As Long
  51.  
  52. SpeachI As Long
  53. Walking As Boolean
  54. DestX As Long
  55. DestY As Long
  56. WalkC As Long
  57.  
  58. dir As nDir
  59.  
  60. B As BattleInfo
  61. Pack As Pack
  62.  
  63. Step As Long
  64. StepC As Long
  65.  
  66. SpellCut As Boolean
  67. SpellFreeze As Boolean
  68. End Type
  69.  
  70. Type Tile
  71. X As Long
  72. Y As Long
  73.  
  74. Type As Long
  75.  
  76. Walkable As Long
  77. DoorPath As String
  78. DoorWay As Long
  79. DoorDir As Long
  80.  
  81. SignText As String
  82. isBattle As Long
  83. isMarket As Long
  84. plID As Long
  85.  
  86. Ani As Long
  87. AniC As Long
  88. End Type
  89.  
  90. Type Map
  91. Name As String
  92. Midi As String
  93. Mapwidth As Long
  94. Mapheight As Long
  95.  
  96. MarketPath As String
  97.  
  98. MaxHP As Long 'the maxium stats of a wild monster in the high grass
  99. MaxAttack As Long
  100. MaxDefense As Long
  101. End Type
  102.  
  103. Type obj
  104. AI As Long
  105. T As Long
  106. Name As String
  107.  
  108. Speek() As String
  109. SpeekI As Long
  110.  
  111. AI_Type As nAI_kinds
  112. dir As Long
  113. Person As Long
  114.  
  115. Walking As Long
  116. WalkC As Long
  117.  
  118. X As Long
  119. Y As Long
  120. DestX As Long
  121. DestY As Long
  122. Step As Long
  123. StepC As Long
  124.  
  125. plID As Long
  126.  
  127. Act As Long
  128. End Type
  129.  
  130. Type enemy
  131. HP As Long
  132. MaxHP As Long
  133.  
  134. Attack As Long
  135. Defense As Long
  136.  
  137. Name As String
  138. End Type
  139.  
  140. Type MessageObject
  141. message As String
  142. Time As Long
  143. End Type
  144.  
  145. Public M As Map
  146. Public T(5000) As Tile
  147. Public p As Player
  148. Public o(1 To 20) As obj
  149. Public Msg As MessageObject
  150. Public Enem As enemy
  151. Public E As New ClsEngine
  152. Public FPS As Long
  153. Public Louis As Long 'to determine whether you beat louis
  154. Public gSpeed As Long
  155. Public Night As Long 'determine whether it is day or night
  156. Public Boss(1 To 5) As Long
  157. Public TFPS As Long
  158.  
  159. Function LoadMap(pth As String, dr As Long, d)
  160. Dim lineread() As String, C() As String, free, tfree, X, Y, func() As String, I
  161. Dim funct As String, u() As String, path, door, dir
  162. door = dr
  163. dir = d
  164. path = pth
  165.  
  166. ClearStuff
  167.  
  168. Msg.Time = 0
  169. Msg.message = ""
  170.  
  171. Open App.path + "\maps\" & path For Input As #1
  172.  
  173. Input #1, M.Name
  174. Input #1, M.MarketPath
  175. Input #1, free, tfree
  176.  
  177. frmGame.market.Picture = LoadPicture(App.path + "\other data\" & free)
  178. frmGame.battle.Picture = LoadPicture(App.path + "\other data\" & tfree)
  179.  
  180. Input #1, M.MaxHP, M.MaxAttack, M.MaxDefense
  181. Input #1, M.Midi
  182. Input #1, M.Mapwidth, M.Mapheight
  183.  
  184. tfree = ""
  185. free = ""
  186.  
  187. Do Until EOF(1)
  188.  
  189.     Line Input #1, free
  190.  
  191.     If free = "END TILES" Then GoTo DoneTiles
  192.  
  193.     tfree = tfree & free & vbCrLf
  194.  
  195. Loop
  196.  
  197. DoneTiles:
  198.  
  199. I = 1
  200.  
  201. Do
  202.  
  203.     Line Input #1, funct
  204.  
  205.     If funct = "END OBJECTS" Then GoTo DoneObjs
  206.  
  207.         u() = Split(funct, ",")
  208.         o(I).Act = True
  209.         o(I).dir = nDir.down
  210.         o(I).Name = u(0)
  211.         o(I).Speek() = Split(u(1), "|")
  212.         o(I).SpeekI = 0
  213.         o(I).dir = Val(u(5))
  214.         o(I).T = Val(u(2))
  215.         o(I).AI = 0
  216.         o(I).AI_Type = Val(u(4))
  217.         o(I).plID = Val(u(3))
  218.         o(I).Person = False
  219.         If isValue(o(I).T, 1, 2, 3) = True Then o(I).Person = True
  220.  
  221.         If o(I).Name = "Louis" And Louis = True Then
  222.         o(I).Speek() = Split("We'll youve beaten me|Bet if we had a rematch I'd win!", "|")
  223.         o(I).Walking = False
  224.         End If
  225.         
  226.     DoEvents
  227.     I = I + 1
  228.  
  229. Loop
  230.  
  231. DoneObjs:
  232.  
  233. lineread() = Split(tfree, vbCrLf)
  234. I = 0
  235.  
  236. frmGame.buffer.Width = M.Mapwidth * TileWidth
  237. frmGame.buffer.Height = M.Mapheight * TileHeight
  238.  
  239. For Y = 1 To M.Mapheight
  240.     
  241.     C() = Split(lineread(Y - 1), "|")
  242.     
  243.     For X = 1 To M.Mapwidth
  244.     
  245.         func() = Split(C(X - 1), ",")
  246.         
  247.         T(I).X = (X - 1) * TileWidth
  248.         T(I).Y = (Y - 1) * TileHeight
  249.         T(I).Type = Val(func(0))
  250.         T(I).DoorPath = func(1)
  251.         If InStr(1, func(1), ":") > 1 Then T(I).DoorPath = Split(func(1), ":")(0)
  252.         If Len(T(I).DoorPath) > 1 Then T(I).DoorWay = Val(Split(func(1), ":")(1))
  253.         If Len(T(I).DoorPath) > 1 Then T(I).DoorDir = Val(Split(func(1), ":")(2))
  254.         T(I).SignText = func(2)
  255.         T(I).isMarket = Val(func(3))
  256.         T(I).plID = Val(func(4))
  257.         If T(I).plID = door Then p.X = T(I).X: p.Y = T(I).Y: p.DestX = p.X: p.DestY = p.Y
  258.         T(I).Walkable = True
  259.         If isValue(T(I).Type, 0, 2, 3, 7, 9, 10, 11, 12, 13) = True Then T(I).Walkable = False
  260.         
  261.         I = I + 1
  262.     Next X
  263.     
  264. Next Y
  265.  
  266. Close #1
  267.  
  268. SetObjs
  269.  
  270. p.dir = dir
  271. End Function
  272.  
  273. Function WalkOn(TileI As Long)
  274. If T(TileI).DoorPath <> "" Then LoadMap T(TileI).DoorPath, T(TileI).DoorWay, T(TileI).DoorDir
  275. If T(TileI).Type = 6 And Int(Rnd * 10) = 5 Then LoadBattle
  276. End Function
  277.  
  278. Function GetTile() As Long
  279. Dim I As Long
  280.  
  281. For I = 0 To M.Mapheight * M.Mapwidth
  282.     
  283.     If T(I).X = p.DestX And T(I).Y = p.DestY Then GetTile = I: Exit For
  284.  
  285. Next I
  286. End Function
  287.  
  288. Function GetObjTile(Ind) As Long
  289. Dim I As Long
  290.  
  291. For I = 0 To M.Mapheight * M.Mapwidth
  292.  
  293.     If T(I).X = o(Ind).DestX And T(I).Y = o(Ind).DestY Then GetObjTile = I: Exit For
  294.  
  295. Next I
  296. End Function
  297.  
  298. Function SetObjs() As Long
  299. Dim I As Long, i2
  300.  
  301. For I = 0 To M.Mapheight * M.Mapwidth
  302.  
  303.      For i2 = 1 To 20
  304.      
  305.         If o(i2).plID = T(I).plID Then
  306.             o(i2).Walking = False
  307.             o(i2).X = T(I).X
  308.             o(i2).Y = T(I).Y
  309.             o(i2).DestX = o(i2).X
  310.             o(i2).DestY = o(i2).Y
  311.             
  312.             If o(i2).Name = "Louis" And Louis = True Then
  313.                 o(i2).X = o(i2).X - 18
  314.                 o(i2).DestX = o(i2).X
  315.             End If
  316.         
  317.         End If
  318.      
  319.      Next i2
  320.      
  321. Next I
  322. End Function
  323.  
  324. Function TalkTo()
  325. If p.SpeachI > 0 Then Exit Function
  326. p.SpeachI = 100
  327.  
  328. Dim TileI As Long
  329.  
  330. Select Case p.dir
  331.  
  332.     Case nDir.up: TileI = GetTile - M.Mapheight
  333.     Case nDir.down: TileI = GetTile + M.Mapheight
  334.     Case nDir.Left: TileI = GetTile - 1
  335.     Case nDir.Right: TileI = GetTile + 1
  336.  
  337. End Select
  338.  
  339. If T(TileI).SignText <> "" Then DoMsg T(TileI).SignText
  340.  
  341. If T(TileI).isMarket = -1 Then LoadMarket
  342.  
  343. If isTileTaken(TileI) = True And Msg.Time < 11 Then
  344.     
  345.     Dim H As Long, odir
  346.  
  347.     H = GetObj(TileI)
  348.  
  349.     If o(H).Person = True Then
  350.         
  351.         Select Case p.dir
  352.         
  353.             Case nDir.down: odir = nDir.up
  354.             Case nDir.Left: odir = nDir.Right
  355.             Case nDir.Right: odir = nDir.Left
  356.             Case nDir.up: odir = nDir.down
  357.             
  358.         End Select
  359.  
  360.     o(H).dir = odir
  361.     
  362. End If
  363.  
  364.     DoMsg o(H).Name & ": " & o(H).Speek(o(H).SpeekI)
  365.  
  366.     If Msg.message = "Old Man: Here I'll teach you the cut spell" Then p.SpellCut = True
  367.     If Msg.message = "Louis: Let's Fight!" Then DoMsg "Fight me you chicken!": LoadSetBattle "Louis", 50, 18, 10, frmGame.bsLouis
  368.     If Msg.message = "I will teach the freeze spell to you" Then p.SpellFreeze = True
  369.     
  370.     o(H).SpeekI = o(H).SpeekI + 1: If o(H).SpeekI > UBound(o(H).Speek()) Then o(H).SpeekI = 0
  371.  
  372. End If
  373. End Function
  374.  
  375. Function ClearStuff()
  376. Dim I As Long
  377.  
  378. For I = 0 To 5000
  379.  
  380.     T(I).X = 0
  381.     T(I).Y = 0
  382.     T(I).Type = 0
  383.     T(I).plID = 0
  384.     T(I).Ani = 0
  385.     T(I).isMarket = False
  386.     T(I).DoorDir = 0
  387.     T(I).DoorPath = ""
  388.     T(I).DoorWay = 0
  389.     T(I).SignText = ""
  390.     
  391. Next I
  392.  
  393. For I = 1 To 20
  394.  
  395.     o(I).Act = False
  396.     o(I).plID = 0
  397.     
  398. Next I
  399. End Function
  400.  
  401. Function isValue(Value As Long, ParamArray Nums() As Variant) As Boolean
  402. Dim I As Long
  403.  
  404. isValue = False
  405.  
  406. For I = LBound(Nums()) To UBound(Nums())
  407.  
  408.     If Value = Nums(I) Then isValue = True
  409.     
  410. Next I
  411. End Function
  412.  
  413. Function CheckInput()
  414. If E.IsPressed(vbKeyLeft) Then
  415.  
  416.     If p.Walking = False Then p.DestX = p.X - TileWidth: p.Walking = True
  417.     
  418. End If
  419.  
  420. If E.IsPressed(vbKeyRight) Then
  421.  
  422.     If p.Walking = False Then p.DestX = p.X + TileWidth: p.Walking = True
  423.     
  424. End If
  425.  
  426. If E.IsPressed(vbKeyUp) Then
  427.  
  428.     If p.Walking = False Then p.DestY = p.Y - TileHeight: p.Walking = True
  429.     
  430. End If
  431.  
  432. If E.IsPressed(vbKeyDown) Then
  433.  
  434.     If p.Walking = False Then p.DestY = p.Y - TileHeight: p.Walking = True
  435.     
  436. End If
  437. End Function
  438.  
  439. Function LoadMenu()
  440. Dim I As Long
  441.  
  442. frmGame.board.Visible = False
  443. frmGame.menu.Visible = True
  444. frmGame.battle.Visible = False
  445. frmGame.main.Visible = False
  446. frmGame.market.Visible = False
  447.  
  448. frmGame.lstItems.Clear
  449.  
  450. For I = 1 To 20
  451.  
  452.     If p.Pack.Item(I).Act = True Then
  453.     
  454.         frmGame.lstItems.AddItem p.Pack.Item(I).Caption
  455.         
  456.     End If
  457.  
  458. Next I
  459. End Function
  460.  
  461. Function UseItem(cap As String, I)
  462. Select Case UCase(cap)
  463.     Case "CANDY" 'candy
  464.         p.B.Health = p.B.Health + 5
  465.     Case "MAGIC DUST" 'magic dust
  466.         p.Pack.mDust = p.Pack.mDust + 10
  467.     Case "ENERGY JUICE" 'energy juice
  468.         p.B.Attack = p.B.Attack + 5
  469.     Case "IRON JUICE" 'iron juice
  470.         p.B.Defense = p.B.Defense + 5
  471.     Case "SPECIAL CANDY"
  472.         p.B.Level = p.B.Level + 1
  473.         p.B.Attack = p.B.Attack + (Int(Rnd * 7) + 1)
  474.         p.B.Defense = p.B.Defense + (Int(Rnd * 5) + 1)
  475. End Select
  476.  
  477. p.Pack.Item(I + 1).Act = False
  478. End Function
  479.  
  480. Function LoadBattle()
  481. frmGame.tmrAttack.Enabled = False
  482. frmGame.tmrAttack2 = False
  483. frmGame.tmrMagic.Enabled = False
  484. frmGame.imgMagic.Visible = False
  485. frmGame.imgAttack.Visible = False
  486. frmGame.imgAttack2.Visible = False
  487. frmGame.imgEnemy.Picture = frmGame.enemy(Int(Rnd * (frmGame.enemy.ubound + 1))).Picture
  488. frmGame.board.Visible = False
  489. frmGame.menu.Visible = False
  490. frmGame.battle.Visible = True
  491. frmGame.main.Visible = False
  492. frmGame.market.Visible = False
  493.  
  494. Enem.HP = Int(Rnd * M.MaxHP) + 1
  495. Enem.MaxHP = Enem.HP
  496. Enem.Attack = Int(Rnd * M.MaxAttack) + 1
  497. Enem.Defense = Int(Rnd * M.MaxDefense) + 1
  498. End Function
  499.  
  500. Function NewGame()
  501. LoadMap "house.dat", 2, 2 'load the house map
  502.  
  503. p.dir = down
  504.  
  505. p.Pack.Item(1).Act = True
  506. p.Pack.Item(1).Value = 50
  507. p.Pack.Item(1).Caption = "Candy"
  508. p.Pack.Item(2).Act = True
  509. p.Pack.Item(2).Value = 50
  510. p.Pack.Item(2).Caption = "Candy"
  511. p.Pack.Item(3).Act = True
  512. p.Pack.Item(3).Value = 100
  513. p.Pack.Item(3).Caption = "Magic Dust"
  514.  
  515. p.SpellCut = False
  516. p.SpellFreeze = False
  517.  
  518. p.B.Level = 1
  519. p.B.Attack = Val(frmGame.txtAttack.text)
  520. p.B.Defense = Val(frmGame.txtDefense.text)
  521. p.B.Health = 50
  522. p.B.MaxHealth = 50
  523. p.B.Exp = 0
  524. p.B.TExp = 10
  525.  
  526. p.Pack.money = 300
  527. p.Pack.mDust = 30
  528. p.Walking = False
  529. p.DestX = p.X
  530. p.DestY = p.Y
  531. End Function
  532.  
  533. Function MovePlayer()
  534. If p.Walking = True And p.WalkC > 3 Then
  535.     p.WalkC = 0
  536.  
  537.     Select Case p.X
  538.         Case Is < p.DestX
  539.           p.X = p.X + 6
  540.         Case Is > p.DestX
  541.             p.X = p.X - 6
  542.         Case Is = p.DestX
  543.             If isValue(p.dir, nDir.Left, nDir.Right) And p.Walking = True Then p.Walking = False: WalkOn GetTile
  544.     End Select
  545.  
  546.     Select Case p.Y
  547.         Case Is < p.DestY
  548.             p.Y = p.Y + 6
  549.         Case Is > p.DestY
  550.             p.Y = p.Y - 6
  551.         Case Is = p.DestY
  552.             If isValue(p.dir, nDir.up, nDir.down) And p.Walking = True Then p.Walking = False: WalkOn GetTile
  553.     End Select
  554.  
  555. Else
  556.  
  557.     p.WalkC = p.WalkC + 1
  558.  
  559. End If
  560.  
  561. If p.StepC > 5 Then
  562.  
  563.     p.StepC = 0
  564.     p.Step = p.Step + 1: If p.Step > 1 Then p.Step = 0
  565.  
  566. Else
  567.  
  568.     p.StepC = p.StepC + 1
  569.  
  570. End If
  571.  
  572. If E.IsPressed(vbKeyUp) Then
  573.  
  574.     If p.Walking = False Then p.DestY = p.Y - 18: p.Walking = True: p.dir = up
  575.     If T(GetTile).Walkable = False Then p.DestY = p.Y
  576.     If isTileTaken(GetTile) = True Then p.DestY = p.Y
  577.     
  578. End If
  579.  
  580. If E.IsPressed(vbKeyDown) Then
  581.  
  582.     If p.Walking = False Then p.DestY = p.Y + 18: p.Walking = True: p.dir = down
  583.     If T(GetTile).Walkable = False Then p.DestY = p.Y
  584.     If isTileTaken(GetTile) = True Then p.DestY = p.Y
  585.     
  586. End If
  587.  
  588. If E.IsPressed(vbKeyLeft) Then
  589.  
  590.     If p.Walking = False Then p.DestX = p.X - 18: p.Walking = True: p.dir = Left
  591.     If T(GetTile).Walkable = False Then p.DestX = p.X
  592.     If isTileTaken(GetTile) = True Then p.DestX = p.X
  593.     
  594. End If
  595.  
  596. If E.IsPressed(vbKeyRight) Then
  597.  
  598.     If p.Walking = False Then p.DestX = p.X + 18: p.Walking = True: p.dir = Right
  599.     If T(GetTile).Walkable = False Then p.DestX = p.X
  600.     If isTileTaken(GetTile) = True Then p.DestX = p.X
  601.     
  602. End If
  603.  
  604. If E.IsPressed(vbKeySpace) Then TalkTo
  605.  
  606. If E.IsPressed(vbKeyZ) Then DoSpell
  607. End Function
  608.  
  609. Function isTileTaken(I As Long)
  610. Dim n
  611. isTileTaken = False
  612.  
  613.         For n = 1 To 20
  614.         
  615.             If o(n).Act = True And o(n).DestX = T(I).X And o(n).DestY = T(I).Y Then isTileTaken = True: Exit Function
  616.         
  617.         Next n
  618.  
  619. End Function
  620.  
  621. Function LoadMarket()
  622. Dim I As Long
  623.  
  624. frmGame.board.Visible = False
  625. frmGame.menu.Visible = False
  626. frmGame.battle.Visible = False
  627. frmGame.main.Visible = False
  628. frmGame.market.Visible = True
  629.  
  630. frmGame.lblMoney.Caption = p.Pack.money & "$"
  631.  
  632. frmGame.lstStuff.Clear
  633. frmGame.lstICost.Clear
  634.  
  635. For I = 1 To 20
  636.  
  637.     If p.Pack.Item(I).Act = True Then
  638.     
  639.         frmGame.lstStuff.AddItem p.Pack.Item(I).Caption
  640.         frmGame.lstICost.AddItem p.Pack.Item(I).Value
  641.         
  642.     End If
  643.  
  644. Next I
  645.  
  646. Dim n As String, n2
  647.  
  648. Open App.path + "\other data\" & M.MarketPath For Input As #1
  649.  
  650. Input #1, n
  651.  
  652. frmGame.market.Picture = LoadPicture(App.path + n)
  653.  
  654. frmGame.lstBuy.Clear
  655. frmGame.lstMCost.Clear
  656.  
  657. Do Until EOF(1)
  658.  
  659.     Input #1, n, n2
  660.  
  661.     frmGame.lstBuy.AddItem n
  662.     frmGame.lstMCost.AddItem n2
  663.  
  664.     DoEvents
  665.     
  666. Loop
  667.  
  668. Close #1
  669. End Function
  670.  
  671. Function AddPackItem(Caption As String, Cost As Long) As Boolean
  672. Dim I As Long
  673.  
  674. AddPackItem = True
  675.  
  676. For I = 1 To 20
  677.  
  678.     If p.Pack.Item(I).Act = False Then
  679.  
  680.         p.Pack.Item(I).Act = True
  681.         p.Pack.Item(I).Caption = Caption
  682.         p.Pack.Item(I).Value = Cost
  683.         GoTo Done
  684.  
  685.     End If
  686.  
  687. Next I
  688.  
  689. AddPackItem = False
  690. MsgBox ("Not enough room in your pack for the item!"), , "MagicQuest"
  691.  
  692. Done:
  693. End Function
  694.  
  695. Function MoveObjs()
  696. Dim I As Long
  697.  
  698. DoAI
  699.  
  700. For I = 1 To 20
  701.  
  702.        MoveObj o(I)
  703.        
  704.  Next I
  705. End Function
  706.  
  707. Function MoveObj(p As obj)
  708. Dim I As Long
  709.  
  710. If p.Walking = True And p.WalkC > 3 Then
  711.     p.WalkC = 0
  712.  
  713.     Select Case p.X
  714.         Case Is < p.DestX
  715.           p.X = p.X + 6
  716.         Case Is > p.DestX
  717.             p.X = p.X - 6
  718.         Case Is = p.DestX
  719.             If isValue(p.dir, nDir.Left, nDir.Right) And p.Walking = True Then p.Walking = False: WalkOn GetTile
  720.     End Select
  721.  
  722.     Select Case p.Y
  723.         Case Is < p.DestY
  724.             p.Y = p.Y + 6
  725.         Case Is > p.DestY
  726.             p.Y = p.Y - 6
  727.         Case Is = p.DestY
  728.             If isValue(p.dir, nDir.up, nDir.down) And p.Walking = True Then p.Walking = False: WalkOn GetTile
  729.     End Select
  730.  
  731. Else
  732.  
  733.     p.WalkC = p.WalkC + 1
  734.  
  735. End If
  736.  
  737. If p.Person = True Then
  738. If p.StepC > 5 Then
  739.  
  740.     p.StepC = 0
  741.     p.Step = p.Step + 1: If p.Step > 1 Then p.Step = 0
  742.  
  743. Else
  744.  
  745.     p.StepC = p.StepC + 1
  746.  
  747. End If
  748. End If
  749.  
  750. End Function
  751.  
  752. Function GetObj(Ind) As Long
  753. Dim I As Long
  754.  
  755. For I = 1 To 20
  756.  
  757.     If o(I).Act = True And o(I).DestX = T(Ind).X And o(I).DestY = T(Ind).Y Then GetObj = I: Exit For
  758.  
  759. Next I
  760. End Function
  761.  
  762. Function isPlayerOnTile(TileI As Long) As Boolean
  763. isPlayerOnTile = False
  764. If p.DestX = T(TileI).X And p.DestY = T(TileI).Y Then isPlayerOnTile = True
  765. End Function
  766.  
  767. Function DoSpell()
  768. Dim TileI As Long
  769.  
  770. Select Case p.dir
  771.  
  772.     Case nDir.up: TileI = GetTile - M.Mapheight
  773.     Case nDir.down: TileI = GetTile + M.Mapheight
  774.     Case nDir.Left: TileI = GetTile - 1
  775.     Case nDir.Right: TileI = GetTile + 1
  776.  
  777. End Select
  778.  
  779. If T(TileI).Type = 3 And p.SpellCut = True And p.Pack.mDust > 0 Then
  780.  
  781.     p.Pack.mDust = p.Pack.mDust - 5: If p.Pack.mDust < 0 Then p.Pack.mDust = 0
  782.     T(TileI).Type = 1
  783.     T(TileI).Walkable = True
  784.     
  785. End If
  786.  
  787. If T(TileI).Type = 2 And p.SpellFreeze = True And p.Pack.mDust > 0 Then
  788.  
  789.     p.Pack.mDust = p.Pack.mDust - 5: If p.Pack.mDust < 0 Then p.Pack.mDust = 0
  790.     T(TileI).Type = 15
  791.     T(TileI).Walkable = True
  792.     
  793. End If
  794. End Function
  795.  
  796. Function DoAI()
  797. Dim I As Long
  798.  
  799. For I = 1 To 20
  800.  
  801.     If o(I).Act = True Then
  802.  
  803.         o(I).AI = o(I).AI + 1
  804.  
  805.         If o(I).AI > 200 And o(I).AI_Type = 1 Then
  806.         
  807.         Select Case o(I).dir
  808.             Case nDir.up: o(I).dir = nDir.Right
  809.             Case nDir.Right: o(I).dir = nDir.down
  810.             Case nDir.down: o(I).dir = nDir.Left
  811.             Case nDir.Left: o(I).dir = nDir.up
  812.         End Select
  813.         
  814.         o(I).AI = 0
  815.     
  816.     Else
  817.     
  818.         o(I).AI = o(I).AI + 1
  819.  
  820.     End If
  821.  
  822.     If o(I).AI > 70 And o(I).AI_Type = 3 Then
  823.     
  824.         o(I).AI = 0
  825.             
  826.         Dim n As Long
  827.         n = Int(Rnd * 8)
  828.  
  829.         Select Case n
  830.             Case 4
  831.                 If o(I).Walking = False Then o(I).DestY = o(I).Y - 18: o(I).Walking = True: o(I).dir = nDir.up
  832.                 If T(GetObjTile(I)).Walkable = False Then o(I).DestY = o(I).Y: o(I).Walking = False
  833.                 If isTileTaken(GetObjTile(I)) = True Then o(I).DestY = o(I).Y: o(I).Walking = False
  834.                 If isPlayerOnTile(GetObjTile(I)) = True Then o(I).DestY = o(I).Y: o(I).Walking = False
  835.             Case 5
  836.                 If o(I).Walking = False Then o(I).DestY = o(I).Y + 18: o(I).Walking = True: o(I).dir = nDir.down
  837.                 If T(GetObjTile(I)).Walkable = False Then o(I).DestY = o(I).Y: o(I).Walking = False
  838.                 If isTileTaken(GetObjTile(I)) = True Then o(I).DestY = o(I).Y: o(I).Walking = False
  839.                 If isPlayerOnTile(GetObjTile(I)) = True Then o(I).DestY = o(I).Y: o(I).Walking = False
  840.             Case 6
  841.                 If o(I).Walking = False Then o(I).DestX = o(I).X - 18: o(I).Walking = True: o(I).dir = nDir.Left
  842.                 If T(GetObjTile(I)).Walkable = False Then o(I).DestX = o(I).X: o(I).Walking = False
  843.                 If isTileTaken(GetObjTile(I)) = True Then o(I).DestX = o(I).X: o(I).Walking = False
  844.                 If isPlayerOnTile(GetObjTile(I)) = True Then o(I).DestX = o(I).X: o(I).Walking = False
  845.             Case 7
  846.                 If o(I).Walking = False Then o(I).DestX = o(I).X + 18: o(I).Walking = True: o(I).dir = nDir.Right
  847.                 If T(GetObjTile(I)).Walkable = False Then o(I).DestX = o(I).X: o(I).Walking = False
  848.                 If isTileTaken(GetObjTile(I)) = True Then o(I).DestX = o(I).X: o(I).Walking = False
  849.                 If isPlayerOnTile(GetObjTile(I)) = True Then o(I).DestX = o(I).X: o(I).Walking = False
  850.             Case Else
  851.                 o(I).dir = n
  852.             End Select
  853.  
  854.         Else
  855.         
  856.             o(I).AI = o(I).AI + 1
  857.             
  858.         End If
  859.         
  860.     End If
  861.  
  862. Next I
  863. End Function
  864.  
  865.  
  866. Function LoadSetBattle(Name, HP, Attack, Defense, pic As PictureBox)
  867. frmGame.tmrAttack.Enabled = False
  868. frmGame.tmrAttack2 = False
  869. frmGame.tmrMagic.Enabled = False
  870. frmGame.imgMagic.Visible = False
  871. frmGame.imgAttack.Visible = False
  872. frmGame.imgAttack2.Visible = False
  873. frmGame.imgEnemy.Picture = pic.Picture
  874. frmGame.board.Visible = False
  875. frmGame.menu.Visible = False
  876. frmGame.battle.Visible = True
  877. frmGame.main.Visible = False
  878. frmGame.market.Visible = False
  879.  
  880. Enem.Name = Name
  881. Enem.HP = HP
  882. Enem.MaxHP = Enem.HP
  883. Enem.Attack = Attack
  884. Enem.Defense = Defense
  885. End Function
  886.  
  887. Function isNight()
  888. isNight = False
  889. Select Case Hour(Time)
  890. Case Is < 6 Or Hour(Time) > 20: isNight = True
  891. Case Is > 6 And Hour(Time) < 20: isNight = False
  892. End Select
  893. End Function
  894.  
  895. Function DoMsg(message As String)
  896.     Dim money
  897.     money = Int(Rnd * 20) + 10
  898.     Msg.message = message
  899.     Msg.Time = Len(Msg.message) + 10
  900. End Function
  901.