-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulationPanel.java
More file actions
59 lines (51 loc) · 2.57 KB
/
SimulationPanel.java
File metadata and controls
59 lines (51 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.awt.*;
import javax.swing.JPanel;
public class SimulationPanel extends JPanel{
private final static int CREATURE_SPRITE_WIDTH = 10;
private final static int CREATURE_SPRITE_HEIGHT = 10;
private final static int FOOD_SPRITE_WIDTH = 4;
private final static int FOOD_SPRITE_HEIGHT = 4;
private final static Color FOOD_COLOR = Color.RED;
private final static int HIGHLIGHT_CIRCLE_DIAMETER = 30;
public SimulationPanel() {
setBackground(Main.loaded.simulationScreenColor);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Where all graphics are rendered
if(Main.loaded.doVisuals){
highlightSubject(g);
drawCreaturesAndFood(g);
}
}
public void drawCreaturesAndFood(Graphics g) {
int[][] foodLocations = Main.loaded.foodLocationsForAllTicks[Math.min(Main.loaded.currentGenerationTick,Main.loaded.generationLength-1)];
Color[][] creatureLocations = Main.loaded.creatureColorsForAllTicks[Math.min(Main.loaded.currentGenerationTick,Main.loaded.generationLength-1)];
for(int x=0; x<Main.loaded.worldSize; x++){
for(int y=0; y<Main.loaded.worldSize; y++){
if(foodLocations[x][y] >= 1){
Coor printPostion = ScreenObject.getPrintPos(x,y);
g.setColor(FOOD_COLOR);
g.fillRect(printPostion.x() - FOOD_SPRITE_WIDTH/2, printPostion.y() - FOOD_SPRITE_HEIGHT/2, FOOD_SPRITE_WIDTH, FOOD_SPRITE_HEIGHT);
}
if(creatureLocations[x][y] != null){
Coor printPosition = ScreenObject.getPrintPos(x,y);
g.setColor(creatureLocations[x][y]);
g.fillRect(printPosition.x() - CREATURE_SPRITE_WIDTH/2, printPosition.y() - CREATURE_SPRITE_HEIGHT/2, CREATURE_SPRITE_WIDTH, CREATURE_SPRITE_HEIGHT);
}
}
}
}
public void highlightSubject(Graphics g){
int creatureIndex = GUIPanel.currentlySelectedCreatureIndex;
int NONE_SELECTED = -1;
if(creatureIndex == NONE_SELECTED || Main.loaded.creaturesList[creatureIndex] == null){
return;
}
Creature creature = Main.loaded.creaturesList[creatureIndex];
g.setColor(Color.red);
Coor printPosition = ScreenObject.getPrintPos(creature.getPosX(), creature.getPosY());
g.fillOval(printPosition.x()-HIGHLIGHT_CIRCLE_DIAMETER/2, printPosition.y()-HIGHLIGHT_CIRCLE_DIAMETER/2, HIGHLIGHT_CIRCLE_DIAMETER, HIGHLIGHT_CIRCLE_DIAMETER);
}
}