In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "Java how to achieve the upgraded version of the cuckoo clearance game". In the daily operation, I believe that many people have doubts about how to achieve the upgraded version of the cuckoo clearance game in Java. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to achieve the upgraded version of the cuckoo clearance game in Java". Next, please follow the editor to study!
Preface
"cuckoo clearance-upgrade version" is a java-based cuckoo clearance game, the left mouse button click to control the position of the bird through the gap between the pipes, need to do collision detection, monitoring keyboard events, background picture switching, obstacles pipeline generated on the y-axis need random position.
Main design
1. Design the game interface and implement it with swing
two。 Design background
3. Design moving wall
4. Design cuckoo
5. Design obstacles
6. Design background music and sound effects
7. Add user account registration and login function
8. Reference mysql database, manage user account passwords and store ranking information
The database "game" needs to be created in advance, and the character set is selected "utf8mb4".
Then execute the mysql table structure and initialize the data script
Modify the parameter values of DBUtils in the code
9. New game mall module
10. New ranking module
Function screenshot
User Registration:
Barrier.bottomHeight) {System.out.println ("hit left edge"); return true;} return false } / / if (bird_x > = barrier.location_x & & bird_x when passing through the pipe
< barrier.location_x + barrier.width){ boolean y1 = bird_y + birdRadius >512-barrier.bottomHeight; boolean Y2 = bird_y = barrier.location_x + barrier.width) {return false;} return false;} / / ifGameOver=false to execute boolean ifGetScore () {return bird_x + birdRadius > barrier.location_x } / / the drawing after the second time public void drawItems (Graphics g) {/ / Bird bird.draw (g); / / Lower obstacle g.drawImage (barrier.img, barrier.location_x, 512-barrier.bottomHeight,33,barrier.bottomHeight, null); / / Upper obstacle g.drawImage (barrier1.img,barrier.location_x, 0mine3m. TopHeight, null) / / ground g.drawImage (ground.getBufferedImage (), 0512-30, null); ground.checkGround (); barrier.checkBarrier ();} / update the position of each object (30 times per second) public void itemMove () {/ / calculate the speed of the bird speed_y + = Globe 0.033 / / the maximum downward speed of the bird is 220 if (speed_y > 220) {speed_y = 220;} / calculate the ordinate of the bird + = speed_y*0.033; bird.y=bird_y; / / calculate the Abscissa of the obstacle and the ground barrier.location_x-= speed_x Ground.setX (ground.getX ()-speed_x);} / / variable speed method, adjust speed public void shift (int score) {if (score < 1) {speed_x = 3;} else if (score < 100) {speed_x = 4;} else if (score < 200) {speed_x = 5 } else if (score < 300) {speed_x = 6;} else if (score < 400) {speed_x = 7;} else if (score < 500) {speed_x = 8;} else speed_x = 9 }} Thread class is used to repeat the drawing public class playingThread implements Runnable {Scene stage; private Image iBuffer; private Graphics gBuffer; List rfs; user_inf user; MainFrame mainframe; Graphics g; GameplayingFrame playingframe; public static boolean flag = true;// control scoreboard variable public int score = 0 / / score playingThread (Scene stage,Graphics ggamma GameplayingFrame playingframe, user_inf user,List rfs,MainFrame mainframe) {this.mainframe=mainframe; this.rfs=rfs; this.user=user; this.stage=stage; this.g=g; this.playingframe=playingframe } @ Override public void run () {while (! stage.ifGameOver ()) {stage.drawItems (g); / / painting stage.itemMove () / / object movement / / 33ms refresh once try {sleep (33);} catch (InterruptedException e) {e.printStackTrace () } if (stage.ifGetScore ()) {score++;} stage.shift (score); / / playingframe.update (g) / / clear the last painting result / / clear the previous painting result if (iBuffer = = null) {iBuffer = playingframe.createImage (playingframe.getSize (). Width,playingframe.getSize () .height); gBuffer = iBuffer.getGraphics () } playingframe.paint (gBuffer); g.drawImage (iBuffer,0,0,null); / / stage.drawItems (g); / / redraw} user.setCoin (user.getCoin () + score); new user_dao () .update (user) Playingframe.setVisible (false); rank_information rf=new rank_information (); rf.setScore (score); rf.setName (user.getUser_name ()); rfs.add (rf); new rank_dao (). Update_rank (rfs) New resultFrame (score,user,rfs,mainframe); System.out.println ("game over");}} at this point, the study on "how to achieve an upgraded version of the cuckoo game with Java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.