📄 bird.java
字号:
/*
* bird.java
*
* Created on 2001年12月27日, 上午10:28
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package shoot_birds;
import java.awt.Image;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.util.Random;
import javax.swing.ImageIcon;
/**
*
* @author open
*/
public class bird {
/** Creates a new instance of bird */
public bird(int x,int y,int dx) {
this.x=x;
this.y=y;
this.dx=dx;
}
public void move(Rectangle2D bounds)//鸟的移动
{
// 当鸟的x坐标超出范围的时候设置其为离开状态
if(x>=bounds.getMaxX()-1)
leave=true;
//当鸟死亡的时候下落,考虑到有一定的惯性所以任x+=dx执行
if(isDead())
y+=dy;
x+=dx;
}
public Ellipse2D getShape()//鸟的形状椭圆代替
{
return new Ellipse2D.Double(x,y,30,10);
}
public Image getImage()
{
String a = System.getProperty("user.dir");
ImageIcon icon=new ImageIcon(a+"\\shoot_birds\\images\\4.gif");
return icon.getImage();
}
public int getImageX()
{
String a = System.getProperty("user.dir");
ImageIcon icon=new ImageIcon(a+"\\shoot_birds\\images\\4.gif");
return icon.getIconWidth();
}
public int getImageY()
{
String a = System.getProperty("user.dir");
ImageIcon icon=new ImageIcon(a+"\\shoot_birds\\images\\4.gif");
return icon.getIconHeight();
}
public boolean isDead() {
return dead;
}
public void setDead(boolean dead) {
this.dead = dead;
}
public boolean isLeave() {
return leave;
}
public void setLeave(boolean leave) {
this.leave = leave;
}
public int getX()//得到鸟及时位置的横坐标
{
return x;
}
public int getY()//y坐标
{
return y;
}
private int x,y;
private int dx,dy=30;//dx,dy表示每步移动的象素
private boolean dead=false,leave=false; //鸟的状态 dead=true表示鸟已经死亡,leave=true表示鸟已经飞走了
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -