0
특정 셀이 갈 수있는 영역을 제한하려고 시도하므로 을 사용하면 spawn.distance()
을 사용하여 해당 스폰에서 너무 멀리 떨어져 있지 않은지 확인할 수 있습니다. 문제는 셀의 현재 위치로 계속 변경된다는 것입니다. 내가 말할 수있는 한 그것이 설정되면 아무것도 바꿀 수 없다. 누구든지 변화하는 이유를 알고 있습니까?이 포인트가 왜 변경됩니까?
엔티티 클래스 :
public abstract class Entity {
protected int width, height;
protected Point location;
protected CellType cellType;
abstract void tick();
abstract void render(Graphics g);
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public Point getLocation() {
return location;
}
public CellType getCellType() {
return cellType;
}
}
셀 등급 :
public class Cell extends Entity{
private Random random;
private CellType cellType;
private Point spawn;
private int angle;
private float xVelocity, yVelocity;
private float maxVelocity = .2f;
public Cell(Point location) {
random = new Random();
cellType = MasterGame.cellTypes.get(random.nextInt(MasterGame.cellTypes.size()));
width = MasterGame.cellSizes.get(cellType);
height = width;
spawn = location;
super.location = location;
}
int ticks = 0;
public void tick() {
if(ticks == 15) {
System.out.println(spawn);
angle = random.nextInt(360);
xVelocity = (float) (maxVelocity * Math.cos(angle));
yVelocity = (float) (maxVelocity * Math.sin(angle));
ticks = 0;
}
if(ticks % 3 == 0){
location.x += xVelocity;
location.y += yVelocity;
}
ticks++;
}
public void render(Graphics g) {
g.setColor(Color.DARK_GRAY);
g.fillOval(location.x, location.y, width, height);
g.setColor(Color.GREEN);
g.fillOval((int)(location.x+(width*.125)), (int)(location.y+(height*.125)), (int)(width*.75), (int)(height*.75));
}
}
[MCVE] (http://stackoverflow.com/help/mcve)를 제공해주십시오. 주어진 코드는 실제로 그 순간에 실제로 일어나고있는 것을 명확히하지 않습니다. – SomeJavaGuy
실제로 위치를 변경하는 코드가 있습니다. if (ticks % 3 == 0) { location.x + = xVelocity; location.y + = yVelocity; }' –
@MikhailKuchma '위치'는 '스폰'가 아닙니다 – TheGamerPlayz