学习HTML5开发RPG游戏第五步>游戏界面设计<二>(结束)

3、战斗界面

战斗界面是经典的回合制战斗界面,其代码如下:

GFunction.loadBattlePanel=function(){//加载战斗界面
    GMain.BattlePanel.clearControls();
    var battlePanel=new JControls.Panel({x:0,y:0},GMain.Size);
    battlePanel.setBGImage(ResourceData.Images.battleBG1);
    battlePanel.loadData=function(){//加载角色到战斗界面
        this.clearControls();
        if(GMain.BattlesGameRole[1].length==1){
            GMain.BattlesGameRole[1][0].setRelativePosition({x:150,y:70});
        }else if(GMain.BattlesGameRole[1].length==2){
            GMain.BattlesGameRole[1][0].setRelativePosition({x:80,y:120});
            GMain.BattlesGameRole[1][1].setRelativePosition({x:280,y:20});
        }else if(GMain.BattlesGameRole[1].length==3){
            GMain.BattlesGameRole[1][0].setRelativePosition({x:80,y:230});
            GMain.BattlesGameRole[1][1].setRelativePosition({x:280,y:130});
            GMain.BattlesGameRole[1][2].setRelativePosition({x:480,y:30});
        }else if(GMain.BattlesGameRole[1].length==4){
            GMain.BattlesGameRole[1][0].setRelativePosition({x:40,y:120});
            GMain.BattlesGameRole[1][1].setRelativePosition({x:240,y:20});
            GMain.BattlesGameRole[1][2].setRelativePosition({x:180,y:180});
            GMain.BattlesGameRole[1][3].setRelativePosition({x:380,y:80});
        }else if(GMain.BattlesGameRole[1].length==5){
            GMain.BattlesGameRole[1][0].setRelativePosition({x:80,y:100});
            GMain.BattlesGameRole[1][1].setRelativePosition({x:280,y:0});
            GMain.BattlesGameRole[1][2].setRelativePosition({x:80,y:230});
            GMain.BattlesGameRole[1][3].setRelativePosition({x:280,y:130});
            GMain.BattlesGameRole[1][4].setRelativePosition({x:480,y:30});
        }
        this.addControlInLast(GMain.BattlesGameRole[1]);
        var size1={x:400,y:380};
        if(GMain.BattlesGameRole[0].length==1){
            GMain.BattlesGameRole[0][0].setRelativePosition({x:size1.x+180,y:size1.y-120});
        }else if(GMain.BattlesGameRole[0].length==2){
            GMain.BattlesGameRole[0][0].setRelativePosition({x:size1.x+120,y:size1.y-80});
            GMain.BattlesGameRole[0][1].setRelativePosition({x:size1.x+240,y:size1.y-160});
        }else if(GMain.BattlesGameRole[0].length==3){
            GMain.BattlesGameRole[0][0].setRelativePosition({x:size1.x+60,y:size1.y-40});
            GMain.BattlesGameRole[0][1].setRelativePosition({x:size1.x+180,y:size1.y-120});
            GMain.BattlesGameRole[0][2].setRelativePosition({x:size1.x+300,y:size1.y-200});
        }else if(GMain.BattlesGameRole[0].length==4){
            GMain.BattlesGameRole[0][0].setRelativePosition({x:size1.x,y:size1.y});
            GMain.BattlesGameRole[0][1].setRelativePosition({x:size1.x+80,y:size1.y-50});
            GMain.BattlesGameRole[0][2].setRelativePosition({x:size1.x+160,y:size1.y-100});
            GMain.BattlesGameRole[0][3].setRelativePosition({x:size1.x+240,y:size1.y-150});
        }
        this.addControlInLast(GMain.BattlesGameRole[0]);
    };

    //加载战斗控制面板
    GMain.BattleControlPanel=new JControls.Panel({x:GMain.Size.width-80, y:120},{width:80,height:200});
    GMain.BattleControlPanel.loadData=function(){
        this.clearControls();
        var btnAttack=new JControls.Button({x:0,y:0},{width:80,height:40});
        btnAttack.buttonLabel.setText("攻击").setFontType("bold").setFontSize(22).setTextPos({x:15,y:5});
        btnAttack.BGColor=JColor.white;
        btnAttack.onClick=function(){
            GMain.FromAttackSelect=true;
            JMain.JForm.canvas.style.cursor="pointer"
            GMain.BattlesGameRole[0][GMain.SelectLeaderNum].usedSkillName="attack1";
        }
        var btnSkill=new JControls.Button({x:0,y:40},{width:80,height:40});
        btnSkill.buttonLabel.setText("技能").setFontType("bold").setFontSize(22).setTextPos({x:15,y:5});
        btnSkill.BGColor=JColor.white;
        btnSkill.onClick=function(){
            JMain.JForm.canvas.style.cursor="default"
            GMain.SkillSelectPanel.loadSkill();
        }
        var btnDefense=new JControls.Button({x:0,y:80},{width:80,height:40});
        btnDefense.buttonLabel.setText("防御").setFontType("bold").setFontSize(22).setTextPos({x:15,y:5});
        btnDefense.BGColor=JColor.white;
        btnDefense.onClick=function(){
            JMain.JForm.canvas.style.cursor="default"
            GMain.BattlesGameRole[0][GMain.SelectLeaderNum].bodyState.defend=true;
            GMain.BattlesGameRole[0][GMain.SelectLeaderNum].clearControls();
            GFunction.nextAttackSelect();
        }
        var btnDrug=new JControls.Button({x:0,y:120},{width:80,height:40});
        btnDrug.buttonLabel.setText("物品").setFontType("bold").setFontSize(22).setTextPos({x:15,y:5});
        btnDrug.BGColor=JColor.white;
        btnDrug.onClick=function(){
            JMain.JForm.canvas.style.cursor="default"
            GMain.DrugUsePanel.loadDrug();
        }
        GMain.BattleBtnRunAway=new JControls.Button({x:0,y:160},{width:80,height:40});
        GMain.BattleBtnRunAway.buttonLabel.setText("逃跑").setFontSize(22).setFontType("bold").setTextPos({x:15,y:5});
        GMain.BattleBtnRunAway.BGColor=JColor.white;
        GMain.BattleBtnRunAway.onClick=function(){
            JMain.JForm.canvas.style.cursor="default"
            if(JFunction.Random(1,100)<=95){
                GFunction.showMapPanel();
            }else{
                new JControls.MessageBox({width:200,height:0},["逃跑失败!"]);
                this.enabled=false;
            }
        }
        this.addControlInLast([btnAttack,btnSkill,btnDefense,btnDrug, GMain.BattleBtnRunAway]);
    };
    GMain.SkillSelectPanel=new JControls.Panel({x:200,y:80},{width:400,height:240});
    GMain.SkillSelectPanel.BGColor=JColor.gray;
    GMain.SkillSelectPanel.visible=false;
    GMain.SkillSelectPanel.loadSkill=function(){//加载技能使用面板
        this.clearControls();
        this.visible=true;
        this.isShowTitle=false;
        this.showTitle("技能");
        var skillName=GMain.BattlesGameRole[0][GMain.SelectLeaderNum].gameRoleData.skills.split(",");
        var skillsButtons=[];
        for(var i=0;i<skillName.length;i++){
            if(GMain.BattlesGameRole[0][GMain.SelectLeaderNum].level>=ResourceData.Skill[skillName[i]].fromGameRole.level){
                var l=skillsButtons.length;
                var wNum= 8,cWidth=200,cHeight=40;
                skillsButtons[l]=new JControls.Button({x:(i%wNum)*cWidth,y:parseInt(i/2)*cHeight+40},{width:cWidth,height:cHeight});
                skillsButtons[l].buttonLabel.setText(ResourceData.Skill[skillName[i]].showName).setFontType("bold").setFontSize(22).setTextPos({x:15,y:5});
                skillsButtons[l].skillName=skillName[i];
                skillsButtons[l].onClick=function(){
                    GMain.BattlesGameRole[0][GMain.SelectLeaderNum].usedSkillName=this.skillName;
                    GMain.SkillSelectPanel.visible=false;
                    if(ResourceData.Skill[this.skillName].toGameRole.num==1){
                        GMain.BattleControlPanel.visible=false;
                        JMain.JForm.canvas.style.cursor="pointer"
                    }else{
                        GFunction.nextAttackSelect();
                    }
                }
            }
        }
        this.addControlInLast(skillsButtons);
        this.closeButton.visible=true;
        this.onCloseButtonClick=function(){
            GMain.BattleControlPanel.visible=true;
        };
    }
    GMain.DrugUsePanel=new JControls.Panel({x:200,y:80},{width:400,height:240});
    GMain.DrugUsePanel.BGColor=JColor.gray;
    GMain.DrugUsePanel.visible=false;
    GMain.DrugUsePanel.loadDrug=function(){//加载物品使用面板
        this.clearControls();
        this.isShowTitle=false;
        this.showTitle("物品");
        this.visible=true;
        GMain.SelectedGoods=null;
        //var level=GMain.BattlesGameRole[0][GMain.SelectLeaderNum].level;
        var drugs=[];
        for(var i=0;i<GMain.Goods.length;i++){
            var l=drugs.length;
            var wNum= 8,cWidth=50,cHeight=50;
            if(GMain.Goods[i].goodsData.goodsType=="drug"){
                drugs[l]=GMain.Goods[i].setRelativePosition({x:(i%wNum)*cWidth,y:parseInt(i/wNum)*cHeight+40}).setSize({width:cWidth,height:cHeight});
                drugs[l].onClick=function(){
                    GMain.BattlesGameRole[0][GMain.SelectLeaderNum].usedSkillName="useDrug";
                    GMain.BattlesGameRole[0][GMain.SelectLeaderNum].usedGoods=this;
                    GMain.DrugUsePanel.visible=false;
                    if(ResourceData.Goods[this.goodsData.showName].toGameRole.num==1){
                        GMain.BattleControlPanel.visible=false;
                        JMain.JForm.canvas.style.cursor="pointer";
                    }else{
                        GFunction.nextAttackSelect();
                    }
                }
            }
        }
        this.addControlInLast(drugs);
        this.onCloseButtonClick=function(){
            GMain.BattleControlPanel.visible=true;
        }
    }
    GMain.BattlePanel.addControlInLast([battlePanel, GMain.BattleControlPanel,GMain.SkillSelectPanel,GMain.DrugUsePanel]);
};

4、数据界面
数据界面,用于查看和使用物品、查看主角数据等。

GFunction.loadDataPanel=function(){//加载数据界面
    GMain.DataPanel.clearControls();
    GMain.DataPanel.loadData=function(){
        for(var i=0;i<GMain.DataPanel.controls.length;i++){
            GMain.DataPanel.controls[i].loadData&&GMain.DataPanel.controls[i].loadData();
        }
    };
    var w1=150;
    var w2=450;
    var w3=200;
    var GameRoleHeadPanel=new JControls.Panel({x:0,y:0},{width:w1,height:120});   
    GameRoleHeadPanel.loadData=function(){//加载主角头像
        this.clearControls();
        var GameRoleHeadPic=new JControls.PictureBox({x:2,y:2},{width:w1-4,height:116});
        GameRoleHeadPic.setPicture(ResourceData.Images[GMain.BattlesGameRole[0][GMain.SelectLeaderNum].getHeadImageName()]);
        this.addControlInLast([GameRoleHeadPic]);
    }

    var LeadersPanel=new JControls.Panel({x:0,y:120},{width:w1,height:96});///
    LeadersPanel.loadData=function(){//加载主角,点击可查看其数据
        this.clearControls();
        var ls=[];
        for(var i=0;i<GMain.BattlesGameRole[0].length;i++){
            ls[i]=new JControls.Label({x:0,y:i*24},GMain.BattlesGameRole[0][i].getShowName()+"("+GMain.BattlesGameRole[0][i].getJobsName()+")")
                .setFontType("Bold").setSize({width:w1,height:24}).setTextPos({x:5,y:2});
            ls[i].num=i;
            if(i== GMain.SelectLeaderNum)ls[i].isSelect=true;
            else ls[i].isSelect=false;
            ls[i].onClick=function(){
                GMain.SelectLeaderNum=this.num;
                GMain.DataPanel.loadData();
                return true;
            }
        }
        this.addControlInLast(ls);
    }

    var EquipmentPanel=new JControls.Panel({x:w1,y:0},{width:w2,height:300});///
    EquipmentPanel.loadData=function(){//加载当前选中主角身上装备
        this.clearControls();
        var bodySlotsSize={width:80,height:80};
        var jg={x:55,y:15};
        for(var bodySlots in GMain.BattlesGameRole[0][GMain.SelectLeaderNum].bodySlots){
            if(GMain.BattlesGameRole[0][GMain.SelectLeaderNum].bodySlots[bodySlots]){
                var p={x:0,y:0};
                switch (bodySlots){
                    case "handR":
                        p={x:jg.x,y:bodySlotsSize.height+jg.y*2};
                        break;
                    case "fingerR":
                        p={x:jg.x,y:bodySlotsSize.height*2+jg.y*3};
                        break;
                    case "head":
                        p={x:bodySlotsSize.width+jg.x*2,y:jg.y};
                        break;
                    case "body":
                        p={x:bodySlotsSize.width+jg.x*2,y:bodySlotsSize.height+jg.y*2};
                        break;
                    case "foot":
                        p={x:bodySlotsSize.width+jg.x*2,y:bodySlotsSize.height*2+jg.y*3};
                        break;
                    case "neck":
                        p={x:bodySlotsSize.width*2+jg.x*3,y:jg.y};
                        break;
                    case "handL":
                        p={x:bodySlotsSize.width*2+jg.x*3,y:bodySlotsSize.height+jg.y*2};
                        break;
                    case "fingerL":
                        p={x:bodySlotsSize.width*2+jg.x*3,y:bodySlotsSize.height*2+jg.y*3};
                        break;
                }
                GMain.BattlesGameRole[0][GMain.SelectLeaderNum].bodySlots[bodySlots].setRelativePosition(p).setSize(bodySlotsSize);
                this.addControlInLast([GMain.BattlesGameRole[0][GMain.SelectLeaderNum].bodySlots[bodySlots]]);
            }
        }
    };

    var GoodsPanel=new JControls.Panel({x:w1,y:300},{width:w2,height:180});//
    GoodsPanel.loadData=function(){//加载物品栏
        this.clearControls();
        for(var i=0;i<GMain.Goods.length;i++){
            if(!GMain.Goods[i].isUsed){
                this.addControlInLast([GMain.Goods[i]]);
            }
        }
        var wNum=10,cWidth=45,cHeight=45;
        for(var i=0;i<this.controls.length;i++){
            this.controls[i].setRelativePosition({x:(i%wNum)*cWidth,y:parseInt(i/wNum)*cHeight}).setSize({width:cWidth,height:cHeight});
        }
        this.goldLabel=new JControls.Label({x:50,y:155}).setFontType("Bold");
        this.goldLabel.setText("金币:"+GMain.GoldNum);
        this.addControlInLast([this.goldLabel]);
    };

    var GoodsStatsPanel=new JControls.Panel({x:w1+w2,y:0},{width:w3,height:450});
    GoodsStatsPanel.loadData=function(){//加载选中物品的属性数据
        this.clearControls();
        if(GMain.SelectedGoods){
            var goodsName=GMain.SelectedGoods.goodsData.showName;
            var btnZBSY=new JControls.Label({x:20,y:3}).setFontType("Bold")
                .setFontColor(JColor.blue).setSize({width:80,height:24}).setBGColor(JColor.red).setTextPos({x:15,y:4});
            if(GMain.SelectedGoods.isUsed){
                btnZBSY.setText("移除装备");
            }else{
                btnZBSY.setText("使用道具");
            }
            btnZBSY.onClick=function(){
                if(GMain.SelectedGoods.isUsed)GMain.BattlesGameRole[0][GMain.SelectLeaderNum].deleteCombatGear(GMain.SelectedGoods);
                else GMain.BattlesGameRole[0][GMain.SelectLeaderNum].useGoods(GMain.SelectedGoods);
                GMain.DataPanel.loadData();
                return true;
            }
            this.addControlInLast([btnZBSY]);
            var i=0;
            var h=18, ls=5,th=30;
            this.addControlInLast([new JControls.Label({x:ls,y:h*(i++)+th},goodsName).setFontType("Bold").setFontColor(JColor.gray)]);
            this.addControlInLast([new JControls.Label({x:ls,y:h*(i++)+th},
                "级别:"+ResourceData.Evaluation[parseInt(GMain.SelectedGoods.goodsData.goodsLevel)])]);
            this.addControlInLast([new JControls.Label({x:ls,y:h*(i++)+th},
                "类型:"+ResourceData.GoodsType[GMain.SelectedGoods.goodsData.goodsType])]);
            for(var attribute in GMain.SelectedGoods.goodsData.attributes){
                this.addControlInLast([new JControls.Label({x:ls,y:h*(i++)+th},ResourceData.AttributesName[attribute]+":"+ GMain.SelectedGoods.goodsData.attributes[attribute])]);
            }

        }
    };
    var ButtonPanel=new JControls.Panel({x:w1+w2,y:450},{width:w3,height:30});//
    ButtonPanel.loadData=function(){//继续游戏按钮
        this.clearControls();
        var btnGoBack=new JControls.Button({x:20,y:0},{width:110,height:30}).setBGColor(JColor.gray).setText("继续游戏");
        btnGoBack.onClick=function(){
            GFunction.showMapPanel();
            return true;
        }
        this.addControlInLast([btnGoBack]);
    }
    var BaseStatsPanel=new JControls.Panel({x:0,y:216},{width:w1,height:336});/
    BaseStatsPanel.loadData=function(){//加载选中主角的各项数据
        this.clearControls();
        var bh=20;
        var i=0
        var SelectLeader=GMain.BattlesGameRole[0][GMain.SelectLeaderNum];
        var baseStatsItem=[
            new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.Level+":"+SelectLeader.level)
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.EXP+":"+SelectLeader.EXP+"/"+SelectLeader.getLevelExp())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.HP+":"+SelectLeader.HP+"/"+SelectLeader.getMaxHP())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.MP+":"+SelectLeader.MP+"/"+SelectLeader.getMaxMP())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.STR+":"+SelectLeader.getSTR())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.VIT+":"+SelectLeader.getVIT())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.DEX+":"+SelectLeader.getDEX())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.INT+":"+SelectLeader.getINT())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.ATK+":"+SelectLeader.getATK())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.DEF+":"+SelectLeader.getDEF())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.MATK+":"+SelectLeader.getMATK())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.MDEF+":"+SelectLeader.getMDEF())
            ,new JControls.Label({x:2,y:2+bh*i++},ResourceData.AttributesName.SPD+":"+SelectLeader.getSpeed())
        ];
        for(var i=0;i<baseStatsItem.length;i++)baseStatsItem[i].setFontType("Bold")
        this.addControlInLast(baseStatsItem);
    };
    GMain.DataPanel.addControlInLast([GameRoleHeadPanel,LeadersPanel,BaseStatsPanel,EquipmentPanel,GoodsPanel,GoodsStatsPanel,ButtonPanel]);
};


除了上面的这些界面外,还有存档界面,商店界面等。

至此,学习HTML5开发RPG游戏就结束了,这些博文只是让大家有个大概了解,具体请看源码。

演示地址源码地址

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值