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

📄 ball.java

📁 J2ME做的打砖块游戏,是学校的课程项目
💻 JAVA
字号:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Random;
public class Ball extends MoveObject
{
	private float right_r, left_r;

	private float acc_r = 0.5f;

	private RandomG randomG = new RandomG();

	private boolean collisioned;


	public Ball(String path, int x, int y, float vx, float vy, int type)
	{
		super(path, x, y, vx, vy, type);
	}

	
	public boolean CollisionWithObject(NormalObject ob)
	{
		float temp;
		collisioned = false;
     
		if ( (this.x + this.cx) > ob.x -3 && (this.x +this.cx) < ob.x+1)
		{
			if ((this.y + this.cy >= ob.y) && (this.y <= ob.y + ob.cy))
			{
		    	if (this.vx - ob.vx > 0.0f)
				{
					collisioned = true;
					this.vx = -1.0f * (this.vx - ob.vx);
					ob.vx = -0.4f * ob.vx;
			     }
			}
		}
		else  
			if (this.x < 3 + (ob.x + ob.cx) && this.x > (ob.x + ob.cx)-1)
			{
				if ((this.y + this.cy >= ob.y) && (this.y <= ob.y + ob.cy))
				{
					if (ob.vx - this.vx > 0.0f)
					{
						collisioned = true;
						this.vx = 1.0f * (ob.vx - this.vx);
						ob.vx = -0.4f * ob.vx;
					}
				}
			}
			else
				if ((this.y + this.cy)>(ob.y-2) &&  (this.y + this.cy)< ob.y  )
				{
					if ((this.x + this.cx >= ob.x) && (this.x <= ob.x + ob.cx))
					{
			  		   if (this.vy - ob.vy > 0.0f)
						{
							collisioned = true;
							this.vy = -1.0f * (this.vy - ob.vy);
							this.vx += ((float)(randomG.nextG(5) % 30 - 15)) / 80.0f;
							this.vx += ob.vx * 0.6;
						}
					}
				}
				else
					if (this.y < 2+(ob.y + ob.cy) && this.y >(ob.y + ob.cy))
					{
						if ((this.x + this.cx >= ob.x) && (this.x < ob.x + ob.cx))
						{
							if (ob.vy - this.vy > 0.0f)
							{
								collisioned = true;
								this.vy = 1.0f * (ob.vy - this.vy);
								this.vx += ((float)(randomG.nextG(5) % 30 - 15)) / 80.0f;
								this.vx += ob.vx * 0.6;
							}
						}
					}
		return collisioned;
	}

	public void generateMove()
	{
		if ((vx - (int)vx) > 0.5f)
			x += ((int)vx + 1);
		else
			x += (int)vx;

		if ((vy - (int)vy) > 0.5f)
			y += ((int)vy + 1);
		else
			y += (int)vy;
	}


}

⌨️ 快捷键说明

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