home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / joystick / game.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-09-05  |  11.4 KB  |  354 lines

  1. VERSION 2.00
  2. Begin Form gameform 
  3.    BackColor       =   &H00FFFFFF&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Joystick Skeet Shoot"
  6.    ClientHeight    =   8490
  7.    ClientLeft      =   1005
  8.    ClientTop       =   1695
  9.    ClientWidth     =   10455
  10.    Height          =   9150
  11.    Left            =   960
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   8490
  16.    ScaleWidth      =   10455
  17.    Top             =   1080
  18.    Width           =   10545
  19.    Begin Joystick Joystick1 
  20.       Left            =   120
  21.       Top             =   7920
  22.    End
  23.    Begin Line Line1 
  24.       BorderColor     =   &H00000000&
  25.       BorderWidth     =   2
  26.       X1              =   0
  27.       X2              =   10440
  28.       Y1              =   7680
  29.       Y2              =   7680
  30.    End
  31.    Begin Label Label4 
  32.       Alignment       =   2  'Center
  33.       BackColor       =   &H00FFFFFF&
  34.       Caption         =   "SCORE"
  35.       Height          =   255
  36.       Left            =   6240
  37.       TabIndex        =   3
  38.       Top             =   7800
  39.       Width           =   3495
  40.    End
  41.    Begin Label Label3 
  42.       Alignment       =   2  'Center
  43.       BackColor       =   &H00FFFFFF&
  44.       Caption         =   "SHOTS"
  45.       Height          =   255
  46.       Left            =   1440
  47.       TabIndex        =   2
  48.       Top             =   7800
  49.       Width           =   2535
  50.    End
  51.    Begin Label Label2 
  52.       Alignment       =   2  'Center
  53.       BackColor       =   &H00FFFFFF&
  54.       Caption         =   "0"
  55.       FontBold        =   -1  'True
  56.       FontItalic      =   0   'False
  57.       FontName        =   "MS Sans Serif"
  58.       FontSize        =   12
  59.       FontStrikethru  =   0   'False
  60.       FontUnderline   =   0   'False
  61.       ForeColor       =   &H000000FF&
  62.       Height          =   255
  63.       Left            =   1560
  64.       TabIndex        =   1
  65.       Top             =   8160
  66.       Width           =   2295
  67.    End
  68.    Begin Label Label1 
  69.       Alignment       =   2  'Center
  70.       BackColor       =   &H00FFFFFF&
  71.       Caption         =   "0000"
  72.       FontBold        =   -1  'True
  73.       FontItalic      =   0   'False
  74.       FontName        =   "MS Sans Serif"
  75.       FontSize        =   12
  76.       FontStrikethru  =   0   'False
  77.       FontUnderline   =   0   'False
  78.       Height          =   255
  79.       Left            =   6360
  80.       TabIndex        =   0
  81.       Top             =   8160
  82.       Width           =   3255
  83.    End
  84.    Begin Menu mnugame 
  85.       Caption         =   "&Game"
  86.       Begin Menu mnunew 
  87.          Caption         =   "&New"
  88.          Shortcut        =   {F2}
  89.       End
  90.       Begin Menu mnupause 
  91.          Caption         =   "&Pause"
  92.          Shortcut        =   {F3}
  93.       End
  94.       Begin Menu mnustop 
  95.          Caption         =   "&Exit"
  96.          Shortcut        =   {F4}
  97.       End
  98.    End
  99.    Begin Menu mnuoptions 
  100.       Caption         =   "&Options"
  101.       Begin Menu mnuspeed 
  102.          Caption         =   "&Speed"
  103.          Begin Menu mnufast 
  104.             Caption         =   "&Fast"
  105.             Index           =   0
  106.          End
  107.          Begin Menu mnufast 
  108.             Caption         =   "&Medium"
  109.             Index           =   1
  110.          End
  111.          Begin Menu mnufast 
  112.             Caption         =   "&Slow"
  113.             Checked         =   -1  'True
  114.             Index           =   2
  115.          End
  116.       End
  117.       Begin Menu mnutargets 
  118.          Caption         =   "&Targets"
  119.          Begin Menu mnumultiple 
  120.             Caption         =   "&Single"
  121.             Checked         =   -1  'True
  122.             Index           =   0
  123.          End
  124.          Begin Menu mnumultiple 
  125.             Caption         =   "&Multiple"
  126.             Index           =   1
  127.          End
  128.       End
  129.    End
  130. DefInt A-Z
  131. Dim tsize As Integer
  132. Dim tdelay As Integer
  133. Dim tcount As Integer
  134. Dim targetx As Integer
  135. Dim targety As Integer
  136. Dim capcolor As Long
  137. Dim score As Long
  138. Dim lppoint As pointapi
  139. Dim kill_target As Integer
  140. Dim shots As Integer
  141. Dim master_time As Single
  142. Dim game_over As Integer
  143. Dim pause_flag As Integer
  144. Dim target(1 To 3) As target_data
  145. Sub draw_target (x As Integer, y As Integer, cqb)
  146.     'Debug.Print x, y, cqb
  147.     gameform.DrawMode = 7' xor mode
  148.     gameform.Line (x, y)-(x + tsize, y + tsize), QBColor(cqb), BF
  149. End Sub
  150. Sub Form_Load ()
  151. tsize = 500
  152. tdelay = 4
  153. tcount = 1
  154. xmax = 20000
  155. ymax = 20000
  156. xmin = 0
  157. ymin = 0
  158. calx = 0
  159. caly = 0
  160. button_mark = False
  161. mousepointer = 2
  162. shots = 50
  163. winxmax = gameform.ScaleLeft + gameform.ScaleWidth
  164. winxmin = gameform.ScaleLeft
  165. winymin = gameform.ScaleTop
  166. winymax = gameform.ScaleTop + gameform.ScaleHeight
  167. joystick1.Capture = True
  168. xmax = getprivateprofileint("gameform", "xmax", -1, "joytest.ini")
  169. If xmax = -1 Then
  170.     need_calibrate = True
  171.     xmin = getprivateprofileint("gameform", "xmin", -1, "joytest.ini")
  172.     ymax = getprivateprofileint("gameform", "ymax", -1, "joytest.ini")
  173.     ymin = getprivateprofileint("gameform", "ymin", -1, "joytest.ini")
  174. End If
  175. deltax = gameform.ScaleWidth / xmax
  176. deltay = gameform.ScaleHeight / ymax
  177. loop_count = 0
  178.     time1! = Timer
  179.     count1 = 0
  180.     Do
  181.         DoEvents
  182.         count1 = count1 + 1
  183.     Loop While Timer - time1! < 1
  184. loop_time = loop_time + count1
  185. loop_count = loop_count + 1
  186. Loop While loop_count < 2
  187. master_time = Int(loop_time / loop_count)
  188. Randomize
  189. game_over = False
  190. End Sub
  191. Sub Joystick1_ButtonDown (button As Integer)
  192. button_mark = True
  193. If need_calibrate Then Exit Sub
  194.     Select Case button
  195.         Case 1
  196.             'Circle (winpoint.x, winpoint.y), 80, RGB(0, 0, 0)
  197.             'fillcolor = QBColor(0)
  198.         Case 2
  199.             'picture2.Circle (winpoint.x, winpoint.y), 80, RGB(0, 0, 0)
  200.             'fillcolor = QBColor(0)
  201.             getcursorpos lppoint
  202.             
  203.             ScreenToClient gameform.hWnd, lppoint
  204.             lppoint.x = lppoint.x * screen.TwipsPerPixelX
  205.             lppoint.y = lppoint.y * screen.TwipsPerPixelY
  206.             For i = 1 To tcount
  207.                 If lppoint.x > target(i).x And lppoint.x < target(i).x + tsize Then
  208.                     If lppoint.y > target(i).y And lppoint.y < target(i).y + tsize Then
  209.                         Beep
  210.                         score = score + 10 * tdelay
  211.                         label1.Caption = Str(score)
  212.                         target(i).kill_target = True
  213.                     End If
  214.                 End If
  215.             Next i
  216.             shots = shots - 1
  217.             label2.Caption = Str(shots)
  218.             If shots = 0 Then
  219.             game_over = True
  220.             MsgBox "Game Over!", 0, "Joystick Skeet Shoot"
  221.             End If
  222.     End Select
  223. End Sub
  224. Sub Joystick1_Move (x As Integer, y As Integer, z As Integer)
  225.     calx = x
  226.     caly = y
  227.     If need_calibrate Then
  228.         Call calibrate(gameform)
  229.         If need_calibrate <> True Then
  230.             t = writeprivateprofilestring("gameform", "xmax", ByVal Format$(xmax), "joytest.ini")
  231.             t = writeprivateprofilestring("gameform", "ymax", ByVal Format$(ymax), "joytest.ini")
  232.             t = writeprivateprofilestring("gameform", "xmin", ByVal Format$(xmin), "joytest.ini")
  233.             t = writeprivateprofilestring("gameform", "ymin", ByVal Format$(ymin), "joytest.ini")
  234.         End If
  235.         Exit Sub
  236.     End If
  237.     convert x, y, gameform
  238.     'Debug.Print "* "; winpoint.x, winpoint.y
  239. End Sub
  240. Sub mnufast_Click (index As Integer)
  241. Select Case index
  242.     Case 0' fast
  243.         tdelay = 8
  244.         mnufast(1).Checked = False
  245.         mnufast(2).Checked = False
  246.     Case 1' medium
  247.         tdelay = 4
  248.         mnufast(0).Checked = False
  249.         mnufast(2).Checked = False
  250.     Case 2' slow
  251.         tdelay = 2
  252.         mnufast(0).Checked = True
  253.         mnufast(1).Checked = True
  254. End Select
  255. mnufast(index).Checked = True
  256. End Sub
  257. Sub mnumultiple_Click (index As Integer)
  258. Select Case index
  259.     Case 0
  260.         tcount = 1
  261.     Case 1
  262.         tcount = 2
  263. End Select
  264. End Sub
  265. Sub mnunew_Click ()
  266. game_over = False
  267. score = 0
  268. shots = 50
  269. label1.Caption = Str(score)
  270. label2.Caption = Str(shots)
  271. '****************************************
  272. ' Create the targets
  273. '****************************************
  274.             Do
  275.                 c1 = Int(15 * Rnd)
  276.             Loop While c1 = 7' don't allow white target
  277.             target(1).color = c1
  278.             target(2).color = c1
  279.     For i = 1 To tcount
  280.             If i = 1 Then
  281.                 
  282.                 target(i).x = Int(((gameform.Width - tsize - gameform.Left + 1) * Rnd / 2) + gameform.Left)
  283.                 target(i).y = gameform.ScaleTop + gameform.ScaleHeight - Int((gameform.ScaleTop + gameform.ScaleHeight) / 4)
  284.                 draw_target target(i).x, target(i).y, target(i).color
  285.             Else
  286.                 
  287.                 target(i).x = target(i - 1).x - 2 * tsize
  288.                 target(i).y = target(i - 1).y - 2 * tsize
  289.                 draw_target target(i).x, target(i).y, target(i).color
  290.             End If
  291.             dummy = DoEvents()
  292.             ' draw a target
  293.             
  294.             target(i).dx = Int(100 * Rnd + 50)
  295.             target(i).dy = -Int(100 * Rnd + 50)
  296.             Do
  297.                 target(i).dxm = Int(3 * Rnd - 1)
  298.                 
  299.             Loop While target(i).dxm = 0
  300.             target(i).dx = target(i).dx * target(i).dxm
  301.             target(i).kill_target = False
  302.             target(i).valid = True
  303.             
  304.     Next i
  305. '*******************************************
  306. ' if paused, wait till cleared
  307. '*******************************************
  308.             Do
  309.                 DoEvents
  310.             Loop While pause_flag = True
  311. '*******************************************
  312. ' delay between movements
  313. '*******************************************
  314.             loop_count = 0
  315.             Do
  316.                 DoEvents
  317.                 loop_count = loop_count + 1
  318.             Loop Until loop_count = Int(master_time / tdelay)
  319. '******************************************
  320. ' move target(s)
  321. '******************************************
  322.         For i = 1 To tcount
  323.             If target(i).kill_target = True Then
  324.                 draw_target target(i).x, target(i).y, c1' erase the target
  325.                 target(i).kill_target = False
  326.                 target(i).valid = False
  327.             End If
  328.         Next i
  329.         For i = 1 To tcount
  330.             If target(i).valid = True Then
  331.                 draw_target target(i).x, target(i).y, c1' erase target
  332.                 target(i).x = target(i).x + target(i).dx          ' move target
  333.                 If target(i).x + tsize < gameform.ScaleLeft Then target(i).kill_target = True
  334.                 If target(i).x > gameform.ScaleWidth Then target(i).kill_target = True
  335.                 target(i).y = target(i).y + target(i).dy
  336.                 If target(i).y + tsize < gameform.ScaleTop Then target(i).kill_target = True
  337.                 If target(i).y > gameform.ScaleHeight Then target(i).kill_target = True
  338.                 draw_target target(i).x, target(i).y, c1' redraw target
  339.             End If
  340.         Next i
  341.     count1 = 0
  342.     For i = 1 To tcount
  343.         If target(i).valid = True Then count1 = count1 + 1
  344.     Next i
  345. Loop While count1 <> 0 And game_over = False
  346. Loop While shots <> 0
  347. If game_over Then End
  348. End Sub
  349. Sub mnupause_Click ()
  350. pause_flag = Not pause_flag
  351. End Sub
  352. Sub mnustop_Click ()
  353. End Sub
  354.