Code cleanup and some improvements

This commit is contained in:
jancoow
2015-05-28 12:25:42 +02:00
parent fab4ac6ce7
commit ea6895c6c1
6 changed files with 49 additions and 66 deletions
+20 -21
View File
@@ -7,8 +7,7 @@ import java.awt.geom.Line2D;
public class Bullet extends DrawObject {
private double speed,lengthOfBullet;
public Line2D bullet;
private Line2D bullet;
private Color c;
public Bullet(double speed,Color c,double lengthOfBullet,int index,Line2D path) {
@@ -16,12 +15,11 @@ public class Bullet extends DrawObject {
this.speed = speed;
this.lengthOfBullet = lengthOfBullet;
this.c = c;
double beginX,beginY,endX,endY;
beginX = path.getX2();
beginY = path.getY2();
endX = beginX;
endY = beginY;
double beginX = path.getX2();
double beginY = path.getY2();
double endX = beginX;
double endY = beginY;
//the 8 richtingen van de octagon
switch(index){
@@ -55,9 +53,6 @@ public class Bullet extends DrawObject {
break;
}
bullet = new Line2D.Double(beginX, beginY, endX, endY);
// System.out.println("Index: "+index);
// System.out.println("X difference: "+(bullet.getX2()-bullet.getX1()));
// System.out.println("Y difference: "+(bullet.getY2()-bullet.getY1()));
}
@Override
@@ -68,13 +63,12 @@ public class Bullet extends DrawObject {
@Override
public void update() {
double x1,x2,y1,y2,yDifference,xDifference;
x1 = bullet.getX1();
x2 = bullet.getX2();
y1 = bullet.getY1();
y2 = bullet.getY2();
yDifference = y2 - y1;
xDifference = x2 - x1;
double x1 = bullet.getX1();
double x2 = bullet.getX2();
double y1 = bullet.getY1();
double y2 = bullet.getY2();
double yDifference = y2 - y1;
double xDifference = x2 - x1;
if(yDifference < 0.0){
y1 -= speed;
@@ -91,7 +85,6 @@ public class Bullet extends DrawObject {
x1 += speed;
x2 = x1+lengthOfBullet;
}
bullet.setLine(x1, y1, x2, y2);
}
@@ -101,7 +94,13 @@ public class Bullet extends DrawObject {
public void setColor(Color c) {
this.c = c;
}
}
public Line2D getBullet() {
return bullet;
}
public void setBullet(Line2D bullet) {
this.bullet = bullet;
}
}
+1 -1
View File
@@ -78,7 +78,7 @@ public class Enemy extends Person{
* @return, true = raakt, false = mis
*/
public boolean bulletHitMe(Bullet bullet){
if(circle.getBounds2D().intersectsLine(bullet.bullet)){
if(circle.getBounds2D().intersectsLine(bullet.getBullet())){
return true;
}
return false;
+10 -4
View File
@@ -9,12 +9,15 @@ import java.awt.image.BufferedImage;
public class Player extends Person {
private BufferedImage img;
private AffineTransform transform;
private int lastindex;
public Player(int x, int y){
super(x,y);
img = Images.getImage(Images.ImageType.player2);
width = img.getWidth();
height = img.getHeight();
height = img.getHeight();
lastindex = -10;
}
public void draw(Graphics2D g2){//
@@ -23,9 +26,12 @@ public class Player extends Person {
}
public void update(){
transform = new AffineTransform();
transform.rotate(Math.toRadians(index*45),middlePoint.getX(),middlePoint.getY());
transform.translate(middlePoint.getX() - width/2, middlePoint.getY() - height);
if(lastindex != index){
transform = new AffineTransform();
transform.rotate(Math.toRadians(index*45),middlePoint.getX(),middlePoint.getY());
transform.translate(middlePoint.getX() - width/2, middlePoint.getY() - height);
lastindex = index;
}
}
}