基本信息
源码名称:JAVA 像素鸟小游戏源码(支持俩人一起玩)
源码大小:0.80M
文件格式:.rar
开发语言:Java
更新时间:2018-07-09
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 7 元 
   源码介绍



双人 像素鸟如下:

package Flappybirid_1;
import java.awt.image.BufferedImage;
import java.io.IOException;//发出IO异常的信号
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.imageio.ImageIO;
import javax.swing.*;
public class World extends JFrame{
	GamePanel fp;
	
	public class GamePanel extends JPanel{
		/**
		 * 
		 */
		private static final long serialVersionUID = 6865748790042152200L;
		BufferedImage background;
		BufferedImage startImage;
		Ground ground;
		Column column1;
		Column column2;
		Bird bird[]=new Bird[2];
		int []score=new int[2];
		GoldCoin gc1,gc2;
		boolean start; //游戏开始的标志位
		boolean gameover;
		boolean []over=new boolean[2];
		boolean overs;
	    boolean getcoin;
		int sign;
		int random;
		public GamePanel(int l) throws IOException {
			sign=l;
			overs=true;
			background=ImageIO.read(getClass().getResource("/images/白天.png"));
			startImage=ImageIO.read(getClass().getResource("/images/上.png"));
			column1=new Column(360);
			column2=new Column(560);
			gc1=new GoldCoin();
			gc2=new GoldCoin();
			for(int i=0;i<sign;i  ) {
				bird[i]=new Bird(100,190 i*100,i);
				score[i]=0;
			}
			//初始化地面
			ground=new Ground();
		}
			/*重写父类的pain方法来绘制图形*/
		public void paint (Graphics g) {
			//绘制背景图片
			g.drawImage(background,0,0,null);
			if(start==true) {
				//绘制开始图片
			   column1.paint(g);
			    column2.paint(g);
			    gc1.paint(g);
			    gc2.paint(g);
			    for(int i=0;i<sign;i  ) {
					bird[i].paint(g);
				}
			}
			if(gameover) {
				try {
					BufferedImage end=ImageIO.read(getClass().getResource("/images/Over.png"));
					g.drawImage(end,0,0,null);
				} catch (IOException e) {
					// TODO 自动生成的 catch 块
					e.printStackTrace();
				}
			}
			
			if(start==false&&gameover==false) {
				//绘制开始图片
			    g.drawImage(startImage,0,0,null);
			}
				//绘制地面
			for(int i=0;i<sign;i  ) {
				g.setFont(new Font(Font.MONOSPACED,Font.BOLD,20));
				g.setColor(Color.WHITE);
				g.drawString("score" i "=" score[i], 30 200*i, 50);
				ground.paint(g);
			}
		}
			

		public void action() throws InterruptedException {
			this.setFocusable(true);
			addMouseListener(new MouseListener() {

				@Override
				public void mouseClicked(MouseEvent arg0) {
					// TODO 自动生成的方法存根
					
				}

				@Override
				public void mouseEntered(MouseEvent arg0) {
					// TODO 自动生成的方法存根
					
				}

				@Override
				public void mouseExited(MouseEvent arg0) {
					// TODO 自动生成的方法存根
					
				}

				@Override
				public void mousePressed(MouseEvent arg0) {
					// TODO 自动生成的方法存根
					if(arg0.getButton()==MouseEvent.BUTTON1) {
						if(gameover==true) {
							try{
								
								column1=new Column(360);
								column2=new Column(560);
								gc1=new GoldCoin();
								gc2=new GoldCoin();
								for(int i=0;i<sign;i  ) {
									bird[i]=new Bird(100,190 i*100,i);
									score[i]=0;
									over[i]=false;
								}
								//初始化地面
								ground=new Ground();
								start=false;
								gameover=false;
							}catch(IOException e1) {
								e1.printStackTrace();
							}
						}
						start=true;
						if(over[0]==false)
						   bird[0].flappy();
					}
					if(arg0.getButton()==MouseEvent.BUTTON3) {
						if(sign==2) {
							if(over[1]==false)
								   bird[1].flappy();
						}
						
					}
					
					
				}

				@Override
				public void mouseReleased(MouseEvent arg0) {
					// TODO 自动生成的方法存根
					
				}
				
			});
		    addKeyListener(new KeyListener() {
	            public void keyPressed(KeyEvent e) {
	            	if(e.getKeyCode()==KeyEvent.VK_X) {
						if(gameover==true) {
							try{
								
								column1=new Column(360);
								column2=new Column(560);
							    gc1=new GoldCoin();
								gc2=new GoldCoin();
								for(int i=0;i<sign;i  ) {
									bird[i]=new Bird(100,190 i*40,i);
									score[i]=0;
									over[i]=false;
								}
								//初始化地面
								ground=new Ground();
								start=false;
								gameover=false;
							}catch(IOException e1) {
								e1.printStackTrace();
							}
						}
						start=true;
						if(over[0]==false)
						   bird[0].flappy();
					}
					if(e.getKeyCode()==KeyEvent.VK_N) {
						if(sign==2) {
							if(over[1]==false)
								   bird[1].flappy();
						}
						
					}
	            }

				@Override
				public void keyReleased(KeyEvent arg0) {
					// TODO 自动生成的方法存根
					
				}

				@Override
				public void keyTyped(KeyEvent e) {
					// TODO 自动生成的方法存根
				}
	        });
			Thread t = new Thread(new Runnable() {

				@Override
				public void run() {
					// TODO 自动生成的方法存根
					while(true) {
						overs=true;
						if(start==true)
						{
							column1.step();
							column2.step();
							if(column1.ran<100&&column1.getcoin==false) {
								gc1.step(column1);
							}
							if(column2.ran<100&&column2.getcoin==false) {
								gc2.step(column2);
							}
							for(int i=0;i<sign;i  ) {
								bird[i].step();
								if(over[i]==false) {
									//如果不加这个的话就会出现只要有一只鸟还活着就可以无限飞
								    over[i]=bird[i].hit(column1,column2,ground);
								
								}
									
								if(bird[i].pass(column1, column2)&&over[i]==false) {
									score[i]  ;
								}
								  overs=overs&over[i];
								if(bird[i].hitCoin(gc1)) {
									score[i] =1;
									gc1.TrackChange();
									column1.getcoin=true;
								}
								if(bird[i].hitCoin(gc2)) {
									score[i] =1;
									gc2.TrackChange();
									column2.getcoin=true;
								}
							}
							
							if(overs) {
								start=false;
								gameover=true;
							}
						}	
				       ground.step();
				       repaint();
				       
				       try {
						Thread.sleep(1000/60);
					} catch (InterruptedException e) {
						// TODO 自动生成的 catch 块
						e.printStackTrace();
					}
				      //每个60是重绘一次
		              }
				}
				
			});
			t.start();
		}
	}

	World(int l) throws IOException, InterruptedException
	{
	    fp = new GamePanel(l);
		setSize(384,448);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    add(fp);
		setVisible(true);
		fp.action();
	}
}