Question:
i am making a space invaders game in VB?
2011-10-17 02:35:13 UTC
i am currently making a space invaders game in and i have made it so the the Invaders are "spawned" onto the form but i cant get them to move across the screen. i can get them to move if i put them on the form before i start but i want it so that i can press enter while in game play and they will spawn onto the screen and move
Three answers:
MT
2011-10-17 02:54:10 UTC
Well, when you "spawn" the Invaders onto the form, you can also assign them to an array or list, so that you can loop the array or list later to move them.



Assuming you're using a label to represent an invader, you can declare a global array of type label:



Dim gInvaders As Label(100) 'Note the 100 can be replace with the number of invader you wish to spawn on the screen.



Then in your "spawning" function you can do something like:



For i = 0 To Number_of_Invaders - 1

    Dim Invader As New Label

    'Setup your Invader here...

    gInvaders(i) = Invader

    Me.Controls.Add(Invader)

Next i



Then to move those Invaders you just do this in your moving function:



For i = 0 To Number_of_Invaders - 1

    Invader = gInvader(i);

    'Move it move it

Next i



That should do it...
2011-10-17 09:56:21 UTC
I'm not completely sure if I'm understanding you correctly, but here's my take on your situation:

You probably have a timer object on your form, and on the timer event, you are updating the Top and Left properties of the invader.

If you want to do that when you press Enter, why not try having a button on the screen that has the "Default" (or "AcceptButton" in VB2008) property set to true, and has zero width and height so that it's invisible. And on the button's click event you simply start up the timer?
Don't sue me!
2011-10-17 09:58:49 UTC
WTF?

Are you making a graphics game in forms?

This type of games requires a special rendering window and uses hardware acceleration, which will give you over 100x boost in framerate (if not more) and a lot more control (scale, resize, rotate, viewports, ...etc).

You can't do more in forms than you can in console.

First you need to find a good VB(.Net) wrapper for some graphics library and use that instead.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...