Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6880733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:00:43+00:00 2026-05-27T05:00:43+00:00

I’m looking to make a simple space invaders type shooter for android and i’m

  • 0

I’m looking to make a simple space invaders type shooter for android and i’m having trouble making the bullets kill the enemies. I’m not so concerned with the collision itself, but the arrayList functions are baffling me. I have an arrayList of bullets and another of bad guys each with their respective x and y placement. I’m trying to make it so that if they collide, the corresponding bad guy disappears. Unfortunately when I try to do this, i’m getting force closes so its really hard to debug. Here’s the relevant code:

Within Bullet.class:

    public List<Placement> bulletsArray = new ArrayList<Placement>();
    public List<Placement> temp = new ArrayList<Placement>();
    public List<Integer> tempKill = new ArrayList<Integer>();

    public List<Integer> kill(List<Placement> badguys){
    for (int i = bulletsArray.size() ; i >= 0 ; i--){
        Placement bulletsBang = bulletsArray.get(i);
        for (int j = badguys.size(); j >=0 ; j--){
            Placement badGuys = badguys.get(j);
            if (bulletsBang.x == bulletsBang.y ){
                if (badGuys.x == bulletsBang.x && badGuys.y == bulletsBang.y){
                    tempKill.add(j);
                }
            }
        }
        //      tempKill.add(0); //Just using this to get something to work. 
        //      temp.add(bullets.get(i)); // should destroy the bullet when it hits.
    }
    return tempKill;
}

Within World.class:

    public void update(float deltaTime) {
    if (gameOver)
        return;

    tickTime += deltaTime;

    while (tickTime > tick) {
        tickTime -= tick;
        bullet.advance();
        bullet.deleteExtra();

        slowDown++;
        if (slowDown == 2){
        badGuy.advance();
        slowDown = 0;
        }

        if (bullet.bulletsArray.size() > 0){
            badGuy.kill(bullet.kill(badGuy.badguys));
        }   
    }
}

Within BadGuy.class;

    public  List<Placement> badguys= new ArrayList<Placement>();
    public BadGuy (){
        for (int i = 0 ; i < 8; i++){
            if (i% 2 == 0 ){
                badguys.add(new Placement(1 + i, 0));//creates 3 rows of bad guys.
                badguys.add(new Placement(1 + i, 1));
                badguys.add(new Placement(1 + i, 2));
            }
        }
    }
    public void kill(List<Integer> die){
            for (int i = die.size() ; i >= 0 ; i --){
        badguys.remove(die.get(i));
        }
    }

I can get the badguys to be removed when I use an Integer. But I want to return the arrayList to remove the badguys I get the force close.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:00:43+00:00Added an answer on May 27, 2026 at 5:00 am

    Your reverse loop must start at size()-1. size() is 1 past the last element and will throw an exception.

    EDIT

    Also, I would suggest that your routine kill() return a List<Placement>, not a List<Integer> of indices. That is simpler conceptually (at least to me, YMMV) and BadGuy.kill() simply does a removeAll()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm making a simple page using Google Maps API 3. My first. One marker
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.