我正在制作一个游戏,游戏中我的角色走过硬币的图像。我想发生的是,当他越过硬币时,它们就消失了。我已经研究并理解了用布尔表达式可以做到这一点,但我不确定如何构造语句。我希望能解释一下我将如何做这件事,也许还有一个例子。谢谢
这就是我展示硬币和字符"胡德"的方式:
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);
如果你用和你画硬币一样的方式画背景。。。
你可以简单地重新绘制整个风景而不需要特定的硬币。。。
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);
}