Here's a program I have made so far. Not finished yet though. I need help. I need help on seperating the distance between one missile fired after the other. Any help?
Well, its not really user friendly yet, so here are some instructions.
Left and Right arrow keys: Push once, he moves slowly, push again, he moves faster.
Up arrow: Jumps.
Space bar: fires missile.
Crap, sorry for the double-post. Meant to edit it.
Here's one thing you need. A Game Loop. Never use multiple timers. One timer alone is slow, inaccurate, and inconsistant. Even worse if it's used on XP machines because the timer goes 10 times faster than usual, making it really inaccurate and inconsistant. Matter of fact, never use timers period.
Here's an example of a game loop:
VB Code:
Option Explicit
Private Declare Function QueryPerformanceCounter Lib "Kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "Kernel32" (lpPerformanceCount As Currency) As Long
Private Ticks_Per_Second As Currency
Private Start_Time As Currency
Private Running As Boolean
Private Sub Game_Loop()
Do While Running = True
DoEvents
'Game code goes here
Lock_FPS 60
QueryPerformanceCounter Start_Time
Loop
End Sub
Private Function Hi_Res_Timer_Initialize() As Boolean
If QueryPerformanceFrequency(Ticks_Per_Second) = 0 Then
Hi_Res_Timer_Initialize = False
Else
QueryPerformanceCounter Start_Time
Hi_Res_Timer_Initialize = True
End If
End Function
Private Function Lock_FPS(ByVal Target_FPS As Byte) As Single
If Target_FPS = 0 Then Target_FPS = 1
Static Last_Time As Currency
Dim Current_Time As Currency
Dim FPS As Single
Last_Time = Start_Time - 1
Do
QueryPerformanceCounter Current_Time
If (Current_Time - Last_Time) <> 0 Then FPS = Ticks_Per_Second / (Current_Time - Last_Time)
The code isn't advanced at all. All it is, is a game loop locked at 60 FPS, with no game code. Of course I needed some extra code to lock the framerate and all of that, but other than that, its easy.