Breakout Aufgabe 1.4
This commit is contained in:
parent
4baf5724eb
commit
f0c323beef
@ -27,6 +27,7 @@ public class Ball implements IBall{
|
|||||||
public Ball() {
|
public Ball() {
|
||||||
this.position = new Position(0, 0);
|
this.position = new Position(0, 0);
|
||||||
this.direction = new Vector2D(Constants.BALL_SPEED,Constants.BALL_SPEED);
|
this.direction = new Vector2D(Constants.BALL_SPEED,Constants.BALL_SPEED);
|
||||||
|
this.direction.rescale();
|
||||||
|
|
||||||
// start at bottom-center
|
// start at bottom-center
|
||||||
this.position.setX(Constants.SCREEN_WIDTH/2);
|
this.position.setX(Constants.SCREEN_WIDTH/2);
|
||||||
|
12
src/break_out/model/IVector2D.java
Normal file
12
src/break_out/model/IVector2D.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package break_out.model;
|
||||||
|
|
||||||
|
public interface IVector2D {
|
||||||
|
|
||||||
|
// Exercise 1
|
||||||
|
public double getDx();
|
||||||
|
public void setDx(double dx);
|
||||||
|
public double getDy();
|
||||||
|
public void setDy(double dy);
|
||||||
|
|
||||||
|
public void rescale();
|
||||||
|
}
|
@ -8,7 +8,7 @@ import break_out.model.Position;
|
|||||||
*
|
*
|
||||||
* @author I. Schumacher
|
* @author I. Schumacher
|
||||||
*/
|
*/
|
||||||
public class Vector2D {
|
public class Vector2D implements IVector2D {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x part of the vector
|
* The x part of the vector
|
||||||
@ -67,4 +67,13 @@ public class Vector2D {
|
|||||||
this.dy = dy;
|
this.dy = dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Rescale part
|
||||||
|
*/
|
||||||
|
public void rescale() {
|
||||||
|
// calc unit vector
|
||||||
|
double vectorlength = Math.sqrt(Math.pow(getDx(), 2) + Math.pow(getDy(), 2));
|
||||||
|
setDx((1/vectorlength) * getDx() * Constants.BALL_SPEED);
|
||||||
|
setDy((1/vectorlength) * getDy() * Constants.BALL_SPEED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user