Skip to content

BatriqCode/Piggy-Revenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Piggy Revenge — libGDX + Box2D

A 2D physics-based projectile game inspired by Angry Birds, built in Java with libGDX and Box2D.

This version is a polished desktop demo with stable physics, a slingshot launch mechanic, level selection, trajectory visualization, and a lightweight UI built directly with libGDX drawing APIs.


Highlights

  • Fixed-step Box2D physics for more stable and predictable gameplay.
  • Gravity disabled at level load and enabled instantly on the first shot.
  • Trajectory tracker that shows:
    • a dotted aim / prediction line while dragging
    • a dotted flight trail after launch
  • Texture caching for generated Pixmap textures to reduce allocation churn.
  • How To Play overlays in both the menu and level select screens.
  • All levels unlocked for demo purposes.
  • A playful re-theme where the visible projectile looks like a pig and the targets look like birds.

Requirements

  • JDK 17 or newer
  • No separate Gradle installation is required — the project includes the Gradle Wrapper

Build and run

From the project root:

.\gradlew.bat clean build
.\gradlew.bat run

If you prefer a Unix-like shell, use:

./gradlew clean build
./gradlew run

Controls

Menu

  • ENTER / SPACE — start the game
  • L — open level select
  • H — open How To Play overlay
  • ESC — exit

Level Select

  • 15 — choose a level
  • H — open How To Play overlay
  • B / ESC — return to the menu

Game

  • Click and drag the projectile on the slingshot to aim
  • Release to launch
  • R — restart the current level
  • D — toggle Box2D debug view
  • ESC — return to level select

Project structure

src/main/java/com/angrybirds/
├── AngryBirdsGame.java
├── DesktopLauncher.java
├── entities/
│   ├── Bird.java
│   ├── Block.java
│   ├── Pig.java
│   └── Slingshot.java
├── game/
│   └── GameInputProcessor.java
├── graphics/
│   ├── TextureCache.java
│   └── TrajectoryTracker.java
├── physics/
│   └── PhysicsWorld.java
└── screens/
    ├── GameScreen.java
    ├── LevelSelectScreen.java
    └── MenuScreen.java

Key files

  • AngryBirdsGame.java — app entry point and screen switching
  • PhysicsWorld.java — Box2D wrapper, fixed-step update loop, gravity control
  • GameScreen.java — main gameplay loop, level setup, damage handling, HUD
  • Slingshot.java — pull / release launch mechanic
  • TrajectoryTracker.java — dotted prediction and flight trail rendering
  • TextureCache.java — reuse generated textures instead of recreating them
  • MenuScreen.java and LevelSelectScreen.java — menu UI and instructions overlays

How the game works

  1. A level is loaded with a slingshot, structures, and targets.
  2. Gravity is disabled so the scene stays stable before the first shot.
  3. The player drags the projectile back to aim.
  4. A dotted prediction line is shown while aiming.
  5. On release, the projectile is launched and gravity is enabled immediately.
  6. The flight trail records the bird path.
  7. Collisions apply damage using Box2D contact impulses.
  8. Clearing all targets wins the level.

Physics and collision design

The game uses Box2D for the world simulation. The important implementation details are:

  • Fixed-step accumulation in PhysicsWorld.update(float delta)
    • makes the simulation less sensitive to fluctuating frame rates
    • clamps large frame spikes so the physics does not overstep badly
  • Collision listener in GameScreen
    • uses postSolve() contact impulses to decide whether a hit should deal damage
  • Entity metadata
    • Box2D bodies store their owning game object in userData so collisions can be mapped back to Bird, Pig, and Block

Graphics and memory notes

  • The project uses SpriteBatch for textures and ShapeRenderer for simple shapes/UI.
  • Generated textures are cached in TextureCache so repeated objects do not create new Texture instances every time.
  • The game disposes cached textures on shutdown to avoid memory leaks.
  • GlyphLayout is used for measuring text width safely, instead of mutating font caches.

Assets

The assets/ folder contains the game art used by the desktop build:

  • background.jpg
  • level_background_1.pnglevel_background_5.png
  • imported art folders under _imported_backgrounds/

If you want to use piggy.webp as the main pig artwork, it is usually easiest to convert it to PNG and load it as a normal libGDX Texture.


Future improvements

  • Add sound effects for launch, hits, and level completion
  • Externalize level layouts into JSON files
  • Improve the aim preview into a full ballistic prediction arc
  • Add persistent level progression instead of always unlocking every level
  • Replace runtime-generated shapes with prebuilt art assets or a texture atlas
  • Add automated tests for physics stepping and entity behavior

Credits

  • Built with libGDX and Box2D
  • Designed as a student project / demo build

License

No explicit license is provided in the repository. If you plan to share or publish the project, add a license file first.

About

2D game made with Java - libGdx framework - Box2D inspired from Angry Birds

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors