Need help on my Space Invaders Game

This is a discussion on Need help on my Space Invaders Game within the Game Programming forums, part of the General Programming Boards category; I attached a faulty version of the game that i have been working on you can try it: left arrrow: ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    7

    Need help on my Space Invaders Game

    I attached a faulty version of the game that i have been working on
    you can try it:
    left arrrow: move left
    right arrow: move right
    space bar: shoot
    i am trying to make the shots disappear once it touches the top of the border
    i don't know y when i resize my shot vector it crashes...
    please help on this~
    thanks
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    59
    i can't compile it since i only have msvc.

    But after a quick glance at the code i see this

    Code:
    for( int index = 0; index < XShot.length(); index ++ )
    {
    gotoxy(XShot[index],YShot[index]);
    cout << " " ;
    if( YShot[index] > 2 )
    {
    YShot[index] --;
    }
    else
    {
    XShot[index] = XShot[index-1]; <---     XShot[-1] when index=0 
    YShot[index] = YShot[index-1]; <---         --""--
    XShot.resize(XShot.length() - 1);
    YShot.resize(YShot.length() - 1);
    }
    }
    Last edited by erikj; 01-02-2004 at 03:02 PM.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    7
    OH
    thanks alot~
    but now the bullets are flying everywhere?!!?
    is there something wrong with the vectors?

    this is what i did

    Code:
    else
                 {
                       if( index > 1 )
                       {
                           XShot[index] = XShot[index-1];
                           YShot[index] = YShot[index-1];
                           XShot.resize(XShot.length() - 1);
                           YShot.resize(YShot.length() - 1);
                       }
                 }
    Last edited by zz3ta; 01-03-2004 at 04:56 PM.

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    59
    doesn't the vector class have a remove or delete function? It would be easier to use.

    If not you can change the "dead" bullet with the last one int the vector.

    XShot[index]=XShot[XShot.length()-1];
    YShot[index]=YShot[YShot.length()-1];
    XShot.resize(XShot.length() - 1);
    YShot.resize(YShot.length() - 1);

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    7
    ummm i dont know how to fully use the vector class yet...
    still to newbie T__T
    and for changing the last bullet ur way....
    doesnt seem to work
    it deletes the bullet when i press space again

  6. #6
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361
    vector.erase(int spot)
    vector.erase(int begin,int end)

    They might be iretators instead of ints though there isn't much difference.
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    7
    Stan can u make its alil clearer....
    i dont really understand or i am just too stupid XD

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  2. Space Invaders. Both shoot and move at once?
    By Swerve in forum Game Programming
    Replies: 13
    Last Post: 10-25-2008, 11:58 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  4. Game Programmer's AIM Circle: Join Today
    By KingZoolerius66 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 12-20-2003, 12:12 PM
  5. Galaxian or Space invaders for my next game (read this)
    By Leeman_s in forum C++ Programming
    Replies: 7
    Last Post: 11-07-2001, 09:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21