1
0
Fork 0

Breakout Aufgabe 1.6 - Comments

This commit is contained in:
rxbn 2019-11-19 15:06:25 +01:00
parent 82987f4710
commit b0ac626407
5 changed files with 17 additions and 14 deletions

View File

@ -6,6 +6,7 @@ import break_out.Constants;
* This class contains the information about the balls characteristics and behavior * This class contains the information about the balls characteristics and behavior
* *
* @author iSchumacher * @author iSchumacher
* @author modified by 175
* *
*/ */
public class Ball implements IBall{ public class Ball implements IBall{
@ -51,31 +52,30 @@ public class Ball implements IBall{
} }
/** /**
* * updates ball position
*/ */
public void updatePosition() { public void updatePosition() {
// @rxbn, Ruben Meyer // sets X position
this.position.setX(this.position.getX()+this.direction.getDx()); this.position.setX(this.position.getX()+this.direction.getDx());
// sets Y position
this.position.setY(this.position.getY()+this.direction.getDy()); this.position.setY(this.position.getY()+this.direction.getDy());
} }
/** /**
* * Ball reacts to contact with the borders
*/ */
public void reactOnBorder() { public void reactOnBorder() {
// reacts on left border
// @rxbn, Ruben Meyer
// left border
if(this.position.getX() < 0) this.direction.setDx(-(this.direction.getDx())); if(this.position.getX() < 0) this.direction.setDx(-(this.direction.getDx()));
// right border // reacts on right border (+Diameter because of hitbox)
if(this.position.getX()+Constants.BALL_DIAMETER > Constants.SCREEN_WIDTH) this.direction.setDx(-(this.direction.getDx())); if(this.position.getX()+Constants.BALL_DIAMETER > Constants.SCREEN_WIDTH) this.direction.setDx(-(this.direction.getDx()));
// top border // reacts on top border
if(this.position.getY() < 0) this.direction.setDy(-(this.direction.getDy())); if(this.position.getY() < 0) this.direction.setDy(-(this.direction.getDy()));
// bottom border // reacts on bottom border (+Diameter because of hitbox)
if(this.position.getY()+Constants.BALL_DIAMETER > Constants.SCREEN_HEIGHT) this.direction.setDy(-(this.direction.getDy())); if(this.position.getY()+Constants.BALL_DIAMETER > Constants.SCREEN_HEIGHT) this.direction.setDy(-(this.direction.getDy()));
} }

View File

@ -6,6 +6,7 @@ package break_out.model;
* *
* @author dmlux * @author dmlux
* @author I. Schumacher * @author I. Schumacher
* @author modified by 175
*/ */
public class Level extends Thread { public class Level extends Thread {

View File

@ -7,6 +7,7 @@ import break_out.model.Position;
* This class represent a two dimensional vector. * This class represent a two dimensional vector.
* *
* @author I. Schumacher * @author I. Schumacher
* @author modified by 175
*/ */
public class Vector2D implements IVector2D { public class Vector2D implements IVector2D {
@ -67,11 +68,11 @@ public class Vector2D implements IVector2D {
this.dy = dy; this.dy = dy;
} }
/* /**
* Rescale part * Rescale part
*/ */
public void rescale() { public void rescale() {
// calc unit vector // calc unit vector and set it
double vectorlength = Math.sqrt(Math.pow(getDx(), 2) + Math.pow(getDy(), 2)); double vectorlength = Math.sqrt(Math.pow(getDx(), 2) + Math.pow(getDy(), 2));
setDx((1/vectorlength) * getDx() * Constants.BALL_SPEED); setDx((1/vectorlength) * getDx() * Constants.BALL_SPEED);
setDy((1/vectorlength) * getDy() * Constants.BALL_SPEED); setDy((1/vectorlength) * getDy() * Constants.BALL_SPEED);

View File

@ -15,7 +15,7 @@ import net.miginfocom.swing.MigLayout;
* The field represents the board of the game. All components are on the board * The field represents the board of the game. All components are on the board
* *
* @author dmlux, modified by iSchumacher * @author dmlux, modified by iSchumacher
* * @author modified by 175
*/ */
public class Field extends JPanel { public class Field extends JPanel {

View File

@ -12,6 +12,7 @@ import break_out.model.Game;
* gets the components from the game which is connected to this class * gets the components from the game which is connected to this class
* *
* @author dmlux * @author dmlux
* @author modified by 175
* *
*/ */
public class View extends JFrame { public class View extends JFrame {
@ -71,7 +72,7 @@ public class View extends JFrame {
setVisible(true); setVisible(true);
pack(); pack();
// hotfix: screen size // hotfix: zero-sized window size on linux
setMinimumSize(new Dimension(1, 1)); setMinimumSize(new Dimension(1, 1));
} }