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

📄 ball.java

📁 简单的弹球游戏,java编写,可设置,好玩,比传统的弹球更刺激,更赋有挑战性
💻 JAVA
字号:
/**
 * @(#) Ball.java 2007-12-31 
 * 
 * Copyright© 2007 Jeff. 该源代码遵循BSD开源协议。 
 */
package joj.thread.swing.bounce;

import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;

public class Ball {
	
	private double left = 0;
	private double top = 0;
	private double width = 15;
	private double height = 15;
	private double dx = 5;
	private double dy = 5;

	public Shape getShape() {
		return new Ellipse2D.Double(left, top, width, height);
	}

	public void move(Rectangle2D bounds) {
		left += dx;
		top += dy;

		if (left < bounds.getMinX()) {
			left = bounds.getMinX();
			dx = -dx;
		}
		
		if (left + width > bounds.getMaxX()) {
			left = bounds.getMaxX() - width;
			dx = -dx;
		}		

		if (top < bounds.getMinY()) {
			top = bounds.getMinY();
			dy = -dy;
		}

		if (top + height > bounds.getMaxY()) {
			top = bounds.getMaxY() - height;
			dy = -dy;
		}

	}
}

⌨️ 快捷键说明

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