Skip to content

Commit

Permalink
remove duplicate image loading
Browse files Browse the repository at this point in the history
  • Loading branch information
vmsaif committed Sep 26, 2023
1 parent 781c061 commit 0089254
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 2 additions & 10 deletions src/main/java/Ant.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,15 @@ public class Ant {
private AStarSearch aStarSearch;
private LinkedList<LinkedList<Tile>> allPath2D = new LinkedList<LinkedList<Tile>>();

public Ant(Tile start, Tile goal, int tileSize, Tile[][] tiles) {
public Ant(Tile start, Tile goal, int tileSize, Tile[][] tiles, Image antImage) {
this.start = start;
this.goal = goal;
this.tiles = tiles;
loadAntImg();
this.antImage = antImage;
antX = start.getXpixel();
antY = start.getYpixel();
}

private void loadAntImg() {
try {
antImage = ImageIO.read(getClass().getResource("/assets/images/ant.png"));
} catch (IOException e) {
e.printStackTrace();
}
}

public void draw(Graphics g, int tileSize) {
g.drawImage(antImage, antX, antY, tileSize, tileSize, null);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public void actionPerformed(ActionEvent e) {

if (startTile != null && goalTile != null) {
resetCameFrom(tiles); // useful if the user wants to search for the second time or more
ant = new Ant(startTile, goalTile, TILE_SIZE, tiles);
ant = new Ant(startTile, goalTile, TILE_SIZE, tiles, antImage);
startClicked = true;
startTimeBeforeAnimation = System.currentTimeMillis();
ant.search();
Expand Down

0 comments on commit 0089254

Please sign in to comment.