0% found this document useful (0 votes)
20 views22 pages

JAVA Dinasoaur

The report details the development of a basic version of the Chrome Dinosaur Game using Java, featuring a T-Rex that players control to avoid obstacles and score points. It outlines the game's mechanics, implementation steps, and technology stack, emphasizing its engaging design and accessibility for all ages. Future enhancements such as multiplayer mode and power-ups are also suggested to enrich the gameplay experience.

Uploaded by

yashagrawal8329
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views22 pages

JAVA Dinasoaur

The report details the development of a basic version of the Chrome Dinosaur Game using Java, featuring a T-Rex that players control to avoid obstacles and score points. It outlines the game's mechanics, implementation steps, and technology stack, emphasizing its engaging design and accessibility for all ages. Future enhancements such as multiplayer mode and power-ups are also suggested to enrich the gameplay experience.

Uploaded by

yashagrawal8329
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

OOPJ-MINI-PROJECT REPORT ON

“CHROME-DINOSOUR-GAME”

By

YASH AGRAWAL 301


ANKIT DUBEY 310
ATHARVA DHAKATE 309

Under the guidance of

Prof. Firdous Shaikh


Abstract
 The Chrome Dinosaur Game, often referred to simply as the "Dino Game," is
a simple yet engaging endless runner game featured in the Google Chrome
web browser.
 It activates when users attempt to navigate to a webpage while offline. The
game features a pixelated T-Rex dinosaur that players control, jumping over
obstacles like cacti and birds to accumulate points.
 The challenge intensifies as the speed increases over time, requiring quick
reflexes and timing.
 The minimalist design and straightforward mechanics make it a nostalgic and
entertaining distraction during internet outages.

Software requirements:
 Operating System: Windows, Linux.
 Software’s: Java SDK 2, Borland JBuilder , Eclipse,vscode.
Problem Statement:
The objective of this project is to implement a basic version of the Chrome Dinosaur
game using Java. The game will feature a graphical user interface, displaying a
dinosaur character that the player controls to avoid obstacles such as cacti and flying
birds. Players can make the dinosaur jump by pressing the spacebar and duck using
the down arrow key. Obstacles will be generated randomly and move from the right
to the left of the screen at varying intervals. A scoring system will be implemented,
awarding points for each successfully avoided obstacle and displaying the current
score at the top of the window. Collision detection will determine if the dinosaur
collides with an obstacle, leading to a game-over screen that shows the final score
and offers the option to restart.

Theory:

Introduction
The Chrome Dinosaur Game is a quintessential example of effective game design,
blending simple mechanics with engaging psychological principles. As an endless
runner, it invites players to control a T-Rex, navigating increasingly challenging
obstacles, which promotes a balance between skill and challenge. The game's
incremental difficulty keeps players motivated, tapping into the theory of instant
gratification as they receive immediate feedback through scoring. Its minimalist
pixel art style and simple sound effects evoke nostalgia, enhancing emotional
engagement.
By utilizing straightforward controls, the game is accessible to a wide audience,
making it easy to pick up and play. Additionally, its offline functionality transforms
moments of internet connectivity loss into opportunities for fun, thereby enriching
the overall user experience and turning a frustrating situation into an enjoyable
distraction.

Project Description:

The Chrome Dinosaur Game is a whimsical offline feature integrated into the
Google Chrome browser, designed to entertain users during internet outages. Players
control a pixelated T-Rex as it runs through a desert landscape, skillfully avoiding
obstacles like cacti and birds. The primary objectives of the game are to engage
players with addictive gameplay, offering intuitive mechanics that are accessible to
all ages and skill levels. The game features dynamic difficulty, where speed and
complexity gradually increase, enhancing the challenge and keeping players
invested. A scoring system tracks players' achievements, fostering a sense of
accomplishment and encouraging competition
Implementation
1. Requirements Gathering

 Game Mechanics:
 Control a T-Rex character.
 Jump over obstacles (cacti and birds).
 Score points based on distance traveled and obstacles avoided.

 Difficulty Levels:

 Increase speed and obstacle frequency as score rises.

2. Architecture Design
1. Game Engine
 Core Logic: Manages game loop, states (running, paused, game over).

2. Game Objects
 Player (T-Rex): Controls position, velocity, and jump mechanics.
 Obstacles: Cacti and birds with properties for position and speed.
3. Collision Detection
 Detects interactions between the T-Rex and obstacles, triggering scoring and
game over events.

3. Technology Stack
While the original Chrome Dinosaur Game is built with web technologies, if you
were to create a similar game using Java, the technology stack would look different.
Here’s a suggested stack:

1. Programming Language
o Java:
 The primary language for developing the game, enabling object-
oriented programming and robust application structure.

2. Development Environment
o IDE:
 Use an integrated development environment like Eclipse or
IntelliJ IDEA for coding, debugging, and project management .
4. Feature Implementation
1. Game Start and Initialization

 Start Screen:
o Display a simple "Press Space to Start" message.
o Initialize game variables (score, speed, obstacles).

2. Character Control

 T-Rex Movement:
o Implement a T-Rex class with properties like position and velocity.
o Use event listeners to detect key presses (e.g., spacebar for jump).
 Jump Mechanic:
o Use a simple physics formula to simulate jumping (gravity effect)
when the spacebar is pressed.

3. Obstacle Generation

 Obstacle Class:
o Create an Obstacle class with properties for type (cactus, bird),
position, and speed.
 Random Generation:
o Use a timer to periodically generate obstacles at random intervals and
positions.
5.User Interface Design
 Start Screen:
 Background: Simple desert landscape.
 Title: "Chrome Dino Game" in a bold, pixelated font.
 Instructions: "Press Space to Start" with an animated T-Rex.

 Game Interface:
 Background: Scrolling desert theme.
 T-Rex: Pixelated character with running and jumping animations.
 Obstacles: Distinct designs for cacti and birds.
 Score Display: Clear, prominent score at the top left.

6. Testing
 Functional Testing:
 Verify T-Rex jumping and ducking mechanics.
 Check correct scoring based on distance and obstacles.
 Ensure game over conditions trigger properly.

 Usability Testing:
 Assess clarity and intuitiveness of UI elements.
 Confirm instructions are easy to understand.
Future Enhancements
 Multiplayer Mode:
 Introduce a competitive mode where players can race against each other in
real-time.

 Power-Ups:
 Add power-ups that players can collect to gain temporary abilities (e.g.,
invincibility, speed boosts).

 Level Variations:
 Implement different environments (e.g., night mode, rain) that introduce
unique obstacles and aesthetics.

References:

 W3schools
 The CODINGTRAIN
Source Code:

APP.JAVA

import javax.swing.*;
public class App {
public static void main(String[] args) throws Exception {
int boardWidth = 750;
int boardHeight = 250;
JFrame frame = new JFrame("Chrome Dinosaur");
// frame.setVisible(true);
frame.setSize(boardWidth, boardHeight);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ChromeDinosaur chromeDinosaur = new ChromeDinosaur();
frame.add(chromeDinosaur);
frame.pack();
chromeDinosaur.requestFocus();
CHROME.JAVA
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;

public class ChromeDinosaur extends JPanel implements ActionListener,


KeyListener {
int boardWidth = 750;
int boardHeight = 250;

//images
Image dinosaurImg;
Image dinosaurDeadImg;
Image dinosaurJumpImg;
Image cactus1Img;
Image cactus2Img;
Image cactus3Img;

class Block {
int x;
int y;
int width;
int height;
Image img;

Block(int x, int y, int width, int height, Image img) {


this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.img = img;
}
}

//dinosaur

int dinosaurWidth = 88;


int dinosaurHeight = 94;
int dinosaurX = 50;
int dinosaurY = boardHeight - dinosaurHeight;

Block dinosaur;
//cactus
int cactus1Width = 34;
int cactus2Width = 69;
int cactus3Width = 102;

int cactusHeight = 70;


int cactusX = 700;
int cactusY = boardHeight - cactusHeight;
ArrayList<Block> cactusArray;

//physics
int velocityX = -12; //cactus moving left speed
int velocityY = 0; //dinosaur jump speed
int gravity = 1;

boolean gameOver = false;


int score = 0;

Timer gameLoop;
Timer placeCactusTimer;

public ChromeDinosaur() {
setPreferredSize(new Dimension(boardWidth, boardHeight));
setBackground(Color.lightGray);
setFocusable(true);
addKeyListener(this);

dinosaurImg = new ImageIcon(getClass().getResource("./img/dino-


run.gif")).getImage();
dinosaurDeadImg = new ImageIcon(getClass().getResource("./img/dino-
dead.png")).getImage();
dinosaurJumpImg = new ImageIcon(getClass().getResource("./img/dino-
jump.png")).getImage();
cactus1Img = new
ImageIcon(getClass().getResource("./img/cactus1.png")).getImage();
cactus2Img = new
ImageIcon(getClass().getResource("./img/cactus2.png")).getImage();
cactus3Img = new
ImageIcon(getClass().getResource("./img/cactus3.png")).getImage();

//dinosaur
dinosaur = new Block(dinosaurX, dinosaurY, dinosaurWidth, dinosaurHeight,
dinosaurImg);
//cactus
cactusArray = new ArrayList<Block>();
//game timer
gameLoop = new Timer(1000/60, this); //1000/60 = 60 frames per 1000ms
(1s), update
gameLoop.start();

//place cactus timer


placeCactusTimer = new Timer(1500, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
placeCactus();
}
});
placeCactusTimer.start();
}

void placeCactus() {
if (gameOver) {
return;
}

double placeCactusChance = Math.random(); //0 - 0.999999


if (placeCactusChance > .90) { //10% you get cactus3
Block cactus = new Block(cactusX, cactusY, cactus3Width, cactusHeight,
cactus3Img);
cactusArray.add(cactus);
}
else if (placeCactusChance > .70) { //20% you get cactus2
Block cactus = new Block(cactusX, cactusY, cactus2Width, cactusHeight,
cactus2Img);
cactusArray.add(cactus);
}
else if (placeCactusChance > .50) { //20% you get cactus1
Block cactus = new Block(cactusX, cactusY, cactus1Width, cactusHeight,
cactus1Img);
cactusArray.add(cactus);
}

if (cactusArray.size() > 10) {


cactusArray.remove(0); //remove the first cactus from ArrayList
}
}

public void paintComponent(Graphics g) {


super.paintComponent(g);
draw(g);
}

public void draw(Graphics g) {


//dinosaur
g.drawImage(dinosaur.img, dinosaur.x, dinosaur.y, dinosaur.width,
dinosaur.height, null);

//cactus
for (int i = 0; i < cactusArray.size(); i++) {
Block cactus = cactusArray.get(i);
g.drawImage(cactus.img, cactus.x, cactus.y, cactus.width, cactus.height,
null);
}

//score
g.setColor(Color.black);
g.setFont(new Font("Courier", Font.PLAIN, 32));
if (gameOver) {
g.drawString("Game Over: " + String.valueOf(score), 10, 35);
}
else {
g.drawString(String.valueOf(score), 10, 35);
}
}

public void move() {


//dinosaur
velocityY += gravity;
dinosaur.y += velocityY;

if (dinosaur.y > dinosaurY) { //stop the dinosaur from falling past the ground
dinosaur.y = dinosaurY;
velocityY = 0;
dinosaur.img = dinosaurImg;
}

//cactus
for (int i = 0; i < cactusArray.size(); i++) {
Block cactus = cactusArray.get(i);
cactus.x += velocityX;

if (collision(dinosaur, cactus)) {
gameOver = true;
dinosaur.img = dinosaurDeadImg;
}

//score
score++;
}

boolean collision(Block a, Block b) {


return a.x < b.x + b.width && //a's top left corner doesn't reach b's top right
corner
a.x + a.width > b.x && //a's top right corner passes b's top left corner
a.y < b.y + b.height && //a's top left corner doesn't reach b's bottom left
corner
a.y + a.height > b.y; //a's bottom left corner passes b's top left corner
}

@Override
public void actionPerformed(ActionEvent e) {
move();
repaint();
if (gameOver) {
placeCactusTimer.stop();
gameLoop.stop();
}
}

@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
// System.out.println("JUMP!");
if (dinosaur.y == dinosaurY) {
velocityY = -17;
dinosaur.img = dinosaurJumpImg;
}

if (gameOver) {
//restart game by resetting conditions
dinosaur.y = dinosaurY;
dinosaur.img = dinosaurImg;
velocityY = 0;
cactusArray.clear();
score = 0;
gameOver = false;
gameLoop.start();
placeCactusTimer.start();
}
}
}

@Override
public void keyTyped(KeyEvent e) {}

@Override
public void keyReleased(KeyEvent e) {}
}

OUTPUT:
Conclusion:
The Chrome Dinosaur Game stands out as a simple yet engaging offline feature
that transforms a frustrating internet outage into a fun and addictive experience.
Through its intuitive gameplay, players control a pixelated T-Rex, skillfully
navigating obstacles while aiming for high scores. The game's design emphasizes
accessibility, with straightforward mechanics suitable for all ages and skill levels .

You might also like