Results 1 to 6 of 6
  1. #1
    Midge is offline Member
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Question Space Invaders help!

    Hi

    I am trying to enhance a version of space invaders for an assignment and i have managed to align the 'aliens' in a row, but i cant work out how to get multiple rows underneath the first row (x).

    I have tried x+1 and various others but i am stuck, can anyone help please?

    Thanks in advance :D
    x

  2. #2
    sonny's Avatar
    sonny is offline Senior Member
    Join Date
    Feb 2010
    Location
    North West England
    Posts
    146
    Rep Power
    0

    Default

    it might help to see some of the relevant bits of code, inside code tags,

    i'm pretty new but can i ask are you using two nested for loops to set them out

    sonny
    :p I still have my "L" plates on...... directions and explanations are far more help than blaring your Horn! :p Watching:CS106a on YouTube \Reading The Art & Science of Java by Eric S Roberts

  3. #3
    Midge is offline Member
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Default

    Hi thanks for the help :D

    ill post the code i have that aligns the first horizontal row of 6 of the aliens.

    public void initWorld() {
    actors = new ArrayList();
    for (int i = 0; i < 6; i++){ // amount of vertical space invaders
    Monster m = new Monster(this);
    m.setX( (int)(Stage.HEIGHT) );
    m.setX( i*70 ); //width gap between space invaders
    m.setVx( (int)(15-10) );

    actors.add(m);

    i need to do another 5 rows of aliens underneath this but im not sure how to shift the rows down by 1 each time, if that makes sense?

    xx

  4. #4
    sonny's Avatar
    sonny is offline Senior Member
    Join Date
    Feb 2010
    Location
    North West England
    Posts
    146
    Rep Power
    0

    Default

    like I said im still new to this but i think you nedd to do something like this

    Java Code:
    public void initWorld() {
    actors = new ArrayList();
    for (int k =0: k <5; k++) { // sets out 5 rows
    for (int i = 0; i < 6; i++){ // amount of vertical space invaders
    
    Monster m = new Monster(this);
    m.setX( (int)(Stage.HEIGHT) );
    m.setX( i*70 ); //width gap between space invaders
    m.setVx( (int)(15-10) );
    
    actors.add(m);
    }
    }
    you may need to use the K index somewhere to set out the height in the vertical.

    hope this helps
    :p I still have my "L" plates on...... directions and explanations are far more help than blaring your Horn! :p Watching:CS106a on YouTube \Reading The Art & Science of Java by Eric S Roberts

  5. #5
    Midge is offline Member
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Default

    i tried to put the 'k' in like you said but it hasnt made the extra rows i need. would i have to put the k index in one of the other classes too? or define it somewhere else?

  6. #6
    sonny's Avatar
    sonny is offline Senior Member
    Join Date
    Feb 2010
    Location
    North West England
    Posts
    146
    Rep Power
    0

    Default

    not sure really, has it set out the rows on top of each other? so it loooks like one row.

    you have used the index i
    Java Code:
    m.setX( i*70 ); //width gap between space invaders
    presumably this sets a distance across from left to right

    you will have to use the k index to set out the vertical distances

    does this bit have something to do with the vertical spacing
    Java Code:
    m.setVx( (int)(15-10)
    :p I still have my "L" plates on...... directions and explanations are far more help than blaring your Horn! :p Watching:CS106a on YouTube \Reading The Art & Science of Java by Eric S Roberts

Similar Threads

  1. add a space after 10 lines?
    By ukemasta in forum New To Java
    Replies: 10
    Last Post: 01-20-2010, 12:12 PM
  2. Replies: 0
    Last Post: 07-05-2009, 12:31 PM
  3. Blank space
    By sandy1028 in forum New To Java
    Replies: 1
    Last Post: 04-21-2009, 10:00 AM
  4. space between images !!
    By nhawlman in forum New To Java
    Replies: 1
    Last Post: 01-09-2009, 11:17 PM
  5. Space Exploration dev 6
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 03-25-2008, 04:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •