Skip to content

AnkeshGG/DinoGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆ• Dino Game โ€“ T-Rex Runner

A faithful recreation of the classic Chrome offline dinosaur game built entirely with Java Swing. Run, jump, and duck your way through an endless desert with smooth 60 fps gameplay, a parallax day/night cycle, and progressively increasing difficulty.

Java Swing License: MIT Release

Dino Game Preview


๐Ÿง  Why This Project?

Most browser-based Dino clones rely on JavaScript or game engines. This one is built purely in Java with no external libraries โ€” a clean demonstration of object-oriented design, Swing rendering, and real-time game-loop architecture using only the standard JDK.


๐Ÿš€ Key Features

๐ŸŽฎ Core Gameplay

  • Jump & Duck: Classic T-Rex controls โ€” Space/โ†‘ to jump, โ†“ to duck
  • Collision Detection: Pixel-accurate hitbox intersection for obstacles and the dino
  • Progressive Speed: Game gradually accelerates every 200 score points, capped at 16 px/tick

๐ŸŒ— Day / Night Cycle

  • Automatic toggle: Scene switches between day and night every 700 score points
  • Parallax clouds: Clouds scroll at 1/3 game speed for a depth illusion
  • Adaptive colours: Sky, ground, text, and HUD all shift palette with the cycle

๐Ÿ“Š HUD & Scoring

  • Live score: Increments every game tick in a zero-padded 5-digit display
  • Session high score: Best score preserved in memory for the session lifetime
  • Speed readout: Current scroll speed shown in the top-left corner
  • Day/Night badge: Emoji badge updates alongside the cycle toggle

๐Ÿชจ Obstacles

  • Cacti variants: Single, double, and triple cactus clusters spawned randomly
  • Pterodactyls: Flying obstacles at varying heights for mid-air challenges
  • Randomised gaps: Spacing between obstacles scales with game speed

๐Ÿ› ๏ธ Tech Stack

  • Java 8+ โ€“ Core language; no third-party dependencies required
  • Java Swing / AWT โ€“ Rendering, window management, and input handling
  • javax.swing.Timer โ€“ Drives the 60 fps (~16 ms) game loop
  • java.awt.Graphics2D โ€“ Anti-aliased 2D rendering with gradient fills

๐Ÿ“‹ System Requirements

Prerequisites

  • JDK 8 or higher
  • Any Java IDE (IntelliJ IDEA, Eclipse, VS Code with Java extension) or a terminal

Verify Your Setup

# Check Java version (should be 8+)
java -version

# Check compiler
javac -version

๐Ÿ“ฆ Download

Don't want to build from source? Just download and run the installer.

Platform Download Notes
๐Ÿ–ฅ๏ธ Windows (64-bit) DinoGame-1.0.0.msi No Java required โ€” JRE is bundled

โšก Quick Start

1. Clone the Repository

git clone https://github.com/AnkeshGG/DinoGame.git
cd DinoGame

2. Compile the Source

javac -d out src/*.java

3. Run the Game

java -cp out DinoGame

IntelliJ IDEA: Open the project, right-click DinoGame.java โ†’ Run 'DinoGame.main()'


๐ŸŽฎ Controls

Key Action
Space / โ†‘ Jump (also starts / restarts the game)
โ†“ Duck (hold to crouch, release to stand)
Enter Restart after Game Over

๐Ÿ—๏ธ Project Structure

DinoGame/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ DinoGame.java          # Main panel, game loop, rendering, input
โ”‚   โ”œโ”€โ”€ Dino.java              # Player character: physics, animation, hitbox
โ”‚   โ”œโ”€โ”€ ObstacleGenerator.java # Spawns, updates, and draws obstacles
โ”‚   โ”œโ”€โ”€ Cloud.java             # Decorative parallax background clouds
โ”‚   โ””โ”€โ”€ GameState.java         # Enum: IDLE | RUNNING | GAME_OVER
โ”œโ”€โ”€ assets/
โ”‚   โ””โ”€โ”€ DinoGame_Preview.gif   # Gameplay demo clip
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md

๐Ÿงฉ Architecture Overview

The game follows a simple component-based architecture driven by a single Swing Timer:

  • DinoGame โ€” Central hub: owns the game loop (actionPerformed), manages all entities, handles rendering back-to-front, and processes keyboard input.
  • Dino โ€” Self-contained player entity with jump physics (gravity + velocity), duck state, leg animation, and a shrinkable hitbox.
  • ObstacleGenerator โ€” Stateless spawner that maintains a list of active Obstacle objects; each obstacle knows its own type, position, and how to draw itself.
  • Cloud โ€” Lightweight value object; scrolls left at reduced speed and is recycled when off-screen.
  • GameState โ€” Three-value enum (IDLE, RUNNING, GAME_OVER) that gates all logic branches cleanly.

๐Ÿงช Testing

Automated unit tests are planned for a future release. Current validation is done through manual playtesting across all three game states and both day/night modes.


๐Ÿ’ก Future Enhancements

  • Add sound effects (jump, game over, milestone)
  • Persist high score to a local file across sessions
  • Add a settings panel (volume, key remapping)
  • Mobile-style touch/click controls
  • Difficulty presets (Easy / Normal / Hard)

๐Ÿค Contributing

You're welcome to contribute to this open-source project!

Steps:

  1. Fork the repo
  2. Create a branch: git checkout -b feature/newFeature
  3. Commit your changes
  4. Push: git push origin feature/newFeature
  5. Submit a pull request

Guidelines

  • Follow standard Java code conventions
  • Keep all rendering logic inside the relevant class's draw() method
  • Test across both day and night modes before submitting PRs

๐Ÿ“„ License

This project is licensed under the MIT License โ€“ see the LICENSE file for details.


๐Ÿ‘จโ€๐Ÿ’ป About the Author

Ankesh Kumar โ€“ Java Developer & Game Enthusiast

I built this project to deepen my understanding of real-time rendering and game-loop design using nothing but the standard Java library โ€” no engines, no frameworks, just pure Swing.

Connect With Me


๐Ÿ™ Acknowledgements

  • Chrome Dino โ€“ The original game by Google that inspired this recreation
  • Java Swing Team โ€“ For a surprisingly capable 2D rendering toolkit
  • Open Source Community โ€“ For countless references and inspiration

๐Ÿ“Š Project Status

๐ŸŸข Actively maintained

  • Version: 1.0.0
  • Last Updated: February 2026
  • Latest Release: v1.0.0
  • Stars: โญ Give this project a star if you enjoyed it!
  • Issues: Tracked via GitHub Issues

๐Ÿ” Ready to Beat Your High Score?

An endless runner with no finish line โ€” just you, a dinosaur, and an ever-faster desert. Jump over cacti, dodge pterodactyls, and push through the night to set a new personal best.

โฌ‡๏ธ Download Installer | ๐Ÿ“ฅ Clone & Play | ๐ŸŽฎ Controls | ๐Ÿค Contribute


ยฉ 2026 Ankesh Kumar.

Keep running โ€” the desert never ends.
Built with love

About

A Chrome Dino-inspired endless runner built with pure Java Swing - featuring parallax clouds, a day/night cycle, progressive difficulty, and smooth 60 fps gameplay. No external libraries.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages