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

📄 ball.java

📁 不但实现了所有的游戏功能
💻 JAVA
字号:

import java.awt.Color;

import acm.graphics.GOval;
import acm.graphics.GPoint;
import acm.util.*;

public class Ball extends GOval{
	/** Radius of the ball in pixels */
	private static final int BALL_RADIUS = 10;
	private double vx, vy;
	
	public double getVx() {
		return vx;
	}

	public void setVx(double vx) {
		this.vx = vx;
	}

	public double getVy() {
		return vy;
	}

	public void setVy(double vy) {
		this.vy = vy;
	}

	public Ball() {
		super(BALL_RADIUS, BALL_RADIUS);
		this.setFilled(true);
		this.setFillColor(Color.RED);
		setOV();
		
	}
	
	/**
	 * set original velocity of the ball
	 *
	 */
	public void setOV(){
		vy = -1.0;
		setRandomVx();
		
	}
	
	public void setRandomVx(){
		vx = rgen.nextDouble(0.3, 0.5);
		if(rgen.nextBoolean(0.5)) vx = -vx;
	}
	
	public GPoint getRightUpPoint(){
		return new GPoint((this.getX() + this.getWidth()), this.getY());
	}
	
	public GPoint getLeftLowerPoint(){
		return new GPoint(this.getX(), (this.getY() + this.getHeight()));
	}
	
	public GPoint getRightLowerPoint(){
		return new GPoint( (this.getX() + this.getWidth()), (this.getY() + this.getHeight()) );
	}

	private RandomGenerator rgen = RandomGenerator.getInstance();

}

⌨️ 快捷键说明

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