Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Need some space invaders help

So i have already got the game working in VB but it seems to messy and i wanted to start again. I'm trying to get the "baddies" to move left and right then down once they have done both. On my last program i had individual code for each baddy but this time i'm going to use an array.

Code
Dim movedleft As Boolean
  Dim movedright As Boolean

  For Me.count = 1 To baddies.Length
    If baddies(count).Left > 0 And baddies(count).Visible = True Then
    baddies(count).Left = baddies(count).Left - 5
    End If
  Next

That's what i've got so far and just get an unexpected error :/

I want it to go, left then right then down. If one was to be killed then i want the next one to continue to the end of the screen, etc. I'm fine with everything else just can't seem to get this bloody thing working !
For Me.count = 1 To baddies.Length - 1
Could that be it?
(Dec 10, 2012 10:40 AM)J!nx Wrote:  For Me.count = 1 To baddies.Length - 1
Could that be it?

Yeah, that got them moving, but now they all just over lap :(
(Dec 10, 2012 10:49 AM)APTO Wrote:  Yeah, that got them moving, but now they all just over lap :(

Do you use drawings?
If so you might need to:
1) Dispose/ make everthing original color and then redraw them on the new position.
OR
2) Draw a white line on the outer of the "baddie".

2) works best because with 1) u can get flickering.
(Dec 10, 2012 10:49 AM)APTO Wrote:  Yeah, that got them moving, but now they all just over lap :(

Change that to:
For Me.count = 0 To baddies.Length - 1

I don't really see the point why aren't you moving the first one? Index's in array's start at 0, not at 1. So the first items is at 0, second at 1, third at 2 etc.
(Dec 10, 2012 10:56 AM)pr3fix Wrote:  Change that to:
For Me.count = 0 To baddies.Length - 1

I don't really see the point why aren't you moving the first one? Index's in array's start at 0, not at 1. So the first items is at 0, second at 1, third at 2 etc.

Yes i know this, i started it at 0 and it did not worked so i put it to 1 and then it did work. I am also using picture boxes to represent my "baddies". It's really bugging me now :( something so simple but just can't get it to work.
Hmm i never did something like this but can't you use the location of the picturebox?
OR
Like something
For Each Baddie As Picturebox In Me.Form ???
(Dec 10, 2012 11:08 AM)J!nx Wrote:  Hmm i never did something like this but can't you use the location of the picturebox?
OR
Like something
For Each Baddie As Picturebox In Me.Form ???

If i used the location i would have to move each of the individually. The problem im dealing with now is if i do "if baddies(count).left < 0" then they will all move because it will move up the array checkng :/
(Dec 10, 2012 09:20 AM)APTO Wrote:  So i have already got the game working in VB but it seems to messy and i wanted to start again. I'm trying to get the "baddies" to move left and right then down once they have done both. On my last program i had individual code for each baddy but this time i'm going to use an array.

Code
Dim movedleft As Boolean
  Dim movedright As Boolean

  For Me.count = 1 To baddies.Length
    If baddies(count).Left > 0 And baddies(count).Visible = True Then
    baddies(count).Left = baddies(count).Left - 5
    End If
  Next

That's what i've got so far and just get an unexpected error :/

I want it to go, left then right then down. If one was to be killed then i want the next one to continue to the end of the screen, etc. I'm fine with everything else just can't seem to get this bloody thing working !

I don't think you understand the concept of 0-based indexing for arrays.

You start at one index higher than the first element's index, and you go 1 past the last index in the array, which would cause an index out of bounds exception.

The way 0-based indexing works for arrays, is the first element starts at index 0, and the last index is the total number of elements - 1, because of the fact that the first element starts at index 0.

Something declared like so:
Code
Dim i As Integer() = New Integer(10) {}

Does not mean that the last index is 10, it means there are 10 elements inside this array. And the indexing goes from 0 to 9.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Dec 10, 2012 01:55 PM)0xDEAD10CC Wrote:  I don't think you understand the concept of 0-based indexing for arrays.

You start at one index higher than the first element's index, and you go 1 past the last index in the array, which would cause an index out of bounds exception.

I've got all of this part working perfect now. I have it to go to the left on the end, but on the right when i hit a "baddie" it just goes to the same part as if it was still there when it isn't visible, if you get me? i've used the same method as on the left side but it still doesn't work :*(


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by iTeDDyFeb 18, 2015 06:42 AM 16 467 Feb 18, 2015 06:42 AM
Last Post: iTeDDy
[Python] by __init__Jul 16, 2013 10:37 AM 9 315 Jul 16, 2013 10:37 AM
Last Post: __init__
[Java] by SIM-524734Feb 26, 2012 03:11 PM 16 420 Feb 26, 2012 03:11 PM
Last Post: SIM-524734