private void generateFieldBackground(Graphics2D g2d, Grid grid) { // Fill the background with a base color g2d.setColor(Color.DARK_GRAY); g2d.fillRect(0, 0, fieldBackgroundImg.getWidth(), fieldBackgroundImg.getHeight()); g2d.setColor(Color.LIGHT_GRAY); Stroke originalStroke = g2d.getStroke(); g2d.setStroke(new BasicStroke(1.0f)); // Draw grid lines over the background if (Debugging.drawGridLines) { grid.draw(g2d); } // Reset the graphics to the original stroke g2d.setStroke(originalStroke); }
public GameState() { super("Game State"); // Init the players and establish player relations myPlayer = new HumanPlayer("Human"); ai1 = new AIPlayer("foo 1.0"); ai2 = new AIPlayer("foo 2.0"); ai3 = new AIPlayer("foo 3.0"); ai4 = new AIPlayer("foo 4.0"); myPlayer.addEnemies(ai1, ai2, ai3, ai4); ai1.addEnemies(ai2, ai3, ai4); ai2.addEnemies(ai1, ai3, ai4); ai3.addEnemies(ai1, ai2, ai4); ai4.addEnemies(ai1, ai2, ai3); ai1.addEnemy(myPlayer); activePlayers = new LinkedList<Player>(); defeatedPlayers = new ArrayList<Player>(); activePlayers.add(myPlayer); activePlayers.add(ai1); activePlayers.add(ai2); activePlayers.add(ai3); activePlayers.add(ai4); // Set the movement margins GamePanel panel = GamePanel.getInstance(); int panelWidth = panel.getWidth(); int panelHeight = panel.getHeight(); // Prepare the HUD rectangle hudPanel.setBounds( 0, panelHeight - Settings.MINI_MAP_HEIGHT, Settings.FIELD_WIDTH, panelHeight); miniMapRect.setBounds( panelWidth - Settings.MINI_MAP_WIDTH, panelHeight - Settings.MINI_MAP_HEIGHT, Settings.MINI_MAP_WIDTH, Settings.MINI_MAP_HEIGHT); // Init the control groups, and link them to my player ControlGroup.initGroups(this, myPlayer); // Initialize the grid int width = Settings.FIELD_WIDTH; int height = Settings.FIELD_HEIGHT; int numRows = 10; int numCols = 10; grid = Grid.initGrid(width, height, numRows, numCols); // Generate the images initImages(grid); /* * Create the initial units * * Each player starts with 1 hive and 10 larva * The hives are evenly spaced around the circumference of a circle centred in the field centre */ boolean createInitialUnits = true; if (createInitialUnits) { int numStartingLarvae = 10; float angle = 0; float deltaAngle = 2 * (float) Math.PI / activePlayers.size(); int centreX = Settings.FIELD_WIDTH / 2; int centreY = Settings.FIELD_HEIGHT / 2; float radius = Settings.FIELD_WIDTH / 2 - 100; for (Player p : activePlayers) { int x = (int) (Math.cos(angle) * radius + centreX); int y = (int) (Math.sin(angle) * radius + centreY); p.spawnHive(x, y, true); for (int i = 0; i < numStartingLarvae; i++) { p.spawnLarvae(x + i, y + i); } angle += deltaAngle; } } }