Add draw wind info
This commit is contained in:
parent
455f6998d7
commit
61420477f8
@ -63,6 +63,7 @@ public class GameCanvas extends DoubleBufferedCanvas implements Runnable, Networ
|
|||||||
terrain.draw(g);
|
terrain.draw(g);
|
||||||
serverTurret.draw(g);
|
serverTurret.draw(g);
|
||||||
clientTurret.draw(g);
|
clientTurret.draw(g);
|
||||||
|
wind.drawInfo(g, metrics);
|
||||||
} else {
|
} else {
|
||||||
g.setColor(Color.WHITE);
|
g.setColor(Color.WHITE);
|
||||||
final int x = (Constants.WIDTH - metrics.stringWidth(WAIT_MESSAGE)) / 2;
|
final int x = (Constants.WIDTH - metrics.stringWidth(WAIT_MESSAGE)) / 2;
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package com.annimon.turrets;
|
package com.annimon.turrets;
|
||||||
|
|
||||||
import com.annimon.turrets.util.Util;
|
import com.annimon.turrets.util.Util;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author aNNiMON
|
* @author aNNiMON
|
||||||
*/
|
*/
|
||||||
public class Wind implements Constants {
|
public class Wind {
|
||||||
|
|
||||||
private double speed;
|
private double speed;
|
||||||
|
|
||||||
@ -15,7 +18,23 @@ public class Wind implements Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void change() {
|
public void change() {
|
||||||
speed = Util.rand(-MAX_WIND_STRENGTH, MAX_WIND_STRENGTH);
|
speed = Util.rand(-Constants.MAX_WIND_STRENGTH, Constants.MAX_WIND_STRENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawInfo(Graphics2D g, FontMetrics metrics) {
|
||||||
|
final int speedPercent = (int) (Math.abs(speed) * 100d / Constants.MAX_WIND_STRENGTH);
|
||||||
|
final String value = String.valueOf(speedPercent);
|
||||||
|
final int valueWidth = metrics.stringWidth(value);
|
||||||
|
final int x = (Constants.WIDTH - valueWidth) / 2;
|
||||||
|
final int y = metrics.getHeight();
|
||||||
|
|
||||||
|
g.setColor(Color.RED);
|
||||||
|
if (speed < 0) {
|
||||||
|
g.drawString("←", x - 2 * valueWidth, y);
|
||||||
|
} else if (speed > 0) {
|
||||||
|
g.drawString("→", x + 2 * valueWidth, y);
|
||||||
|
}
|
||||||
|
g.drawString(String.valueOf(speedPercent), x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user