libgdx新手引导

来源:互联网 发布:物流网络的若干特性 编辑:程序博客网 时间:2024/05/29 16:37
package com.jicent.flyisland.entity;import java.util.LinkedList;import com.badlogic.gdx.Gdx;import com.badlogic.gdx.InputAdapter;import com.badlogic.gdx.graphics.Color;import com.badlogic.gdx.graphics.Texture;import com.badlogic.gdx.math.Rectangle;import com.badlogic.gdx.scenes.scene2d.Group;import com.badlogic.gdx.scenes.scene2d.Touchable;import com.badlogic.gdx.scenes.scene2d.ui.Image;import com.badlogic.gdx.utils.Align;import com.badlogic.gdx.utils.Timer;import com.badlogic.gdx.utils.Timer.Task;import com.jicent.flyisland.data.Const;import com.jicent.flyisland.data.Data;import com.jicent.flyisland.entity.dialog.PackInfoDialog;import com.jicent.flyisland.entity.javabean.GameProperty;import com.jicent.flyisland.entity.uitype.UI_Backpack;import com.jicent.flyisland.entity.uitype.UI_LevelFront;import com.jicent.flyisland.entity.uitype.UI_Main;import com.jicent.flyisland.entity.uitype.UI_Shop;import com.jicent.flyisland.extend.ImageEx;import com.jicent.flyisland.extend.LabelEx;import com.jicent.flyisland.extend.SkeletonActor;import com.jicent.flyisland.screen.BigMapScreen;import com.jicent.flyisland.screen.FatherScreen;import com.jicent.flyisland.screen.FatherScreen.GameState;import com.jicent.flyisland.screen.GameScreen;import com.jicent.flyisland.screen.MainScreen;import com.jicent.flyisland.screen.ResLoadingScreen;import com.jicent.flyisland.utils.DataDealUtil;import com.jicent.flyisland.utils.DataDealUtil.DataKind;import com.jicent.flyisland.utils.GdxUtil;import com.jicent.flyisland.utils.PixmapFactroy;import com.jicent.flyisland.utils.SPUtil;import com.jicent.flyisland.utils.StringUtil;public class Guide extends InputAdapter{public GuideType type;Group guideGroup;LinkedList<SingleGuideData> guideList=new LinkedList<SingleGuideData>();public enum GuideType{MAIN,GAME,UP}public void start(GuideType type){if(!Const.GUIDEENABLED)return;if(this.type!=null)return;//教程完成不在有if(type==GuideType.MAIN&&Data.isMainGuideOk)return;if(type==GuideType.GAME&&Data.isGameGuideOk)return;if(type==GuideType.UP&&Data.isUpgradeGuideOk)return;this.type=type;switch (type) {case MAIN://教一下背包强制进入游戏guideList.add(new SingleGuideData(new Rectangle(865,361, 80,80),"点击这里:购买和更换人物坐骑",new ShowShopRunnable(),0.2f,600,305));guideList.add(new SingleGuideData(new Rectangle(Data.roleType==0?171:330,88, 120,54),"点击选择人物专属宠物",new BackMainRunnable(),0.2f,200,160));guideList.add(new SingleGuideData(new Rectangle(866,276, 76,76),"点击这里进入背包界面浏览背包物品",new ShowBackPackRunnable(),0.2f,615,215));guideList.add(new SingleGuideData(new Rectangle(212,296, 80,80),"点击一个道具图标",new ShowPropDialogRunnable(),0.2f,175,130));guideList.add(new SingleGuideData(new Rectangle(487,203, 93,47),"点击是,加入快捷栏。之后就可以在游戏中使用了",new PropDialogOKRunnable(),0.2f,490,20));guideList.add(new SingleGuideData(new Rectangle(16,462, 76,76),"返回到主页面",new BackMainRunnable(),0.2f,15,285));guideList.add(new SingleGuideData(new Rectangle(516,10, 208,93),"点击这里开始游戏吧",new LevelBtnRunnable(),1.6f,475,135));guideList.add(new SingleGuideData(new Rectangle(199,145, 66,66),"当前模式为闯关模式,点击关卡图标",new IntoLev1Runnable(),0.2f,300,125));guideList.add(new SingleGuideData(new Rectangle(412,108, 136,55),"此页面显示关卡信息,点击开始游戏,游戏将正式开始",new StartLev1Runnable(),0.2f,565,55));break;case GAME://解释游戏右下角按钮guideList.add(new SingleGuideData(new Rectangle(759,4, 106,155),"点击此区域按钮使用背包添加的道具",new EmptyRunnable(),0.2f,515,110));guideList.add(new SingleGuideData(new Rectangle(853,9, 100,181),"此区域上方为宠物技能按钮,下方为人物技能按钮",new EmptyRunnable(),0.2f,605,110));guideList.add(new SingleGuideData(new Rectangle(759,4, 77,77),"受伤了?尝试使用血瓶道具来回血吧。",new UsePropRunnable(),0.2f,605,110));break;case UP://失败时激活的升级教程guideList.add(new SingleGuideData(new Rectangle(404,51, 151,60),"失败了别灰心,点击这里提升等级才是王道",new MainScreenRunnable(),0.2f,585,20));guideList.add(new SingleGuideData(new Rectangle(375,467, 407,57),"你的金币钻石数量显示在这里,现在免费赠送你2000金币",new Get2000CoinRunnable(),0.2f,515,300));guideList.add(new SingleGuideData(new Rectangle(282,131, 124,52),"点击这里尝试升级人物,人物属性会随着人物等级提高",new RoleUpBtnRunnable(),0.2f,425,90));guideList.add(new SingleGuideData(new Rectangle(213,386,110,41),"好了,让我们看看我们可爱的宠物,点击宠物选项卡",new PetCarBtnRunnable(),0.2f,315,240));guideList.add(new SingleGuideData(new Rectangle(282,131, 124,52),"点击这里提升宠物的等级,宠物的攻击防御等属性会随之提高。过不了关的时候记得来升级哦。",new PetUpBtnRunnable(),0.2f,425,90));break;default:break;}show(guideList.getFirst());}private void show(SingleGuideData singleGuideData){FatherScreen screen=GdxUtil.getFatherScreen();if(screen instanceof GameScreen){screen.setGameState(GameState.pause);}guideGroup=new Group();addGrayImg(guideGroup,singleGuideData.focus.x,singleGuideData.focus.y,singleGuideData.focus.width,singleGuideData.focus.height);Group txtGroup=new Group();txtGroup.setPosition(singleGuideData.txtGroupX,singleGuideData.txtGroupY);ImageEx img=new ImageEx(Const.IMG_SCR+"backpackInfoBg.png");txtGroup.addActor(img);//添加字LabelEx labelEx=new LabelEx(StringUtil.getAlignTxt(singleGuideData.txt, 10), Color.WHITE, singleGuideData.txt);labelEx.setSca(0.6f);labelEx.setBounds(0, 0, img.getWidth(), img.getHeight());labelEx.setAlign(Align.center);txtGroup.addActor(labelEx);guideGroup.addActor(txtGroup);//添加手指在焦点中心SkeletonActor sk=new SkeletonActor("effectSke/finger.atlas", "click",true);sk.setScale(0.8f);sk.setTouchable(Touchable.disabled);sk.setPosition(singleGuideData.focus.x+singleGuideData.focus.width/2,singleGuideData.focus.y+singleGuideData.focus.height/2);guideGroup.addActor(sk);screen.guideStage.addActor(guideGroup);//new LayoutDebug(guideGroup, txtGroup);}@Overridepublic boolean touchDown(int screenX, int screenY, int pointer, int button) {int touchX=screenX*960/Gdx.graphics.getWidth();int touchY=540-screenY*540/Gdx.graphics.getHeight();//没有触碰到焦点区域if(!guideList.getFirst().focus.contains(touchX, touchY))return false;FatherScreen screen=GdxUtil.getFatherScreen();if(screen instanceof GameScreen)screen.setGameState(GameState.run);SingleGuideData singleGuideData=guideList.removeFirst();singleGuideData.clickRun.run();guideGroup.remove();if(guideList.isEmpty()){//教程完毕if(type==GuideType.MAIN){Data.isMainGuideOk=true;SPUtil.commit("isMainGuideOk", true);}else if(type==GuideType.GAME){Data.isGameGuideOk=true;GdxUtil.getGameScreen().control.isFirstPanData=true;SPUtil.commit("isGameGuideOk", true);}else if(type==GuideType.UP){Data.isUpgradeGuideOk=true;SPUtil.commit("isUpgradeGuideOk", true);}type=null;//释放事件}else{new Timer().scheduleTask(new Task() {@Overridepublic void run() {show(guideList.getFirst());}}, singleGuideData.nextDelay);}return false;}private void addGrayImg(Group group,float x,float y,float w,float h){Rectangle[] grayRects=getRects(new Rectangle(x, y, w, h));for (int i = 0; i < 4; i++) {Image img=new Image(new Texture(PixmapFactroy.get(1, 1, 0, 0, 0, 0.7f)));img.setBounds(grayRects[i].x, grayRects[i].y, grayRects[i].width, grayRects[i].height);group.addActor(img);}ImageEx img=new ImageEx(Const.IMG_SCR+"grayImg.png");img.setBounds(x, y, w, h);group.addActor(img);}private Rectangle[] getRects(Rectangle focus){Rectangle rects[]=new Rectangle[4];rects[0]=new Rectangle(0, focus.y+focus.height, 960, 960-(focus.y+focus.height));rects[1]=new Rectangle(0, 0,focus.x, focus.y+focus.height);rects[2]=new Rectangle(focus.x+focus.width, 0,960-(focus.x+focus.width), focus.y+focus.height);rects[3]=new Rectangle(focus.x, 0,focus.width, focus.y);return rects;}public class SingleGuideData{public Rectangle focus;public String txt;public Runnable clickRun;public float nextDelay;public float txtGroupX,txtGroupY;public SingleGuideData(Rectangle focus,String txt,Runnable clickRun,float nextDelay,float txtGroupX,float txtGroupY){this.focus=focus;this.txt=txt;this.clickRun=clickRun;this.nextDelay=nextDelay;this.txtGroupX=txtGroupX;this.txtGroupY=txtGroupY;}}class EmptyRunnable implements Runnable{@Overridepublic void run() {}}class StartLev1Runnable implements Runnable{@Overridepublic void run() {FatherScreen screen=GdxUtil.getFatherScreen();screen.changeScreen(true, new ResLoadingScreen(screen.main, new GameProperty(1)));}}class IntoLev1Runnable implements Runnable{@Overridepublic void run() {FatherScreen screen=GdxUtil.getFatherScreen();screen.changeScreen(true, new MainScreen(screen.main, new UI_LevelFront(1)));}}class UsePropRunnable implements Runnable{@Overridepublic void run() {GdxUtil.getGameScreen().control.useProp(0);}}class PauseRunnable implements Runnable{@Overridepublic void run() {FatherScreen screen=GdxUtil.getFatherScreen();screen.setGameState(GameState.pause);}}class MainScreenRunnable implements Runnable{@Overridepublic void run() {FatherScreen screen=GdxUtil.getFatherScreen();screen.changeScreen(true, new MainScreen(screen.main, new UI_Main()));}}class Get2000CoinRunnable implements Runnable{@Overridepublic void run() {DataDealUtil.change(DataKind.coin, 2000);}}class RoleUpBtnRunnable implements Runnable{@Overridepublic void run() {((UI_Main)GdxUtil.getMainScreen().uiType).mainGroup.rolePetMoreFrame.roleGroup.upBtn();}}class PetCarBtnRunnable implements Runnable{@Overridepublic void run() {((UI_Main)GdxUtil.getMainScreen().uiType).mainGroup.rolePetMoreFrame.setFocus(1);}}class PetUpBtnRunnable implements Runnable{@Overridepublic void run() {((UI_Main)GdxUtil.getMainScreen().uiType).mainGroup.rolePetMoreFrame.petGroup.upBtn();}}class ShowShopRunnable implements Runnable{@Overridepublic void run() {GdxUtil.getMainScreen().changeUIGroup(new UI_Shop(0));}}class ShowBackPackRunnable implements Runnable{@Overridepublic void run() {GdxUtil.getMainScreen().changeUIGroup(new UI_Backpack());}}class BackMainRunnable implements Runnable{@Overridepublic void run() {GdxUtil.getMainScreen().changeUIGroup(new UI_Main());}}class LevelBtnRunnable implements Runnable{@Overridepublic void run() {GdxUtil.getFatherScreen().changeScreen(true,new BigMapScreen(GdxUtil.getFatherScreen().main));}}PackInfoDialog packInfoDialog;class ShowPropDialogRunnable implements Runnable{@Overridepublic void run() {packInfoDialog=new PackInfoDialog(0);packInfoDialog.show(GdxUtil.getFatherScreen().mainStage);}}class PropDialogOKRunnable implements Runnable{@Overridepublic void run() {Data.fastBar.add(0);Data.fastBar.poll();//存储快捷栏Object[] propIds=Data.fastBar.toArray();for (int i = 0; i < propIds.length; i++) {SPUtil.commit("fastBar"+i, (int)propIds[i]);}packInfoDialog.hide();}}private static final Guide INSCANCE=new Guide();public static Guide getInst(){return INSCANCE;}}

新手引导其实就是一步一步的知道玩家熟悉游戏的过程,新手引导的过程应该添加到一个数组中,这样一步步的去让玩家学习,每次学习完一个过程,就移除到一步,从而达到引导过程。






0 0
原创粉丝点击