資源描述:
《Flappy Bird java 源代碼》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
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
2、.IOException;importjava.util.Random;importjavax.imageio.ImageIO;importjavax.swing.JFrame;importjavax.swing.JPanel;importsun.audio.AudioPlayer;importsun.audio.AudioStream;/***FlappyBird*@authormcnk*@version1.0*/publicclassFlappyBird{publicstaticvoidmain
3、(String[]args)throwsException{JFrameframe=newJFrame("我是一只小小小小鳥~!");Worldworld=newWorld();frame.add(world);frame.setSize(432,644+30);frame.setVisible(true);//快捷鍵:代碼快速提示alt+/frame.setResizable(false);//是否重設(shè)大小frame.setLocationRelativeTo(null);//設(shè)置位置frame.
4、setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//關(guān)閉操作world.action();}}/***游戲界面(鳥活動(dòng)的世界)*@authormcnk*快捷鍵:alt+↑(↓)移動(dòng)代碼*JPanel:javax.swing.JPanel面板*快捷鍵:ctrl+shift+o導(dǎo)入(引入)包*/classWorldextendsJPanel{BufferedImagebackground;//圖像緩存區(qū),保存圖片Groundground;Columncolu
5、mn1;Columncolumn2;Birdbird;booleangameover;BufferedImagegameoverImage;BufferedImagestartedImage;intscore;booleanstart;publicWorld()throwsIOException{background=ImageIO.read(getClass().getResource("bg.png"));gameoverImage=ImageIO.read(getClass().getReso
6、urce("gameover.png"));startedImage=ImageIO.read(getClass().getResource("start.png"));start();}publicvoidstart()throwsIOException{ground=newGround();column1=newColumn(1);column2=newColumn(2);bird=newBird();gameover=false;score=0;start=false;}publicvoidp
7、aint(Graphicsg){g.drawImage(background,0,0,null);g.drawImage(column1.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
8、,ground.y,null);g.setColor(Color.WHITE);Fontfont=newFont(Font.SANS_SERIF,Font.BOLD,30);g.setFont(font);g.drawString(score+"",20,40);Graphics2Dg2d=(Graphics2D)g;g2d.rotate(-bird.alpha,bird.x,bird.y);//旋轉(zhuǎn)坐標(biāo)系g.drawImage(bird.image,bird.x-b