Skip to content

Rbrtpv/Simple-Java-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 

Repository files navigation

Simple-Java-Game

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.

Features

  • Player Control: Move your character using W, A, S, D or the arrow keys.
  • Character Swapping: Press SPACE to 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, and RESTART state.
  • Pause Functionality: Press ESC to pause and unpause the game.
  • Collision Detection: Basic collision handling for projectiles and AOE attacks with enemies, and enemy projectiles with the player.

How to Run

To run this project, you will need a Java Development Kit (JDK) installed on your system.

  1. Clone the repository (if applicable) or download the project files.
  2. Navigate to the project's root directory in your terminal.
  3. Compile the Java source files:
    javac -d bin src/**/*.java
    This command compiles all .java files in the src directory and its subdirectories, placing the compiled .class files into a bin directory.
  4. Run the game:
    java -cp bin Main
    This command executes the Main class, which is the entry point of the game.

How to Create and Run an Executable (JAR)

  1. Ensure the project is compiled as described in step 3 of "How to Run".

  2. Create a manifest file (e.g., manifest.txt) in the project's root directory with the following content:

    Main-Class: Main
    

    Make sure there is a newline character at the end of the Main-Class line.

    • On Linux/macOS:
      echo "Main-Class: Main" > manifest.txt
    • On Windows (Command Prompt):
      echo Main-Class: Main> manifest.txt
      (Note: Ensure there's a newline at the end of the file after creation, or create it manually with a text editor.)
  3. Create the executable JAR file:

    jar cvfm JavaGame.jar manifest.txt -C bin .

    This command creates a JAR file named JavaGame.jar, using manifest.txt to specify the main class, and includes all compiled classes from the directory. This command works on both Linux and Windows.

  4. 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.

Project Structure

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: Defines GameCharacter and its subclasses (Pierce, Slash).
    • dmg: Defines damage-related entities like Projectile and AreaOfEffect.
    • enemies: Defines Enemy and its subclasses (Machines, Organic).
  • game: Manages the main game loop, window, and game states.
  • ui: Contains classes for user interface elements like MainMenu, PauseMenu, RestartMenu, LevelsMenu, and StatsMenu.
  • user: Manages the player's character and HUD.

Technologies Used

  • Java: Core programming language.
  • AWT (Abstract Window Toolkit): Used for basic graphics and event handling (e.g., Graphics, KeyEvent, MouseEvent, JFrame, Canvas).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages