Results 1 to 3 of 3

Thread: [RESOLVED] Harpoon Based Game Help Needed

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    6

    Resolved [RESOLVED] Harpoon Based Game Help Needed

    Hey guys, I'm currently working on a project which involves a harpoon being shot, to retrieve objects, pull them back up, and repeat.
    An example of the game I'm making is Gold Miner found on many game websites.

    I've gotten my swinging motion down pretty well I believe, and had some good progress going, but have found my shooting to be quite faulty. I need the harpoon to shoot directly from whatever angle it is at when shot and travel in a straight path until it makes contact with an object or the bottom.

    I simplified my game down to the bare minimum code, and would greatly appreciate input to correct my shooting actions.

    Thanks
    Attached Files Attached Files

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Harpoon Based Game Help Needed

    Moved From The Vb6 Codebank (which is for sharing code rather than asking questions )

  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [RESOLVED] Harpoon Based Game Help Needed

    Well one problem is you are using too many timers. Even one is bad enough. Multiple timers are bad cause one timer has to complete before the next one can fire. For games, even the professional ones, everyone uses whats called a managed game loop:

    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
    4. Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
    5.  
    6. Private Ticks_Per_Second As Currency
    7. Private Start_Time As Currency
    8. Private Milliseconds As Long
    9. Private Last_Time As Long
    10.  
    11. Private Get_Frames_Per_Second As Long
    12. Private Frame_Count As Long
    13.  
    14. Private Running As Boolean
    15.  
    16. Public Function Hi_Res_Timer_Initialize() As Boolean
    17.  
    18.     If QueryPerformanceFrequency(Ticks_Per_Second) = 0 Then
    19.         Hi_Res_Timer_Initialize = False
    20.     Else
    21.         QueryPerformanceCounter Start_Time
    22.         Hi_Res_Timer_Initialize = True
    23.     End If
    24.  
    25. End Function
    26.  
    27. Public Function Get_Elapsed_Time() As Single
    28.    
    29.     Dim Last_Time As Currency
    30.     Dim Current_Time As Currency
    31.    
    32.     QueryPerformanceCounter Current_Time
    33.     Get_Elapsed_Time = (Current_Time - Last_Time) / Ticks_Per_Second
    34.     QueryPerformanceCounter Last_Time
    35.    
    36. End Function
    37.  
    38. Private Sub Lock_Framerate(Target_FPS As Long)
    39.  
    40.     Static Last_Time As Currency
    41.     Dim Current_Time As Currency
    42.     Dim FPS As Single
    43.    
    44.     Do
    45.         QueryPerformanceCounter Current_Time
    46.         FPS = Ticks_Per_Second / (Current_Time - Last_Time)
    47.     Loop While (FPS > Target_FPS)
    48.    
    49.     QueryPerformanceCounter Last_Time
    50.  
    51. End Sub
    52.  
    53. Private Function Get_FPS() As String
    54.  
    55.     Frame_Count = Frame_Count + 1
    56.        
    57.     If Get_Elapsed_Time - Milliseconds >= 1 Then
    58.         Get_Frames_Per_Second = Frame_Count
    59.         Frame_Count = 0
    60.         Milliseconds = Get_Elapsed_Time
    61.     End If
    62.    
    63.     Get_FPS = "FPS: " & Get_Frames_Per_Second
    64.  
    65. End Function
    66.  
    67. Private Sub Shutdown()
    68.  
    69.     Running = False
    70.     Unload Me
    71.  
    72. End Sub
    73.  
    74. Private Sub Main()
    75.    
    76.     With Me
    77.         .Show
    78.         .ScaleMode = 3
    79.         .AutoRedraw = True
    80.         .BackColor = RGB(0, 0, 0)
    81.     End With
    82.  
    83.     Running = True
    84.     Hi_Res_Timer_Initialize
    85.     Milliseconds = Get_Elapsed_Time
    86.     Game_Loop
    87.  
    88. End Sub
    89.  
    90. Private Sub Game_Loop()
    91.  
    92.     Do While Running = True
    93.  
    94.         '//Timer Code Goes Here
    95.  
    96.         Me.Caption = Get_FPS
    97.         Lock_Framerate 60
    98.         DoEvents
    99.     Loop
    100.  
    101. End Sub
    102.  
    103. Private Sub Form_Load()
    104.    
    105.     Main
    106.  
    107. End Sub
    108.  
    109. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    110.  
    111.     If KeyCode = vbKeyEscape Then
    112.         Shutdown
    113.     End If
    114.  
    115. End Sub
    116.  
    117. Private Sub Form_Unload(Cancel As Integer)
    118.  
    119.     Shutdown
    120.  
    121. End Sub

    All of your timer based code should be located within your Game_Loop:

    Code:
    Private Sub Game_Loop()
    
        Do While Running = True
     
            '//Timer Code Goes Here
    
            Me.Caption = Get_FPS
            Lock_Framerate 60
            DoEvents
        Loop
    
    End Sub
    Once thats done, you need to make some boolean flags. Like for your harpoon you can make a flag called Fire. Dim Fire As Boolean up in your General Declarations. In your game loop:

    Code:
    If Fire = True Then
    
    //firing code here
    
    End if
    Once the harpoon is done retrieving, have Fire = False so you can fire again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width