This repository contains a fully functional 2D arcade tank combat game developed as part of the BBM 104: Introduction to Programming Laboratory II course at Hacettepe University.The gameplay involves a player-controlled tank and enemy tanks trying to destroy the player tank.
Designed with a strict engineering constraint: No visual layout tools (SceneBuilder) or markup languages (FXML/CSS) were used. The entire Graphical User Interface (GUI) and game rendering loop are programmatically constructed using pure JavaFX 8 code.
This project acts as a lightweight 2D game engine, implementing core systems required for real-time interactive simulations:
- Custom Game Loop & Event Handling: Utilizes key listeners to capture real-time input. The player can move in 4 cardinal directions with arrow keys and fires a bullet with the "x" key. Each time a tank moves, an animation displays the thread movement.
- Dynamic Enemy AI: Enemy entities operate on autonomous logic. With specific intervals, the enemy chooses a random direction and moves continuously until it decides to change its path. They also constantly fire projectiles at random intervals, creating a dynamic challenge.
- Physics & Collision Detection: Custom collision algorithms govern the map logic. The game takes place in an arena surrounded by indestructible walls. It is impossible for tanks to pass through the walls. Bullets travel at a constant speed until they hit a wall or tank.
- State Machine Management: Handles complex application states (Play, Pause, Game Over). The player starts with three lives. Pressing the "P" key brings up a pause menu, halting the game loop. Upon losing all lives, a game-over screen allows restarting via the "R" key or exiting via the "Escape" key.
- Advanced Viewport Camera (Bonus Feature): Implements vertical and horizontal scrolling to render dynamic map environments larger than the initial window size.
- Explosion Animations: Bullets hitting indestructible walls or enemy tanks trigger a temporary explosion effect before the entities are removed from the DOM[cite: 681, 683].
- Entity Respawning: If the player is hit, an explosion occurs, a life is lost, and the player respawns at the original starting coordinates after a brief delay[cite: 684, 685].
- Language: Java 8 (Oracle)
- Framework: JavaFX (Pure Code Implementation)
- Prohibited Tools: FXML, SceneBuilder, CSS, Swing, AWT, external JSON libraries
- Documentation: Extensively documented using JavaDoc style.
- Movement:
Up,Down,Left,RightArrow Keys - Fire/Shoot:
X - Pause Game:
P - Restart (Game Over/Pause):
R - Exit Game:
Escape
The application is designed to be compiled and executed via the Command-Line Interface (CLI).
- Clone the repository:
git clone [https://github.com/OsmanerdemDutar/Tank-2025-JavaFX-Engine.git](https://github.com/OsmanerdemDutar/Tank-2025-JavaFX-Engine.git) cd Tank-2025-JavaFX-Engine - Compile the engine:
javac Tank2025.java
- Run the simulation:
java Tank2025
Developed with a focus on Clean Code, custom 2D rendering mathematics, and strict architectural constraints.