首页>代码>JAVA swing开发飞机大战小游戏>/javatfly/src/javatfly/Ep.java
package javatfly;

import java.util.Random;

/**
 * ���
 * @author XXX
 *��Ϸ�еĵл�
 *1.�л��������δ֪��  
 *2.�л�������ܶ�  JAVA�д�Ŷ���̳�   1.ʹ������(������ȷ�л������,��˲�������)  2.ʹ�ü���
 */
public class Ep extends FlyObject {
         //�������ֵл���ٶ�
	    int sp;//�л���ٶ�
		int hp;//�л��Ѫ��
		int type;//������
		
	    /**
		 * ������:����
		 */
		public Ep() {
			//������������
			Random rd=new Random();
			//nextInt(num)��ʾ����[0,num]֮��������0~num-1
			//���һ�����������ѡȡͼƬ
			int index =rd.nextInt(15)+1;
			//���õл�����Ͱ汾
			type=index;
			//��Ŀ�����
			//��ʽ:�������ʽ?ʽ1��ʽ2��
			//��ʾ�������true��ִ��ʽ1��false��ִ��ʽ2
			String path="/img/ep"+(index<10?"0":"")+index+".png";
			//ȷ���л���ʾͼƬ
			img= App.getlmg(path);
			//ȷ���л�Ĵ�С
			//ʹ��ͼƬ�Ĵ�С����Ϊ�ɻ�Ĵ�С
			w=img.getWidth();
			h=img.getHeight();
			//ȷ���л��λ�� 
			x=rd.nextInt(512-w);
		    y=-h;
		    //�����ٶ�
		    sp=18-index;
		    //����Ѫ��
		    hp=index;
		}
		/**
		 * �л��ƶ��ķ���
		 * Ŀǰ:�õл������ƶ�
		 */
		public void move()
		{
			if(type==11)
			{
				x-=2;
				y+=sp;
			}else if(type==9)
			{
				x+=2;
				y+=sp;
			}else
			{
			y+=sp;
			}
		}
		/**
		 * ���ӵ���л���ײ����ʧ
		 * @param f
		 * @return
		 */
		public boolean shootBy(Fire f) {
			// TODO Auto-generated method stub
			boolean hit = (x<=f.x+f.w  && 
					      x>=f.x-w  &&  
					      y<=f.y+f.h &&
					      y>=f.y-h);
			return hit;
		}
		
		public boolean hitBy(Hero f) {
			boolean hit = (x<=f.x+f.w  && 
				      x>=f.x-w  &&  
				      y<=f.y+f.h &&
				      y>=f.y-h);
		return hit;
		}
}
最近下载更多
dusk red  LV2 2024年9月2日
12345678ajkdakjd  LV1 2024年7月2日
3334004690  LV10 2024年6月22日
bssheep  LV1 2023年12月31日
陈小灏  LV18 2023年12月15日
我的java  LV8 2023年12月14日
1061404770  LV3 2022年9月26日
agjbvfhjbg  LV6 2022年9月9日
Jasonast  LV1 2022年6月12日
testuser1234567  LV24 2022年5月31日
最近浏览更多
dusk red  LV2 2024年9月2日
12345678ajkdakjd  LV1 2024年6月26日
3334004690  LV10 2024年6月22日
半核野兽  LV1 2024年4月29日
gzcznb  LV8 2024年4月1日
bssheep  LV1 2023年12月31日
我的java  LV8 2023年12月14日
jkjfdgbkl  LV2 2023年11月1日
1766545549  LV1 2022年11月17日
李沛阳  LV1 2022年11月6日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友