Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Aufgabe8/build/built-jar.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Wed, 10 Jan 2018 13:33:12 +0100


/home/hannes/Netbeans/Semester\ 2/Softwareprojekt/Aufgabe8=
#Wed, 10 Jan 2018 21:13:24 +0100
C\:\\Users\\DanielHirsch\\Desktop\\Student\\Aufgabe8=
Binary file added Aufgabe8/build/classes/heart2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Aufgabe8/build/classes/simplePong/SimpleEngine$Court.class
Binary file not shown.
Binary file modified Aufgabe8/build/classes/simplePong/SimpleEngine$Game.class
Binary file not shown.
Binary file modified Aufgabe8/build/classes/simplePong/SimpleEngine.class
Binary file not shown.
Binary file modified Aufgabe8/build/classes/simplePong/SimpleMain.class
Binary file not shown.
Binary file modified Aufgabe8/build/classes/simplePong/SimplePanel$1.class
Binary file not shown.
Binary file modified Aufgabe8/build/classes/simplePong/SimplePanel$2.class
Binary file not shown.
Binary file modified Aufgabe8/build/classes/simplePong/SimplePanel$3.class
Binary file not shown.
Binary file modified Aufgabe8/build/classes/simplePong/SimplePanel.class
Binary file not shown.
Binary file modified Aufgabe8/dist/Aufgabe8.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion Aufgabe8/nbproject/private/private.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
user.properties.file=/home/hannes/.netbeans/8.1/build.properties
user.properties.file=C:\\Users\\DanielHirsch\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
22 changes: 11 additions & 11 deletions Aufgabe8/nbproject/private/private.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/hannes/Netbeans/Semester%202/Softwareprojekt/Aufgabe8/src/simplePong/SimpleMain.java</file>
<file>file:/home/hannes/Netbeans/Semester%202/Softwareprojekt/Aufgabe8/src/simplePong/SimplePanel.java</file>
<file>file:/home/hannes/Netbeans/Semester%202/Softwareprojekt/Aufgabe8/src/simplePong/SimpleEngine.java</file>
</group>
</open-files>
</project-private>
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/DanielHirsch/Desktop/Student/Aufgabe8/src/simplePong/SimpleEngine.java</file>
<file>file:/C:/Users/DanielHirsch/Desktop/Student/Aufgabe8/src/simplePong/SimpleMain.java</file>
<file>file:/C:/Users/DanielHirsch/Desktop/Student/Aufgabe8/src/simplePong/SimplePanel.java</file>
</group>
</open-files>
</project-private>
Binary file added Aufgabe8/src/heart2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 32 additions & 48 deletions Aufgabe8/src/simplePong/SimpleEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public Game(Point2D.Float polyCenter) {
this.puckSpeed = 1;
speedUp = 1;
this.paddlePosition = 165;
//this.puckSpeed = (oldPosition - paddlePosition) / (oldTimestamp - paddleTimestamp);

}
}

Expand All @@ -50,12 +48,9 @@ private Court() {

// Roughly 18 lines of implementation
this.polyCenter = new Point2D.Float(200, 200);
Game g = new Game(polyCenter);

this.drawRectangle = new Rectangle2D.Float(0, 0, 200, 200);
this.rectCenter = new Point2D.Float(drawRectangle.width / 2, drawRectangle.height / 2);
this.gamePath = new Path2D.Float(drawRectangle);
System.out.println(gamePath.getBounds2D());

}
}
Expand All @@ -64,12 +59,13 @@ private Court() {
public static final int RACKETQUOTE = 70;
public static final int SQUARE_SIZE = 400;
public static final int BORDER = 4;
public static final int LINEWIDTH = 2;
public static final int LINEWIDTH = 7;
public static final float PI = 3.141593f;
public static final int RACKETSPEED = 2;
public static boolean first = true;
public int xTemp = (int) (Math.random() * 5) * ((Math.random() > 0.49) ? 1 : -1);
public int yTemp = (int) (Math.random() * 5) * ((Math.random() > 0.49) ? 1 : -1);
public int leben;
public float velX = xTemp / sqrt((xTemp * xTemp) + (yTemp * yTemp));
public float velY = yTemp / sqrt((xTemp * xTemp) + (yTemp * yTemp));
public int betrag = (int) ((velX * velX) + (velY * velY));
Expand All @@ -80,6 +76,7 @@ public SimpleEngine() {
// Roughly 2 lines of implementation
this.court = new Court();
this.game = new Game(this.court.polyCenter);
this.leben = 3;
}

private float sin(float angle) {
Expand All @@ -104,7 +101,7 @@ private float sqrt(float x) {

private float random() {
// Roughly 1 lines of implementation
return (float) Math.random();
return (float) Math.random() * 3 - 2;
}

private float round(float angle) {
Expand All @@ -114,7 +111,7 @@ private float round(float angle) {

private float toDegrees(float angle) {
// Roughly 1 lines of implementation
return (float) (180 / PI) * angle;
return (float) Math.toDegrees(angle);
}

public void speedUp(float speedUp) {
Expand All @@ -124,12 +121,18 @@ public void speedUp(float speedUp) {

public void step(int id) {
// Roughly 45 lines of implementation
//initialize again if Lifes are left
if (first) {
game.puckPoint.x += Math.random() * 2;
game.puckPoint.y += Math.random() * 2;
game.puckPoint.x = 200;
game.puckPoint.y = 200;
xTemp = (int) random();
yTemp = (int) random();
first = false;
}

float puckY = getPuck().y;
float puckX = getPuck().x;
Point[] racket = getRacket();
//turn Polygon int 2 Border Lines, Left and Right
int minX = getPolygon().getBounds().x;
int minY = getPolygon().getBounds().y;
int height = getPolygon().getBounds().height + minX;
Expand All @@ -139,30 +142,30 @@ public void step(int id) {
Point leftU = new Point(minX, height);
Line2D left = new Line2D.Float(midO, leftU);
Line2D right = new Line2D.Float(midO, rightU);
// System.out.println(getPolygon().getBounds());

//
float puckY = getPuck().y;
float puckX = getPuck().x;
if (puckY + BALLSIZE >= getRacket()[0].y) {
if (puckX + BALLSIZE >= getRacket()[0].x && puckX <= getRacket()[0].x + RACKETQUOTE) {
Line2D racketline = new Line2D.Float(new Point(racket[0].x - RACKETSPEED, racket[0].y), new Point(racket[racket.length - 1].x + RACKETSPEED, racket[racket.length - 1].y));
Line2D puckLine = new Line2D.Float(getPuck(), new Point.Float(puckX + velX + BALLSIZE, puckY + velY + BALLSIZE));

//if puck on Racket then it is reflected
if (puckY + BALLSIZE >= racket[0].y) {
if (puckX + BALLSIZE >= racket[0].x && puckX <= racket[0].x + RACKETQUOTE) {
velY = -velY;
}
}

if (puckY < 0) {
velY = -velY;
}

if (puckY + BALLSIZE >= getDrawRectangle().height) {
System.out.println("vorbei");
// JOptionPane.showMessageDialog(null, "You failed");
System.exit(0);
//if puckpoint under the racket than loses one life or Game Over
if (puckY + BALLSIZE >= racket[0].y + LINEWIDTH) {
if (leben > 0) {
leben--;
first = true;
} else {
JOptionPane.showMessageDialog(null, "GAME OVER!");
System.exit(0);
}
}

Line2D puckLine = new Line2D.Float(getPuck(), new Point.Float(puckX + velX + BALLSIZE, puckY + velY + BALLSIZE));
//if intersects right Bound of Polygon
if (puckLine.intersectsLine(right)) {
game.puckPoint.x -= 5;
float xDifferenz = (float) (right.getX2() - right.getX1());
float yDifferenz = (float) (right.getY2() - right.getY1());

Expand All @@ -185,7 +188,6 @@ public void step(int id) {
float intersectDegree = toDegrees((float) Math.acos((dotProduct) / (normRight * normPuck)));

float newDegree;
// float outputIncline = 1f;

if (intersectDegree < 90) {
newDegree = puckDegree + 2 * intersectDegree;
Expand All @@ -207,17 +209,14 @@ public void step(int id) {
newY = -outputIncline;
}

// outputIncline *= (float) Math.tan((newDegree * Math.PI) / 180);
// float newY = -outputIncline;
float newX = -1f;
float betrag = sqrt((newY * newY) + (newX * newX));
velX = newX / betrag;
velY = newY / betrag;
;
}

//if intersects Left Bound of Polygon
if (puckLine.intersectsLine(left)) {
game.puckPoint.x += 5;
float xDifferenz = (float) (left.getX2() - left.getX1());
float yDifferenz = (float) (left.getY2() - left.getY1());
float[] vectorLeft = {xDifferenz, yDifferenz};
Expand Down Expand Up @@ -261,33 +260,21 @@ public void step(int id) {
newY = -outputIncline;
}

// outputIncline *= (float) Math.tan((newDegree * Math.PI) / 180);
// float newY = -outputIncline;
float newX = 1f;
float betrag = sqrt((newY * newY) + (newX * newX));
velX = newX / betrag;
velY = newY / betrag;
;
}

//change Puck in Game
game.puckPoint.x += velX;
game.puckPoint.y += velY;

Point[] racket = getRacket();

//racket um Racketspeed größer da sonst aus dem Fenster
Line2D racketline = new Line2D.Float(new Point(racket[0].x - RACKETSPEED, racket[0].y), new Point(racket[racket.length - 1].x + RACKETSPEED, racket[racket.length - 1].y));
//Polygon Linien

//Rectangle r = new Rectangle(racket[0].x, racket[0].y, RACKETQUOTE , 10);
// if(getPolygon().intersects(r))
//if KeyListener gets Left or Right Key than Racket moves
if (id == KeyEvent.VK_RIGHT) {
// if(game.paddlePosition < this.getBorderPoint(350).x) {
if (!racketline.intersectsLine(right)) {
game.paddlePosition += RACKETSPEED;
}
// }
} else if (id == KeyEvent.VK_LEFT) {
if (!racketline.intersectsLine(left)) {
game.paddlePosition -= RACKETSPEED;
Expand Down Expand Up @@ -326,8 +313,6 @@ public Point.Float getPuck() {

public Point[] getBorderLine(int i) {
// Roughly 2 lines of implementation
// Point[] p = getPolygon();
// return new Point[i];
Polygon p = getPolygon();
throw new UnsupportedOperationException("Not yet implemented");
}
Expand All @@ -353,7 +338,6 @@ public void setPosition(float position) {

public Point getBorderPoint(int i) {
// Roughly 5 lines of implementation

throw new UnsupportedOperationException("Not yet implemented");
}

Expand Down
5 changes: 0 additions & 5 deletions Aufgabe8/src/simplePong/SimpleMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ public void run() {
};

SwingUtilities.invokeLater(r);






}
}
Expand Down
36 changes: 27 additions & 9 deletions Aufgabe8/src/simplePong/SimplePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.Timer;

/**
*
* @author Peter Heusch
*/
public class SimplePanel extends javax.swing.JPanel implements KeyListener {
public class SimplePanel extends javax.swing.JPanel implements KeyListener {

public final static int LINEGAP = 4;
public final static float PI = (float) Math.PI;
Expand All @@ -25,20 +30,26 @@ public class SimplePanel extends javax.swing.JPanel implements KeyListener {
private Rectangle drawRect;
private SimpleEngine engine;
public int id;
private BufferedImage image;

/**
* Creates new form MasterPanel
*/
public SimplePanel() {
initComponents();
try {
image = ImageIO.read(getClass().getResourceAsStream("/heart2.png"));
} catch (IOException ex) {
Logger.getLogger(SimplePanel.class.getName()).log(Level.SEVERE, null, ex);
}
engine = new SimpleEngine();
Timer t = new Timer(5, (evt) -> {
engine.step(id);
repaint();
});
t.start();
setFocusable(true);

}

/**
Expand Down Expand Up @@ -86,31 +97,38 @@ private void initScaling() {
public void paintComponent(Graphics gc) {
super.paintComponent(gc);
Graphics2D g2d = (Graphics2D) gc;

Rectangle rcBounds = this.getBounds();
Polygon poly = engine.getPolygon();
Point[] racket = engine.getRacket();

//draw poly
g2d.setStroke(new BasicStroke(4.5f));
g2d.setColor(new Color(169, 169, 169));
g2d.fill(poly);
g2d.draw(poly);

//Puck
//draw Puck
g2d.setColor(Color.WHITE);
Ellipse2D.Double circle = new Ellipse2D.Double(engine.getPuck().x, engine.getPuck().y, SimpleEngine.BALLSIZE, SimpleEngine.BALLSIZE);
g2d.fill(circle);

//Racket
//draw Racket
g2d.setColor(Color.BLACK);
Point[] racket = engine.getRacket();
g2d.setStroke(new BasicStroke(4.5f));
g2d.drawLine(racket[0].x, racket[0].y, racket[racket.length - 1].x, racket[racket.length - 1].y);


}
//draw Lifes
String lifes = "Lifes: ";
g2d.drawString(lifes, rcBounds.width - 80, 30);
for (int i = 0; i < engine.leben; i++) {
g2d.drawImage(image, rcBounds.width - (50 - 15 * i), 17, 15, 15, null);
}

}

@Override
public void keyTyped(KeyEvent ke) {}
public void keyTyped(KeyEvent ke) {
}

@Override
public void keyPressed(KeyEvent ke) {
Expand Down