Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the classic game of Boxing King mistakenly entering Adventure Island by Java

Shulou Source: shulou.com Published: 2022-06-01 15:10:55 09月20日 Update

This article mainly shows you "Java how to achieve the classic Boxing King mistakenly adventurous island game", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to achieve the classic Boxing King mistakenly adventurous island game" this article.

Main design

1. Game panel generation display

2. Background selection of adventure island material map

3. Design heroes, including health, spells, action changes and special effects of heroes.

4. Design monsters, including monster health, attack power, position, step size, etc.

5. Keyboard monitoring:

Press the space: jump

Press An or left Arrow: to the right

Press S or Down Arrow + K: release the skill

Press J key: attack

Function screenshot

The game begins.

The king of boxing attacked

Boxing king unleashes skills

The code realizes the game main interface public class MainFrame extends JFrame {/ * / private static final long serialVersionUID = 7492509868810783126L; private static KeyWork key; / / A double buffer method to solve the flicker problem Image ImageBuffer=null; Graphics img; / * * to realize animation

* Image frame index

* sri:stand_right_index: the character stands still (right)

* sli:stand_left_index: the character stands still (left)

* jri:jump_right_index: character jump action (right)

* jli:jump_left_index: character jump action (left)

* wli:walk_left_index: characters walk (left)

* wri:walk_right_index: characters walk (right)

* ari:attack_right_index: character attack (right)

* ali:attach_left_index: character attack (left)

* s0i:skill0_index: 1st Skill attacks * / public static int sri=0,sli=0,jri=0,jli=0,wli=0,wri=0, ari=0,ali=0,s0i=0; / * * scenario * / int bgindex=0; public static List monsters=new ArrayList (); public MainFrame () {this.setTitle ("Boxing King misbreak Adventure Island") This.setBounds ((int) (GameValue.WIDTH-GameValue.Width) / 2, (int) (GameValue.HEIGHT-GameValue.Hight) / 2, this.setLayout (null); this.setResizable (false); key=new KeyWork (); this.addKeyListener (key) This.addWindowListener (new WindowAdapter () {@ Override public void windowClosing (WindowEvent e) {/ / TODO Auto-generated method stub isclose () }}); initMonster (); new ActionThread () } private void initMonster () {new Thread (new Runnable () {@ Override public void run () {/ / TODO Auto-generated method stub) While (true) {try {Monster m=new Monster () Monsters.add (m); / * * interval between generating monsters * / Thread.sleep (10000) } catch (InterruptedException e) {/ / TODO Auto-generated catch block e.printStackTrace () }). Start ();} public void isclose () {System.exit (0); int choose=JOptionPane.showConfirmDialog (this, "exit?" , "JOptionPane.YES_NO_OPTION"); if (choose==0) {System.exit (0);} else setDefaultCloseOperation (JFrame.DO_NOTHING_ON_CLOSE) } public void display (boolean show) {this.setVisible (show);} @ Override public void paint (Graphics g) {if (ImageBuffer==null) {ImageBuffer=createImage (this.getWidth (), this.getHeight ());} img=ImageBuffer.getGraphics () Super.paint (img); img.drawImage (GameValue.bgimgs [bgindex], 0ZEOJEO GameValue.Width GameValue.HightMagi this); / * * build protagonist information * / img.setColor (Color.WHITE); img.setFont (GameValue.display_font) Int x0prime30dyy0precinct yhong8; img.drawString ("health value", x0memeny0); img.drawString ("mana value", x0memyh); / * * are health values and mana values * / img.drawRect (x0spell 3 cycles 8-1, y 0-15-1, 150 cycles 1, 15 cycles 1) Img.drawRect (x0triple 8-1, y0+yh-15-1, 150mm 1,15001); img.setColor (Color.GREEN); int hp_width= (int) (double) (Hero.HP_NOW) / Hero.HP_ALL) * 150); img.fillRect (x0triple 8, y0-15, hp_width, 15) Img.setColor (Color.BLUE); int mp_width= (int) (double) (Hero.MP_NOW) / Hero.MP_ALL) * 150); img.fillRect (x03x8, y0+yh-15, mp_width, 15); img.setColor (Color.WHITE) Img.drawString (Hero.HP_NOW+ "/" + Hero.HP_ALL,x0*3+8-11645, y0); img.drawString (Hero.MP_NOW+ "/" + Hero.MP_ALL,x0*3+8-11645, y0+yh); for (int item0) I0) {if (! Hero.ishurted) {/ * non-jump status * / if (! Hero.jump) { / * priority attack > walk > skill > stand*/ if (Hero.attack) { For (int iTunes 0 I

Tags: Character picture material attack picture material character boxing king skill adventure island adventure one skill spell state life hero classic content action animation monster Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Linux NVidia MariaDB