《奇迹蕾蕾》制作存档

第一阶段 -java swing

刚刚学完java的gui,想做个游戏练练手。所以开始做《奇迹蕾蕾》
在这里插入图片描述在这里插入图片描述
用Aseprite画了几个像素小人和背景
但是由于画工太差像素小人走起来实在很鬼畜
也发现了java-swing写游戏的局限实在太大了
所以先暂停用java写,今天开始学习cocos
贴一下目前为止所写出来的代码和运行时的图片

被放弃的几版设计

第一版形象设计
第二版动起来


怎么会这么丑啊天呐T T,对不住女儿,但是我画功实在太差了
在这里插入图片描述
这才是女儿真实的美貌

游戏代码

游戏开始

package Game;

import javax.swing.*;

public class StartGame {
    public static void main(String[] args) {
                JFrame jFrame = new JFrame("假如谢蕾蕾登上鸟巢我就死而无憾了");
                jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                jFrame.setBounds(10, 10, 800, 600);
                jFrame.setVisible(true);
                jFrame.setResizable(false);
                jFrame.add(new GamePanel());
            }
 }

数据中心

package Game;

import javax.swing.*;
import java.net.URL;
//数据中心
public class Data {

    
    public static URL backgroundURL  =  Data.class.getResource("/static/bggg.png");
    public static ImageIcon bg=new ImageIcon(backgroundURL);
	
	//小人运动
    public static URL yd1URL  =  Data.class.getResource("/static/R1.png");
    public static ImageIcon yd1=new ImageIcon(yd1URL);

    public static URL leftURL  =  Data.class.getResource("/static/L1.png");
    public static ImageIcon  left=new ImageIcon(leftURL);

    public static URL yd2LURL  =  Data.class.getResource("/static/L2.png");
    public static ImageIcon yd2L=new ImageIcon(yd2LURL);

    public static URL yd2RURL  =  Data.class.getResource("/static/R2.png");
    public static ImageIcon  yd2R=new ImageIcon(yd2RURL);

	//对话框
    public static URL TalkURL  =  Data.class.getResource("/static/talk.png");
    public static ImageIcon  talk=new ImageIcon(TalkURL);

	//对话时出现的背景
    public static URL BG1URL  =  Data.class.getResource("/static/bg1.png");
    public static ImageIcon  BG1=new ImageIcon(BG1URL);

    public static URL BG2URL  =  Data.class.getResource("/static/bg2.png");
    public static ImageIcon  BG2=new ImageIcon(BG2URL);

    public static URL BG3URL  =  Data.class.getResource("/static/bg3.png");
    public static ImageIcon  BG3=new ImageIcon(BG3URL);

}

游戏面板

package Game;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
import sun.font.FontRunIterator;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Timer;
import java.util.TimerTask;

public class GamePanel extends JPanel  implements KeyListener, ActionListener {
    int LLX;//蕾蕾的x坐标
    int LLY;//蕾蕾的Y坐标
    String direction;
    boolean yd;
    int Xspeed;
    int Yspeed;
    boolean talkStop;//对话停止判断
    int[] talk={0};
    String[] str=new String[34];//对话框的里的对话
    int i;//第几句对话


  java.util.Timer timer =new Timer(true);

    public GamePanel() {
        init();
        //获得焦点和键盘事件
        this.setFocusable(true);//获得焦点事件
        this.addKeyListener(this);//获得键盘监听事件
    }

    public void  init(){
         LLX=250;
         LLY=450;
         direction="R";
         yd=true;
         Xspeed=10;
         Yspeed=10;
         talkStop=false;
         //对话
         i=0;
        str[0]="喵~喵~喵~~~";
        str[1]="luna似乎十分不安地在房间里一直打圈的走";
        str[2]="\"我该怎么和她说呢\"";
        str[3]="睡梦中,谢蕾蕾的耳朵捕捉到了几句低沉的女声";
        str[4]="\"这种事要怎么说才不会吓到她\"";
        str[5]="\"啊啊啊啊 天呐爸爸 我为什么要写那篇小说\"";
        str[6]="谢蕾蕾从被子里探出头,想探寻房间中声音的来源";
        str[7]="不像是从隔壁传来,但是...房间里没有别人啊";
        str[8]="那么...只可能是...";
        str[9]="\"蕾蕾你醒啦\"";
        str[10]="luna挥了挥爪子";
        str[11]="......";
        str[12]="谢蕾蕾揉了揉眼睛";
        str[13]="\"我在做梦吧?\"";
        str[14]="\"蕾蕾...那个...我\"";
        str[15]="啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊!!!";
        str[16]="\"啊啊啊啊啊啊啊啊啊啊啊啊蕾蕾你别叫\"";
        str[17]="\"听我说\"";
        str[18]="\"这一切都要从一场不知道什么时候能开学的寒假说起\"";
        str[19]="\"我本来只是一只幸福的戆卵\"";
        str[20]="\"我还记得那天...\"";
        str[21]="\"那天,平静无风\"";
        str[22]="\"不是,那天我刚看完《青春没我》\"";
        str[23]="\"被气得吃了三瓶速效救心丸\"";
        str[24]="\"因为过于生气,就上河组写了篇爽文\"";
        str[25]="\"《假如谢蕾蕾登上鸟巢我就死而无憾了》\"";
        str[26]="\"没想到我竟然火了\"";
        str[28]="\"全中国三万戆卵都在看我的文\"";
        str[27]="\"四大 沙儿雕 创青河都转了\"";
        str[29]="\"也许是由于戆卵的怨念过深\"";
        str[30]="老天让我穿进文里";
        str[31]="要想回到现实世界";
        str[32]="只有完成终极目标——";
        str[33]="——登上鸟巢";
    }

    protected void paintComponent(Graphics g){
        super.paintComponent(g);//清屏,不使用的话会出现闪烁
        this.setBackground(Color.black);
        if(i==24||i==25||i==26){
            Data.BG1.paintIcon(this, g, 0, 0);
        }
        if(i==27||i==28){
            Data.BG2.paintIcon(this, g, 0, 0);
        }
        if(i==33){
            Data.BG3.paintIcon(this, g, 0, 0);
        }
        if(talkStop==true) {
            Data.bg.paintIcon(this, g, 0, 0);
        }

        if(talkStop==false) {
            Data.talk.paintIcon(this, g, 0, 365);
            g.setColor(Color.black);
            g.setFont(new Font("微软雅黑", Font.BOLD, 20));
            //对话
            g.drawString(str[i], 100, 470);

        }




        if(direction.equals("R")&&(yd==false)&&talkStop==true){
            Data.yd1.paintIcon(this,g,LLX,LLY);
            yd=!yd;
        } else if(direction.equals("R")&&(yd==true)&&talkStop==true){
            Data.yd2R.paintIcon(this,g,LLX,LLY);
            yd=!yd;
        } else if(direction.equals("L")&&(yd==false)&&talkStop==true){
            Data.left.paintIcon(this,g,LLX,LLY);
            yd=!yd;
        } else if(direction.equals("L")&&(yd==true)&&talkStop==true){
            Data.yd2L.paintIcon(this,g,LLX,LLY);
            yd=!yd;
        }

        if(LLX==50&&LLY==420){

        }

    }

    @Override
    public void actionPerformed(ActionEvent e) {

    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {
        int KeyCode = e.getKeyCode();
        if (KeyCode == KeyEvent.VK_SPACE) {
            if(talkStop==false){
                i++;
                if(i==str.length){
                    talkStop=true;
                }
            }else{
            LLY=LLY-40;
            timer.schedule(new TimerTask() {
                public void run() {
                    LLY=LLY+40;
                }
            }, 5 );
            }

            repaint();
        } else if (KeyCode == KeyEvent.VK_LEFT) {
            direction="L";
            if(LLX>=0){LLX-=10;}
            repaint();
        } else if (KeyCode == KeyEvent.VK_DOWN) {
            if(LLY<500){
                LLY+=10;
                repaint();
            }
        } else if (KeyCode == KeyEvent.VK_UP) {
            if(LLY>400){
                LLY-=10;
                repaint();
            }
        }else if (KeyCode == KeyEvent.VK_RIGHT) {
            if(LLX<670){LLX+=10;}
            direction="R";
            repaint();
        }
    }

    @Override
    public void keyReleased(KeyEvent e) {

    }
}

游戏界面

对话时的窗口
在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
今天开始学习cocos

发布了9 篇原创文章 · 获赞 1 · 访问量 80

猜你喜欢

转载自blog.csdn.net/weixin_43968392/article/details/105578395