Results 1 to 2 of 2

Thread: Need Help with Victory Screen(for my MMO)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    19

    Need Help with Victory Screen(for my MMO)

    Hell! I need help with my Victory Screen. Basically when you win a battle, the Victory Screen Comes up. Everything is good BUT i'm kinda having trouble with something. I made 2 Timers for 2 labels, tmrCoins(for lblCoins), and tmrSP(for lblEXP). Basically what i want it to do is count down the label to 0/ subtract it till it hits 0. But it wont do anything. I also want it so in the Timer, if you press Enter/Return, it skips the count down and exits the form.

    vb Code:
    1. Option Explicit
    2. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    3. Public FrmMove As Boolean
    4. Public DragX As Long
    5. Public Dragy As Long
    6.  
    7. Private Sub Form_Load()
    8. Dim I As Integer
    9.     MakeTransparent Me.hwnd, 100
    10.     'Ex: all transparent at ratio 140/255
    11.     'ActiveTransparency Me, True, False, 140, Me.BackColor
    12.     'Ex: Form transparent, visible component at ratio 140/255
    13.     'ActiveTransparency Me, True, True, 140, Me.BackColor
    14.      
    15.     'Example display the form transparency degradation
    16.     ActiveTransparency Me, True, False, 0
    17.     Me.Show
    18.     For I = 0 To 255 Step 3
    19.         ActiveTransparency Me, True, False, I
    20.         Me.Refresh
    21.     Next I
    22.     Call StopBGM
    23.     'Call StopSound
    24.     frmVictory.SetFocus
    25. End Sub
    26.  
    27. Private Sub Form_KeyPress(KeyAscii As Integer)
    28.     If KeyAscii = vbKeyReturn Then
    29.         tmrCoins.Enabled = True
    30.         tmrSP.Enabled = True
    31.     End If
    32. End Sub
    33.  
    34. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    35.     FrmMove = True
    36.     DragX = X
    37.     Dragy = Y
    38. End Sub
    39.  
    40. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    41. Dim nx, ny
    42.     If FrmMove Then
    43.         nx = frmVictory.Left + X - DragX
    44.         ny = frmVictory.top + Y - Dragy
    45.         frmVictory.Left = nx
    46.         frmVictory.top = ny
    47.     End If
    48. End Sub
    49.  
    50. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    51. Dim nx, ny
    52.     nx = frmVictory.Left + X - DragX
    53.     ny = frmVictory.top + Y - Dragy
    54.     frmVictory.Left = nx
    55.     frmVictory.top = ny
    56.     FrmMove = False
    57. End Sub
    58.  
    59. Private Sub tmrCoins_Timer()
    60. Dim Num As Integer
    61.  
    62. If GetAsyncKeyState(vbKeyReturn) And tmrCoins.Enabled = True Then
    63.     tmrCoins.Enabled = False
    64.     frmVictory.Visible = False
    65.     Call StopBGS
    66.     Call PlayBGM(Map(GetPlayerMap(MyIndex)).Music)
    67. End If
    68.  
    69. Num = Val(lblCoins.Caption)
    70.  
    71. If Num <= 0 Then
    72.     tmrCoins.Enabled = False
    73. Else
    74.     Num = Num - 1
    75.     Call PlaySound("MP_Coin.wav.wav")
    76. End If
    77. End Sub
    78.  
    79. Private Sub tmrSP_Timer()
    80. Dim Num As Integer
    81.  
    82. If GetAsyncKeyState(vbKeyReturn) And tmrSP.Enabled = True Then
    83.     tmrSP.Enabled = False
    84.     frmVictory.Visible = False
    85.     Call StopBGS
    86.     Call PlayBGM(Map(GetPlayerMap(MyIndex)).Music)
    87. End If
    88.  
    89. Num = Val(lblEXP.Caption)
    90.  
    91. If Num <= 0 Then
    92.     tmrSP.Enabled = False
    93. Else
    94.     Num = Num - 1
    95.     Call PlaySound("Magic_coin.wav")
    96. End If
    97. End Sub

    It doesnt Count down/ Subtract to 0, and when you press Enter once, it exits the form. I tried to have it so when you press enter once, it activates the timers, then when you press enter again it skips the countdown/ subtracting and Exits the form. Any Help? And sorry, im still learning VB, so I might've not done it properly.
    Paper Mario Online!
    A Visual Basic 6 Project Im Currently Making!

    Includes all 3 Paper Mario games!
    Download Link:http://www.mediafire.com/?awjn280n800n4dw

    Also try my friend MegaShark21 and I's SMO Remake 2010 Client: http://www.mediafire.com/?fxv3kni85doxg03

    Server is,

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

    Re: Need Help with Victory Screen(for my MMO)

    It's a bad idea to use multiple Timers (let alone Timers in general) in games. The reason why is cause it is hideously slow, inconsistent, inaccurate, and get worse the more timers you use at the same time cause you have to wait on one timer to fire before the other one can perform. What you will need is a realtime managed game loop locked at 60 frames per second:

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

    Your game code should be within game loop. If you are wanting something to count down, do this:

    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 Get_Frames_Per_Second As Long
    10. Private Frame_Count As Long
    11.  
    12. 'Countdown variables
    13. Private Time As Long
    14. Private Time_Milliseconds As Long
    15. Private Countdown As Long
    16.  
    17. Private Running As Boolean
    18.  
    19. Public Function Hi_Res_Timer_Initialize() As Boolean
    20.  
    21.     If QueryPerformanceFrequency(Ticks_Per_Second) = 0 Then
    22.         Hi_Res_Timer_Initialize = False
    23.     Else
    24.         QueryPerformanceCounter Start_Time
    25.         Hi_Res_Timer_Initialize = True
    26.     End If
    27.  
    28. End Function
    29.  
    30. Public Function Get_Elapsed_Time() As Single
    31.    
    32.     Dim Last_Time As Currency
    33.     Dim Current_Time As Currency
    34.    
    35.     QueryPerformanceCounter Current_Time
    36.     Get_Elapsed_Time = (Current_Time - Last_Time) / Ticks_Per_Second
    37.     QueryPerformanceCounter Last_Time
    38.    
    39. End Function
    40.  
    41. Private Sub Lock_Framerate(Target_FPS As Long)
    42.  
    43.     Static Last_Time As Currency
    44.     Dim Current_Time As Currency
    45.     Dim FPS As Single
    46.    
    47.     Do
    48.         QueryPerformanceCounter Current_Time
    49.         FPS = Ticks_Per_Second / (Current_Time - Last_Time)
    50.     Loop While (FPS > Target_FPS)
    51.    
    52.     QueryPerformanceCounter Last_Time
    53.  
    54. End Sub
    55.  
    56. Private Function Get_FPS() As String
    57.  
    58.     Frame_Count = Frame_Count + 1
    59.        
    60.     If Get_Elapsed_Time - Milliseconds >= 1 Then
    61.         Get_Frames_Per_Second = Frame_Count
    62.         Frame_Count = 0
    63.         Milliseconds = Get_Elapsed_Time
    64.     End If
    65.    
    66.     Get_FPS = "FPS: " & Get_Frames_Per_Second
    67.  
    68. End Function
    69.  
    70. Private Sub Shutdown()
    71.  
    72.     Running = False
    73.     Unload Me
    74.  
    75. End Sub
    76.  
    77. Private Sub Main()
    78.    
    79.     With Me
    80.         .Show
    81.         .ScaleMode = 3
    82.         .AutoRedraw = True
    83.         .BackColor = RGB(0, 0, 0)
    84.         .ForeColor = RGB(0, 255, 0)
    85.     End With
    86.    
    87.     Hi_Res_Timer_Initialize
    88.     Countdown = 10
    89.     'This starts the countdown
    90.     Milliseconds = Get_Elapsed_Time
    91.     Time_Milliseconds = Get_Elapsed_Time
    92.     Running = True
    93.     Main_Loop
    94.  
    95. End Sub
    96.  
    97. Private Sub Main_Loop()
    98.  
    99.     Do While Running = True
    100.        
    101.         '//Timer Code Goes Here
    102.         Time = (Get_Elapsed_Time - Time_Milliseconds)
    103.         If Time >= 1 Then
    104.             Countdown = Countdown - 1
    105.             Time_Milliseconds = Get_Elapsed_Time
    106.         End If
    107.         Cls
    108.         Print Countdown
    109.         Me.Caption = Get_FPS
    110.         If Countdown <= 0 Then
    111.             MsgBox ("VICTORY!!!"), vbExclamation
    112.             Shutdown
    113.         End If
    114.         DoEvents
    115.         Lock_Framerate 60
    116.        
    117.     Loop
    118.  
    119. End Sub
    120.  
    121. Private Sub Form_Load()
    122.    
    123.     Main
    124.  
    125. End Sub
    126.  
    127. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    128.  
    129.     If KeyCode = vbKeyEscape Then
    130.         Shutdown
    131.     End If
    132.  
    133. End Sub
    134.  
    135. Private Sub Form_Unload(Cancel As Integer)
    136.  
    137.     Shutdown
    138.  
    139. End Sub

    Also note the PlaySound API doesn't play multiple sounds at once, only one sound at a time. I have multiple game tutorials in my signature if you wanna learn how to make games, and can answer anything you need game related as I am the game expert in this forum.

    Speaking of MMO's, I'm currently making one in VB6 using DirectX8:

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