A classic tower defense game built in Java with Swing, featuring a custom level editor and multiple enemy types. Players can create their own levels, place towers, and defend against waves of enemies following pathfinding routes.
- Play Mode: Experience tower defense gameplay with enemies following pathfinding routes
- Edit Mode: Create and customize your own levels with an intuitive level editor
- Settings: Configure game options and preferences
- Main Menu: Easy navigation between all game modes
- Enemy Types: Four unique enemy types (Orc, Bat, Knight, Wolf) with different characteristics
- Path-based Movement: Enemies follow designated road paths from start to end points
- Tile-based Level System: 20x20 grid system with multiple tile types (Water, Grass, Road)
- Custom Levels: Save and load custom level designs
- Animated Sprites: Support for both static and animated tiles
- Tile Placement: Paint tiles directly onto the grid
- Path Points: Set custom start and end points for enemy routes
- Live Preview: See selected tiles before placement
- Sprite Rotation: Rotate tiles using the 'R' key
- Save/Load: Persist custom levels to disk
- Intuitive Toolbar: Easy-to-use tile selection interface
The game follows a clean MVC-inspired architecture with the following components:
- Main Package: Core game loop, rendering, and window management
- Scenes Package: Different game states (Menu, Playing, Editing, Settings)
- Managers Package: Entity management (Enemies, Towers, Tiles)
- Objects Package: Game objects (Towers, Tiles, Path Points)
- UI Package: User interface components (Buttons, Toolbars, Action Bars)
- Inputs Package: Mouse and keyboard event handling
- Enemies Package: Enemy entity definitions
- Helper Package: Utilities for image loading, level persistence, and constants
- 120 FPS rendering
- 60 UPS (Updates Per Second) game logic
- Optimized tile-based rendering
- Efficient sprite atlas system
- Custom sprite atlas with all game graphics
- 32x32 pixel tile system
- Support for animated sprites
- Clean, pixel-art aesthetic
- Java Development Kit (JDK) 11 or higher
- Java Runtime Environment (JRE)
# Compile the project
javac -d bin src/**/*.java
# Run the game
java -cp bin main.Gamesrc/
├── UI/ # User interface components
│ ├── ActionBar.java # In-game action bar
│ ├── Bar.java # Generic bar component
│ ├── MyButton.java # Custom button implementation
│ └── Toolbar.java # Level editor toolbar
├── enemies/ # Enemy definitions
│ ├── Bat.java
│ ├── Enemy.java # Abstract enemy base class
│ ├── Knight.java
│ ├── Orc.java
│ └── Wolf.java
├── helper/ # Utility classes
│ ├── Constants.java # Game constants and enums
│ ├── ImgFix.java # Image manipulation utilities
│ ├── LoadSave.java # Level save/load functionality
│ └── Util.java # General utilities
├── inputs/ # Input handling
│ ├── KeyboardListener.java
│ └── MyMouseListener.java
├── main/ # Core game files
│ ├── Game.java # Main game class and loop
│ ├── GameScreen.java # Game canvas
│ ├── GameStates.java # Game state enum
│ └── Render.java # Rendering manager
├── managers/ # Entity managers
│ ├── EnemyManager.java # Enemy spawning and updates
│ ├── TileManager.java # Tile type management
│ └── TowerManager.java # Tower management
├── objects/ # Game objects
│ ├── PathPoint.java # Enemy path waypoints
│ ├── Tile.java # Tile definition
│ └── Tower.java # Tower definition
├── scenes/ # Game scenes/states
│ ├── Editing.java # Level editor scene
│ ├── GameScene.java # Abstract scene base
│ ├── Menu.java # Main menu
│ ├── Playing.java # Gameplay scene
│ ├── SceneMethods.java # Scene interface
│ └── Settings.java # Settings menu
└── spriteatlas.png # Game sprite sheet
- Play: Start playing the current level
- Edit: Open the level editor
- Settings: Configure game settings
- Quit: Exit the game
- Enemies spawn at the designated start point
- They follow the road path to reach the end point
- Use the action bar to place towers (feature in development)
- Prevent enemies from reaching the end point
- Select tiles from the toolbar at the bottom
- Click on the grid to place tiles
- Use the 'R' key to rotate certain tiles
- Set start and end points for enemy paths (must be placed on road tiles)
- Save your level when finished
- Return to menu and play your custom level
- Left Click: Select tiles, place objects, interact with UI
- Mouse Move: Preview tile placement, hover effects
- Mouse Drag: Paint tiles continuously in edit mode
- R: Rotate selected sprite (in edit mode)
- Water Tile (0): Decorative, blocks enemy movement
- Grass Tile (1): Decorative, blocks enemy movement
- Road Tile (2): Pathable terrain for enemies
- Orc (0): Basic enemy type
- Bat (1): Flying enemy variant
- Knight (2): Armored enemy type
- Wolf (3): Beast enemy type
- Left (0)
- Up (1)
- Right (2)
- Down (3)
- Tower placement not yet implemented
- No wave system for enemy spawning
- Limited number of enemy types
- No sound effects or music
- Basic UI without themes
- Tower placement and upgrade system
- Wave-based enemy spawning
- Resource management (gold/currency)
- Power-ups and special abilities
- Multiple level campaigns
- Difficulty settings
- Sound effects and background music
- High score tracking
- More enemy and tower varieties
- The game runs at 120 FPS by default
- Monitor console for FPS/UPS metrics
- Reduce sprite animations for lower-end systems
- Close unnecessary background applications
Feel free to fork this project and submit pull requests for:
- Bug fixes
- New features
- Performance improvements
- Documentation enhancements
- Additional levels or assets