我正在制作Tron LightCycle游戏(这是一个基本游戏,您必须使用lightcycle推翻第二个玩家),在检测玩家与其Lightcycle之间的碰撞并检查图像时遇到了问题
这是Lightcycle类:
#include <ostream>
namespace std{
extern ostream cout;
};
int main(){
std::cout << "Hello world\n";
}
播放器类:
public class Lightcycle {
private int xCor , yCor , width , height ;
public Lightcycle(int xCor , int yCor , int tileSize , int tile) {
this.xCor = xCor;
this.yCor = yCor;
this.width = tileSize ;
this.height = tile ;
}
public void tick() {
}
public void render(Graphics g) {
g.setColor(Color.red);
g.fillRect(xCor, yCor, width, height);
}
public int getxCor() {
return xCor;
}
public void setxCor(int xCor) {
this.xCor = xCor;
}
public int getyCor() {
return yCor;
}
public void setyCor(int yCor) {
this.yCor = yCor;
}
public Rectangle getBounds() {
return new Rectangle((int) xCor ,(int) yCor, 18, 19);
}
}
这是ArrayList:
public class Player extends Entity {
private Game game;
private int dir = 0;
/* dir = 0 Normal State
* dir = 1 Up State
* dir = 2 Down State
* dir = 3 Reverse State
*/
public Player(Game game,float x , float y) {
super(x, y);
this.game = game;
}
public void tick() {
if(game.getKeyManager().up) {
y -= 2;
}
if(game.getKeyManager().down) {
y += 2;
}
if(game.getKeyManager().right) {
x += 2;
}
if(game.getKeyManager().left) {
x -= 2;
}
}
public void render(Graphics g) {
g.drawImage(Assets.player1,(int) x,(int) y, 18,19,null);
}
public Rectangle getBounds() {
return new Rectangle((int) x,(int) y, 18, 19);
}
public Rectangle getBounds2() {
return new Rectangle((int) x + 20 ,(int) y, 18, 19);
}
public int getX() {
return (int) x;
}
public int getY() {
return (int) y;
}
public void playerStop() {
}
}
在这里,我在ArrayList中添加一个对象:
Light = new ArrayList<Lightcycle>();
冲突检查:
if(game.getKeyManager().moving) {
Light.add(new Lightcycle(xCor, yCor, size , sizze));
score++;
}