简单游戏设计(改进与新增)(JAVA)

--更换了场景资源,人物资源,敌人资源--

--相比基础人物功能,新增人物攻击大招:高高跃起,范围秒杀。--

主要改变的是工具类和人物类

工具类(部分):

public static final String ImagePath = System.getProperty("user.dir")+"/ykm/";

public static List<BufferedImage> LeftPersonDZImgs=new ArrayList<>();
public static List<BufferedImage> rightPersonDZImgs=new ArrayList<>();
try{
            //图片获取
            B01= ImageIO.read(new File(ImagePath+"BGD/B01.png"));
            B02= ImageIO.read(new File(ImagePath+"BGD/B02.png"));
            B03= ImageIO.read(new File(ImagePath+"BGD/B03.png"));
            B04= ImageIO.read(new File(ImagePath+"BGD/B04.png"));
            //遍历人物图库
            for (int i=1;i<=12;i++){
//                DecimalFormat decimalFormat=new DecimalFormat("00");
//                String num=decimalFormat.format(i);
                LeftPersonImgs.add(ImageIO.read(new File(ImagePath+"111_JS_/left/"+i+".png")));
                rightPersonImgs.add(ImageIO.read(new File(ImagePath+"111_JS_/right/"+i+".png")));
                LeftPersonDZImgs.add(ImageIO.read(new File(ImagePath+"111_JS_/left/DZ/"+i+".png")));
                rightPersonDZImgs.add(ImageIO.read(new File(ImagePath+"111_JS_/right/DZ/"+i+".png")));
            }
            //加载敌人图片
            for(int i = 1;i <= 13; i++){
                File rightfile = new File(ImagePath+"DR/right/"+i+".png");
                File leftfile = new File(ImagePath+"DR/left/"+i+".png");

                LeftEnemyImgs.add(ImageIO.read(leftfile));
                rightEnemyImgs.add(ImageIO.read(rightfile));
            }

还有人物类(部分):

    protected List<BufferedImage> leftDZImages;//左大
    protected List<BufferedImage> rightDZImages;//右大
 protected void setImageList() {
        ......
        LDeadImages=StaticValue.LeftEnemyImgs.subList(12,12);
        rDeadImages=StaticValue.rightEnemyImgs.subList(12,12);
    }
//人物类run方法部分  
case 5:         //大招
                        if (this.moving>=11){     //循环下标9-11的图片
                            this.moving=0;      //超出范围就重置
                        }
                        //设置显示当前下标图片
                        this.showImage=rightDZImages.get((int)moving);
                        moving += 0.5;
                        if (this.moving >= 11) {
                            this.status=this.status>0?1:-1;
                        }
                        break;

 case -5:            //大招
                        if (this.moving>=11){     //循环下标9-11的图片
                            this.moving=0;      //超出范围就重置
                        }
                        //设置显示当前下标图片
                        this.showImage=leftDZImages.get((int)moving);
                        moving += 0.5;
                        if (this.moving >= 11) {
                            this.status=this.status>0?1:-1;
                        }
                        break;

 //DZ
                if(this.background != null){
                    List<Enemy> allEnemy = this.background.getAllEnemy();
                    for (int i=0;i<allEnemy.size();i++){
                        Enemy enemy = allEnemy.get(i);
                        if (this.status == 5 && (this.x+150) > (enemy.getX()) && (this.x+150)<(enemy.getX()+100)){
                            enemy.dead();
                        }
                        else if (this.status == -5 && (this.x+150)<(enemy.getX()+180)
                                && (this.x+150)>(enemy.getX()+100)) {
                            enemy.dead();
                        }
                    }
                }
    public void daozhao() {
        if (this.status!=3 && this.status!=-3){
            this.status=this.status>0?5:-5;

        }
            //设置大招状态;

    }

还要在窗体类(部分)补上按键控制:

public void keyPressed(KeyEvent e) {
        int KeyCode=e.getKeyCode();
        if (KeyCode == 68) {        //按D向右
            this.person.rightRun();
        }
        if (KeyCode == 65){         //按A向左
            this.person.LefttRun();
        }
        if (KeyCode == 87){         //按W向上
            this.person.jump();
        }
        if (KeyCode == 74){         //按K攻击
            this.person.attack();
        }
        if (KeyCode == 32){         //按空格放大
            this.person.daozhao();
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值