我正在编织辫子。我有一个类Wall
,可以防止物体进入墙壁。 所有与Wall
正在工作。但现在我正在试图使天花板一样。 我的吊顶等级延伸Wall
。我只是做了一个构造函数是这样的:扩展类的问题
public Ceiling(boolean deadly, int[] xPositions, int[] yPositions)
{
super(deadly,
Direction.Down, //Enum: the direction you have to leave the wall (Left, Right)
//Here of course down
xPositions, yPositions);
}
现在,我有我的级别类中的所有墙壁的ArrayList
和所有的天花板的ArrayList
。 我要补充的墙壁上是这样的:
walls.add(new Wall(false, Direction.Right, ..., ...));
而且天花板上是这样的:
ceilings.add(new Ceiling(false, ..., ...));
的...
取代的坐标。
如果我检查天花板上是否有物体:什么也没有发生:物体穿过天花板。如果我用这种方式来添加一个天花板,它的工作原理:
ceilings.add(new Wall(false, Direction.Down, ..., ...));
我希望我已经很好地解释。 有人知道问题是什么吗?
感谢
编辑:
这是我的collition代码:
public boolean intersects(Rectangle r)
{
if (!bounds.intersects(r))
{
return false;
}
for (int i = 1; i < yPositions.length; i++) {
Line l = new Line(xPositions[i - 1], yPositions[i - 1], xPositions[i], yPositions[i]);
if (r.intersectsLine(l)) {
return true;
}
}
return false;
}
我的代码
'
doodelijk
' 是指致命
华尔街:
package levels;
import domein.Direction;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
public class Wall
{
public boolean doodelijk;
public int[] yPositions;
public int[] xPositions;
private Rectangle bounds;
public Direction directionToLeave;
public Wall(boolean doodelijk, Direction directionToLeave, int[] yPositions, int[] xPositions)
{
this.doodelijk = doodelijk;
this.yPositions = yPositions;
this.xPositions = xPositions;
this.directionToLeave = directionToLeave;
createRectangle();
}
public boolean intersects(Rectangle r)
{
if (!bounds.intersects(r))
{
return false;
}
for (int i = 1; i < yPositions.length; i++) {
Line l = new Line(xPositions[i - 1], yPositions[i - 1], xPositions[i], yPositions[i]);
if (r.intersectsLine(l)) {
return true;
}
}
return false;
}
private void createRectangle()
{
int x = Integer.MAX_VALUE;
int y = Integer.MAX_VALUE;
int x1 = 0;
int y1 = 0;
for (int i = 0; i < xPositions.length; i++)
{
int tx = xPositions[i];
int ty = yPositions[i];
if (x > tx)
{
x = tx;
}
if (y > ty)
{
y = ty;
}
if (x1 < tx)
{
x1 = tx;
}
if (y1 < ty)
{
y1 = ty;
}
}
bounds = new Rectangle(x, y, x1 - x + 1, y1 - y +1);
System.out.println("Rect: " + bounds);
}
class Line extends Line2D
{
Point2D p1;
Point2D p2;
public Line()
{
p1 = new Point();
p2 = new Point();
}
public Line(Point2D p1, Point2D p2)
{
this.p1 = p1;
this.p2 = p2;
}
public Line(double X1, double Y1, double X2, double Y2)
{
this();
setLine(X1, Y1, X2, Y2);
}
@Override
public double getX1()
{
return p1.getX();
}
@Override
public double getY1()
{
return p1.getY();
}
@Override
public Point2D getP1()
{
return p1;
}
@Override
public double getX2()
{
return p2.getX();
}
@Override
public double getY2()
{
return p2.getY();
}
@Override
public Point2D getP2()
{
return p2;
}
@Override
public void setLine(double X1, double Y1, double X2, double Y2)
{
p1.setLocation(X1, Y1);
p2.setLocation(X2, Y2);
}
public Rectangle2D getBounds2D()
{
return new Rectangle((int) getX1(), (int) getY1(), (int) (getX2() - getX1()), (int) (getX2() - getY1()));
}
}
public void setXpositions(int ... xPos)
{
this.xPositions = xPos;
}
public void setYpositions(int ... yPos)
{
this.yPositions = yPos;
}
public void setPositions(int[] yPos, int[] xPos)
{
setXpositions(xPos);
setYpositions(yPos);
}
}
天花板:
package levels;
import domein.Direction;
public class Ceiling extends Wall
{
public Ceiling(boolean doodelijk, int[] xPositions, int[] yPositions)
{
super(doodelijk, Direction.Down, yPositions, xPositions);
}
}
你正在编织?最后我检查Braid已经制作并发布。我找不到任何提及制作Braid的参考资料? – 2009-08-31 12:12:07
呃,究竟是什么问题? – 2009-08-31 12:13:56
那么你的问题究竟是什么?如何在类Ceiling中调用超类构造函数?没有看到你的代码的其余部分,很难告诉你什么是错的。在IDE中运行代码(例如Eclipse或NetBeans),并使用调试器遍历代码,逐行执行程序运行时发生的情况。 – Jesper 2009-08-31 12:16:49