📄 healthbar.java
字号:
/*
Netwar
Copyright (C) 2002 Daniel Grund, Kyle Kakligian, Jason Komutrattananon, & Brian Hibler.
This file is part of Netwar.
Netwar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Netwar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Netwar; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package netwar.gui;
import java.awt.*;
import netwar.game.GameObject;
import netwar.utils.vectorgraphics.MalleableColor;
import netwar.utils.vectorgraphics.ColorSpectrum;
/** This class is a stripped down, streamlined health bar display. */
class HealthBar extends Component {
GameObject current = null;
static Color back = new Color(64, 64, 64);
//I know some of the colors are outside [0,255].
//I added a new feature to ColorSpectrum that makes it deal with these.
//So, the lower half will have red clipped down to 255 and the upper half will have green = 255.
//Thus, it goes red -> yellow -> green.
static ColorSpectrum redToGreen = new ColorSpectrum(510, 0, 0, 510, 0, 0, 255, 255, 101);
static MalleableColor fore = new MalleableColor(redToGreen);
public HealthBar() {
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
int h = getHeight();
int w = getWidth();
int x;
float f;
if(current == null)
f = 0;
else
f = current.getStatusFraction();
fore.setCurrent(((int)(f * 100)) + 1);
x = (int)(f * w);
g.setColor(fore);
g.fillRect(0, 0, x, h);
g.setColor(back);
g.fillRect(x, 0, w - x, h);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -