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

📄 game_4.java

📁 j2me写的虽然只写了一关但是个方面只是很健全.最好的就是子弹方向的处理.不愧是我们老师的作品
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				{
					girl.init_girl();
					--girl.girl;
					girl.bomb = 3;
					girl.is_over = false;
				}
				else
				{
					g.setClip(0, 0, 176, 208);
					g.setColor(255, 255, 255);
					g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));
					g.drawString("游戏结束", 176 / 2 - g.getFont().stringWidth("游戏结束") / 2, 100, G_TL);
					++girl.i_over;
					if(girl.i_over > 50)
					{
						ss_pp = TITLE;
						i_title = 0;
						is_start = false;
						shifang(START);
						init_img(TITLE);
						v_girl_zidan.removeAllElements();
						v_bomb.removeAllElements();
						v_plane.removeAllElements();
						v_zidan.removeAllElements();
						v_pb.removeAllElements();
						boss = null;
					}
				}
			}
		}
	}
	private void map_png(Graphics g)
	{
		switch(i_guan)
		{
			case 0:
				for(int y = 0; y < 2; y++)
				{
					paint_png(g, map_0, 0, (y - 1) * 208 + i_map, 1, 0, 1, 0);
				}
				break;
			case 1:
				for(int y = 0; y < 2; y++)
				{
					paint_png(g, map_1, 0, (y - 1) * 208 + i_map, 1, 0, 1, 0);
				}
				break;
			case 2:
				for(int y = 0; y < 2; y++)
				{
					paint_png(g, map_2, 0, (y - 1) * 208 + i_map, 1, 0, 1, 0);
				}
				break;
			case 3:
				for(int y = 0; y < 2; y++)
				{
					paint_png(g, map_3, 0, (y - 1) * 208 + i_map, 1, 0, 1, 0);
				}
				break;
		}
		if(ss_pp == START)
			i_map += 4;
		if(i_map > 208)
			i_map = 0;
		for(int i = 0; i < girl.girl; ++i)
		{
			paint_png(g, girl_girl_png, i * 12, 198, 1, 0, 1, 0);
		}
		for(int i = 0; i < girl.bomb; ++i)
		{
			paint_png(g, girl_bomb_png, 176 - 8 - i * 8, 190, 1, 0, 1, 0);
		}
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
		g.setClip(0, 0, 176, 208);
		g.setColor(255, 255, 255);
		g.drawString(girl.defen + "", 2, -2, G_TL);
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));
		g.setColor(255, 255, 255);
		if(girl.start_time < 15)
		{
			switch(i_guan)
			{
				case 0:
					g.drawString("第一关", 176 / 2 - g.getFont().stringWidth("第一关") / 2, 100, G_TL);
					break;
				case 1:
					g.drawString("第二关", 176 / 2 - g.getFont().stringWidth("第二关") / 2, 100, G_TL);
					break;
				case 2:
					g.drawString("第三关", 176 / 2 - g.getFont().stringWidth("第三关") / 2, 100, G_TL);
					break;
				case 3:
					g.drawString("第四关", 176 / 2 - g.getFont().stringWidth("第四关") / 2, 100, G_TL);
					break;
			}
		}
	}
	private int zidan_fangxiang(int plane_x, int plane_y)//共36个方向,每个方向10度
	{
		int girl_x = girl.x + 9;
		int girl_y = girl.y + 11;
		if(plane_y > girl_y && ((plane_y - girl_y) * 1000 > Math.abs(girl_x - plane_x) * 11430))//85-95
		{
			return 10;
		}
		else if(plane_y < girl_y && (girl_y - plane_y) * 1000 > Math.abs(plane_x - girl_x) * 11430)//275-265
		{
			return 28;
		}
		else if(plane_x > girl_x && Math.abs(girl_y - plane_y) * 1000 < (plane_x - girl_x) * 87)//5-355
		{
			return 1;
		}
		else if(plane_x < girl_x && Math.abs(girl_y - plane_y) * 1000 < (girl_x - plane_x) * 87)//185-175
		{
			return 19;
		}
		else
		{
			if(plane_y > girl_y)
			{
				if(plane_x > girl_x)//向左上开炮
				{
					if((plane_y - girl_y) * 1000 >= (plane_x - girl_x) * 3732)//>75
					{
						return 9;
					}
					else if((plane_y - girl_y) * 1000 >= (plane_x - girl_x) * 2144)//>65
					{
						return 8;
					}
					else if((plane_y - girl_y) * 1000 >= (plane_x - girl_x) * 1428)//>55
					{
						return 7;
					}
					else if((plane_y - girl_y) * 1000 >= (plane_x - girl_x) * 1000)//>45
					{
						return 6;
					}
					else if((plane_y - girl_y) * 1000 >= (plane_x - girl_x) * 700)//>35
					{
						return 5;
					}
					else if((plane_y - girl_y) * 1000 >= (plane_x - girl_x) * 466)//>25
					{
						return 4;
					}
					else if((plane_y - girl_y) * 1000 >= (plane_x - girl_x) * 267)//>15
					{
						return 3;
					}
					else if((plane_y - girl_y) * 1000 >= (plane_x - girl_x) * 87)//>5
					{
						return 2;
					}
				}
				else if(plane_x < girl_x)//向右上开炮
				{
					if((plane_y - girl_y) * 1000 <= (girl_x - plane_x) * 267)//<165
					{
						return 18;
					}
					else if((plane_y - girl_y) * 1000 <= (girl_x - plane_x) * 466)//<155
					{
						return 17;
					}
					else if((plane_y - girl_y) * 1000 <= (girl_x - plane_x) * 700)//<145
					{
						return 16;
					}
					else if((plane_y - girl_y) * 1000 <= (girl_x - plane_x) * 1000)//<135
					{
						return 15;
					}
					else if((plane_y - girl_y) * 1000 <= (girl_x - plane_x) * 1428)//<125
					{
						return 14;
					}
					else if((plane_y - girl_y) * 1000 <= (girl_x - plane_x) * 2144)//<115
					{
						return 13;
					}
					else if((plane_y - girl_y) * 1000 <= (girl_x - plane_x) * 3732)//<105
					{
						return 12;
					}
					else if((plane_y - girl_y) * 1000 <= (girl_x - plane_x) * 11430)//<95
					{
						return 11;
					}
				}
			}
			else if(plane_y < girl_y)
			{
				if(plane_x < girl_x)//向右下开炮
				{
					if((girl_y - plane_y) * 1000 >= (girl_x - plane_x) * 3732)//>255
					{
						return 27;
					}
					else if((girl_y - plane_y) * 1000 >= (girl_x - plane_x) * 2144)//>245
					{
						return 26;
					}
					else if((girl_y - plane_y) * 1000 >= (girl_x - plane_x) * 1428)//>235
					{
						return 25;
					}
					else if((girl_y - plane_y) * 1000 >= (girl_x - plane_x) * 1000)//>225
					{
						return 24;
					}
					else if((girl_y - plane_y) * 1000 >=(girl_x - plane_x) * 700)//>215
					{
						return 23;
					}
					else if((girl_y - plane_y) * 1000 >= (girl_x - plane_x) * 466)//>205
					{
						return 22;
					}
					else if((girl_y - plane_y) * 1000 >= (girl_x - plane_x) * 267)//>195
					{
						return 21;
					}
					else if((girl_y - plane_y) * 1000 >= (girl_x - plane_x) * 87)//>185
					{
						return 20;
					}
				}
				else if(plane_x > girl_x)//向左下开炮
				{
					
					if((girl_y - plane_y) * 1000 <= (plane_x - girl_x) * 267)//<345
					{
						return 36;
					}
					else if((girl_y - plane_y) * 1000 <= (plane_x - girl_x) * 466)//<335
					{
						return 35;
					}
					else if((girl_y - plane_y) * 1000 <= (plane_x - girl_x) * 700)//<325
					{
						return 34;
					}
					else if((girl_y - plane_y) * 1000 <= (plane_x - girl_x) * 1000)//<315
					{
						return 33;
					}
					else if((girl_y - plane_y) * 1000 <= (plane_x - girl_x) * 1428)//<305
					{
						return 32;
					}
					else if((girl_y - plane_y) * 1000 <= (plane_x - girl_x) * 2144)//<295
					{
						return 31;
					}
					else if((girl_y - plane_y) * 1000 <= (plane_x - girl_x) * 3732)//<285
					{
						return 30;
					}
					else if((girl_y - plane_y) * 1000 <= (plane_x - girl_x) * 11430)//<275
					{
						return 29;
					}
				}
			}
			return 0;
		}
	}
	private void stop_png(Graphics g)
	{
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));
		g.setClip(0, 74, 176, 60);
		g.setColor(0, 0, 0);
		g.fillRect(0, 74, 176, 134);
		g.setColor(255, 255, 255);
		g.drawString("是否退出", 59, 74, G_TL);
		g.drawString("是", 0, 116, G_TL);
		g.drawString("否", 163, 116, G_TL);
	}
	private void game_png(Graphics g)
	{
		switch(i_game)
		{
			case 0:
				paint_png(g, game_0, 0, 0, 1, 0, 1, 0);
				break;
			case 1:
				paint_png(g, game_1, 0, 0, 1, 0, 1, 0);
				break;
			case 2:
				paint_png(g, game_2, 0, 0, 1, 0, 1, 0);
				break;
			case 3:
				paint_png(g, game_3, 0, 0, 1, 0, 1, 0);
				break;
			case 4:
				paint_png(g, game_4, 0, 0, 1, 0, 1, 0);
				break;
		}
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
		g.setClip(0, 0, 176, 208);
		g.setColor(0, 0, 0);
		g.drawString("OK", 4, 208 - 16, G_TL);
		g.drawString("BREAK", 176 - g.getFont().stringWidth("BREAK") - 4, 208 - 16, G_TL);
	}
	private void apropos_png(Graphics g)
	{
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
		g.setClip(0, 0, 176, 208);
		g.setColor(0, 0, 0);
		g.fillRect(0, 0, 176, 208);
		g.setColor(255, 255, 255);
		g.drawString("Company home page :", 176 / 2 - g.getFont().stringWidth("Company home page :") / 2, 10, G_TL);
		g.drawString("http://www.sygamepx.com", 176 / 2 - g.getFont().stringWidth("http://www.sygamepx.com") / 2, 30, G_TL);
		g.drawString("Game Design :  YQ", 176 / 2 - g.getFont().stringWidth("Game Design :  YQ") / 2, 50, G_TL);
		g.drawString("Game Development :  YQ", 176 / 2 - g.getFont().stringWidth("Game Development :  YQ") / 2, 70, G_TL);
		g.drawString("QQ:  123357690", 176 / 2 - g.getFont().stringWidth("QQ:  123357690") / 2, 90, G_TL);
		g.drawString("BREAK", 176 - g.getFont().stringWidth("BREAK") - 4, 208 - 16, G_TL);
	}
	private void help_png(Graphics g)
	{
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
		g.setClip(0, 0, 176, 208);
		g.setColor(0, 0, 0);
		g.fillRect(0, 0, 176, 208);
		g.setColor(255, 255, 255);
		g.drawString("2:    上", 176 / 2 - g.getFont().stringWidth("8:    DOWN") / 2, 15, G_TL);
		g.drawString("8:    下", 176 / 2 - g.getFont().stringWidth("8:    DOWN") / 2, 35, G_TL);
		g.drawString("4:    左", 176 / 2 - g.getFont().stringWidth("8:    DOWN") / 2, 55, G_TL);
		g.drawString("6:    右", 176 / 2 - g.getFont().stringWidth("8:    DOWN") / 2, 75, G_TL);
		g.drawString("5:    BOMB", 176 / 2 - g.getFont().stringWidth("8:    DOWN") / 2, 95, G_TL);
		g.drawString("0:    蓄力", 176 / 2 - g.getFont().stringWidth("8:    DOWN") / 2, 115, G_TL);
		g.drawString("BREAK", 176 - g.getFont().stringWidth("BREAK") - 4, 208 - 16, G_TL);
	}
	private void title_png(Graphics g)
	{
		paint_png(g, title_a, 0, 0, 1, 0, 1, 0);
		paint_png(g, title_b, 61, 189, 1, 0, 7, i_title);
		if(i_quanju % 2 == 0)
		{
			paint_png(g, title_c, 49, 189, 2, 0, 1, 0);
			paint_png(g, title_c, 118, 189, 2, 1, 1, 0);
		}
	}
	private void logo_png(Graphics g)
	{
		g.setClip(0, 0, 176, 208);
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, 176, 208);
		g.setClip((176 - logo.getWidth()) / 2, (208 - logo.getHeight()) / 2, logo.getWidth(), logo.getHeight());
		g.drawImage(logo, 176 / 2, 208 / 2, G_HV);
	}
	private void paint_png(Graphics g, Image img, int x, int y, int i_tux, int i_x, int i_tuy, int i_y)
	{
		int w = img.getWidth();
		int h = img.getHeight();
		g.setClip(x, y, w / i_tux, h / i_tuy);
		g.drawImage(img, x - i_x * w / i_tux, y - i_y * h / i_tuy, G_TL);
	}
	private void shifang(int ss_pp)
	{
		switch(ss_pp)
		{
			case LOGO:
				if(logo != null)					logo = null;
				break;
			case TITLE:
				if(title_a != null)					title_a = null;
				if(title_b != null)					title_b = null;
				if(title_c != null)					title_c = null;
				break;
			case HELP:
				break;
			case APROPOS:
				break;
			case GAME:
				if(game_0 != null)					game_0 = null;
				if(game_1 != null)					game_1 = null;
				if(game_2 != null)					game_2 = null;
				if(game_3 != null)					game_3 = null;
				if(game_4 != null)					game_4 = null;
				break;
			case START:
				if(map_0 != null)					map_0 = null;
				if(boss_0 != null)					boss_0 = null;
				if(boss_1 != null)					boss_1 = null;
				if(map_1 != null)					map_1 = null;
				if(map_2 != null)					map_2 = null;
				if(map_3 != null)					map_3 = null;
				if(girl_png != null)				girl_png = null;
				if(girl_baozha != null)				girl_baozha = null;
				if(girl_zidan_png_0 != null)		girl_zidan_png_0 = null;
				if(girl_zidan_png_1 != null)		girl_zidan_png_1 = null;
				if(girl_zidan_png_2 != null)		girl_zidan_png_2 = null;
				if(girl_zidan_png_3 != null)		girl_zidan_png_3 = null;
				if(girl_zidan_png_4 != null)		girl_zidan_png_4 = null;
				if(bomb_0 != null)					bomb_0 = null;
				if(bomb_1 != null)					bomb_1 = null;
				if(bomb_2 != null)					bomb_2 = null;
				if(bomb_3 != null)					bomb_3 = null;
				if(girl_girl_png != null)			girl_girl_png = null;
				if(girl_bomb_png != null)			girl_bomb_png = null;
				if(plane_0 != null)					plane_0 = null;
				if(plane_1 != null)					plane_1 = null;
				if(plane_2 != null)					plane_2 = null;
				if(plane_3 != null)					plane_3 = null;
				if(plane_4 != null)					plane_4 = null;
				if(plane_5 != null)					plane_5 = null;
				if(plane_6 != null)					plane_6 = null;
				if(plane_7 != null)					plane_7 = null;
				if(plane_8 != null)					plane_8 = null;
				if(plane_baozha != null)			plane_baozha = null;
				if(plane_zidan_0 != null)			plane_zidan_0 = null;
				if(plane_zidan_1 != null)			plane_zidan_1 = null;
				if(plane_zidan_2 != null)			plane_zidan_2 = null;
				if(p_png != null)					p_png = null;
				if(b_png != null)					b_png = null;
				break;
			case STOP:
				break;
			case OVER:
				if(player != null);					player = null;
				break;
		}
	}
	private void init_midi()
	{
		try
		{
			InputStream in = getClass().getResourceAsStream("/midi/midi.mid");
			player = Manager.createPlayer(in, "audio/midi");
			player.setLoopCount(-1);
		}
		catch (Exception e)	{System.out.println("init_midi");} 
	}
	private void init_img(int ss_pp)
	{
		switch(ss_pp)
		{	
			case LOGO:
				try
				{
					if(logo == null)		logo = Image.createImage("/img/logo.png");
				}
				catch (Exception e)	{System.out.println("LOGO_PNG");}
				break;
			case TITLE:
				try
				{
					if(title_a == null)		title_a = Image.createImage("/img/title_a.png");
					if(title_b == null)		title_b = Image.createImage("/img/title_b.png");
					if(title_c == null)		title_c = Image.createImage("/img/title_c.png");
				}
				catch (Exception e)	{System.out.println("TITLE_PNG");}
				break;
			case HELP:
				break;
			case APROPOS:
				break;
			case GAME:
				try
				{
					switch(i_game)
					{
						case 0:
							if(game_0 == null)			game_0 = Image.createImage("/img/game_0.png");
							break;
						case 1:
							if(game_1 == null)			game_1 = Image.createImage("/img/game_1.png");
							break;
						case 2:
							if(game_2 == null)			game_2 = Image.createImage("/img/game_2.png");
							break;
						case 3:
							if(game_3 == null)			game_3 = Image.createImage("/img/game_3.png");
							break;
						case 4:
							if(game_4 == null)			game_4 = Image.createImage("/img/game_4.png");
							break;
					}
				}
				catch (Exception e)	{System.out.println("GAME_PNG");}
				break;
			case START:
				try
				{
					switch(i_guan)
					{
						case 0:
							if(map_0 == null)			map_0 = Image.createImage("/img/map_0.png");
							if(boss_0 == null)			boss_0 = Image.createImage("/img/boss_0.png");
							if(boss_1 == null)			boss_1 = Image.createImage("/img/boss_1.png");
							break;
						case 1:
							if(map_1 == null)			map_1 = Image.createImage("/img/map_1.png");
							break;
						case 2:
							if(map_2 == null)			map_2 = Image.createImage("/img/map_2.png");
							break;
						case 3:
							if(map_3 == null)			map_3 = Image.createImage("/img/map_3.png");
							break;
					}
					if(girl_png == null)				girl_png = Image.createImage("/img/girl.png");
					if(girl_baozha == null)				girl_baozha = Image.createImage("/img/girl_baozha.png");
					if(girl_zidan_png_0 == null)		girl_zidan_png_0 = Image.createImage("/img/girl_zidan_0.png");
					if(girl_zidan_png_1 == null)		girl_zidan_png_1 = Image.createImage("/img/girl_zidan_1.

⌨️ 快捷键说明

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