현재 우주 침략자 스타일 게임에서 작업하고 있지만 총알이 여러 개있는 경우 문제가 발생했습니다. 지금은 하나만 발사 할 수 있습니다. 나는 그것을 배열리스트와 함께 작동 시키려고 노력해 왔지만 나는 그것을 작동시키지 못하고있다. 가장 가까운 곳에서 여러개의 총알을 발사했으나 총알이 우주선 위치와 관련하여 스폰하지 않은 것과 같은 위치에서 산란했습니다. 오브젝트가 경계를 초과 한 후 오브젝트를 제거하면 게임이 충돌했습니다. 누구든지 제가 잘못 가고있는 곳을 보도록 도와 줄 수 있습니까? 여기에 지금까지 주석 부분 내 시도가 Bullet bullet
인스턴스 변수에 대해 잊지 모든ArrayLIst를 사용하여 우주 침략자 스타일의 게임에서 총알 개체 만들기
import java.util.ArrayList;
import org.newdawn.slick.Input;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.GameContainer;
public class Player extends Entity
{
private int speed = 5;
private ArrayList<Bullet> bulletList;
private boolean firing;
private Bullet bullet;
public Player()
{
bullet = new Bullet();
//bulletList = new ArrayList<Bullet>();
this.setImage("ship");
this.setPosition(350,450);
this.setDimenseions(100, 100);
this.createRectangle();
}
@Override
public void entityLogic(GameContainer gc, int deltaTime)
{
Input input = gc.getInput();
if(input.isKeyDown(Input.KEY_A))
{
this.x -= speed;
}
if(input.isKeyDown(Input.KEY_D))
{
this.x += speed;
}
if(input.isKeyDown(Input.KEY_W))
{
this.y -= speed;
}
if(input.isKeyDown(Input.KEY_S))
{
this.y += speed;
}
if(input.isKeyPressed(Input.KEY_SPACE))
{
firing = true;
bullet.x = this.getX()+40;
//BulletList.add(new Bullet());
}
if(firing)
{
/*Carries out the logic for the bullet*/
//for(Bullet b : bulletList)
//{
//b.entityLogic(gc, deltaTime);
//}
//Moves the bullet negativly along the y axis
bullet.entityLogic(gc, deltaTime);
}
}
@Override
public void entityRendering(Graphics g)
{
g.drawImage(this.getImage(), this.getX(), this.getY());
if(firing)
{
/*Draws each bullet object in the list*/
//for(Bullet b : bulletList)
//{
//b.entityRendering(g);
//}
bullet.entityRendering(g);
}
}
}
감사합니다. 그것은 그것을 바로 정렬했습니다. 나는 내가 어떻게 보지 못했는지 모른다. 나는 휴일 후에 녹슬 게되기 시작하고 있다고 생각한다. – Crispy91