Skip to content

yeanh16/Multiplayer-Java-Game

Repository files navigation

Multiplayer Java Game

A real‑time multiplayer Java game featuring AI‑driven non‑player entities and a custom audio system.
This repository represents a team project; however, the Artificial Intelligence (AI) systems and the Audio subsystem highlighted below are my personal contributions and are showcased here as part of my engineering portfolio.


1. Overview

This project is a Java‑based multiplayer game (codename “Zucchini”) developed as part of an academic/team initiative. It combines:

  • Real‑time networking
  • Interactive world simulation
  • AI agents with layered decision logic
  • A custom audio pipeline for adaptive and spatial sound
  • Logging & debug

The game aims to demonstrate systems design, clean modular architecture, and extensibility for future mechanics or content.


2. Gameplay Summary

Core Loop (example):

  1. Players/AI spawn in a shared map.
  2. AI players patrol or react to stimuli.
  3. Weapons appear throughout the map, with the most powerful ones near the centre.
  4. All actors (players and AI agents) must fight to survive with the map shrinking over time.
  5. Session ends on last man standing as the winner.

3. My Personal Contributions (AI & Audio)

I personally designed and implemented:

  • AI Core Loop: update scheduling, decision tick cadence, separation of “sense / think / act”
  • Behavior architecture: finite state machine (FSM) with pluggable action nodes
  • Pathfinding integration using A*
  • AI difficulty adjustments
  • Audio subsystem: asset loading, caching
  • Event dispatcher linking gameplay events to audio triggers
  • Positional / spatial audio approximation (volume attenuation)

All AI and audio sections in this README are intentionally framed to highlight portfolio‑relevant engineering depth.

4. Architecture

High‑level layers:

  • Presentation: Rendering + UI
  • Domain / Game Logic: Entities, world state, systems
  • AI Layer (my work): Perception → Decision → Action
  • Audio Layer (my work): Event queue → Dispatcher → Output channels
  • Networking: Session management, state replication, authoritative logic
  • Utilities: Math helpers, configuration, logging

Design Principles:

  • Separation of concerns
  • Interfaces for swappable strategies (AI behaviors, audio backends)
  • Defensive programming & fail‑fast logging where appropriate

5. AI System (My Work)

Overview: The AI subsystem is structured around a multi‑phase update cycle:

Sense Phase:

  • Collects environmental inputs (nearby entities, obstacles, player states)
  • Perception filters (LOS, distance thresholds, field of view)

Think Phase:

  • Behavior selection via Finite State Machine
  • Priority resolution (e.g., threat > patrol > idle)
  • Blackboard / context object for passing world facts

Act Phase:

  • Issues movement intents (path requests) & action commands (attack, flee, broadcast)
  • Integrates with physics/movement system

Pathfinding:

  • Grid representation
  • Algorithm: [A* with heuristic manhattan distance]

Extensibility:

  • Add new behavior: implement State (e.g. HidingState implements State)
  • Inside update, drive the bot exactly as other states do—issue actions with aiPlayer.handleAction(...), query the world via the helpers on AIPlayer, and jump to other behaviors by calling aiPlayer.getStateMachine().changeState(new SomeOtherState()) (see src/game/ai/state/EvadeState.java:30 for a template).
  • Tune difficulty through config file: src\game\ai\Difficulty.java

6. Audio System (My Work)

Goals:

  • Low overhead
  • Declarative event → sound mapping
  • Support for layering (music + SFX + ambience)
  • Spatial cues for immersion (pan/attenuate)

Architecture:

  • Asset Loader: Preloads audio clips
  • Channel Mixer: Maintains categories (Music, SFX, UI, Ambience)

Features:

  • Positional Calculation: Pan = function(player_position, source_position)
  • Volume Falloff: exponential attenuation where the gain (volume) decreases exponentially with distance from the listener, based on the source's rolloff factor and reference distance. Specific sounds like explosions and gunshots have customized rolloff factors and reference distances to adjust how quickly their volume drops off.
  • Cleanup: prevent memory leaks and ensure proper shutdown of the audio system.

Extending:

  1. Add new sound file to resources\audio_assets
  2. Load sound into buffer src\game\audio\AudioManager.java
  3. Emit event from gameplay: audioManager.play("explosion.wav", 1.0f, explosionPos);

7. Networking Model

  • Client → Server RPC: inputs / intents
  • Server authoritative state with periodic snapshot or delta updates
  • Entity interpolation on clients
  • Deterministic simulation shards for AI server-side

8. Technical Stack

  • Language: Java
  • Build / IDE: Eclipse project
  • Libraries:
    • LWJGL
    • Audio: OpenAL
  • Testing: JUnit

9. Project Structure

Multiplayer-Java-Game/
├── src/                          # Main source code directory
│   ├── main/
│   │   └── java/
│   │       └── game/             # Root package for game logic
│   │           ├── audio/        # Audio management (e.g., AudioManager.java, SoundBuffer.java, SoundSource.java)
│   │           │   └── AudioManager.java  # Handles OpenAL audio playback, sources, and cleanup
│   │           ├── (other packages)/  # Likely includes core game classes (e.g., for entities, networking, rendering)
│   │           │   ├── Resources.java  # Manages game assets (imported in AudioManager)
│   │           │   ├── Util.java       # Utility functions (imported in AudioManager)
│   │           │   └── ...             # Additional classes for game mechanics, UI, etc.
│   └── test/                        # Unit tests (if present; e.g., AudioManagerTest.java as suggested earlier)
│       └── java/
│           └── game/
│               └── audio/
│                   └── AudioManagerTest.java  # Tests for audio functionality
├── resources/                      # Non-code assets
│   ├── audio_assets/               # WAV files for sounds (e.g., explosion.wav, zombie1.wav) loaded by AudioManager
│   └── (other assets)/             # Textures, models, configs, etc.
├── lib/                            # External libraries (e.g., LWJGL JARs for OpenAL, OpenGL)
├── target/ or build/               # Compiled output (generated by build tool)
├── pom.xml or build.gradle         # Build configuration (Maven/Gradle; includes LWJGL dependencies)
└── README.md or docs/              # Project documentation

10. Build & Run Instructions

Eclipse Setup:

Open up Eclipse and click on File->New->Java Project.... Type in c3 for the project name and press Finish.

Go to Window->Preferences, then navigate to Java->Build Path->User Libraries. Press Import.... Click Browse... and navigate to the project location. Then double click on libs.userlibraries, and press Ok, and Ok again.

Finally! Everything should be imported and setup correctly.


11. Portfolio Summary

This project showcases my contributions in designing and implementing:

  • A modular AI framework (sensing, decision, pathfinding, scalable ticking)
  • Adaptive audio engine (event-driven, layered, positional) Emphasis on clean abstractions, performance-awareness, and extensibility.

About

Multiplayer game create in Java as part of a team software engineering project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages