Skip to content

Commit 6d05aef

Browse files
committed
refactored code
1 parent a27d25c commit 6d05aef

File tree

8 files changed

+90
-44
lines changed

8 files changed

+90
-44
lines changed

src/Bomberman/entity/Entity.java

+2
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ public interface Entity {
1313
boolean isColliding(Entity b);
1414
void draw();
1515
void removeFromScene();
16+
int getPositionX();
17+
int getPositionY();
1618
}

src/Bomberman/entity/MovingEntity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
package bomberman.entity;
77

8-
import bomberman.animations.Direction;
8+
import bomberman.constants.Direction;
99

1010
/**
1111
*

src/Bomberman/entity/player/Player.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package bomberman.entity.player;
22

33
import bomberman.Renderer;
4-
import bomberman.animations.Direction;
4+
import bomberman.constants.Direction;
55
import bomberman.animations.PlayerAnimations;
66
import bomberman.animations.Sprite;
77
import bomberman.constants.GlobalConstants;
@@ -43,7 +43,7 @@ private void init() {
4343
name = "Player";
4444
playerBoundary = new RectBoundedBox(positionX, positionY, GlobalConstants.PLAYER_WIDTH, GlobalConstants.PLAYER_HEIGHT);
4545

46-
playerAnimations = new PlayerAnimations();
46+
playerAnimations = new PlayerAnimations(this);
4747

4848
positionX = GlobalConstants.PLAYER_X;
4949
positionY = GlobalConstants.PLAYER_Y;
@@ -83,8 +83,7 @@ public boolean isColliding(Entity b) {
8383

8484
@Override
8585
public void draw() {
86-
currentSprite.setPosition(positionX, positionY);
87-
if (currentSprite != null) {
86+
if (currentSprite != null) {
8887
Renderer.playAnimation(currentSprite);
8988
}
9089
}
@@ -133,4 +132,14 @@ public void reduceHealth(int damage) {
133132
public void removeFromScene() {
134133
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
135134
}
135+
136+
@Override
137+
public int getPositionX() {
138+
return this.positionX;
139+
}
140+
141+
@Override
142+
public int getPositionY() {
143+
return this.positionY;
144+
}
136145
}

src/Bomberman/entity/staticobjects/Wall.java

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* @author kdost
1515
*/
1616
public class Wall implements StaticEntity {
17+
public int positionX = 0;
18+
public int positionY = 0;
1719
private int height;
1820
private int width;
1921
private int health;
@@ -40,5 +42,15 @@ public void draw() {
4042
public void removeFromScene() {
4143
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
4244
}
45+
46+
@Override
47+
public int getPositionX() {
48+
return this.positionX;
49+
}
50+
51+
@Override
52+
public int getPositionY() {
53+
return this.positionY;
54+
}
4355

4456
}

src/bomberman/entity/Entity.java

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
5-
*/
6-
package bomberman.entity;
7-
8-
/**
9-
*
10-
* @author Ashish
11-
*/
12-
public interface Entity {
13-
boolean isColliding(Entity b);
14-
void draw();
15-
void removeFromScene();
16-
}
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package bomberman.entity;
7+
8+
/**
9+
*
10+
* @author Ashish
11+
*/
12+
public interface Entity {
13+
boolean isColliding(Entity b);
14+
void draw();
15+
void removeFromScene();
16+
int getPositionX();
17+
int getPositionY();
18+
}
+19-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
5-
*/
6-
package bomberman.entity;
7-
8-
import bomberman.animations.Direction;
9-
10-
/**
11-
*
12-
* @author kdost
13-
*/
14-
public interface MovingEntity extends Entity {
15-
16-
17-
public void move(int steps, Direction direction);
18-
19-
}
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package bomberman.entity;
7+
8+
import bomberman.constants.Direction;
9+
10+
/**
11+
*
12+
* @author kdost
13+
*/
14+
public interface MovingEntity extends Entity {
15+
16+
17+
public void move(int steps, Direction direction);
18+
19+
}

src/bomberman/entity/player/Player.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package bomberman.entity.player;
22

33
import bomberman.Renderer;
4-
import bomberman.animations.Direction;
4+
import bomberman.constants.Direction;
55
import bomberman.animations.PlayerAnimations;
66
import bomberman.animations.Sprite;
77
import bomberman.constants.GlobalConstants;
@@ -43,7 +43,7 @@ private void init() {
4343
name = "Player";
4444
playerBoundary = new RectBoundedBox(positionX, positionY, GlobalConstants.PLAYER_WIDTH, GlobalConstants.PLAYER_HEIGHT);
4545

46-
playerAnimations = new PlayerAnimations();
46+
playerAnimations = new PlayerAnimations(this);
4747

4848
positionX = GlobalConstants.PLAYER_X;
4949
positionY = GlobalConstants.PLAYER_Y;
@@ -83,8 +83,7 @@ public boolean isColliding(Entity b) {
8383

8484
@Override
8585
public void draw() {
86-
currentSprite.setPosition(positionX, positionY);
87-
if (currentSprite != null) {
86+
if (currentSprite != null) {
8887
Renderer.playAnimation(currentSprite);
8988
}
9089
}
@@ -133,4 +132,14 @@ public void reduceHealth(int damage) {
133132
public void removeFromScene() {
134133
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
135134
}
135+
136+
@Override
137+
public int getPositionX() {
138+
return this.positionX;
139+
}
140+
141+
@Override
142+
public int getPositionY() {
143+
return this.positionY;
144+
}
136145
}

src/bomberman/entity/staticobjects/Wall.java

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* @author kdost
1515
*/
1616
public class Wall implements StaticEntity {
17+
public int positionX = 0;
18+
public int positionY = 0;
1719
private int height;
1820
private int width;
1921
private int health;
@@ -40,5 +42,15 @@ public void draw() {
4042
public void removeFromScene() {
4143
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
4244
}
45+
46+
@Override
47+
public int getPositionX() {
48+
return this.positionX;
49+
}
50+
51+
@Override
52+
public int getPositionY() {
53+
return this.positionY;
54+
}
4355

4456
}

0 commit comments

Comments
 (0)