How do i remove an Object (aliens/ bullets) from my Space Invaders game??

Creating Space Invaders game and im getting confused on removing objects from my game. How do you actually remove an object (i.e bullets and aliens).
I know this isnt the right way to do it, but for the bullets i had an array of the Objects bullets[] and set the x and y coordinates off screen so u cant see then wen they are painted you cant see them, then wen the player fires them, the x and y coordinates change so they come from the players ship till it hits an alien or goes off screen, then i reset the coordinates so they are pasted off screen again. Im relatively new to this so i would appreciate any help. Im going to have to do the same with aliens wen a collision is detected. Is there a way of actually removing an object?
Here is sum code incase you need to see it:
public void checkCollision()
          Rectangle playerRec = new Rectangle(player1.getBoundingBox());
          for(int i=0; i<alienRow; i++)
               for(int j=0; j<alienCol; j++){
                    if(playerRec.intersects(aliens[i][j].getBoundingBox()))
                         collisionDetected();
                    for(int k=0; k<bulletNum; k++){
                         Rectangle bulletRec = new Rectangle(bullets[k].getBoundingBox());
                         if(bulletRec.intersects(aliens[i][j].getBoundingBox()))
                              removeBullet(bullets[k]);
                              collisionDetected();
     public static void collisionDetected()
          System.out.println("COLLISION");
private void removeBullet(Bullets bullet){
          bullet.fired=false;
          bullet.setX(-10);
          bullet.setY(-10);
     }Edited by: deathwings on Nov 25, 2009 8:20 AM

deathwings wrote:
I was thinking bout that arraylist angle before, but it makes sense now so i think that will work ok. Thx kevin.Not a problem.
Taking the List idea one step further, you could have a parent Object/Interface that all of your game objects extend/implement. Let's call it GameObject.
A GameObject would have a draw(Graphics g) function that you call from your paintComponent( ) method, and for example an act( ) function as well.
You'd have a single List of GameObjects that you add everything in your game into. Now painting is simply a matter of looping over a single List. And in your game logic loop, you could do a similar thing with the act( ) function: your bullet's act( ) would simply move it forward and check for collisions and going off screen. An alien's act( ) function would move it around and maybe shoot a weapon every so often.
Just an idea.

Similar Messages

  • How can I remove an object using Photoshop Elements 7?

    How can I remove an object using Photoshop Elements 7?

    You could probably use the 8 point garbage matte in this situation. I personally think the 8-point garbage matte is a bit cumbersome, but it should get the job done.
    1. Use the Razor Blade tool to place a cut before and after the shot with the bottle.
    2. Select the bottle clip.
    3. Press and hold Shift + Option, then drag the bottle clip up one track. This should create a duplicate clip directly above your original clip. (I'll refer to this duplicated clip as bottle2.)
    4. Locate the 8-point Garbage Matte filter and apply it to bottle2.
    5. Locate the Gaussian Blur filter and apply it to bottle2.
    6. Control click bottle1, and uncheck the "Clip Enable" setting from the shortcut menu. This will disable that clip.
    7. Double click bottle2 to load it into the Viewer. Then select the Filter tab.
    8. For the Garbage Matte filter, you'll notice 8 rows of numbers, these are the current locations for the control points, which you should be able to see in the Canvas. Start with point #1, and click the "+" button in the filters area, then in the Canvas click and drag to move the point. When you release the mouse button, you'll need to reclick the "+" button in the filters tab. Repeat these steps until you've isolated the bottle.
    9. Feather the edge of the matte.
    10. Adjust the Blur amount.
    11. Reenable bottle1. Playback the clip and make any necessary adjustments.
    Depending on your experience with Motion, you might also want to try sending bottle1 to Motion, then use Motion to control the layering.

  • How do I remove an object from the foreground of a photo eg a fence?

    How do I remove an object from the foreground of a photo eg a fence?

    What version of Photoshop?
    If CC then try here
    Learn Photoshop CC | Adobe TV

  • How do you remove an object from a picture.  Newbie to program CS6

    how do you remove an object from a picture.  Newbie to program CS6

    Well, generally you can use the clone-stamp tool for one, shortcut is S. It basically allows you to take data from any part of the image and copy that over. What I do is draw on a new layer above the one to modify- make sure you select Sample:"This layer and below" in the top toolbar when doing so. Other ways include blending something on top of the object too, using different blending modes. Painting over it works too at times (rarely). It'd be easier if we knew a specific case though...

  • How do I remove or delete a page from a Section?

    How do I remove or delete a page from a Section in Pages?

    The blank page is not blank, there is something on it like a return or word space, or a page break or return on the previous page that forces over to the "blank" page.
    Menu > View > Show Invisibles and delete it.
    Think of a word processing document like a scroll which you view through a set of frames (the pages).
    The scroll is filled from the front and flows through as many pages as necessary to accomodate the text in the main text area between the margins.
    Pages has one quirk however which catches out many users. Floating objects stay on their absolute page, the one where they were placed. If that page no longer exists because the text no longer flows that far, the floating objects are no longer visible. They are still in the document but off the end page, much like objects moved completely off the page to the right or down are still there but not visible.
    So if you want to make sure floating objects are entirely removed from the document delete, or move, those first, then select the text on that page by dragging over it or shift clicking from top to bottom and hit delete.
    Peter

  • How do i remove an e-mail mailbox from my iPad (leaving one behind)?

    How do I remove an e-mail mailbox from my iPad, as it appears to be causing problems with an nhs.net account?

    You can deactivate an email account in Settings > Mail, Contacts, Calendars > the account > Account. Turn it OFF.

  • How do I remove a credit/debit card from my account? I ask because I currently have a VISA gift/debit card with 50 dollars on it, but the money has run out so I want to usea new card. Also, there is no 'None' check option for payment type on my account.

    How do I remove a credit/debit card from my account? I ask because I currently have a VISA gift/debit card with 50 dollars on it, but the money has run out so I want to usea new card. Also, there is no 'None' check option for payment type on my account.

    Depending on how you created your account, "None" may or may not be an option. I believe it has something to do with whether the account was made through an App Store request or the regular iTunes Store. For example, my account allows no card but my father's doesn't allow there to be no card.
    To change the card, go to your account settings and change the information to your new card, and hit save.

  • How to get an ArrayList Object in servlet from JSP?

    How to get an ArrayList Object in servlet from JSP?
    hi all
    please give the solution for this without using session and application...
    In test1.jsp file
    i am setting values for my setter methods using <jsp:usebean> <jsp:setproperty> tags as shown below.
    After that i am adding the usebean object to array list, then using request.setAttribute("arraylist object")
    ---------Code----------
    <jsp:useBean id="payment" class="com.common.PaymentHandler" scope="request" />
    <jsp:setProperty name="payment" property="strCreditCardNo" param="creditCardNumber" />
    <%-- <jsp:setProperty name="payment" property="iCsc" param="securityCode" /> --%>
    <jsp:setProperty name="payment" property="strDate" param="expirationDate" />
    <jsp:setProperty name="payment" property="strCardType" param="creditCardType" />
    <%--<jsp:setProperty name="payment" property="cDeactivate" param="deactivateBox" />
    <jsp:setProperty name="payment" property="fAmount" param="depositAmt" />
    <jsp:setProperty name="payment" property="fAmount" param="totalAmtDue" /> --%>
    <jsp:useBean id="lis" class="java.util.ArrayList" scope="request">
    <%
    lis.add(payment);
    %>
    </jsp:useBean>
    <%
    request.setAttribute("lis1",lis);
    %>
    -----------Code in JSP-----------------
    In testServlet.java
    i tried to get the arraylist object in servlet using request.getAttribute
    But I unable to get that arrayObject in servlet.....
    So if any one help me out in this, it will be very helpfull to me..
    Thanks in Advance
    Edward

    Hi,
    Im also facing the similar problen
    pls anybody help..
    thax in advance....
    Litty

  • How do i remove my old Apple Id from iPhone's iCloud setting which does not exist anymore

    Purchased new iphone 5s, installed with itunes restoring backup from iphone 4 (which was too old a backup). It restored an old apple id (which i do not use anymore) in the iCloud settings while having my new Apple Id in the Itunes & App Store. I cannot turn off the iCloud setting due to old AppleId popping up - which does not exist.. How do i remove the old Apple Id from icloud setting on the phone.
    I cannot erase the phone as it asks for the password for the old Apple Id. And i cannot do the restore again (after i made a recent back up my iphone 4) as itunes asks me to turn off Find my phone.

    The Apple ID exists. The email address you used to create it may not, but the Apple ID does. Call AppleCare and ask to speak to someone in account security.

  • How do i remove my e mail address from my i message

    Can anyone tell me how I can remove my e mail address from my i mail, was notified by friends that everytime I i mail them my full e mail address shows instead of my name as usual?????
    Hope somebody can help

    Perhaps I don't understand your question.  Above you mention "i mail"; I'm assuming you meant "iMessage".  If that is want you meant, then have you turned iMessage to On in Settings>Messages?  And if so, does it say anything just below the iMessage On/Off button (such as "waiting for activation")?

  • How do I remove an unwanted Airport Express from my network?

    I have been using a Time Capsule for several years.  I am having trouble backing up to my Time Capsule.  I have discovered an unknown Airport Express in my network.  I've changed networks, added passwords to the network, etc.  How do I remove this unwanted Airport Express from my network?  I think he is wreaking havoc with my system!!  Help...

    Maybe this is an issue I should consult my ISP about??
    No question about that. If you can "see" Travis's device, then he can likely "see" your Time Capsule.
    I'm just concerned that whomever the APExpress belongs to could be changing settings on my computer or Time Capsule that would cause the issues with me not being able to backup.
    Make sure that you have a Time Capsule base station password. Unless a user has that password, they might be able to "see" your Time Capsule, but they cannot access any of the data on the Time Capsule or change the settings.
    Open AirPort Utility, click on the Time Capsule and click Manual Setup
    Then, click the Time Capsule tab below the icons to see the device name and password for your device. Make sure that you have entered the password and confirmed. Click Update if you have made any changes.
    The message I get is "The backup was not performed because an error occurred while copying files to the backup disk.  The problem may be temporary.  Try again later to back up.  If the problem persists, use Disk Utility to repair your backup disk."
    I am not sure what this error means, because I cannot duplicate it here to test.
    If it were me, I would try this "fix".
    http://pondini.org/TM/A5b.html

  • How do I remove an empty gmail folder from my iPad2?

    How do I remove an empty gmail folder from my iPad2?

    I Think that you had a corrupt email or an email with a really large attachment in that folder and it is now causing the mail app to crash. When the app closes and goes back to the home screen, that is an app crashing. I would try to delete this folder on the server. Log into your Gmail in a web browser and try to delete it there. If you delete it there, that will delete it on the iPad.

  • How do I remove a false mail notice from my iPad inbox when there is no new emails, How do I remove a false mail notice from my iPad inbox when there is no new emails

    How do I remove a false mail notice from my iPad inbox when there is no new emails?

    Reset your iPad.  Hold the on/off and home buttons together for about 10 seconds till the Apple logo appears.

  • How can i remove unwanted e-mail address from my list?

    how can i remove unwanted e-mail address from my list?

    Go to settings -> mail contacts and calendars -> tap on the desired account and choose delete at the bottom of the page. This will delete the email accunt from the device.

  • How do I remove an obsolete email address from my ipad

    how do I remove an obsolete email address from my ipad?

    If, when you see the address, you see a white arrow in a blue circle to the right, press that symbol.  You would see a "Delete" option at the bottom.

Maybe you are looking for