Need Help With Bullets
Need Help With Bullets
Need Help With Bullets
Need Help With Bullets
Need Help With Bullets
Need Help With Bullets Need Help With Bullets Need Help With Bullets Need Help With Bullets Need Help With Bullets Need Help With Bullets Need Help With Bullets Need Help With Bullets
Need Help With Bullets Need Help With Bullets
Need Help With Bullets
Go Back  Xtreme Visual Basic Talk > > > Need Help With Bullets


Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2009, 06:27 PM
airsim15 airsim15 is offline
Newcomer
 
Join Date: May 2009
Posts: 2
Default Need Help With Bullets


Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)


Dim shooting As Boolean
Dim vArray As Integer


If (KeyCode = vbKeyRight) Then
imgship.Left = imgship.Left + 500
End If

If (KeyCode = vbKeyLeft) Then
imgship.Left = imgship.Left - 500
End If

If (KeyCode = vbKeySpace) Then
    Do
    shooting = True
   imgbullet.Left = imgship.Left + 1000
   imgbullet.Visible = True
   For i = 1 To 100
   imgbullet.Top = imgbullet.Top - 61
  If imgbullet.Left < img1.Left + img1.Width And img1.Left < imgbullet.Left + imgbullet.Width Then
If imgbullet.Top < img1.Top + img1.Height And img1.Top < imgbullet.Top + imgbullet.Height Then
Timerfire.Enabled = True

End If
End If
Next i
   End If

   


End Sub

Private Sub Timer1_Timer()
Randomize
num1 = Rnd() * 100
img1.Top = img1.Top + num1
If img1.Top > 8000 Then
img1.Top = 100
End If


End Sub






Private Sub Timerfire_Timer()
img1 = LoadPicture("C:\Users\SHAN\Desktop\Asteriods Game\fireblast.jpg")
DoEvents
Sleep 100
img1.Visible = False
DoEvents
Sleep 200
img1 = LoadPicture("C:\Users\SHAN\Desktop\Asteriods Game\asteroid-ida-1993-by-Galileo-spacecraft.jpg")
img1.Visible = True
Timerfire.Enabled = False
Timer1.Enabled = True




End Sub
I have been trying for several days now to get multiple bullets to shoot out and cant seem to get it to work. Ive read many tutorials on the site and still no luck. Can someone please help me with the bullets, Im making a asteriods game and would really apreciate it. I know this isnt the best type of coding but my teacher only accepts the simplest of codes. Any help would be apreciated thank you. Please no links to tutorials btw i have read them ALL and cannot seem to figure it out
Reply With Quote
  #2  
Old 05-25-2009, 08:27 PM
vb5prgrmrNeed Help With Bullets vb5prgrmr is offline
Senior Contributor

* Expert *
 
Join Date: Mar 2009
Posts: 1,087
Default

Well, I only see one image control in your code...

Would you not need three?


Good Luck
Reply With Quote
  #3  
Old 05-25-2009, 09:01 PM
airsim15 airsim15 is offline
Newcomer
 
Join Date: May 2009
Posts: 2
Default

Huh?
Reply With Quote
  #4  
Old 05-28-2009, 08:31 AM
3G Alarm 3G Alarm is offline
Newcomer
 
Join Date: May 2009
Posts: 3
Default

wow am having the same problem but still cant solve it

-----------------------------------------------------------
visit my page IP Camera Alarm & Monitoring
Reply With Quote
  #5  
Old 05-28-2009, 10:54 AM
Flamespewer Flamespewer is offline
Freshman
 
Join Date: Sep 2008
Posts: 35
Default

you need a control array for this to work efficiently so make 4 bullets
bullet(0)
bullet(1)
bullet(2)
bullet(3)
and a ship
paste this code in and it will work
Code:
Dim bulletNumber As Integer

Private Sub Form_Load()
  For i = 0 To 3
        Bullet(i).Visible = False 'Makes them Invisible
        Bullet(i).Tag = "dead" ' Extra information, Dead meaning it has not been shot
    Next i
bulletNumber = 0
End Sub


Private Sub Form_KeyPress(KeyAscii As Integer)
 If KeyAscii = vbKeySpace Then
        
            If Bullet(bulletNumber).Tag = "dead" Then
                Bullet(bulletNumber).Tag = "alive"'no longer dead it is now being shot
                Bullet(bulletNumber).Left = ship.Left 'Comes out of where the space ship is
                Bullet(bulletNumber).Top = ship.Top
                Bullet(bulletNumber).Visible = True
            End If
            bulletNumber = bulletNumber + 1 '
            If bulletNumber = 4 Then 'past max array value
                bulletNumber = 0'sets it back to 0
            End If
End If
end sub

Private Sub TimerBullet_Timer()
   For i = 0 To 3
            If Bullet(i).Tag = "alive" Then
                Bullet(i).Top = Bullet(i).Top - 100 ' Move the Bullet up if it is alive
            
            If Bullet(i).Top < 0 Then 'collision code would go here
                Bullet(i).Tag = "dead"
                Bullet(i).Visible = False
            End If
            
            End If
            Next i
End Sub
so first it makes every single Bullet invisible and every Bullet have a tag of "dead"

when you press the space bar it makes the bullet(BulletNumber) 's tag "alive"

the timer, which is constantly checking, will check all the bullets and if a bullet is alive then move it up. the same timer should check collision and move any sprites on your form(enemies).

it is best if you use as few timers as possible.

Last edited by Flamespewer; 05-28-2009 at 04:14 PM.
Reply With Quote
  #6  
Old 05-30-2009, 04:20 AM
tmaximus89 tmaximus89 is offline
Newcomer
 
Join Date: May 2009
Posts: 2
Default

Thanks to the help, I managed to solve the problem.
Thanks again.
__________________
monster milk Hair Care
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Need Help With Bullets
Need Help With Bullets
Need Help With Bullets Need Help With Bullets
Need Help With Bullets
Need Help With Bullets
Need Help With Bullets Need Help With Bullets Need Help With Bullets Need Help With Bullets Need Help With Bullets Need Help With Bullets Need Help With Bullets
Need Help With Bullets
Need Help With Bullets
 
Need Help With Bullets
Need Help With Bullets
 
-->