📄 chiphart.java
字号:
package role;
import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.JFrame;
import assistant.PublicVar;
public class ChipHart extends SportRole{
public static Image chipHartImage;
public static boolean isAlpha = true;
/**透明度*/
private float alpha = 0.0f;
/**是否不再透明*/
public boolean isShow;
private int count;
public static boolean isStop;
private boolean isBig;
private int hartCount;
public ChipHart(int x, int y) {
super(x, y, 30,30,0);
this.img = chipHartImage;
}
public void move() {
count++;
if(isStop == false){
this.x+=2;
this.y = 390;
this.changeHart();
if(count>80){
isStop = true;
}
}
if(count>100){
PublicVar.roleList.remove(this);
}
}
public void setState(int state){
this.state = state;
}
/**
* Method: drawMyself
* Desctiptoin: 绘制自身图形
* @param g : 画笔
* @param jf : 窗体画布
*/
public void drawMyself(Graphics g,JFrame jf){
if(isAlpha){
Graphics2D g2d =(Graphics2D)g;
if(alpha<1){
alpha+=0.003f;
if(alpha>1){
alpha = 1.0f;
//this.isShow = true;
}
}
else{
isAlpha = false;
}
this.changeHart();
g2d.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_ATOP, alpha)); // 开始
g2d.drawImage(img, x, y, width, height, jf);
g2d.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER)); // 结束
}
else{
g.drawImage(img, x, y, width, height, jf);
if(this.state == 1){
move();
}
}
}
private void changeHart(){
hartCount ++;
if(hartCount == 8){
if(isBig == false){
this.width += 5;
this.height += 5;
isBig = true;
}
else{
this.width -= 5;
this.height -= 5;
isBig = false;
}
hartCount = 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -