[x]
All Deviations

Visual Basic Space Invaders Problem

[x] Advertisement
~xenobli:iconxenobli: May 10, 2008, 7:50:21 PM
Ok, so in my form, I've got 4 lines of 14 invaders, all in an array. I've got "farleft" and "farright" as Integers. Now, what I'm trying to do is when I kill an Invader on the far left or FarRight of a row for the rest of the invaders to move to the very edge of the screen before switching direction.

So far, I have Farleft = 0 and FarRight = 13.

For X = farleft To farright

' FAR LEFT AND FAR RIGHT INVADERS

If imgInvaders4(farleft).Visible = False Then
farleft = farleft + 1
End If

If imgInvaders4(farright).Visible = False Then
farright = farright - 1
End If

' MOVEMENT
imgInvaders4(X).Left = imgInvaders4(X).Left + dx3

' SWITCH TO RIGHT AND MOVE DOWN
If imgInvaders4(farleft).Left <= FrmMain.ScaleLeft Then
dx3 = dx3 * -1
For X2 = farleft To farright
imgInvaders4(X2).Top = imgInvaders4(X2).Top + dy
Next X2
imgInvaders4(0).Left = imgInvaders4(0).Left + 115
End If

' SWITCH TO LEFT AND MOVE DOWN
If imgInvaders4(farright).Left + 735 >= formright Then
dx3 = dx3 * -1
For X2 = 0 To 13
imgInvaders4(X2).Top = imgInvaders4(X2).Top + dy
Next X2
End If

' REACHING THE BOTTOM
If imgInvaders4(X).Top + 735 >= formbottom Then
endfail = MsgBox("They've invaded the planet and you are at fault. You shall be smited by Xenu.", vbOKOnly, "You fail")
End
End If

Next X


My problem is that when they reach the edge of the form, then they just take a shit and fall straight down rather than move down dy (100) and switch direction.

Any reason why it's messing up?

--
Life is a waterfall, we're one in the river and one again after the fall.

Devious Comments

love 0 0 joy 0 0 wow 0 0 mad 0 0 sad 0 0 fear 0 0 neutral 0 0

=Tadmod:iconTadmod: May 10, 2008, 8:32:33 PM
I think the variable "dy" is working in a huge number, I was never good at desk-checking... I always have an easier time proof-reading code when it's my own, because I know the variables and placement of everything...


sorry I cant help

--
~NO animals were harmed in the making of this movie...they were all killed instantly.

MY PROFILE: [link]

Here's the deal, you watch me, I watch you, but you've got to actually like my work.
~xenobli:iconxenobli: May 10, 2008, 8:42:05 PM
I've got dy dimmed as an integer and in FrmMain_Load i have it equal to 100.

--
Life is a waterfall, we're one in the river and one again after the fall.
~xenobli:iconxenobli: May 11, 2008, 10:17:25 AM
Anyone??

--
Life is a waterfall, we're one in the river and one again after the fall.
=philho:iconphilho: May 12, 2008, 1:11:19 AM
Use the Reply button, please.

--
82% of statistics in signatures are made up. :rip: (This is a recursive signature...)
Spreading them is un-original and sheepish. If you agree, copy this in your... wait, no! :D
No to signature clichés! You are on an art site, be creative!
~sirdelirium:iconsirdelirium: May 12, 2008, 5:53:51 PM
Ummm, learn a new language thats readable? the lack of whitespace is killing me. I cant even decipher that.

Sorry I cant help.

--
Hamburgers: The cornerstone of any nutritious breakfast - Samuel Jackson
~KOLNstyle:iconKOLNstyle: May 12, 2008, 8:10:01 PM
You're going to hate improperly formatted z80 assembly.
`summaro:iconsummaro: May 12, 2008, 9:06:22 PM
I believe your problem is here:


' SWITCH TO LEFT AND MOVE DOWN
If imgInvaders4(farright).Left + 735 >= formright Then
dx3 = dx3 * -1
For X2 = 0 To 13
imgInvaders4(X2).Top = imgInvaders4(X2).Top + dy
Next X2
End If


I think the issue is, all of this is in a loop, where you essentially loop through all of your little space invaders.
Then, when you check whether you need to change direction and move down, you check a static value - the far right one, and then determine if they all need to move down.
Essentially, you're moving them all down as many times as you have space invaders visible.
This also happens on the check to switch to the right.

--
The DataGrid control is intended for viewing data, and not as a layout tool like an HTML table - Adobe
=philho:iconphilho: May 13, 2008, 6:16:26 AM
Hey, I made a long answer two days ago, were is it gone? I had several system maintenances this week-end, perhaps one stroke when I posted this answer.

Arh, quick summary:
You change the loop boundaries in code after ' FAR LEFT AND FAR RIGHT INVADERS, it is often bad practice: some languages just set the bounds before first loop and won't change, others will take the new bound in account, other will become crazy... You can probably put this test outside of the loop since it doesn't rely on X anyway.
In For X2 = 0 To 13 you forgot to use your variables. There is also a raw 115 in the code.

Not sure if it addresses your issues, but it is worth checking.

--
82% of statistics in signatures are made up. :rip: (This is a recursive signature...)
Spreading them is un-original and sheepish. If you agree, copy this in your... wait, no! :D
No to signature clichés! You are on an art site, be creative!
~xenobli:iconxenobli: May 13, 2008, 1:03:55 PM
Hehe, I got that fixed.

New problem though.

So when I copy and paste that into my other rows (and tweak it accordingly) and then shoot one of the guys on the end, everything above that just freezes. In place. If you shoot it, it disappears. But it just stays in one spot and doesn't move.

Here's a link to my project so far:
[link]

--
Life is a waterfall, we're one in the river and one again after the fall.