Skip to content

Commit cff33ce

Browse files
committed
General fix
1 parent 58452f3 commit cff33ce

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

src/evhh/common/imagemanipulation/ImageTiler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ public static BufferedImage tileImage(BufferedImage image, int cols, int rows)
1919
int height = image.getWidth()*rows;
2020
BufferedImage tiledImage = new BufferedImage(width,height, BufferedImage.TYPE_INT_ARGB);
2121
Graphics2D graphics2D = tiledImage.createGraphics();
22+
Color oldColor = graphics2D.getColor();
23+
graphics2D.setPaint(Color.BLACK);
24+
graphics2D.fillRect(0, 0, width, height);
25+
graphics2D.setColor(oldColor);
2226
for (int i = 0; i < cols; i++)
2327
{
2428
for (int j = 0; j < rows; j++)
2529
{
26-
graphics2D.drawImage(image,null,image.getWidth()*cols,image.getHeight()*cols);
30+
graphics2D.drawImage(image,null,image.getWidth()*i,image.getHeight()*j);
2731
}
2832
}
33+
graphics2D.drawImage(tiledImage,null,0,0);
2934
graphics2D.dispose();
3035
return tiledImage;
3136

src/evhh/model/GameInstance.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,6 @@ public void setGridSavePath()
338338
{
339339
this.gridSavePath = AssetLoader.setPathToSaveData();
340340
}
341+
342+
341343
}

src/evhh/model/Grid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Grid(int gridWidth, int gridHeight)
3636
dynamicObjects = new ArrayList<>();
3737
}
3838

39-
public GameObject get(int x, int y)
39+
synchronized public GameObject get(int x, int y)
4040
{
4141
if (!isValidCoordinates(x, y))
4242
throw new NoSuchElementException("The coordinates :{x=" + x + " ,y=" + y + "} Are not valid coordinates");

src/evhh/model/ObjectPrefab.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
import java.io.Serializable;
66

77
/***********************************************************************************************************************
8-
* @project: MainProject
9-
* @package: evhh.model
10-
* ---------------------------------------------------------------------------------------------------------------------
11-
* @authors: Hamed Haghjo & Elias Vahlberg
12-
* @date: 2021-05-13
13-
* @time: 14:31
148
**********************************************************************************************************************/
159
public interface ObjectPrefab extends Serializable
1610
{
11+
/**
12+
* @param x X position in grid
13+
* @param y Y position in grid
14+
* @return instantiated Game object
15+
*/
1716
public GameObject getInstance(int x, int y);
17+
18+
/**
19+
* When creating the sprite the (@param GameObject parent) should be null
20+
* @return A reference sprite used in map editing
21+
*/
1822
public Sprite getSprite();
1923
}

src/evhh/view/renderers/GridPanel.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package evhh.view.renderers;
22

3+
import evhh.model.gamecomponents.Sprite;
4+
35
import javax.swing.*;
46
import java.awt.*;
7+
import java.util.ArrayList;
58

69
/***********************************************************************************************************************
710
* @project: MainProject
@@ -35,7 +38,8 @@ public void paintComponent(Graphics g) {
3538
Graphics2D g2d = (Graphics2D) g;
3639
if(backgroundImage!=null)
3740
g2d.drawImage(backgroundImage,0,0,this);
38-
gridRenderer.getSprites().forEach(s->
41+
ArrayList<Sprite> sprites = (ArrayList<Sprite>) gridRenderer.getSprites().clone(); //This is to avoid ConcurrentModificationException
42+
sprites.stream().parallel().forEach(s->
3943
g2d.drawImage(
4044
s.getTexture(),
4145
(int) s.getX()*cellSize,

0 commit comments

Comments
 (0)