《游戏学习》java代码实现《愤怒的小鸟》实战源码

Posted 洛阳泰山

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了《游戏学习》java代码实现《愤怒的小鸟》实战源码相关的知识,希望对你有一定的参考价值。

项目代码结构目录

部分代码展示



import javax.swing.ImageIcon;
import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.World;

/**
 *
 * @author tarzan
 */
public class AngryBirdsModel extends AngryBirdsCharacter{
    
   public ImageIcon birds1=new ImageIcon("src/AngryBirdsImagePack/birds.png");
   public ImageIcon birds2=new ImageIcon();
   public ImageIcon birds3=new ImageIcon();
   
  public  AngryBirdsModel() {
     super();
         }
      
  
   public Body createBirds(World mom,int birdtype,Vec2 pos) {
      this.getCharacterdef().position.set(pos);
      this.getCharacterdef().linearDamping=0.01f;
      this.getCharacterfixdef().filter.groupIndex=-1;
      this.charactershape=new CircleShape();
      Body bird=mom.createBody(characterdef);
      switch(birdtype) {
          case 1:
              this.charactershape.m_radius=0.5f;
              this.getCharacterfixdef().shape= this.charactershape;
              this.getCharacterinfo().setName("Lil Bird");
              this.getCharacterinfo().setHafheight(0.5f);
              this.getCharacterinfo().setHafwidth(0.5f);
              this.getCharacterinfo().setAppearance(birds1.getImage());
              bird.m_userData=this.getCharacterinfo();
              bird.createFixture(characterfixdef);
              break;
          case 2:
              this.charactershape.m_radius=0.7f;
              this.getCharacterfixdef().shape= this.charactershape;
              this.getCharacterinfo().setName("Strong Bird");
              this.getCharacterinfo().setHafheight(0.7f);
              this.getCharacterinfo().setHafwidth(0.7f);
              this.getCharacterinfo().setAppearance(birds2.getImage());
              bird.m_userData=this.getCharacterinfo();
              bird.createFixture(characterfixdef);
              break;   
          case 3:
              this.charactershape.m_radius=1f;
              this.getCharacterfixdef().shape= this.charactershape;
              this.getCharacterinfo().setName("Angry Bird");
              this.getCharacterinfo().setHafheight(1f);
              this.getCharacterinfo().setHafwidth(1f);
              this.getCharacterinfo().setAppearance(birds3.getImage());
              bird.m_userData=this.getCharacterinfo();
              bird.createFixture(characterfixdef);
              break;
      }
      return bird;
  }
  

}
   

 启动类  AngryBirdsMain


import AngryBirdsLevel.BirdsLevel;

/**
 *
 * @author tarzan
 */
public class AngryBirdsMain {

    /**
     * Entrance of This Game.
     */
    public static void main(String[] args){

            
            BirdsLevel ts=new BirdsLevel();
          
            AngryBirdsMenu menu=new AngryBirdsMenu();
            AngryBirdsPanel game=new AngryBirdsPanel();

            AngryBirdsViewFrame mainframe=new AngryBirdsViewFrame(menu,game);
            //MusicController music=new MusicController();
            AngryBirdsController tc=new AngryBirdsController(ts,game);
            AngryBirdsMenuController mc=new AngryBirdsMenuController(menu);
            AngryBirdsPanelController pc=new AngryBirdsPanelController(mainframe.getLayoutpanel(),mc,tc);        

            
            ts.getWorld().setContactListener(tc);
            //music.start();

            Thread switcher=new Thread(pc);
            
            switcher.start();
            mainframe.setVisible(true);
        
    }
}

游戏截图

项目源码下载地址

https://download.csdn.net/download/weixin_40986713/21477148

以上是关于《游戏学习》java代码实现《愤怒的小鸟》实战源码的主要内容,如果未能解决你的问题,请参考以下文章

Pygame实战:过气游戏?小鸟不angry?惊现Python版愤怒的小鸟!

爷青回|用Python重构愤怒的小鸟小游戏来啦~ 免费下载源码

U3D小游戏愤怒的小鸟场景搭建以及小鸟功能实现

U3D小游戏愤怒的小鸟场景搭建以及小鸟功能实现

U3D小游戏愤怒的小鸟场景搭建以及小鸟功能实现

小游戏Unity游戏愤怒的足球(小鸟)