可能重复:
检查索引数组
所以我有我的代码,每次按下鼠标时,它都会在 mouseX 和 mouseY 处绘制一个新粒子并将位置存储在一个数组中,以便它可以更新直到它到达屏幕底部时被告知停止。我想做的是检查当前位置与已经“制造”的粒子的位置,如果它具有相同的坐标,则让它更快停止,以产生堆叠效果,有人可以帮我吗?
import java.awt.Point;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
public class Control extends BasicGameState {
public static final int ID = 1;
public Methods m = new Methods();
public Point[] point = new Point[(800 * 600)];
int pressedX;
int pressedY;
int num = 0;
String Build = "1.1";
public void init(GameContainer container, StateBasedGame game) throws SlickException{
}
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
for (int index = 0; index < point.length; index++) {
Point p = point[index];
if (p != null) {
if (p.y >= 598) {
m.drawParticle(point[index].x,(point[index].y));
} else {
m.drawParticle(p.x, p.y);
p.y++;
}
}
}
g.drawString("Particle Test", 680, 0);
g.drawString("Build: " + Build, 680, 15);
g.drawString("Pixels: " + num, 10, 25);
}
public void update(GameContainer container, StateBasedGame game, int delta) {
}
public void mousePressed(int button, int x, int y) {
pressedX = x;
pressedY = y;
num = num + 1;
point[num] = new Point(pressedX, pressedY);
}
public int getID() {
return ID;
}
}