Project File Edited
Project File Edited
A. PROJECT. REPORT
Submitted by
Undertheguidanceof
of
BACHELOR OF TECHNOLOGY
in
BONAFIDE CERTIFICATE
Certified that this project report titled “Car Racing Game ” is the
bonafidework of Yash Yadav RA2111003030450 who carried out the project work
under my supervision. Certified further, that to the best of my knowledge the
work reported herein does not form any other project report onthe basis of which
a degree or award was conferred.
SIGNATURE SIGNATURE
Table of contents
1.ACKNOWLEDGEMENTS.
3
2.ABSTRACT.
5
3. INTRODUCTION.
6
4.LITERATURESURVEY.
7
5.SYSTEMANALYSIS.
7-8
6.SYSTEMDESIGN.
9
7.CODING,TESTING
10
8.LIMITATION &
FUTURE ENHANCEMENIS
23
9.CONCLUSION
24
REFERENCS
Abstract
The Car Racing Game is a Java-based 2D arcade game designed to
provide an engaging, interactive experience where players control a car
and navigate through an obstacle-filled road. The primary objective of the
game is to avoid randomly generated obstacles while accumulating points
as the player survives longer. The game features increasing difficulty as
the player progresses, with obstacles appearing more frequently and
moving faster. The graphical user interface (GUI) is built using Java’s
Swing framework, while real-time game events, such as car movement
and obstacle collision, are managed using a Timer and KeyListener.
Arcade games have long been popular for their straightforward mechanics,
fast-paced action, and emphasis on high scores. The Car Racing Game
draws on these elements by combining intuitive controls with progressively
more difficult gameplay. Players can move the car left or right using the
keyboard's arrow keys, while the obstacles, represented as yellow blocks,
move downward at varying speeds. The longer the player survives, the
higher the score, with the challenge increasing as obstacles appear more
frequently and move faster.
1. Game Architecture:
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.util.prefs.Preferences;
public CarRacingGame() {
this.setBackground(Color.DARK_GRAY);
this.setFocusable(true);
this.addKeyListener(new CarKeyAdapter());
timer.start();
playBackgroundMusic("background.wav");
@Override
if (showInstructions) {
drawInstructions(g);
} else {
g.setColor(Color.GRAY);
g.setColor(Color.WHITE);
g.setColor(Color.RED);
g.setColor(Color.YELLOW);
g.setColor(Color.WHITE);
g.setColor(Color.RED);
stopMusic();
} else if (isPaused) {
g.setColor(Color.YELLOW);
g.setColor(Color.WHITE);
@Override
obstacleY += 10 * difficultyLevel;
difficultyLevel++;
obstacleY = -50;
playCollisionSound("collision.wav");
highScore = score;
preferences.putInt("HighScore", highScore);
repaint();
@Override
if (showInstructions) {
showInstructions = false;
return;
if (!gameOver) {
}
if (key == KeyEvent.VK_RIGHT && carX < 300) {
carX += 20;
if (key == KeyEvent.VK_P) {
isPaused = !isPaused;
if (isPaused) {
timer.stop();
} else {
timer.start();
repaint();
restartGame();
score = 0;
carX = 220;
carY = 600;
obstacleY = -50;
difficultyLevel = 1;
playBackgroundMusic("background.wav");
timer.start();
repaint();
try {
backgroundMusic = AudioSystem.getClip();
backgroundMusic.open(AudioSystem.getAudioInputStream(new
File(soundFile)));
backgroundMusic.loop(Clip.LOOP_CONTINUOUSLY);
} catch (Exception e) {
e.printStackTrace();
collisionSound = AudioSystem.getClip();
collisionSound.open(AudioSystem.getAudioInputStream(new
File(soundFile)));
collisionSound.start();
} catch (Exception e) {
e.printStackTrace();
backgroundMusic.stop();
frame.add(game);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
9. Advantages
1. Educational Value: The project provides a hands-on
introduction to various key Java programming concepts,
including object-oriented programming (OOP), event-driven
programming, collision detection, real-time game loops, and
graphical rendering using Java's Swing framework. It also
introduces sound handling through the javax.sound.sampled
library, giving developers a comprehensive learning
experience in multimedia application development.