我正在制作一个游戏,让我的角色走过硬币的图像。我想要发生的是,当他经过硬币时,他们会消失。我已经研究并理解可以用布尔表达式来做这个,但我不确定如何构造语句。我会很感激我会如何做到这一点,也许是一个例子。谢谢
这就是我展示硬币和角色“胡德”的方式:
g.drawImage(coin1, cx1, cy1, this);
int heightd = coin1.getHeight(this);
int widthd = coin1.getWidth(this);
g.drawImage(coin2, cx2, cy2, this);
int heighte = coin1.getHeight(this);
int widthe = coin1.getWidth(this);
g.drawImage(coin3, cx3, cy3, this);
int heightf = coin1.getHeight(this);
int widthf = coin1.getWidth(this);
g.drawImage(coin4, cx4, cy4, this);
int heightg = coin1.getHeight(this);
int widthg = coin1.getWidth(this);
g.drawImage(Hood,hx , hy,this);
int width = Hood.getWidth(this);
int height = Hood.getHeight(this);
答案 0 :(得分:1)
如果你以与绘制硬币相同的方式绘制背景......
你可以简单地重绘整个风景没有某个硬币......
boolean drawCoin1 = true; //change this, maybe programatically
boolean drawCoin2 = true; //like:
boolean drawCoin3 = true; // boolean drawCoin3 = calculateCoinState();
boolean drawCoin4 = true; //
if(drawCoin1){
g.drawImage(coin1, cx1, cy1, this);
int heightd = coin1.getHeight(this);
int widthd = coin1.getWidth(this);
}
if(drawCoin2){
g.drawImage(coin2, cx2, cy2, this);
int heighte = coin1.getHeight(this);
int widthe = coin1.getWidth(this);
}
if(drawCoin3){
g.drawImage(coin3, cx3, cy3, this);
int heightf = coin1.getHeight(this);
int widthf = coin1.getWidth(this);
}
if(drawCoin4){
g.drawImage(coin4, cx4, cy4, this);
int heightg = coin1.getHeight(this);
int widthg = coin1.getWidth(this);
}