Are you having trouble getting a shooting code to work in VB? I've had the same problem many times, and I'll
help you! In the AI in VB tutorial, you'll see this code, but here it is simplified...
On to the lessons!
To do a standard shooting (Shows no bullets or flash), use this code:
Sub firemainleft() If esub1.Left > yousub.Left - 5000 And esub1.Left < yousub.Left And esub1.Visible Then esub1.Visible = False ElseIf esub2.Left > yousub.Left - 5000 And esub2.Left < yousub.Left And esub2.Visible = True Then esub2.Visible = False ElseIf ship1.Left > yousub.Left - 5000 And ship1.Left < yousub.Left And ship1.Visible = True Then ship1.Visible = False ElseIf ship2.Left > yousub.Left - 5000 And ship2.Left < yousub.Left And ship2.Visible = True Then ship2.Visible = False ElseIf ship3.Left > yousub.Left - 5000 And ship3.Left < yousub.Left And ship3.Visible = True Then ship3.Visible = False End If End Sub
For this example, you'll need to save the following pictures to your hard drive:
and
(You'll see the cannon better in your program).
Okay, now, use this code:
Sub firemainleft() youtank.Picture = LoadPicture(app.Path & "tankshooting.gif") tankswitchtimer.Enabled = True If etank1.Left > youtank.Left - 5000 And etank1.Left < youtank.Left And etank1.Visible Then etank1.Visible = False ElseIf etank2.Left > youtank.Left - 5000 And etank2.Left < youtank.Left And etank2.Visible = True Then etank2.Visible = False ElseIf ship1.Left > yousub.Left - 5000 And ship1.Left < yousub.Left And ship1.Visible = True Then ship1.Visible = False ElseIf ship2.Left > yousub.Left - 5000 And ship2.Left < yousub.Left And ship2.Visible = True Then ship2.Visible = False ElseIf ship3.Left > yousub.Left - 5000 And ship3.Left < yousub.Left And ship3.Visible = True Then ship3.Visible = False End If End Sub
Name: tankswitchtimer
Enabled: False
Interval: 500
Sub tankswitchtimer_Timer() youtank.picture = LoadPicture(app.Path & "tankl.gif") tankswitchtimer.Enabled = False End Sub