This is a simple 2D Java game where the player controls a character to fight against various enemies. The game features character swapping, different attack types, and basic UI elements like a main menu, pause menu, and restart screen.
- Player Control: Move your character using
W,A,S,Dor the arrow keys. - Character Swapping: Press
SPACEto switch between two distinct characters:- Pierce: Attacks with projectiles.
- Slash: Attacks with an area-of-effect (AOE) ability.
- Mouse-based Attacks: Click the left mouse button to unleash your character's attack.
- Enemy Types: Encounter different enemies with unique behaviors:
- Machines: Ranged enemies that shoot projectiles.
- Organic: Melee enemies that attack when in close range.
- Health System: Both the player and enemies have health points displayed via health bars.
- Game States: Includes a
MAIN_MENU,PLAYING,PAUSE, andRESTARTstate. - Pause Functionality: Press
ESCto pause and unpause the game. - Collision Detection: Basic collision handling for projectiles and AOE attacks with enemies, and enemy projectiles with the player.
To run this project, you will need a Java Development Kit (JDK) installed on your system.
- Clone the repository (if applicable) or download the project files.
- Navigate to the project's root directory in your terminal.
- Compile the Java source files:
This command compiles all
javac -d bin src/**/*.java
.javafiles in thesrcdirectory and its subdirectories, placing the compiled.classfiles into abindirectory. - Run the game:
This command executes the
java -cp bin Main
Mainclass, which is the entry point of the game.
-
Ensure the project is compiled as described in step 3 of "How to Run".
-
Create a manifest file (e.g.,
manifest.txt) in the project's root directory with the following content:Main-Class: MainMake sure there is a newline character at the end of the
Main-Classline.- On Linux/macOS:
echo "Main-Class: Main" > manifest.txt
- On Windows (Command Prompt):
(Note: Ensure there's a newline at the end of the file after creation, or create it manually with a text editor.)
echo Main-Class: Main> manifest.txt
- On Linux/macOS:
-
Create the executable JAR file:
jar cvfm JavaGame.jar manifest.txt -C bin .This command creates a JAR file named
JavaGame.jar, usingmanifest.txtto specify the main class, and includes all compiled classes from the directory. This command works on both Linux and Windows. -
Run the executable JAR file:
java -jar JavaGame.jar
This command executes the JAR file and starts the game. This command works on both Linux and Windows.
The project is organized into several packages:
controls: Handles user input from keyboard and mouse.entities: Contains base classes for game objects and specific implementations for characters, enemies, and damage types.characters: DefinesGameCharacterand its subclasses (Pierce,Slash).dmg: Defines damage-related entities likeProjectileandAreaOfEffect.enemies: DefinesEnemyand its subclasses (Machines,Organic).
game: Manages the main game loop, window, and game states.ui: Contains classes for user interface elements likeMainMenu,PauseMenu,RestartMenu,LevelsMenu, andStatsMenu.user: Manages the player's character and HUD.
- Java: Core programming language.
- AWT (Abstract Window Toolkit): Used for basic graphics and event handling (e.g.,
Graphics,KeyEvent,MouseEvent,JFrame,Canvas).