Skip to content

2024 · Games / Physics

1v1 Physics Platformer Game

Competitive two-player collision-physics game built in pure Java.

Java Versus Platformer

1v1 competitive platformer match with real-time velocity collision.

The problem

Two players need to fight on one keyboard at the same time, with sprites animating and platforms colliding, in plain Java with no game engine. A single-player-AI opponent should be able to join the same fight.

The constraint

Swing's event listeners only fire on discrete events — they can't sample two players' *simultaneous, continuous* key-holds reliably. That rules out the naive listener approach and forces a frame-driven loop that polls held keys directly.

What I built

A Swing Timer every 10 ms is the heart. Each tick polls the actual held keys for both players, runs gravity and per-axis platform collision (top stops a fall, bottom stops a jump, left/right stop a slide), and advances 12-frame running sprites (Minotaur vs Reaper) so animation follows state. Player 2 becomes a simple tracking AI when toggled. Stomping the opponent's top edge resets both players and costs a life (3 hearts each). Random platform rows plus an easy/medium/hard level selector keep every match fresh.

The outcome

A responsive arcade platformer holding a consistent frame rate with two simultaneous inputs, animated sprites, sound, and an optional AI opponent — built entirely in Java GUI primitives.

Links