Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


pbx Movement?


pbx Movement?

Author
Message
mtull
mtull
Forum God
Forum God (363 reputation)Forum God (363 reputation)Forum God (363 reputation)Forum God (363 reputation)Forum God (363 reputation)Forum God (363 reputation)Forum God (363 reputation)Forum God (363 reputation)Forum God (363 reputation)

Group: Forum Members
Posts: 1, Visits: 7
hi,

im a student, and we have been learning VB.Net 2003 in class the last few months and in really enjoyin it!

however ive decided to make a space invaders game, and have come to a dead end.
the problem is the whole of the game is coded and has collision detection and the missile fires and hits the "aliens" and they explode.

however i wish to make the "aliens", there are 10 of them, all picturebox's move left-to-right or right to left it dosent reallt matter aslong as their are moving from one side of the form to the other like they do in the game?

i havent got a clue were to start with this movement code, Please help!!!

Thanks!

thesilentpyro
thesilentpyro
Forum God
Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)

Group: Forum Members
Posts: 59, Visits: 115
I presume you are not using a control array since you just started, so I'll keep this down to the very basics.



Put the following line in the Declarations portion of your code (at the top):



dim AlienLeft as boolean



This will control whether your aliens are moving left or right. Next, put a timer on your form. This will control the movement of your aliens. Under its properties, set it's interval to 250 (about a quarter of a second). Double click on the timer. Under the code window that pops up, put the following:

if AlienLeft then 'This will detect if they are
                       'supposed to be moving left or not
     if Alien1.left <= 480 then 'Change "Alien1" to the name of your
                                      'leftmost alien. This will detect if they
                                      'need to start moving the other way or
                                      'not.
          AlienLeft = False 'Tell the code that they need to move the
                                 'other way.
     else 'If they still have room to move...
          Alien1.left = Alien1.left-360 'Moves the alien left 360 units.
                                               'Copy this line and change "Alien1"
                                               'to the name of each of your
                                               'aliens.
     End If
else 'If the aliens are supposed to be moving right...
     if (Alien10.left + Alien10.width) >= (form.width - 480) then
          'Change "Alien10" to the name of your rightmost alien. This
          'line detects if the aliens need to switch directions again.
          AlienLeft = True 'tell the code to start moving the aliens left.
     else 'if they still have room to move...
          Alien1.left = Alien1.left+360 'Move the aliens right 360 units.
                                               'Copy this line and change "Alien1"
                                               'to the name of each of your
                                               'aliens.
     end if
end if




This code is very rudimentary, and the numbers are probably off from what you want, but you can adjust them until you get there. If you need any other help, I'm glad to be of service when I can.
Edited
2/26/2006 by thesilentpyro
Mobius
Mobius
Forum God
Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)

Group: Forum Members
Posts: 632, Visits: 1K
All that code that pyro-dude-whatever BigGrin just supplied was to define the bounds of movement, if you picked that up. Just remember that horizontal movement is based on the Left Method, and rightward movement is accomplished by a negative value. Syntax being: 

Object.Left =  Value for movement





-Mobius

Mobius
Mobius
Forum God
Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)

Group: Forum Members
Posts: 632, Visits: 1K
Thanks for specifying .NET, mtull, btw. It'd be nice to have a dropdown box or something specifying what language your thread is based on. Hint Hint admins.....Smile





-Mobius

Edited
2/26/2006 by Mobius
thesilentpyro
thesilentpyro
Forum God
Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)

Group: Forum Members
Posts: 59, Visits: 115
Mobius (2/27/2006)
All that code that pyro-dude-whatever BigGrin just supplied was to define the bounds of movement, if you picked that up. Just remember that horizontal movement is based on the Left Method, and rightward movement is accomplished by a negative value. Syntax being:



Object.Left = Value for movement




Just a quick correction: Rightward movement is a POSITIVE value. In VB, Up is lesser Y coordinates, Left is lesser X coordinates.



And yes, most of that code is just specifying which way the thing should move, as if you had code that only made them go left, fairly soon you'd have them off of your form.
Mobius
Mobius
Forum God
Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)Forum God (105K reputation)

Group: Forum Members
Posts: 632, Visits: 1K
Yes, it is a positive value if you are actually subtracting from the value. You can set the parameters for the Left() method, in which rightward movement would be negative. Which only makes sense because right is the opposite of left. But you are also correct because it would have to be positive for the way you were doing it. There's just more than one way.





-Mobius

thesilentpyro
thesilentpyro
Forum God
Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)Forum God (7.1K reputation)

Group: Forum Members
Posts: 59, Visits: 115
I see. I didn't know about setting properties of the Left() method, but I don't think I'll use it--it makes sense to me this way, as I've been doing it like this for a year and a half, not to mention in every Algebra class I've ever taken.
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search