贪吃蛇
帧:如果时间片足够小,就是动画,一秒30帧。连起来动画,拆开就是静态的图片。
键盘监听:
定时器Timer
回去补图excel表格上画蛇的截图
放图片可以放在跟目录下,也可以放在当前目录下
public class Data {
//absolute path start with /,current project, relative path
public static URL headerUrl = Data.class.getResource("/statics/head.png");
public static ImageIcon header = new ImageIcon(headerUrl);
public static URL upUrl = Data.class.getResource("/statics/up.png");
public static URL downUrl = Data.class.getResource("/statics/down.png");
public static URL leftUrl = Data.class.getResource("/statics/left.png");
public static URL rightUrl = Data.class.getResource("/statics/right.png");
public static URL bodyUrl = Data.class.getResource("/statics/body.png");
public Data() {
// TODO Auto-generated constructor stub
}
}
public class StartGame {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame();
frame.setBounds(10, 10, 900, 720);
//size is fixed
frame.setResizable(false);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//Game should in panel
frame.add(new GamePanel());
frame.setVisible(true);
}
}
public class GamePanel extends JPanel {
// Paint panel, all the things in our game using this paint brush
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);// clear screen
this.setBackground(Color.black);
}
}