资源描述:
《flappybirdjava源代码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、packagemcnk;importjava.awt.Color;importjava.awt.Font;importjava.awt.Graphics;importjava.awt.Graphics2D;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.awt.event.MouseListener;importjava.awt.image.BufferedImage;importjava.io.IOExceptio
2、n;importjava.util.Random;importjavax.imageio.ImageIO;importjavax.swing.JFrame;importjavax.swing.JPanel;importsun.audio.AudioPlayer;importsun.audio.AudioStream;/***FlappyBird*@authormcnk*@version1.0*/publicclassFlappyBird{publicstaticvoidmain(String[]args)throwsEx
3、ception{JFrameframe=newJFrame("我是一只小小小小鸟~!");Worldworld=newWorld();frame.add(world);frame.setSize(432,644+30);frame.setVisible(true);//快捷键:代码快速提示alt+/frame.setResizable(false);//是否重设大小frame.setLocationRelativeTo(null);//设置位置frame.setDefaultCloseOperation(JFrame.E
4、XIT_ON_CLOSE);//关闭操作world.action();}}/***游戏界面(鸟活动的世界)*@authormcnk*快捷键:alt+↑(↓)移动代码*JPanel:javax.swing.JPanel面板*快捷键:ctrl+shift+o导入(引入)包*/classWorldextendsJPanel{BufferedImagebackground;//图像缓存区,保存图片Groundground;Columncolumn1;Columncolumn2;Birdbird;booleangameover;B
5、ufferedImagegameoverImage;BufferedImagestartedImage;intscore;booleanstart;publicWorld()throwsIOException{background=ImageIO.read(getClass().getResource("bg.png"));gameoverImage=ImageIO.read(getClass().getResource("gameover.png"));startedImage=ImageIO.read(getClas
6、s().getResource("start.png"));start();}publicvoidstart()throwsIOException{ground=newGround();column1=newColumn(1);column2=newColumn(2);bird=newBird();gameover=false;score=0;start=false;}publicvoidpaint(Graphicsg){g.drawImage(background,0,0,null);g.drawImage(colum
7、n1.image,column1.x-column1.width/2,column1.y-column1.height/2,null);g.drawImage(column2.image,column2.x-column2.width/2,column2.y-column2.height/2,null);g.drawImage(ground.image,ground.x,ground.y,null);g.setColor(Color.WHITE);Fontfont=newFont(Font.SANS_SERIF,Font
8、.BOLD,30);g.setFont(font);g.drawString(score+"",20,40);Graphics2Dg2d=(Graphics2D)g;g2d.rotate(-bird.alpha,bird.x,bird.y);//旋转坐标系g.drawImage(bird.image,bird.x-b