Skip to content

A physics-based 2D platformer built with Java and the City Physics Engine (Box2D). Features multi-level progression, dynamic collision handling, projectile combat, and object-oriented design patterns. Developed as coursework for City, University of London.

Notifications You must be signed in to change notification settings

YusufQuresh1/Java-2D-Platformer-Game

Repository files navigation

🤖 Robot City – Physics-Based Platformer

A multi-level 2D action game built with Java and the City Physics Engine.

Project Status Language Engine


📍 Overview

Robot City is a side-scrolling platformer that demonstrates advanced Object-Oriented Programming (OOP) concepts and real-time physics simulation.

Developed as coursework for City, University of London, this project implements a game engine using the university's proprietary City Physics Engine (a customized wrapper for JBox2D). The player controls a character who must navigate hostile environments, combat robotic enemies, and solve physics-based puzzles to progress through three distinct levels.


✨ Key Features

⚛️ Physics & Mechanics

  • Rigid Body Simulation: All movement and collisions are governed by a physics engine, allowing for realistic momentum and object interactions.
  • Projectile Combat: A custom shooting mechanic (DestroyProjectile) that calculates trajectory based on mouse input to destroy enemies.
  • Dynamic Collision Handling: Specialized listeners (KillPlayer, PlayerCollision) manage complex interactions between the player, enemies, and environment.

🎮 Gameplay Elements

  • Enemy Variety:
    • Ground Units: Patrol platforms and deal contact damage (RobotSmall).
    • Flying Drones: Aerial enemies (RobotFlying) that track player movement.
    • Heavy Units: Larger, tougher enemies (RobotBig) acting as obstacles.
  • Level Progression: A key-and-door system requires players to explore the map to unlock the path to the next level.
  • Resource Management: Collect coins for score and manage health (displayed via a custom HUD).

🖥️ Technical Implementation

  • Game Loop: Custom timer-based game loop managing physics steps and rendering.
  • View Management: A GameView class that overlays a custom HUD (Heads-Up Display) for health and score tracking onto the physics world.
  • Audio Integration: Integrated sound effects for actions like shooting, jumping, and collecting items.

🛠️ Tech Stack

  • Language: Java (JDK 8+)
  • Physics Engine: City Engine (Proprietary JBox2D wrapper provided by City, University of London)
  • Graphics: Java Swing & AWT (Custom painting)
  • Concepts: Inheritance, Polymorphism, Event Handling, Finite State Machines

🏗️ Project Structure

src/game/
├── Game.java               # Main entry point; manages level switching and window
├── GameLevel.java          # Abstract base class handling common level logic
├── Level1.java             # Concrete implementation of the first level
├── Level2.java             # Intermediate level with increased difficulty
├── Level3.java             # Final level implementation
├── Player.java             # Main character controller with physics attributes
├── PlayerController.java   # Keyboard input handling (WASD/Arrow keys)
├── GameView.java           # Renders the background, character, and UI overlays
├── DestroyProjectile.java  # Logic for projectile physics and impact
├── Coins.java              # Collectible item logic
├── Key.java                # Quest item logic for level progression
└── Enemies/
    ├── RobotSmall.java     # Basic enemy AI
    ├── RobotBig.java       # Heavy enemy logic
    └── RobotFlying.java    # Flying enemy logic

🚀 How to Run

Prerequisites

  • Java Development Kit (JDK): Version 8 or higher.
  • CityEngine Library: You must add the city-engine.jar (and jbox2d.jar) to your project's classpath.

Installation

  1. Clone the repository:
    git clone [https://github.com/YusufQuresh1/Robot-City-Platformer.git](https://github.com/YusufQuresh1/Robot-City-Platformer.git)
  2. Import into IDE: Open the project in IntelliJ IDEA, Eclipse, or VS Code.
  3. Configure Libraries: Add the CityEngine .jar files to your project dependencies/build path.
  4. Run: Execute Game.java as the main class.

🕹️ Controls

Key Action
W / Space Jump
A Move Left
D Move Right
Mouse Click Aim & Shoot Projectile

📬 Contact

Yusuf Qureshi Connect with me on LinkedIn to discuss this project further.

About

A physics-based 2D platformer built with Java and the City Physics Engine (Box2D). Features multi-level progression, dynamic collision handling, projectile combat, and object-oriented design patterns. Developed as coursework for City, University of London.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages