나는 단순한 우주 침략자를 android 용 사수 유형으로 만들고 싶습니다. 총알이 적을 죽이는 데 어려움을 겪고 있습니다. 나는 충돌 자체에별로 관심이 없지만 arrayList 함수는 나를 당황하게하고있다. 나는 배열의 총알을 가지고 있고 다른 하나는 각각의 x와 y 위치에있다. 나는 그들이 충돌하면 대응하는 나쁜 사람이 사라질 수 있도록하려고 노력 중입니다. 불행히도이 작업을 수행하려고하면 강제 종료가 발생하여 디버깅하기가 어렵습니다. Bullet.class 내총알의 ArrayList로 badGuys의 ArrayList를 삭제하려고 시도했습니다.
: World.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;
}
: 여기에 관련 코드의 BadGuy.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));
}
}
}
는;
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));
}
}
Integer를 사용할 때 badguys가 제거 될 수 있습니다. 하지만 arrayList를 반환하여 강제로 가까이에있는 badguys를 제거하고 싶습니다.
int i = bulletsArray.size(); i> = 0; 나는 // 예외를 throw해야합니다. –
예외를 throw하지 않습니다. 그것은 단지 for 루프를 뒤로 돌리고 있습니다. 내가 의견을 말하면 게재 위치 bulletsBang = bulletsArray.get (i); 및 게재 위치 badGuys = badguys.get (j); 더 이상 강제로 닫히지 않아 문제가되지 않습니다. 편집 : 내 코드를보다 완전하게 반영하기 위해 편집을 추가했습니다. 감사! – Funlamb
루프 크기() + 1 번 실행하는 것처럼 보입니다. –