home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / joystick / game.frm < prev    next >
Text File  |  1993-09-05  |  12KB  |  381 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. End
  131. DefInt A-Z
  132. Dim tsize As Integer
  133. Dim tdelay As Integer
  134. Dim tcount As Integer
  135. Dim targetx As Integer
  136. Dim targety As Integer
  137. Dim capcolor As Long
  138. Dim score As Long
  139. Dim lppoint As pointapi
  140. Dim kill_target As Integer
  141. Dim shots As Integer
  142. Dim master_time As Single
  143. Dim game_over As Integer
  144. Dim pause_flag As Integer
  145. Dim target(1 To 3) As target_data
  146.  
  147. Sub draw_target (x As Integer, y As Integer, cqb)
  148.     'Debug.Print x, y, cqb
  149.     gameform.DrawMode = 7' xor mode
  150.     gameform.Line (x, y)-(x + tsize, y + tsize), QBColor(cqb), BF
  151.  
  152. End Sub
  153.  
  154. Sub Form_Load ()
  155. tsize = 500
  156. tdelay = 4
  157. tcount = 1
  158. xmax = 20000
  159. ymax = 20000
  160. xmin = 0
  161. ymin = 0
  162. calx = 0
  163. caly = 0
  164. button_mark = False
  165. mousepointer = 2
  166. shots = 50
  167. winxmax = gameform.ScaleLeft + gameform.ScaleWidth
  168. winxmin = gameform.ScaleLeft
  169. winymin = gameform.ScaleTop
  170. winymax = gameform.ScaleTop + gameform.ScaleHeight
  171. joystick1.Capture = True
  172. xmax = getprivateprofileint("gameform", "xmax", -1, "joytest.ini")
  173. If xmax = -1 Then
  174.     need_calibrate = True
  175. Else
  176.     xmin = getprivateprofileint("gameform", "xmin", -1, "joytest.ini")
  177.     ymax = getprivateprofileint("gameform", "ymax", -1, "joytest.ini")
  178.     ymin = getprivateprofileint("gameform", "ymin", -1, "joytest.ini")
  179. End If
  180. deltax = gameform.ScaleWidth / xmax
  181. deltay = gameform.ScaleHeight / ymax
  182.  
  183. loop_count = 0
  184. Do
  185.     time1! = Timer
  186.     count1 = 0
  187.     Do
  188.         DoEvents
  189.         count1 = count1 + 1
  190.     Loop While Timer - time1! < 1
  191. loop_time = loop_time + count1
  192. loop_count = loop_count + 1
  193. Loop While loop_count < 2
  194. master_time = Int(loop_time / loop_count)
  195. Randomize
  196. game_over = False
  197. End Sub
  198.  
  199. Sub Joystick1_ButtonDown (button As Integer)
  200. button_mark = True
  201. If need_calibrate Then Exit Sub
  202.     Select Case button
  203.         Case 1
  204.             'Circle (winpoint.x, winpoint.y), 80, RGB(0, 0, 0)
  205.             'fillcolor = QBColor(0)
  206.         Case 2
  207.             'picture2.Circle (winpoint.x, winpoint.y), 80, RGB(0, 0, 0)
  208.             'fillcolor = QBColor(0)
  209.             getcursorpos lppoint
  210.             
  211.             ScreenToClient gameform.hWnd, lppoint
  212.             lppoint.x = lppoint.x * screen.TwipsPerPixelX
  213.             lppoint.y = lppoint.y * screen.TwipsPerPixelY
  214.             For i = 1 To tcount
  215.                 If lppoint.x > target(i).x And lppoint.x < target(i).x + tsize Then
  216.                     If lppoint.y > target(i).y And lppoint.y < target(i).y + tsize Then
  217.                         Beep
  218.                         score = score + 10 * tdelay
  219.                         label1.Caption = Str(score)
  220.                         target(i).kill_target = True
  221.                     End If
  222.                 End If
  223.             Next i
  224.             shots = shots - 1
  225.             label2.Caption = Str(shots)
  226.             If shots = 0 Then
  227.             game_over = True
  228.             MsgBox "Game Over!", 0, "Joystick Skeet Shoot"
  229.             End If
  230.     End Select
  231.  
  232. End Sub
  233.  
  234. Sub Joystick1_Move (x As Integer, y As Integer, z As Integer)
  235.     calx = x
  236.     caly = y
  237.     If need_calibrate Then
  238.         Call calibrate(gameform)
  239.         If need_calibrate <> True Then
  240.             t = writeprivateprofilestring("gameform", "xmax", ByVal Format$(xmax), "joytest.ini")
  241.             t = writeprivateprofilestring("gameform", "ymax", ByVal Format$(ymax), "joytest.ini")
  242.             t = writeprivateprofilestring("gameform", "xmin", ByVal Format$(xmin), "joytest.ini")
  243.             t = writeprivateprofilestring("gameform", "ymin", ByVal Format$(ymin), "joytest.ini")
  244.         End If
  245.         Exit Sub
  246.     End If
  247.     
  248.     convert x, y, gameform
  249.     
  250.     'Debug.Print "* "; winpoint.x, winpoint.y
  251.     
  252. End Sub
  253.  
  254. Sub mnufast_Click (index As Integer)
  255. Select Case index
  256.     Case 0' fast
  257.         tdelay = 8
  258.         mnufast(1).Checked = False
  259.         mnufast(2).Checked = False
  260.     Case 1' medium
  261.         tdelay = 4
  262.         mnufast(0).Checked = False
  263.         mnufast(2).Checked = False
  264.     Case 2' slow
  265.         tdelay = 2
  266.         mnufast(0).Checked = True
  267.         mnufast(1).Checked = True
  268. End Select
  269. mnufast(index).Checked = True
  270. End Sub
  271.  
  272. Sub mnumultiple_Click (index As Integer)
  273. Select Case index
  274.     Case 0
  275.         tcount = 1
  276.     Case 1
  277.         tcount = 2
  278. End Select
  279. End Sub
  280.  
  281. Sub mnunew_Click ()
  282. game_over = False
  283. score = 0
  284. shots = 50
  285. label1.Caption = Str(score)
  286. label2.Caption = Str(shots)
  287.  
  288. Do
  289. '****************************************
  290. ' Create the targets
  291. '****************************************
  292.             Do
  293.                 c1 = Int(15 * Rnd)
  294.             Loop While c1 = 7' don't allow white target
  295.             target(1).color = c1
  296.             target(2).color = c1
  297.     
  298.     For i = 1 To tcount
  299.             If i = 1 Then
  300.                 
  301.                 target(i).x = Int(((gameform.Width - tsize - gameform.Left + 1) * Rnd / 2) + gameform.Left)
  302.                 target(i).y = gameform.ScaleTop + gameform.ScaleHeight - Int((gameform.ScaleTop + gameform.ScaleHeight) / 4)
  303.                 draw_target target(i).x, target(i).y, target(i).color
  304.             Else
  305.                 
  306.                 target(i).x = target(i - 1).x - 2 * tsize
  307.                 target(i).y = target(i - 1).y - 2 * tsize
  308.                 draw_target target(i).x, target(i).y, target(i).color
  309.             End If
  310.             dummy = DoEvents()
  311.             ' draw a target
  312.             
  313.             target(i).dx = Int(100 * Rnd + 50)
  314.             target(i).dy = -Int(100 * Rnd + 50)
  315.             Do
  316.                 target(i).dxm = Int(3 * Rnd - 1)
  317.                 
  318.             Loop While target(i).dxm = 0
  319.             target(i).dx = target(i).dx * target(i).dxm
  320.             target(i).kill_target = False
  321.             target(i).valid = True
  322.             
  323.     
  324.     Next i
  325. Do
  326. '*******************************************
  327. ' if paused, wait till cleared
  328. '*******************************************
  329.  
  330.             Do
  331.                 DoEvents
  332.             Loop While pause_flag = True
  333. '*******************************************
  334. ' delay between movements
  335. '*******************************************
  336.  
  337.             loop_count = 0
  338.             Do
  339.                 DoEvents
  340.                 loop_count = loop_count + 1
  341.             Loop Until loop_count = Int(master_time / tdelay)
  342. '******************************************
  343. ' move target(s)
  344. '******************************************
  345.         For i = 1 To tcount
  346.             If target(i).kill_target = True Then
  347.                 draw_target target(i).x, target(i).y, c1' erase the target
  348.                 target(i).kill_target = False
  349.                 target(i).valid = False
  350.             End If
  351.         Next i
  352.         For i = 1 To tcount
  353.             If target(i).valid = True Then
  354.                 draw_target target(i).x, target(i).y, c1' erase target
  355.                 target(i).x = target(i).x + target(i).dx          ' move target
  356.                 If target(i).x + tsize < gameform.ScaleLeft Then target(i).kill_target = True
  357.                 If target(i).x > gameform.ScaleWidth Then target(i).kill_target = True
  358.                 target(i).y = target(i).y + target(i).dy
  359.                 If target(i).y + tsize < gameform.ScaleTop Then target(i).kill_target = True
  360.                 If target(i).y > gameform.ScaleHeight Then target(i).kill_target = True
  361.                 draw_target target(i).x, target(i).y, c1' redraw target
  362.             End If
  363.         Next i
  364.     count1 = 0
  365.     For i = 1 To tcount
  366.         If target(i).valid = True Then count1 = count1 + 1
  367.     Next i
  368. Loop While count1 <> 0 And game_over = False
  369. Loop While shots <> 0
  370. If game_over Then End
  371. End Sub
  372.  
  373. Sub mnupause_Click ()
  374. pause_flag = Not pause_flag
  375. End Sub
  376.  
  377. Sub mnustop_Click ()
  378. End
  379. End Sub
  380.  
  381.