|
-
Dec 3rd, 2002, 12:27 PM
#1
Thread Starter
Fanatic Member
Space Invaders
Hi, im trying to make a space invaders game and am stuck moving my gun. Ive put a loop in that moves the ship to the right when a button is pressed and then should stop when released. the stop part doesnt work. can anyone help! here is the code.
Private Sub CmdRight_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Do Until LblBullet.Left = 324
For i = 1 To 5000
DoEvents
Next i
Dim MyVar As Variant
MyVar = f
If MyVar = t Then
ImgGun.Left = ImgGun.Left + 1
LblBullet.Left = LblBullet.Left + 1
Else: Exit Do
End If
Loop
End Sub
Private Sub CmdRight_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
MyVar = f
End Sub
have i just got my variable or if statements in the wrong place
-
Dec 3rd, 2002, 12:35 PM
#2
Thread Starter
Fanatic Member
sorry, in the mousedown sub MyVar is initially set to t, i set it to f to test if it was seeing the variable at all
-
Dec 3rd, 2002, 12:44 PM
#3
-
Dec 3rd, 2002, 12:47 PM
#4
You don't declear t in your code, so what is it....
BTW..use [Highlight=VB] and [ /vbcode] tags whenposting code...
-
Dec 3rd, 2002, 12:55 PM
#5
Addicted Member
Re: Space Invaders
Couple of no-no's that pop right out:
1)
Originally posted by davebat
For i = 1 To 5000
DoEvents
Next i
NEVER, I repeat, NEVER do this. A loop like this will run as quickly as the PC will let it, guaranteeing different results on different machines.
2)
Originally posted by davebat
Dim MyVar As Variant
MyVar = f
If MyVar = t Then
ALWAYS, I repeat, ALWAYS use descriptive variable names. When you go back to look at code like this, you probably won't even remember what you were trying to do or what the variables are.
Are you using Option Explicit in all of your modules and forms? If not, DO IT NOW!
-
Dec 3rd, 2002, 06:37 PM
#6
Fanatic Member
well
Dim Keys(0 to 255) as boolean
------------------------------------------
Sub Keydown (lalalalala)
Keys(keycode) = true
end sub
------------------------------------------
Sub keyUp(lallalala)
Keys(KeyCode) = false
End sub
So as long as you know which key uses which code you always know when one is down
Don't pay attention to this signature, it's contradictory.
-
Dec 4th, 2002, 05:18 AM
#7
Thread Starter
Fanatic Member
thanks guys, Ive taken note of your advice and will change the code when i get in from work. what did you mean by open explicit? Im new to this you see.
-
Dec 4th, 2002, 05:22 AM
#8
From the MSDN:
When Option Explicit appears in a module, you must explicitly declare all variables using the Dim, Private, Public, ReDim, or Static statements. If you attempt to use an undeclared variable name, an error occurs atcompile time.
If you don't use the Option Explicit statement, all undeclared variables are of Variant type unless the default type is otherwise specified with a Deftype statement.
On the filemenu click Tools, then Options and check the check box "Require Variable Delaration"....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|