home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / pathfi1a / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-04  |  10.2 KB  |  345 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BackColor       =   &H00000000&
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   6210
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   7170
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   6210
  11.    ScaleWidth      =   7170
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.TextBox Text1 
  14.       BackColor       =   &H00000000&
  15.       ForeColor       =   &H00FFFFFF&
  16.       Height          =   285
  17.       Left            =   2040
  18.       TabIndex        =   7
  19.       Text            =   "200"
  20.       Top             =   5040
  21.       Width           =   975
  22.    End
  23.    Begin VB.Timer Timer2 
  24.       Enabled         =   0   'False
  25.       Interval        =   200
  26.       Left            =   2520
  27.       Top             =   5400
  28.    End
  29.    Begin VB.PictureBox picsrch 
  30.       AutoRedraw      =   -1  'True
  31.       AutoSize        =   -1  'True
  32.       Height          =   300
  33.       Left            =   1560
  34.       Picture         =   "Form1.frx":0000
  35.       ScaleHeight     =   240
  36.       ScaleWidth      =   240
  37.       TabIndex        =   6
  38.       Top             =   5520
  39.       Visible         =   0   'False
  40.       Width           =   300
  41.    End
  42.    Begin VB.PictureBox main 
  43.       AutoRedraw      =   -1  'True
  44.       AutoSize        =   -1  'True
  45.       Height          =   300
  46.       Index           =   1
  47.       Left            =   960
  48.       Picture         =   "Form1.frx":0342
  49.       ScaleHeight     =   240
  50.       ScaleWidth      =   240
  51.       TabIndex        =   4
  52.       Top             =   5520
  53.       Visible         =   0   'False
  54.       Width           =   300
  55.    End
  56.    Begin VB.Timer Timer1 
  57.       Interval        =   1
  58.       Left            =   3360
  59.       Top             =   5400
  60.    End
  61.    Begin VB.PictureBox buffer 
  62.       AutoRedraw      =   -1  'True
  63.       Height          =   4935
  64.       Left            =   5280
  65.       ScaleHeight     =   325
  66.       ScaleMode       =   3  'Pixel
  67.       ScaleWidth      =   361
  68.       TabIndex        =   1
  69.       Top             =   4080
  70.       Visible         =   0   'False
  71.       Width           =   5475
  72.    End
  73.    Begin VB.PictureBox main 
  74.       AutoRedraw      =   -1  'True
  75.       AutoSize        =   -1  'True
  76.       Height          =   300
  77.       Index           =   0
  78.       Left            =   600
  79.       Picture         =   "Form1.frx":0684
  80.       ScaleHeight     =   240
  81.       ScaleWidth      =   240
  82.       TabIndex        =   0
  83.       Top             =   5520
  84.       Visible         =   0   'False
  85.       Width           =   300
  86.    End
  87.    Begin VB.Label Label1 
  88.       AutoSize        =   -1  'True
  89.       BackStyle       =   0  'Transparent
  90.       Caption         =   "Change speed(milliseconds)"
  91.       ForeColor       =   &H00FFFFFF&
  92.       Height          =   195
  93.       Left            =   1560
  94.       TabIndex        =   8
  95.       Top             =   4800
  96.       Width           =   1965
  97.    End
  98.    Begin VB.Label pthfnd 
  99.       AutoSize        =   -1  'True
  100.       BackStyle       =   0  'Transparent
  101.       Caption         =   "Path Not Found"
  102.       ForeColor       =   &H00FFFFFF&
  103.       Height          =   195
  104.       Left            =   240
  105.       TabIndex        =   5
  106.       Top             =   5280
  107.       Width           =   1125
  108.    End
  109.    Begin VB.Label lbly 
  110.       AutoSize        =   -1  'True
  111.       BackStyle       =   0  'Transparent
  112.       Caption         =   "Y"
  113.       ForeColor       =   &H00FFFFFF&
  114.       Height          =   195
  115.       Left            =   120
  116.       TabIndex        =   3
  117.       Top             =   5040
  118.       Width           =   105
  119.    End
  120.    Begin VB.Label lblx 
  121.       AutoSize        =   -1  'True
  122.       BackStyle       =   0  'Transparent
  123.       Caption         =   "X"
  124.       ForeColor       =   &H00FFFFFF&
  125.       Height          =   195
  126.       Left            =   120
  127.       TabIndex        =   2
  128.       Top             =   4800
  129.       Width           =   105
  130.    End
  131. Attribute VB_Name = "Form1"
  132. Attribute VB_GlobalNameSpace = False
  133. Attribute VB_Creatable = False
  134. Attribute VB_PredeclaredId = True
  135. Attribute VB_Exposed = False
  136. 'Written by Jonathon Lopez
  137. 'jjmlopez@flash.net
  138. Dim i As Integer, j As Integer, a As Integer, b As Integer, c As Variant, d As Variant, e As Variant, f As Variant, px As Variant, py As Variant, sqbufx As Integer, sqbufy As Integer, pos As Variant, found As Boolean, tries As Integer, try1 As Integer, direc As Integer
  139. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  140. If X < 4841.12 And Y < 4841.12 Then 'if the mousedown was in the correct area then find path
  141.     a = (X \ 242.56)       'set the labels to hold the x,y values
  142.     b = (Y \ 242.56)
  143.     lblx = "X:" & a
  144.     lbly = "Y:" & b
  145.     ReDim d(0 To 19, 0 To 19) 'set up data for finding the path
  146.     ReDim e(0 To 19, 0 To 19)
  147.     ReDim f(0 To 19, 0 To 19)
  148.     ReDim px(0 To 19, 0 To 19)
  149.     ReDim py(0 To 19, 0 To 19)
  150.     For i = 0 To 19
  151.     For j = 0 To 19
  152.     d(i, j) = c(i, j)
  153.     e(i, j) = 0
  154.     f(i, j) = 0
  155.     py(i, j) = 0
  156.     Next j
  157.     Next i
  158.     found = False
  159.     e(pos(0, 0), pos(0, 1)) = 1
  160.     f(a, b) = 1
  161.     tries = 0
  162.     'the two following fors run whenever you click on the squares
  163.     'they basically do this:
  164.     'start with the goal square
  165.     'if the square next to me hasn't been reached yet then
  166.     'tell it that its been reached now
  167.     'and that it came from my direction(later, when the destination has been reached, it will use the direction data to retrace its steps)
  168.     'repeat for all sqaures until destination has been reached
  169.     For i = 0 To 19
  170.     For j = 0 To 19
  171.     If e(i, j) = 1 Then
  172.         On Error Resume Next
  173.         If d(i - 1, j) = 0 And e(i - 1, j) = 0 Then
  174.         e(i - 1, j) = 1
  175.         px(i - 1, j) = 1
  176.         py(i - 1, j) = j
  177.         End If
  178.         If d(i - 1, j - 1) = 0 And e(i - 1, j - 1) = 0 Then
  179.         e(i - 1, j - 1) = 1
  180.         px(i - 1, j - 1) = 2
  181.         py(i - 1, j - 1) = j
  182.         End If
  183.         If d(i - 1, j + 1) = 0 And e(i - 1, j + 1) = 0 Then
  184.         e(i - 1, j + 1) = 1
  185.         px(i - 1, j + 1) = 3
  186.         py(i - 1, j + 1) = j
  187.         End If
  188.         If d(i + 1, j) = 0 And e(i + 1, j) = 0 Then
  189.         e(i + 1, j) = 1
  190.         px(i + 1, j) = 4
  191.         py(i + 1, j) = j
  192.         End If
  193.         If d(i + 1, j - 1) = 0 And e(i + 1, j - 1) = 0 Then
  194.         e(i + 1, j - 1) = 1
  195.         px(i + 1, j - 1) = 5
  196.         py(i + 1, j - 1) = j
  197.         End If
  198.         If d(i + 1, j + 1) = 0 And e(i + 1, j + 1) = 0 Then
  199.         e(i + 1, j + 1) = 1
  200.         px(i + 1, j + 1) = 6
  201.         py(i + 1, j + 1) = j
  202.         End If
  203.         If d(i, j - 1) = 0 And e(i, j - 1) = 0 Then
  204.         e(i, j - 1) = 1
  205.         px(i, j - 1) = 7
  206.         py(i, j - 1) = j
  207.         End If
  208.         If d(i, j + 1) = 0 And e(i, j + 1) = 0 Then
  209.         e(i, j + 1) = 1
  210.         px(i, j + 1) = 8
  211.         py(i, j + 1) = j
  212.         End If
  213.     End If
  214.     tries = tries + 1
  215.     If e(a, b) = 1 Then
  216.     try1 = 0
  217.     found = True
  218.     pthfnd.Caption = "Path Found"
  219.     Call bitblt(Me.hDC, pos(0, 0) * 16, pos(0, 1) * 16, 16, 16, picsrch.hDC, 0, 0, SRCCOPY)
  220.     Call bitblt(Me.hDC, (a) * 16, (b) * 16, 16, 16, picsrch.hDC, 0, 0, SRCCOPY)
  221.     sqbufx = a
  222.     sqbufy = b
  223.     direc = 0
  224.     direc = px(a, b)
  225.     If direc = 1 Then sqbufx = sqbufx + 1
  226.     If direc = 2 Then
  227.     sqbufx = sqbufx + 1
  228.     sqbufy = sqbufy + 1
  229.     End If
  230.     If direc = 3 Then
  231.     sqbufx = sqbufx + 1
  232.     sqbufy = sqbufy - 1
  233.     End If
  234.     If direc = 4 Then sqbufx = sqbufx - 1
  235.     If direc = 5 Then
  236.     sqbufx = sqbufx - 1
  237.     sqbufy = sqbufy + 1
  238.     End If
  239.     If direc = 6 Then
  240.     sqbufx = sqbufx - 1
  241.     sqbufy = sqbufy - 1
  242.     End If
  243.     If direc = 7 Then sqbufy = sqbufy + 1
  244.     If direc = 8 Then sqbufy = sqbufy - 1
  245.     Timer2.Enabled = True
  246.     Exit Sub
  247.     End If
  248.     Next j
  249.     Next i
  250.      If tries > 3500 Then 'if there have been too many tries then stop
  251.     found = False
  252.     MsgBox "Path Not Found"
  253.     pthfnd.Caption = "Path Not Found"
  254.     Exit Sub
  255.     End If
  256.     If found = False Then GoTo top
  257. End If
  258. End Sub
  259. Private Sub Text1_Change()
  260. Timer2.Interval = Text1.Text
  261. End Sub
  262. Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
  263. If KeyCode < 48 And KeyCode > 57 Then
  264. KeyCode = 0
  265. End If
  266. End Sub
  267. Private Sub Timer1_Timer()
  268. 'Timer that draws the original pic on the form
  269. ReDim c(0 To 19, 0 To 19)
  270. For i = 0 To 19 'variant c contains the data for the map, if c(x,y) = 1, then a little wall will appear there
  271. For j = 0 To 19
  272. c(i, j) = 0
  273. Next j
  274. Next i
  275. c(8, 12) = 1
  276. c(8, 13) = 1
  277. c(9, 11) = 1
  278. c(9, 12) = 1
  279. c(10, 10) = 1
  280. c(10, 11) = 1
  281. c(11, 9) = 1
  282. c(11, 10) = 1
  283. c(14, 0) = 1
  284. c(14, 1) = 1
  285. c(14, 2) = 1
  286. c(14, 3) = 1
  287. c(15, 3) = 1
  288. c(16, 3) = 1
  289. c(17, 3) = 1
  290. c(17, 2) = 1
  291. ReDim pos(0 To 1, 0 To 1) 'this holds the data for the target square, you can change the goal by changing the following two values
  292. pos(0, 0) = 0
  293. pos(0, 1) = 0
  294. For i = 0 To 19
  295. For j = 0 To 19
  296. 'Calls the bitblt function, the hsrcdc is based on the data in the current map position
  297. Call bitblt(buffer.hDC, i * 16, j * 16, 16, 16, main(c(i, j)).hDC, 0, 0, SRCCOPY)
  298. Next j
  299. Next i
  300. Call bitblt(Me.hDC, 0, 0, 320, 320, buffer.hDC, 0, 0, SRCCOPY)
  301. Timer1.Enabled = False
  302. End Sub
  303. Private Sub Timer2_Timer()
  304. try1 = try1 + 1
  305.     Call bitblt(Me.hDC, sqbufx * 16, sqbufy * 16, 16, 16, picsrch.hDC, 0, 0, SRCCOPY)
  306.     If sqbufx = pos(0, 0) + 1 And sqbufy = pos(0, 1) + 1 Then 'if we have reached the first square, or the goal, then stop
  307.     Timer2.Enabled = False
  308.     Else
  309.     On Error Resume Next
  310.     direc = px(sqbufx, sqbufy)
  311.    If direc = 1 Then   'if the direction is west, add one to the x value, and so on for each direction
  312.    sqbufx = sqbufx + 1
  313.    End If
  314.    If direc = 2 Then
  315.     sqbufx = sqbufx + 1
  316.     sqbufy = sqbufy + 1
  317.     End If
  318.     If direc = 3 Then
  319.     sqbufx = sqbufx + 1
  320.     sqbufy = sqbufy - 1
  321.     End If
  322.     If direc = 4 Then
  323.     sqbufx = sqbufx - 1
  324.     End If
  325.     If direc = 5 Then
  326.     sqbufx = sqbufx - 1
  327.     sqbufy = sqbufy + 1
  328.     End If
  329.     If direc = 6 Then
  330.     sqbufx = sqbufx - 1
  331.     sqbufy = sqbufy - 1
  332.     End If
  333.     If direc = 7 Then
  334.     sqbufy = sqbufy + 1
  335.     End If
  336.     If direc = 8 Then
  337.     sqbufy = sqbufy - 1
  338.     End If
  339.     'Stop
  340.     If try1 > 50 Then
  341.     Timer2.Enabled = False
  342.     End If
  343.     End If
  344. End Sub
  345.