Class BugDefense

All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class BugDefense extends JPanel implements ActionListener
Anahata Bug Swarm Defense (Tactical Edition).

A fast-paced "Space Invaders" style game where the user defends the digital continent from descending logic bugs.

Author:
anahata
See Also:
  • Field Details

    • timer

      private Timer timer
      The game loop timer.
    • shieldX

      private int shieldX
      The horizontal X position of the player's shield.
    • shieldY

      private final int shieldY
      The fixed vertical Y position of the player's shield.
      See Also:
    • shieldWidth

      private final int shieldWidth
      The width of the shield.
      See Also:
    • shieldHeight

      private final int shieldHeight
      The height of the shield.
      See Also:
    • playing

      private boolean playing
      Flag indicating if the game is currently active.
    • score

      private int score
      The player's current score.
    • lives

      private int lives
      The player's remaining lives.
    • optimizationPulses

      private List<Rectangle> optimizationPulses
      The list of active projectile pulses fired by the player.
    • bugs

      private List<Rectangle> bugs
      The list of descending logic bug obstacles.
    • rand

      private final Random rand
      Random number generator for spawning bug coordinates.
    • bugSpawnTick

      private int bugSpawnTick
      Tick counter to regulate enemy spawning frequency.
  • Constructor Details

    • BugDefense

      public BugDefense()
      Constructs a new BugDefense panel and adds the start button.
  • Method Details

    • setupKeyBindings

      private void setupKeyBindings()
      Installs left/right arrow and spacebar key bindings.
    • startGame

      private void startGame()
      Starts/resets the game state and kicks off the timer.
    • spawnPulse

      private void spawnPulse()
      Fires a new optimization pulse from the shield's position.
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Specified by:
      actionPerformed in interface ActionListener
    • checkCollisions

      private void checkCollisions()
      Performs collision detection between optimization pulses and bugs, updating scores.
    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • renderGameOver

      private void renderGameOver(Graphics2D g2d)
      Renders the Barça Red 'PRODUCTION CRASHED' game over screen.
      Parameters:
      g2d - The graphics context.
    • main

      public static void main(String[] args)
      Launcher method for testing BugDefense as a standalone application.
      Parameters:
      args - Command line arguments (ignored).