资源简介
打砖块JAVA游戏代码。可以运行的。。。。。
代码片段和文件信息
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
/*
* To change this template choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Administrator
*/
public class ball {
private Point location;
private Point bound;
private int diameter;
private int dx;
private int dy;
private gamePanel gameP;
private block blk;
private pad pd;
private boolean padCanBounce = false;
public static int nt=0;
public static int[] mt=new int[]{};
public ball(gamePanel gp pad p block bk) {
gameP = gp;
blk = bk;
pd = p;
diameter = 20;
location = new Point(pd.location.x + (pd.size.x - diameter) / 2 pd.location.y - pd.size.y);
dx = 5;
dy = -5;
bound = new Point(gp.width gp.heigth);
}
@SuppressWarnings(“empty-statement“)
public void move() {
if (gameP.ballMove) {
location.x += dx;
location.y += dy;
wallBounced();
blockBounced();
padBounced();
} else {
location.setLocation(pd.location.x + (pd.size.x - diameter) / 2 pd.location.y - pd.size.y);
}
}
public void draw(Graphics g) {
g.setColor(Color.blue);
g.fillOval(location.x location.y diameter diameter);
}
public boolean Bounce(Point bk_location Point bk_size) {
// if (((location.x > bk_location.x - diameter / 2) && (location.x < bk_location.x + bk_size.x - diameter / 2) && (location.y < bk_location.y + bk_size.y) && (location.y > bk_location.y - diameter)) || ((location.y > bk_location.y - diameter / 2) && (location.y < bk_size.y - diameter / 2) && (location.x > bk_location.x - diameter) && (location.x < bk_location.x + bk_size.x))) {
if ((location.x > bk_location.x - diameter) && (location.x < bk_location.x + bk_size.x) && (location.y > bk_location.y - diameter) && (location.y < bk_location.y + bk_size.y)) {
// gamePanel.fen+=10;
return true;
} else {
return false;
}
}
public void wallBounced() {
if ((location.x > bound.x - diameter) || (location.x < 0)) {
dx = -dx;
padCanBounce = true;
}
if (location.y < 0) {
dy = -dy;
}
if (location.y > bound.y) {
dy = -dy;
gameP.ballMove = false;
nt+=1;
// }
}
}
public void blockBounced() {
Point local1 local2 local3 size1 size2 size3;
for (int i = 0; i < block.num; i++) {
local2 = new Point(blk.location[i].x + blk.size.x * 9 / 10 blk.location[i].y);
size2 = new Point(blk.size.x * 1 / 10 blk.size.y);
local1 = blk.location[i];
size1 = new Point(blk.size.x * 1 / 10 blk.size.y);
local3 = new Point(blk.location[i].x + blk.size.x * 1 / 10 blk.location[i].y);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5087 2009-06-07 14:23 Java试验二\ball.java
文件 1350 2009-06-07 14:28 Java试验二\block.java
文件 913 2009-06-07 14:23 Java试验二\Gamefr
文件 5291 2009-06-07 14:51 Java试验二\gamePanel.java
文件 13796 2009-06-07 14:53 Java试验二\JavaProject15.jar
文件 286 2009-06-07 14:18 Java试验二\MathRondom.java
文件 1010 2009-04-03 11:30 Java试验二\pad.java
文件 54 2009-06-07 14:57 Java试验二\一些问题.txt
目录 0 2009-06-07 14:55 Java试验二
----------- --------- ---------- ----- ----
27787 9
评论
共有 条评论