麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

Super Mario(easy ver.)

2019-11-10 20:07:42
字體:
來源:轉載
供稿:網友

超級瑪麗

幾個重要細節:

1.跳躍單獨開個線程,兩次循環一次上一次下

2.開啟“萬有引力”線程,讓人物在跳躍結束后或者走到空中時y坐標增加直到到達地面

3.人物與障礙物對象要有預碰撞否則會粘住不動

public class Mario extends Rectangle implements Runnable{	public int x = 20,y = 359;	public int width = 28,height = 34;	public int xspeed = 2,yspeed = 3;	public boolean isUp,isDown,isLeft,isRight;	public boolean isjump = false;	public UI ui;		public Image c_stop = new ImageIcon("images/mari1.png").getImage();	public Image c_left = new ImageIcon("images/mari_left.gif").getImage();	public Image c_right = new ImageIcon("images/mari_Right.gif").getImage();	public Image currentImage = c_stop;		public Mario(UI ui) {		this.ui = ui;		startGravityThread();	}	public void run() {		while(true){			if(isUp){					if(!isjump){					if(!isGravity){						isjump =true;						jump();					}				}			}			 if(isDown){				 			 }			 if(isLeft){				 currentImage = c_left;				 boolean hit = crash(StaticParams.direction_left);				 if(hit){										}				 				 else{					if(x>0){					 x-=xspeed;					} 				 } 			}			 if(isRight){				 currentImage = c_right;				 boolean hit = crash(StaticParams.direction_right);				 if(hit){									}				else {					if(x > 370){						ui.n-=xspeed;						for (int i = 0; i < StaticParams.list.size(); i++) {							Barrier b = StaticParams.list.get(i);							b.x-=xspeed;						}					}else{						x+=xspeed;					}				}							}			 			 if(StaticParams.isShoot)			 {				 				 if(!(StaticParams.bulletlist.size()>StaticParams.bullet_Num))				 {					 //發子彈					 Image image = new ImageIcon("images/coin.png").getImage();					 String dir = "right";					 if(isLeft)						 dir ="left";					 					 Bullet bullet = new Bullet(x, y, 15, 15, image , dir);					 StaticParams.bulletlist.add(bullet);					 					 StaticParams.isShoot = false;				 }				 				 			 }			 			 			 			 Thread_Util.sleep(10);		}				}	public void jump(){				new Thread(){			public void run(){								for (int i = 0; i < 50; i++) {						boolean hit = crash(StaticParams.direction_up);						if(hit){							break;						}						 						else {														y-=yspeed;						}												Thread_Util.sleep(10);					}					for (int i = 0; i < 100; i++) {						boolean hit = crash(StaticParams.direction_down);						if(hit){							break;						} 						else {							if(y >= StaticParams.floor_height){								break;							}							else if(y < StaticParams.floor_height){								y+=yspeed;							}													}						Thread_Util.sleep(10);					}										isjump = false;			}		}.start();	}	public boolean crash(String direction){		Rectangle rect = null;				if("up".equals(direction)){			rect = new Rectangle(x,y-2,width,height);		}				else if("down".equals(direction)){			rect = new Rectangle(x,y+3,width,height);		}		else if("left".equals(direction)){			rect = new Rectangle(x-1,y,width,height);		}		else if("right".equals(direction)){			rect = new Rectangle(x+1,y,width,height);		}		boolean hit = false; 		for (int i = 0; i < StaticParams.list.size(); i++) {			Barrier b = StaticParams.list.get(i);			hit = b.intersects(rect);			if(hit){				if(b instanceof Coin){					StaticParams.list.remove(b);					StaticParams.coin_Num++;				}				if(b instanceof Bank){					Thread_Util.sleep(10);					y+=yspeed;					if(y >= 450){						StaticParams.isPause = !StaticParams.isPause;						Thread_Util.sleep(10);					}				}								return true;			}				}		return hit;	}	boolean isGravity = false;		public void startGravityThread(){		new Thread(){			public void run(){				while(true){					Thread_Util.sleep(10);					boolean hit = crash(StaticParams.direction_down);					if(hit){						isGravity = false;						continue;					} 					if(y >= StaticParams.floor_height){						isGravity = false;						continue;					}					if(isjump){						isGravity = false;						continue;					}					isGravity = true;					y+=yspeed;				}			}		}.start();	}}4.字符流的讀,地圖信息的讀取

public class StaticParams {		public final static int floor_height = 359;	public static int coin_Num = 0;	public static int bullet_Num = 3;	public final static String direction_up = "up";	public final static String direction_down = "down";	public final static String direction_left = "left";	public final static String direction_right = "right";	public static boolean isPause = false;	public static boolean isShoot = false;	public static List<Barrier> list = new ArrayList<Barrier>();	public static List<Bullet> bulletlist = new ArrayList<Bullet>();		public static void genBarrier(){		mapToBarrier();	}	public static List<String> readMap(){		BufferedReader br = null;		List<String> lines = new ArrayList<String>();		try {			br = new BufferedReader(new FileReader("marioMap"));			String l = null;			while((l = br.readLine())!=null){				lines.add(l);			}			return lines;		} catch (Exception e) {						e.PRintStackTrace();		}finally{			try {				if(br != null)					br.close();				} catch (IOException e) {					e.printStackTrace();				}		}		return null;			}	public static void mapToBarrier(){		List<String> lines = readMap();		for (int i = 0; i < lines.size(); i++) {			String s = lines.get(i);							for (int j = 0; j < s.length(); j++) {					char c = s.charAt(j);					if('0' == c){											}					else if('1' == c){						ImageIcon imageIcon1 = new ImageIcon("images/brick.png");						Image image1 = imageIcon1.getImage();						Brick brick = new Brick(j*30, i*30, 30, 30,image1);						list.add(brick);					}else if('2' == c){						ImageIcon imageIcon2 = new ImageIcon("images/coin.png");						Image image2 = imageIcon2.getImage();						Coin coin = new Coin(j*30, i*30, 30, 30,image2);						list.add(coin);					}else if('3' == c){						ImageIcon imageIcon3 = new ImageIcon("images/pipe.png");						Image image3 = imageIcon3.getImage();						Pipe pipe = new Pipe(j*30, i*30, 60, 120,image3);						list.add(pipe);					}else if('5' == c){						Bank bank = new Bank(j*30, i*30+3, 30, 30,null);						list.add(bank);										}else if('4' == c){						ImageIcon imageIcon4 = new ImageIcon("images/coin_brick.png");						Image image4 = imageIcon4.getImage();						CoinBrick coin_brick = new CoinBrick(j*30, i*30, 30, 30,image4);						list.add(coin_brick);												}				}		}	}		}


上一篇:注解 Annotation

下一篇:c中break和continue

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久99久久99免费视频 | 国产午夜亚洲精品理论片大丰影院 | 国产一区二区三区视频在线 | 久久精品国产久精国产 | 日韩视频精品一区 | 国产精品久久久久久久亚洲按摩 | 一级做a爱视频 | 法国极品成人h版 | 欧美一区二区网站 | 极品五月天 | 免费欧美一级视频 | 九九精品久久 | 久久草草影视免费网 | 一级黄片毛片免费看 | 亚洲国产精品久久久久久久久久久 | 亚洲精品成人18久久久久 | 欧美黄色大片免费观看 | 老师你怎么会在这第2季出现 | 欧美 中文字幕 | 美国一级免费视频 | 国产精品视频一区二区噜噜 | 日韩午夜一区二区三区 | 中国妞xxxhd露脸偷拍视频 | 蜜桃av鲁一鲁一鲁一鲁 | 欧洲精品久久久 | 久久久国产精品成人免费 | 欧美成人高清在线 | www噜噜偷拍在线视频 | 成人精品| 欧美a∨一区二区三区久久黄 | 欧美一级色片 | 主播粉嫩国产在线精品 | 欧美人与牲禽动交精品一区 | 成人免费网视频 | 鲁丝片一区二区三区免费入口 | a一级黄色毛片 | 最新一级毛片 | 天堂精品久久 | 久久精品79国产精品 | 成人在线观看一区二区 | 亚洲爱爱图|