hello, im making a game, (multiplayer) and i would basicaly like an image (bullet) fly accross the scren on the vbkeyx command. however, i can not figure out how to do it.

the bullet should move left accross my form but then i must have one to move right also (for the other player).

so in short, wen the user presses the X key, the bullet should fly accross(left), and wen the 2nd user presses the M key the bullet for that player should move accross the form but in the oposite direction. (right).

please could you post code and not links for downloads.

Thankyou!

Recommended Answers

All 8 Replies

The simplest way for a test, is to use a control that can contain a graphic and has a visable property like the picture box control or an image control. You will need at least a couple of these. Then use a timer or two (one would do) and within the timer you would either increment (left to right) or decrement (right to left) the left property of the control. Thus you have your animation.

Now that is one of the easiest ways to accomplish what you want but you will need to do a fair amount of coding to make it work correctly. From there, it only takes more code.

Good Luck

Thanks for that, i will have a go, so basically am i making a sort of marquee effect?

and would i just use the code "vbkeyx" ? (as my fireing button.)

Yes, and yes.

Form1.Keypreview = true

in the timer you will need to check to see if the user actually pressed the key via a form level variable or two.

Then as you become more accustomed to VB check out the forms/pictureboxes graphical methods (line circle) and then move onto the API BitBlt.

Good Luck

been trying to do it for hours now. still not getting anywhere.

im a bit of a noob when it comes to this, lol.

anychance of you helping me with some sample code? just use "bomb1" as the bullet variable if you can.

thanks

new project>add timer control (timer1), image control(image1)
give image1 an image to display>add code

Option Explicit

Dim Bomb1 As Boolean, Bomb1Animation As Boolean

Private Sub Form_Load()
Image1.Visible = False
Me.KeyPreview = True
Timer1.Interval = 10
Timer1.Enabled = True
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)

If KeyAscii = 88 Or KeyAscii = 120 Then 'x or X
  Bomb1 = True
End If

End Sub

Private Sub Timer1_Timer()

Timer1.Enabled = False

If Bomb1 = True Then
  If Bomb1Animation = True Then
    If Image1.Left + Image1.Width < 0 Then
      Bomb1Animation = False
      Bomb1 = False
    Else
      Image1.Left = Image1.Left - 50
      Me.Refresh
      Image1.Refresh
    End If
  Else
    Bomb1Animation = True
    Image1.Visible = True
    Image1.Left = Me.Width - 1
  End If
End If

Timer1.Enabled = True

End Sub

as you can see there is no error checking but this should work for you

Good Luck

ok, i did all this. and...

when the program runs it stated "member already exists in a module from which this module derives" highliting the :

Dim bomb1 As Boolean

therefore i entered it into a module and declared it globaly. but to no prevale.

also in your code where you state "image1" is that suposed to be bomb1 or should my image be named image1?

so all in all it didnt work, lol, thanks for the help and if you could come up with a solution that works for me then i would greatly aprieciate it.

oh no, i got it to work! yey! thanks, however the bullet flows right to left how do i make it go left to right?

Image1.left=image1.left+10

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.