1
0
Fork 0

Breakout Aufgabe 1.4

This commit is contained in:
rxbn 2019-11-19 14:11:56 +01:00
parent 4baf5724eb
commit f0c323beef
3 changed files with 23 additions and 1 deletions

View File

@ -27,6 +27,7 @@ public class Ball implements IBall{
public Ball() {
this.position = new Position(0, 0);
this.direction = new Vector2D(Constants.BALL_SPEED,Constants.BALL_SPEED);
this.direction.rescale();
// start at bottom-center
this.position.setX(Constants.SCREEN_WIDTH/2);

View 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();
}

View File

@ -8,7 +8,7 @@ import break_out.model.Position;
*
* @author I. Schumacher
*/
public class Vector2D {
public class Vector2D implements IVector2D {
/**
* The x part of the vector
@ -67,4 +67,13 @@ public class Vector2D {
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);
}
}