⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mycanvas.java~105~

📁 这是个功能比较多的RPG 但是也存在比较多的BUG 有待完善中
💻 JAVA~105~
📖 第 1 页 / 共 2 页
字号:
                text.setText(2, "痴情就帮你吧!");
                break;
            case 33:
                text.setText(0, "诺奇奥尼:谢谢你了!");
                break;
            case 34:
                text.setText(0, "胡尔:先别谢的那么快");
                text.setText(1, ",你要答应我件事,在");
                text.setText(2, "附近的河旁有个叫萨耶");
                break;
            case 35:
                text.setText(0, "的人,他打赌输了欠我");
                text.setText(1, "一种药材。你帮我要过");
                text.setText(2, "来!");
                break;
            case 36:
                text.setText(0, "诺奇奥尼:成!好的!");
                text.setCanEnd(true); //与胡尔第一次对话结束
                process = 3;
                break;
            case 37: //========== 与胡尔第二次对话
                text.setText(0, "胡尔:站在这傻愣干嘛");
                text.setText(1, ",还不快去!");
                text.show();
                text.setCanEnd(true); //此次对话结束
                break;
            case 38: //========== 与萨耶第一次对话
                text.setText(0, "诺奇奥尼:你就是萨耶");
                text.setText(1, "?");
                text.show();
                break;
            case 39:
                text.setText(0, "萨耶:嗯,就是我!");
                break;
            case 40:
                text.setText(0, "诺奇奥尼:那就好了~");
                text.setText(1, "是胡尔叫我来的,他说");
                text.setText(2, "你欠他一种药材,叫我");
                break;
            case 41:
                text.setText(0, "帮他拿过去!");
                break;
            case 42:
                text.setText(0, "  …………");
                break;
            case 43:
                text.setText(0, "欲知后事如何");
                text.setText(1, "    请听下回分解");
                text.setCanEnd(true); //此次对话结束
                process = 4;
                SlideState = 3;

                break;
            case 44:
                text.setText(0, "…………");
                text.show();
                text.setCanEnd(true); //此次对话结束
                break;
            case 45:
                text.setText(0, "");
                break;
            case 46:
                text.setText(0, "");
                break;
            case 47:
                text.setText(0, "");
                break;
            case 48:
                text.setText(0, "");
                break;
            case 49:
                text.setText(0, "");
                break;
            case 50:
                text.setText(0, "");
                break;
            }
            dialogOn = false;
        }
        if (text.getTextState() == 3 && confirm == true) {
            dialogID++;
            dialogOn = true;
            confirm = false;
        }
    }

    public void SwitchScene() {
        switch (SlideState) {
        case 0: //没有渐变,继续判断主角是否走到场景切换点
            switch (scene) {
            case 0: //战斗页面
                break;
            case 1: //在大地图中( 1 号地图)
                if (hero.getNextGrid() == 15 ||
                    hero.getNextGrid() == 14) {
                    toScene = 2; //开始渐变,渐变完进入场景 2
                    SlideState = 3;

                }

                //当在泉水附近并面向泉水时,饮用泉水,恢复体力
                if (hero.getNextGrid() == 39 && hero.getFaceDir() == 1 ||
                    hero.getNextGrid() == 39 && hero.getFaceDir() == 2 ||
                    hero.getNextGrid() == 40 && hero.getFaceDir() == 1 ||
                    hero.getNextGrid() == 45 && hero.getFaceDir() == 2 ||
                    hero.getNextGrid() == 45 && hero.getFaceDir() == 3 ||
                    hero.getNextGrid() == 46 && hero.getFaceDir() == 3) {
                    if (confirm) { //按下确定时
                        //提示身体恢复
                        if (text.getTextState() == 0) { //此时没有显示文本时
                            text.emptyText();
                            text.setText(0, "啊,这小泉水真甜!");
                            text.setText(1, "混身顿时一身轻松。");
                            text.show();
                            text.setCanEnd(true);
                        }
                        hero.restoreHPMP(); //恢复生命体力
                        confirm = false;
                    }
                }
                break;
            case 2:
                if (hero.getNextGrid() == 86 || //在门口处
                    hero.getPosX() == 120 && hero.getPosY() == 100 &&
                    hero.getFaceDir() == 2 ||
                    hero.getPosX() == 120 && hero.getPosY() == 92 &&
                    hero.getFaceDir() == 2 ||
                    hero.getPosX() == 128 && hero.getPosY() == 96 &&
                    hero.getFaceDir() == 2) {
                    toScene = 1; //开始渐变,渐变完进入场景 1
                    SlideState = 3;
                }

                //在房间中( 2 号地图)

                break;
            }
            break;
        case 1: //渐入(由暗变亮)
        case 2: //渐出(由亮变暗)
            if (switchFightState == 1 ||
                switchFightState == 2)

                break;
        case 3: //变暗后转换场景
            if (process == 4 && text.getTextState() == 0) { //是否剧情结束
                gameState = 0; //设为菜单页
                menu.setGameStarted(false);
                return;
            }
            switch (toScene) {
            case 0: //场景与战斗画面的切换
                if (switchFightState == 1) { //场景->战斗,亮->暗
                    toScene = sceneAfterFight; //先保存战斗前所在的场景号
                    switchFightState = 2; //进入战斗画面前也有渐变
                    SlideState = 0;
                } else if (switchFightState == 3) { //战斗->场景,亮->暗
                    switchFightState = 4; //进入场景页面也有渐变
                    SlideState = 0;
                }
                break;
            case 1: //即将切换到 1 号地图
                hero.loadScene(scene, 1); //切换到 1 号地图
                scene = 1;
                SlideState = 0;
                break;
            case 2: //即将切换到 2 号地图
                hero.loadScene(scene, 2);
                scene = 2;
                SlideState = 0;

                break;
            }

            break;
        }
    }


    /////////////////////////////////////////////////////////////////////
    public void keyPressed(int keyCode) {
        System.out.println("---------------------------------");
        System.out.println("scene = " + scene);
        System.out.println("SlideState = " + SlideState);
        System.out.println("gameState = " + gameState);

        if (SlideState == 0) { //只有在没有渐变的情况下才可以响应按键信息
            if (firstBoot) {
                firstBoot = false;
                dialogOn = true;
            }
            switch (keyCode) {
            case FIRE:
                confirm = true; //按下确定
                break;
            }

            switch (gameState) {
            case 0: //菜单页
                menu.keyPressed(keyCode);

                break;
            case 1: //游戏页
                if (text.getTextState() == 0) //不显示对话框时才能响应
                    hero.keyPressed(keyCode);
                text.keyPressed(keyCode);
                break;
            }
        }

    }

    protected void keyReleased(int keyCode) {
        hero.keyReleased(keyCode);
        confirm = false;

    }

    protected void paint(Graphics g) {
//        System.out.println("---------------------------------");
//        System.out.println("scene = " + scene);
//        System.out.println("SlideState = " + SlideState);
//        System.out.println("gameState = " + gameState);

        Graphics tg = g;
        g = gg;
        //*****************************【PAINT START】************************
         ClearScreen(g);

        //游戏处理
        switch (gameState) {
        case 0: //菜单页
            menu.draw(g);
            if (menu.isGameStarted()) { //游戏开始
                hero.reset();
                dialogOn = false;
                dialogID = 1;
                gameState = 1;

                hero.loadScene(0, 2);
                scene = 2;
                SlideState = 0;
                switchFightState = 4;
                firstBoot = true;
            }

            break;
        case 1: //游戏页

            if (hero.isFighted()) { //已触发战斗,或正在战斗
                if (hero.isDead()) {
                    gameState = 0; //主角死亡,回到游戏菜单
                    menu.reset();
                }
                if (scene != 0) { //已经触发战斗,但还在场景页面渐变
                    toScene = 0; //即将切换到战斗画面
                    sceneAfterFight = scene; //记录战斗完后应该返回的场景号
                    scene = 0; //此次战斗这条 if 语句不再执行
                    SlideState = 3;
                    switchFightState = 1; //场景->战斗
                }
            } else { //处于场景页面

                if (scene == 0) {
                    scene = toScene; //渐变完后回到原来场景
                    toScene = 0; //战斗结束渐暗处理完,即将处理变暗后的场景转换
                    SlideState = 3;
                    switchFightState = 3; //战斗->场景
                }
            }
            switch (switchFightState) {
            case 1: //场景->战斗,亮->暗 应该:场景画面
            case 4: //战斗->场景,暗->亮 应该:场景画面
                hero.drawMap(g);
                hero.drawNPC(g);
                hero.drawPlayer(g);
                checkTalk(); //是否主角触发了对话
                setDialog(); //设置对话内容
                break;
            case 2: //场景->战斗,暗->亮 应该:战斗画面
            case 3: //战斗->场景,亮->暗 应该:战斗画面
                hero.drawBattle(g);
                break;
            }
            SwitchScene();
            text.paint(g);
            break;
        }
        //******************************【PAINT END】**************************
         g = tg;
        g.drawImage(this.imgBuffer, 0, 0, 20);
    }

    /**
     * 画菜单
     * @param g Graphics
     */

    public void run() {

        while (running) {
            long start = System.currentTimeMillis();
            try {
                this.game_logic();
                this.repaint();
                this.serviceRepaints();
            } catch (Exception e) {
                e.printStackTrace();
            }
            ;
            long end = System.currentTimeMillis();
            if ((80 - (end - start)) > 0) {
                try {
                    thread.sleep(80 - (end - start));
                } catch (InterruptedException ex) {
                }
            }
        }
    }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -