A Java implementation of Chrome's Offline T-Rex Game with smooth 100 fps gameplay. This project demonstrates various Object-Oriented Programming concepts through a fun, interactive game.
- Dynamic Background with scrolling land and clouds
- Infinite Gameplay with progressive difficulty
- Multiple Obstacles: Cactuses and Birds (Pterodactyls)
- Player Controls: Jump and Duck
- Game Sounds for jumps and collisions
- Score & High Score tracking with file persistence
- Dynamic jump height based on key holding time
- Quick fall: pressing duck key in midair drops Dino faster
- Pause functionality
- Intro sequence
- Debug mode for development
Jump: ARROW UP, SPACE, W
Duck: ARROW DOWN, S
Debug: ` (backtick)
Pause: ESC, P
-
Using the JAR file:
java -jar dino.jar -
From source code:
javac src/user_interface/GameWindow.java java -cp src user_interface.GameWindow
The game is built using multiple classes, each responsible for specific functionality:
GameWindow: Main window setup and entry pointGameScreen: Core game logic and renderingDino: Player character with behavior and propertiesCactuses/Birds: Enemy objects with specific behaviorsLand/Clouds: Environment objectsScore: Score tracking system
- Private fields with getter/setter methods to control access
- Data hiding for implementation details (e.g., animation frames, collision detection)
- Package organization to group related classes
- Extends JFrame for the main window (
GameWindow) - Extends JPanel for the game screen (
GameScreen) - Extends AbstractAction for keyboard input handlers
- Method overriding in subclasses
- Common interface for different enemy types
- Runtime behavior determination based on game state
- High-level methods hide implementation details
- Complex behaviors (like animation, physics) abstracted into dedicated classes
- Clean separation between game logic and rendering
- ActionListener for handling user input
- Runnable implementation for game loop threading
GameState: Represents different states (START, INTRO, IN_PROGRESS, OVER, PAUSED)DinoState: Different states for the dinosaur (RUN, DOWN_RUN, JUMP, DEAD)EnemyType: Types of enemies (CACTUS, BIRD)
- Game objects composed of various components
- Managers (EnemyManager, SoundManager) handling collections of objects
- Complex objects built from simpler ones
- Different versions of methods to handle various input types
- Flexible interfaces for game objects
- Try-catch blocks for resource loading
- Graceful error handling for file operations
- Game loop runs on a dedicated thread
- Sound processing in separate threads
- Thread synchronization for consistent gameplay
- Singleton Pattern: For resource management
- State Pattern: For managing game states and dino states
- Factory Pattern: For creating enemies
- Observer Pattern: For event handling
- game_object/: Contains all game entities
- manager/: Classes that manage groups of objects
- misc/: Utility classes and enumerations
- user_interface/: UI components and rendering
- util/: Helper utilities for resources
High scores are stored in a text file next to the JAR file. Debug mode disables collisions and shows hitboxes and speed information.
- Multiplayer support
- Additional obstacles and power-ups
- Enhanced graphics and animations
- Sound settings
- Difficulty levels


