0% found this document useful (0 votes)
29 views

Space Invader Game in JavaFX

The project report details the development of an arcade game software titled 'Space Wars', created using Java and JavaFX, which allows players to control a spaceship and destroy enemy ships for points. The game features modules for score counting, enemy creation, bullet shooting, and a game over screen, and is designed to be platform-independent. The report includes acknowledgments, an abstract, software requirements, and a comprehensive overview of Java and its features, alongside the game design and implementation process.

Uploaded by

gmstchs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Space Invader Game in JavaFX

The project report details the development of an arcade game software titled 'Space Wars', created using Java and JavaFX, which allows players to control a spaceship and destroy enemy ships for points. The game features modules for score counting, enemy creation, bullet shooting, and a game over screen, and is designed to be platform-independent. The report includes acknowledgments, an abstract, software requirements, and a comprehensive overview of Java and its features, alongside the game design and implementation process.

Uploaded by

gmstchs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

A Project Report on

Arcade Game Software: Space Wars


Submitted for the partial fulfillment of Polytechnic Diploma

To

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


PACIFIC POLYTECHNIC COLLEGE, UDAIPUR
SESSION 2020-21

0
A Project Report on

Arcade Game Software : Space Wars


Submitted for the partial fulfillment of Polytechnic Diploma

To

Submitted To: Submitted By:


MR. RAJIV SIR LUCKY BAIRAGI
C.S.E. DEPARTMENT (III Year Diploma)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

PACIFIC POLYTECHNIC COLLEGE, UDAIPUR


SESSION 2020-21
Acknowledgement

We wish to express our deep sense of gratitude to our guide Mr Rajiv shrma, Lecturer,
Dept. of computer science engineering, of Pacific Polytechnic College who through their excellent
guidance have enabled us to accomplish this work. He has been great source of inspiration to us,
all through. We are very grateful to him for guiding us how to conduct research and how to clearly
& effectively present the work done.

I extend my sincere thanks to our Director Mr. Mukesh Shrimali and Mr Rajiv Sharma,
H.O.D (C.S.E), Pacific Polytechnic College, for providing the adequate means and support to
pursue this work.

Finally, we would like to add few heartfelt words for the people who were the part of the
project in various ways, especially our friends and classmates who gave us unending support right
from the beginning. Without their support, persistence and love we would not be where we are
today.

LUCKY BAIRAGI

DIPLOMA III year


ABSTRACT

The project titled Arcade Game Software: Space Invader is game software in which player play as hero
space ship through which he/she destroy other enemy ships. This game is developed in Java language
and using GUI library JavaFX which is very helpful in making GUI related application in Java.

This game is focused on a battle ship which is equipped with bullets to destroy enemies. Every time an
enemy ship get destroyed player get a point for that.

“Arcade Game Software: Space Invader” is a platform independent software which means you can run
it on any device like Windows machine, linux machine and Mac. This software is developed in JDK 14
which means it require JRE8-JRE14.

This software is very easy to use, just play it with two arrows keys to move ship and space bar to shoot
bullets.

It shows real time score on screen and when you clash with other ships it pop-up with “Game Over”
screen. Longer you last ,faster the game become.

This software contains 4 modules:

• Score counting module

• Enemy ship creating module

• Bullet Shooting module

• Game Over module


TABLE OF CONTENTS

CERTFICATE

ACKNOWLEDGEMENT

ABSTRACT

1 Introduction 1-2

1.1 Game Overview 1

1.1.1 Synopsis 1

1.1.2 Target Audience 1

1.1.3 Game description 1

1.2 Game Objectives 2

1.3 Why Game as Project? 2

2 Software Requirements 3

3 Java Introduction 4-6

3.1 Overview 4

3.2 Features of Java 4-5

3.3 History of Java 6

3.4 Basic Syntax of Java 6

3.4.1 Class 6

3.4.2 Objects 6

3.4.3 Instance Variables 6

3.4.4 Methods 6

3.5 Object Oriented in Java 7

3.5.1 Classes 7

3.5.2 Inheritance 7
3.5.3 Polymorphism 7

3.5.4 Abstraction 7

3.5.5 Encapsulation 7

4 JavaFx 8-9

4.1 Overview 8

4.2 Features of JavaFX 8-9

4.3 History of JavaFX 9

5 Feasibility Study 10-11

5.1 Financial Feasibility 10

5.2 Technical Feasibility 10

5.3 Economic Feasibility 11

5.4 Legal Feasibility 11

6 System Design 12-20

6.1 List of Classes and their responsibilities 12

6.2 Class Diagram 13-18

6.2.1 Hero Class 13

6.2.2 HeroBullets Class 13

6.2.3 Enemies Class 14

6.2.4 PauseScreen Class 14

6.2.5 Space Class 15

6.2.6 GameScene Class 15-16

6.2.7 SelectShip Class 16

6.2.8 StartMenu Class 17

6.2.9 OptionMenu Class 17

6.2.10 GameOverScreen Class 18


6.2.11 VFXSound Class 18

6.3 Relationship Among Classes 19-20

7 User Interface 21-25

7.1 View of the Game World 21

7.2 Heads up Display 21-25

7.2.1 Hero Ship 21

7.2.2 Score Board 22

7.2.3 Game Stage 22

7.2.4 Start Menu 23

7.2.5 Option Menu 23

7.2.6 Game Over Screen 24

7.2.7 Select Ship Screen 24

7.2.8 Pause Screen 25

8 Programming and Implementing Game 26-35

8.1 Packages and Files 26-27

8.1.1 Directory Tree of Game Project 26-27

8.2 Functionality 28-35

8.2.1 Creating Game Window 28

8.2.2 Creating Space and Elements of Space 28

8.2.3 Creating Hero Ship 29

8.2.4 Controls 29

8.2.5 Creating Enemy Ship 30

8.2.6 Creating Bullets 31

8.2.7 Creating Start Menu 32

8.2.8 Creating Pause Screen 32


8.2.9 Creating Option Menu 33

8.2.10 Creating Select Ship Menu 34

8.2.11 VFX and Background Sound 35

9 Future Plans 36-37

9.1 Removing Errors and bugs 36

9.2 Adding New Bullets for Hero Ship 36

9.3 Adding New Levels 36

9.4 Adding Public Score Board 37

CONCLUSION
Chapter 1 - INTRODUCTION

This report describes process involved in making a 2D Arcade game, Space War, This game is for all devices
which support latest version of Java. This chapter discusses the game overview including synopsis, target
audience, description, then focus on game design and how game is implemented .

1.1 Game Overview

The primary objective of this game is to kill enemies and achieve high score, He can achieve high score by
killing more number of enemy ships. Each time player kills enemy, speed of ships increase.

1.1.1 Synopsis

HeroShip is protagonist of our game, whose mission is to spread peace in Universe. He can’t achieve peace
in Universe without killing all enemies, who are doing evil things in universe. After killing 20 enemies
HeroShip get new bullets.

1.1.2 Target Audience

Arcade games were really popular in 90s Video Games. People used to play a lot such games like Snake,
Space Invaders and Pac-man. Even today people like to play such games for entertainment, we upgraded
Space Invaders so that people can enjoy it more.

1.1.3 Game Description

This game starts with HeroShip with a gun as the weapon which fire bullets which can kill enemy ships.
When he enters into enemy territory, all ships start attacking him. To kill those alien ships he can fire
bullets through his ship and on every kill he get 1 point which allow him to upgrade his bullets. When his
score get above 20 he get new bullets to kill more number of enemies. To control peace in universe, he
needs to achieve highest score and assert dominance.

1
1.2 Game Objectives

The major objectives of this game project are :

• To create a Arcade game which will have all functionalities of Arcade games.

• To add space as background, adding elements like stars.

• To implement gun attack feature on ship.

• To implement up gradation of gun after certain score.

• To implement how enemy ship or HeroShip can get killed.

• To make a User Friendly Interface that will be pleasant to look at.

• To increase speed of enemies after each kill.

1.3 Why Game as project?

Video games are not just any computer software which are made to benefit user’s daily life. Games are
rather made for user’s entertainment purpose, so more than anything we need to pay attention to what
the user wants from the game, how to make it more entertaining, just making any game will not do. That
is why it’s more challenging because I always have to carefully consider if I’m making developing it
correctly to entertain users. I also have to invest a lot of time on the proper game designing to make it
visually accepted, And to ass that game requires a lot of scripts. The scripts are like pieces of a puzzle
which you need to put all of them together to make it work. Thus I think game is a perfect project to prove
myself as a CSE student.

2
Chapter 2 – SOFTWARE REQUIREMENT

Arcade Game Software: Space War is developed in Java using JavaFX library, It can run on any platform
which support latest version of java.

Operating System – Windows/Linux/Unix / MacOS

Programming langauge – Java (jdk14)

Library used for GUI – JavaFX 11

3
Chapter 3 – JAVA INTRODUCTION

This chapter gives basic introduction of java. We will discuss about Features of Java, History of Java, Basic
Syntax of Java, Object Orient Concepts and JavaFX library.

3.1 Overview

Java, the programming language, was introduced by Sun Microsystems. This work was initiated by James
Gosling and the final version of Java was released in the year 1995. However, initially Java was released
as a component of the core Sun Microsystem platform for Java called J2SE or Java 1.0. The latest release
of Java or J2SE is Java Standard Version 6.

The rising popularity of Java, as a programming platform and language has led to the development of
several tools and configurations, which are made keeping Java in mind. For instance, the J2ME and J2EE
are two such configurations. The latest versions of Java are called Java SE and Java EE or Java ME instead
of J2SE, J2EE and J2ME. The biggest advantage of using the Java platform is the fact that it allows you to
run your code at any machine. So, you just need to write your code once and expect it to run everywhere.

3.2 Features of Java

Java have many features which attract many programmers to choose this language for both software
development and web development.

This features are :

• Object Oriented - In Java, everything is an object. Java can be effectively stretched out
and extended to unimaginable dimensions since it is focused around the Object model.

• Independent of the platform - Dissimilar to numerous other programming dialects


including C and C++, when Java is aggregated, it is not converted into a form, which is
particular to any machine. Instead, it is converted into a machine-independent byte code.
This byte code is conveyed over the web and deciphered by Virtual Machines or JVM on
whichever stage it is generally run.

4
• Simple - Java is intended to be not difficult to learn. In the event that you comprehend
the essential idea of OOP, Java would not be difficult to ace.

• Secure - With Java’s security framework, it empowers to create frameworks, which are
free of viruses and tampering. Public-key encryption is used as the core authentication
strategy.

• Independent of Machine Architecture - Java compiler produces an object file format,


which is independent of the architecture of the machine. The assembled code can be
executed on numerous processors, with the single requirement that they must all have
Java runtime framework.

• Portability - The fact that Java code is machine and platform independent makes it
extremely compact. Compiler in Java is composed in ANSI C with a clean conveyability
limit, which is a POSIX subset.

• Robustness - Java tries to kill circumstances, which can lead to potential system failures,
by stressing chiefly on runtime checking and compile time checking.

• Support for Multithreaded Applications - With Java’s multithreaded feature, it is


conceivable to compose programs that can do numerous assignments at the same time.
This configuration gimmick permits designers to build easily running intelligent
applications.

• Interpreted Code - Java byte code is interpreted on the fly to local machine. The
advancement methodology is more quick and expository since the interfacing is an
incremental and lightweight process.

• High Performance - With the utilization of Just-In-Time compilers, Java enhances the
performance of the system.

• Distributed - Java is intended for the conveyed environment of the web.

• Dynamic - Java is thought to be more dynamic than C or C++ since it is intended to adjust
to an advancing environment. Java projects can convey broad measure of run-time data
that can be utilized to check for accesses and respond to the same on run-time.

5
3.3 History of Java

James Gosling started working on the Java programming language in June 1991 for utilization in one of his
numerous set-top box ventures. The programming language, at first, was called Oak. This name was kept
after an oak tree that remained outside Gosling’s office. This name was changed to the name Green and
later renamed as Java, from a list of words, randomly picked from the dictionary. Sun discharged the first
open usage as Java 1.0 in 1995. It guaranteed Write Once, Run Anywhere (WORA), giving no-expense run-
times on prominent stages. On 13 November 2006, Sun discharged much of Java as free and open source
under the terms of the GNU General Public License (GPL). On 8 May 2007, Sun completed the procedure,
making the greater part of Java’s center code free and open-source, beside a little parcel of code to which
Sun did not hold the copyright.

3.4 Basic Syntax of Java

A basic Java program can be broken down into several constructs and elements. Typically, it can be
characterized as a collection of objects, which communicate with each other by calling each other’s
routines. The basic definitions of objects and classes are given below:

• Class - A class can be described as a blueprint that portrays the practices/expresses all the
behaviors and states of its objects.

Object - Objects are characterized by two components namely, methods and attributes or
variables. For instance, if you consider the example of a puppy, then it has the following attributes
or states: name, color and breed. In addition, it also has the following behaviours, which include
woofing, wagging and consuming. Any object is nothing but an instance of a class.

• Instance Variables - Each object has its set of variables. An object’s state is made by the qualities
alloted to these variables during program execution.

• Methods - A method is the definition of a method. Moreover, a class can contain numerous
methods. It is in these methods that behaviours like where the rationales are composed,
information is controlled and all the activities are executed.

6
3.5 Object Orient in Java

Object means a real-world entity such as a pen, chair, table, computer, watch, etc. Object-Oriented
Programming is a methodology or paradigm to design a program using classes and objects. It simplifies
software development and maintenance by providing some concepts like Classes, Inheritance,
Polymorphism, Abstraction, Encapsulation.

3.5.1 Classes

Collection of objects is called class. It is a logical entity.

A class can also be defined as a blueprint from which you can create an individual object. Class doesn't
consume any space.

3.5.2 Inheritance
When one object acquires all the properties and behaviors of a parent object, it is known as inheritance.
It provides code reusability. It is used to achieve runtime polymorphism.

3.5.3 Polymorphism
If one task is performed in different ways, it is known as polymorphism. For example: to convince the
customer differently, to draw something, for example, shape, triangle, rectangle, etc.

In Java, we use method overloading and method overriding to achieve polymorphism.

Another example can be to speak something; for example, a cat speaks meow, dog barks woof, etc.

3.5.4 Abstraction
Hiding internal details and showing functionality is known as abstraction. For example phone call, we
don't know the internal processing.

In Java, we use abstract class and interface to achieve abstraction.

3.5.5 Encapsulation
Binding (or wrapping) code and data together into a single unit are known as encapsulation. For
example, a capsule, it is wrapped with different medicines.A java class is the example of encapsulation.
Java bean is the fully encapsulated class because all the data members are private here.

7
Chapter 4 - JAVAFX

In this chapter we will learn about JavaFx library, features of JavaFx and how we can use it inside our
project.

4.1 Overview

JavaFX is a collection of Java packages that lets you add fancy graphical user interfaces to your Java
applications. With JavaFX, you can create traditional windows-style user interfaces that include familiar
controls such as labels, buttons, text boxes, check boxes, drop-down lists, and so on. But you can also
adorn these user interfaces with fancy effects such as light sources, perspective, and animation. Hence
the FX in JavaFX.

4.2 Features of JavaFX

There are many features of JavaFX :

• Java APIs - JavaFX is a Java library that consists of classes and interfaces that are written in native
Java code. The APIs are designed to be a friendly alternative to Java Virtual Machine (Java VM)
languages, such as JRuby and Scala.

• FXML and Scene Builder - FXML is an XML-based declarative markup language for constructing a
JavaFX application user interface. A designer can code in FXML or use JavaFX Scene Builder to
interactively design the graphical user interface (GUI). Scene Builder generates FXML markup that
can be ported to an IDE where a developer can add the business logic.

• WebView - A web component that uses WebKitHTML technology to make it possible to embed
web pages within a JavaFX application. JavaScript running in WebView can call Java APIs, and Java
APIs can call JavaScript running in WebView.

• Swing interoperability - Existing Swing applications can be updated with new JavaFX features, such
as rich graphics media playback and embedded Web content.

• Built-in UI Controls and CSS - JavaFX provides all the major UI controls required to develop a full-
featured application. Components can be skinned with standard Web technologies such as CSS

8
• Canvas API - The Canvas API enables drawing directly within an area of the JavaFX scene that
consists of one graphical element (node).

• Multi-touch support - JavaFX provides support for multitouch operations, based on the
capabilities of the underlying platform.

• Hardware-accelerated graphics pipeline - JavaFX graphics are based on the graphics rendering
pipeline (Prism). JavaFX offers smooth graphics that render quickly through Prism when it is used
with a supported graphics card or graphics processing unit (GPU). If a system does not feature
one of the recommended GPUs supported by JavaFX, then Prism defaults to the Java 2D software
stack.

• High-performance media engine - The media pipeline supports the playback of web multimedia
content. It provides a stable, low-latency media framework that is based on the GStreamer
multimedia framework.

• Self-contained application deployment model - Self-contained application packages have all of the
application resources and a private copy of the Java and JavaFX runtimes. They are distributed as
native install-able packages and provide the same installation and launch experience as native
applications for that operating system.

4.3 History of JavaFX

JavaFX was originally developed by Chris Oliver at SeeBeyond and it was called F3 (Form Follows Function).
F3 was a Java scripting language for easily developing GUI applications. It offered declarative syntax, static
typing, type inference, data binding, animation, 2D graphics, and Swing components. SeeBeyond was
bought by Sun Microsystems and F3 was renamed JavaFX in 2007. Oracle acquired Sun Microsystems in
2010. Oracle then open sourced JavaFX in 2013.

The first version of JavaFX was released in the fourth quarter of 2008. The current release for JavaFX is
version 8.0. The version number jumped from 2.2 to 8.0. From Java 8, the version numbers of Java SE and
JavaFX are same.

9
Chapter 5 – Feasibility Study

This chapter describes all the feasibilities that come as questions to both the developers and other users
during the development of software. The chapter contains financial feasibility, technical feasibility,
economic feasibility and legal feasibility.

5.1 Financial Feasibility

Space War is single player offline game so there is no hosting cost.

For the PC players, it is completely a free to play game, It will not even consume any internet data.

Additionally if we add some premium weapons or player skins in future updates the player need to pay to
acquire them which is a choice for the players and is not must.

The points mentioned above indicate that the project is financially feasible.

5.2 Technical Feasibility

The tools and technology that were used in the making Space Ware are:

Game Engine/GUI: JavaFX 14

Image Editor For making Characters : Online Editors

Code Editor/IDE : JetBrains IntelIJ IDEA Community Edition

Programming Language : Java

These mentioned above technologies are completely free for students. There were no other additional
tools required to make this game.

JavaFX provides all features to make GUI elements in this game.

IntelIij IDEA Community edition provides all features to write code, maintenance library and deployment
of project in Jar file. We added Maven in IDE to maintain all resources and libraries.

The simplicity of the projects along with the facts mentioned above proves that this software is also
technically feasible.

10
5.3 Economic Feasibility

The resources that are required for this project are :

• Development machine. Any regular laptop/PC with a Minimum Ram of 4GB and a decent GPU can
be used for the development of this game.

• Technical tools and software. As mentioned previously, the tools needed to develop this software
are available to developers at no change.

• Game Developers and Graphic Designers.

Although for now I have used free assets to design the game, if I want to release the game for monetizing
purposes this project will also require graphic designers for the game to get proper recognition. As these
are largely free of cost, the only expenses lie in the payment of the programming individual(s), graphic
designers and the machine. Neither of these is scarce in availability nor are they extremely expensive.

5.4 Legal Feasibility

The game assets that were used to make this game are completely free with either CC0 or CC3 licenses so
I can use them as long as I properly credit them which I already did by uploading the project to github.
And as mentioned in the previous sections this game uses freely available software and tools which are
intended for the use of game developers everywhere. There cannot be any conflict regarding any illegal
use of any software, because I have already followed the rules of the licenses to make this game.

11
Chapter 6 – System Design

6.1 List of Classes and their responsibilities

Number Class Name Responsibility

1 Hero.java Responsible for creating hero space ship.

2 HeroBullets.java Responsible for firing bullets on enemies.

3 Enemies.java Generate enemies’ space ships and move them.

4 Space.java Generate elements in background and give feel of


space(universe) in game.

5 PauseScreen.java Helps to pause game, It creates overlay on running game and


pause all characters.

6 GameScene.java Control all characters in game, responsible for most of the


task like moving characters, calling all functions of other
classes like calling move(Space space) of Space class etc,
showing score, checking for collation etc

7 GameOverScreen.java Stop all movements of Characters and create overlay to show


“Game Over” message, Open Menu of New game after game
over.

8 StartMenu.java Create Start Menu window when starts. It contains logo


“Space War”, and “Option” button.

9 OptionMenu.java Create Option Menu when user clicks on “Option” buttton. It


contains “Select Ship” button and VFX sound and Background
Music On/Off button.

10 SelectShip.java Create window to select different ship, other than default


ship

11 VFXSound.java Control VFX sounds of game like Background Music, Fire


sound, Bomb sound.

12
6.2 Class Diagram (UML Diagram)

These class diagrams will explain classes in simpler way and will show relation between each class.

6.2.1 Hero Class

Hero class is derived from ImageView class from javafx.scene.image.ImageView. Object of Hero class is
created inside GameScene to create our hero battle ship in our game.

It contains getHeroX() method which return current X position of Hero object and setHeroX(double x)
which set X position of Hero object.

ImageView

Hero
-path:File
-image:Image
+getHeroX():double
+setHeroX(double x)

6.2.2 HeroBullets Class

HeroBullets class is derived from Rectangle class from javafx.scene.shape.Rectangle. Object of Hero class
is passed through constructor of HeroBullets class. HeroBullets class is used to fire bullet whenever player
press spacebar.

It contains move() method to move bullets upward, collide(Enemies enemies) method take object of
Enemies and return true whenever enemy ship collide with bullet and shipCase(int x) method which
change skin of ship of our hero.

Rectangle

HeroBullets

<<constructor>>HeroBullets(Hero hero)
+move()
+collide(Enemies enemies):boolean
+ship(int x)

13
6.2.3 Enemies Class

Enemies class extends ImageView class. Object of Enemies class is created inside GameScene class. It is
used to create enemy ship in our game. Enemies are created randomly using Random Class of java.util.

Constructor of this class takes double posX, double posY, double height and doube width as parameter
and this parameters are used to plot Enemy ship on game stage.

It contains move() method to move enemy ships, show() method return Enemies object to show how
many enemy ship are there on stage, getPosY() return Y position of enemy ship in double data type,
collide(Hero hero) method return true if enemy ship collide with hero ship.

ImageView

Enemies

-images:Image[]
-random:Random

<<constructor>>Enemies(double posX, double posY,


double height, double width)
+move(double SPEED)
+show():Enemies(this)
+getPosY():double
+collide(Hero hero):boolean

6.2.4 PauseScreen Class

PauseScreen class extends StackPane class from javafx.scene.layout.StackPane. Whenever user press P
button on keyboard object of PauseScreen class get created and pause game.

Rectangle class is used to create overlay on game stage.

StackPane

PauseScreen

-rectangle:Rectangle
-head:Text

14
6.2.5 Space Class

Space class extends Circle class from javafx.scene.shape.Circle. This class create environment of space on
our game stage. Object of this is class is created inside GameScene class.

Random class is used to generate elements of random size in Space.

It contains move(double SPEED) method which helps to move elements of Space.

Circle

Space

- random:Random
- RADIUS:int

+move(double SPEED)

6.2.6 GameScene Class

GameScene class contain main method, this class is main stage of our game in which object of all other
classes is created. It contains object of Hero, Enemies, Space , StackPane, HeroBullets, VFXSound,
PauseScreen and StartMenu class. This class contain many methods like

1) gameReset():- This method reset whole game when player click on New Game button.

2) gameScene():- This method control whole game from showing current score to checking collision
between hero ship and enemy ship and between enemy ship and bullet.

3) gameStartMenu():- This method is called just after game is opened, this method create object of
StartMenu class.

4) start():- This method overrides the start method from Application class, this method create window for
our game, control user inputs and call gameScene() method.

5) checkPause():- Checks whether game is in pause mode or not.

6) controls(KeyCode keyCode, Hero hero):- This method take inputs from user through keyboard and
control hero ship.

15
7) setSHIPCASE(int x):- change hero ship.

8) setStart(boolean flag):- this method change value of START variable.

9) getVfxCheck():- Check if VFX sound are enabled or not.

10) setVfxCheck(boolean x):- set value of vfxCheck.

11) getBgMusicCheck():- Check if Background Music is enabled or not.

12) setBgMusicCheck(boolean x):- set status of bgMusicCheck.

GameScene

-stackpane:StackPane
-pane:Pane
-SCORE:int
-gameScene:GameScene(this)
-hero:Hero
-START:boolean
-SHIPCASE:int
-vfxSound:VFXSound
-vfxCheck:boolean
-bgMusicCheck:boolean
-enemies:Enemies
+setSHIPCASE(int x)
+setStart(boolean flag)
+getBgMusicCheck():boolean
+getVfxCheck():boolean
+setVfxCheck(boolean x)
+setBgMusicCheck(boolean x)
+gameReset();

6.2.7 SelectShip Class

SelectShip class extends AnchorPane. This class create menu to select skin for our hero ship. User click on
new skin and our hero ship get changed into that ship.

This class doesn’t have any method, It just take parameter through constructor and create Select Ship
menu whenever user click on “Select Ship” button from Option Menu window.

AnchorPane

SelectShip
-ship1, ship2. ship3, ship4, ship5,
ship6:ImageView

16
6.2.8 StartMenu Class

StartMenu class extends AnchorPane. This class is responsible for create start menu when game starts. It
contains “New Button” and “Options” button.

Its constructor take object of StackPane, GameScene, Pane, Hero, and VFXSound class as parameter.

AnchorPane

StartMenu

-logo:Text
-newGame:Text
-option:Text

<<constructor>>StartMenu(StackPane stackPane,
GameScene gameScene, Pane pane, Hero hero,
VFXSound vfxSound)

6.2.9 OptionMenu Class

OptionMenu class extends AnchorPane. It is used to show options like “Select Ship”, “VFXSound
enable/disable”, “Background Music enable/disable”.

Its constructor take object of StackPane, AnchorPane ,GameScene, Pane, Hero, and VFXSound class as
parameter.

AnchorPane

OptionMenu

-selectShip:Text
-vfxBox:CheckBox
-backgroundSound:CheckBox
VfxCheck:boolean
BgMusicCheck:boolean

<<constructor>>OptionMenu(StackPane
stackPane, Hero hero, Pane pane, AnchorPane
anchorPane, GameScene gameScene, VFXSound
vfxSound)

17
6.2.10 GameOverScreen Class

This class extends VBox class from javafx.scene.layout.Vbox. This class is used to create overlay when hero
ship get killed. User can again start new game by clicking “New Game” button from GameOverScreen.

VBox

GameOverScreen

-head:Text
-scoreToShow:Text

6.2.11 VFXSound Class

VFXSound class is responsible for VFX sound and background sound in our game. This class contain many
methods to control background music and VFX sound.

1) fireSound():- Play fire sound when player shoot bullets.

2) bombSound():- Play bomb sound when enemy ship get killed using bullet.

3) muteAll():- Mute all VFX sound.

4) unmuteAll():- Unmute all VFX sound.

5) muteBgMusic():- Mute background music of our game.

6) unmuteBgMusic():- Unmute background music of our game.

VFXSound

-background:AudioClip
-fireClip:AudioClip
-bombClip:AudioClip

<<constructor>>VFXSound()
+fireSound()
+bombSound()
+muteAll()
+unmuteAll()
+muteBgMusic()
+unmuteBgMusic()

18
6.3 Relationship Among Classes

GameScene
Circle ImageVie
-stackpane:StackPane w
-pane:Pane
-SCORE:int
-gameScene:GameScene(this)
-hero:Hero
-START:boolean
-SHIPCASE:int Hero
Space -vfxSound:VFXSound
-vfxCheck:boolean -path:File
-random:Random
-bgMusicCheck:boolean -image:Image
-RADIUS:int
-enemies:Enemies
+move(double SPEED) +getHeroX():double
+setSHIPCASE(int x)
+setHeroX(double x)
+setStart(boolean flag)
+getBgMusicCheck():boolean
+getVfxCheck():boolean
+setVfxCheck(boolean x)
+setBgMusicCheck(boolean x)
+gameReset();
ImageView Rectangle

Enemies HeroBullets
-images:Image[] <<constructor>>HeroBullets(Hero hero)
-random:Random +move()
+collide(Enemies enemies):boolean
<<constructor>>Enemies(double posX, +ship(int x)
double posY, double height, double width)
+move(double SPEED)
+show():Enemies(this)
+getPosY():double
+collide(Hero hero):boolean

AnchorPan
AnchorPane e

StartMenu
OptionMenu
-logo:Text
-selectShip:Text -newGame:Text
-vfxBox:CheckBox -option:Text
-backgroundSound:CheckBox
VfxCheck:boolean <<constructor>>StartMenu(StackPane
BgMusicCheck:boolean stackPane, GameScene gameScene, Pane
pane, Hero hero, VFXSound vfxSound)
<<constructor>>OptionMenu(StackPane
stackPane, Hero hero, Pane pane,
AnchorPane anchorPane, GameScene
gameScene, VFXSound vfxSound)

19
AnchorPane OptionMen
u

SelectShip
-ship1, ship2. ship3, ship4, ship5,
ship6:ImageView

VFXSound
GameScene -background:AudioClip
-fireClip:AudioClip
-bombClip:AudioClip

<<constructor>>VFXSound()
StackPane +fireSound()
+bombSound()
+muteAll()
+unmuteAll()
+muteBgMusic()
+unmuteBgMusic()
PauseScreen

-rectangle:Rectangle
-head:Text

VBox

GameOverScreen

-head:Text
-scoreToShow:Text

20
Chapter 7 – USER INTERFACE

User Interface (UI) is the visual part of an application or device that determines how a user interacts with
it and how information is displayed on the screen.

This User Interface chapter will provide us detailed view of our game.

7.1 View of the Game World

View of our game is Top View is Top View which is used in most of the classical arcade games.

Because of this view we can see Hero Ship as well as Enemy ship clearly.

7.2 Heads up Display

The HUD shows vital information about the game and allows for additional actions.

7.2.1 Hero Ship

Hero Ship is our main protagonist which is controlled by the player and kill enemies using bullets.

Player can move Hero Ship using arrow keys and can fire using space bar. He can change skin of Hero
Ship using “Select Ship” option from “Option Menu”.

Fig 1: Default Hero


Ship

Fig 2: Skins for Hero


Ship

21
7.2.2 Score Board

Score board shows the real time score of player. Whenever player kill enemy, his score get incremented
by one.

Fig 3 : Score Board

7.2.3 Game Stage

Game Stage is main window of our game from where player can play game. Here player can move Hero
Ship and can fire bullets, Enemies appear here and player can kill enemies by firing bullets.

Fig 4 : Game Stage

22
7.2.4 Start Menu

Start Menu is the first window appears when we open our game. We can start our game from here, we
can go into option menu by clicking on “Option” button from this menu.

Fig 4 : Start Menu

7.2.5 Option Menu

Option Menu provide options to player to change skin of Hero Ship, to turn on and off VFX sounds like
firing sound, explosion sound when enemy ship get killed and background music using checkbox.

Fig 5 : Option Menu

23
7.2.6 Game Over Screen

Game Over Screen appears when Hero Ship get killed. We can start new game from Game Over Screen.

Fig 6 : Game Over Screen

7.2.7 Select Ship Screen

Select Ship Screen is for changing skin Hero Ship. Player can change appearance of Hero Ship just by
clicking on the desired ship.

Fig 6 : Game Over Screen

24
7.2.8 Pause Screen

Pause Screen is showed when game is paused. Player can pause game by pressing P on keyboard and
can resume game by again pressing P on keyboard.

Fig 6 : Game Over Screen

25
Chapter 8 – PROGRAMMING AND IMPLEMENTING GAME

This Chapter will talk about some programming stuffs and how we implemented this game.

8.1 Packages and Files

We used single package in our game and its called “game” which is inside “src” folder. “src” folder is
automatically created by IntellIj IDEA IDE.

Inside “game” package we have all java files we need to develop our game.

“images” folder contain all images we need in our game, example HeroShip image to create our
protagonist.

“Sounds” folder contain our background music and VFX sound like fire sound, explosion sound.

8.1.1 Directory Tree of Game Project

Space War/
images

heroShip.png
ship1.png
ship2.png
ship3.png
ship4.png
ship5.png
ship6.png
enemyShip1.png
enemyShip2.png
enemyShip3.png
enemyShip4.png
enemyShip5.png

sounds

backgroundMusic.wav
bomb.wav
fire.wav

26
src

java

main

game

Enemies.java
GameLauncher.java
GameOverScreen.java
GameScene.java
Hero.java
HeroBullets.java
OptionMenu.java
PauseScreen.java
SelectShip.java
Space.java
StartMenu.java
VFXSound.java

target

classes
generate-sources
maven-archiver
maven-status
GameScene-1.0-SNAPSHOT.jar

pom.xml
GameScene.iml
SpaceInvader.iml

27
8.2 Functionality

Here we will talk about how we created elements of our game with code.

8.2.1 Creating Game Window

We created game window using JavaFX library.


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;

public class GameScene extends Application{

private final int SCENE_WIDTH = 1080; //Width of Window


private final int SCENE_HEIGHT = 720; //Height of Window
private StackPane stackPane = new StackPane();

public void start(Stage primaryStage) throws Exception {

Scene scene =new Scene(stackPane, SCENE_WIDTH, SCENE_HEIGHT);


primaryStage.setScene(scene);
primaryStage.setTitle("Space War");
primaryStage.show(); //Enable to show window on screen

}
public static void main(String[] args){
launch(args)
}
}

8.2.2 Creating Space and Elements of Space

We used Circle class of JavaFX library to create elements of space and set background color of StackPane
to black to show dark space.
package game;

import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;

import java.util.Random;

public class Space extends Circle {


private Random random = new Random();
private int SCENE_WIDTH = 1080;

int RADIUS = random.nextInt(3);


Space(){
this.setRadius(RADIUS);
this.setFill(Color.rgb(255, 255, 255, 0.5));
this.setCenterX(random.nextInt(SCENE_WIDTH));
this.setCenterY(0);
}

public void move(double SPEED){


this.setCenterY(this.getCenterY() + SPEED);
}
}

28
8.2.3 Creating Hero Ship

We created hero ship using an png image. We added image using ImageViewer class from JavaFX library.

package game;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.io.File;

public class Hero extends ImageView {


private int height = 70; //Height of Image
private int width = 130; //Width of Image
Hero() throws Exception{
this.setImage(new Image(String.valueOf(new File("images/heroSpace-
Ship.png").toURI().toURL()))); //Image Path

this.setFitHeight(height);
this.setFitWidth(width);
this.setTranslateX(480);
this.setTranslateY(650);
}
public double getHeroX(){
return this.getTranslateX();
}
}

8.2.4 Controls

To control hero ship, firing and pausing game.


package game;
//All Imported classes

public class GameScene extends Application{


//same variables from previous gamescene class

public void start(Stage primaryStage){

//Usual Code
scene.setOnKeyPressed(e ->{
if(!GAME_OVER && collide && START){
if (e.getCode() == KeyCode.P)
checkPause();
else
controls(e.getCode(), hero);
}
});
}

public void controls(KeyCode keyCode, Hero hero){ //This method control everything.
if (keyCode == KeyCode.RIGHT)
hero.setTranslateX(hero.getHeroX() + 10); //Move Hero Ship to the Right Side
if (keyCode == KeyCode.LEFT)
hero.setTranslateX(hero.getHeroX() - 10); //Move Hero Ship to the Left Side

if (keyCode == KeyCode.SPACE) {
bullets = new HeroBullets(hero);
bullets.shipCase(SHIPCASE); //Check Skin of Hero Ship
bulletsList.add(bullets); //Fire bulltes
pane.getChildren().add(bullets);
vfxSound.fireSound(); //Play sound of gun when bullet is fired
}
}
}

29
8.2.5 Creating Enemy Ship

We created Enemy ships in same way as we created hero ship. We just added random position of ships
so that Enemy ships can appear randomly on screen.
package game;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.io.File;
import java.net.MalformedURLException;
import java.util.Random;

public class Enemies extends ImageView {


private Image[] images = new Image[]{
new Image(String.valueOf(new File("images/enemtship3.png").toURI().toURL())),
//Path of all ship Images.
new Image(String.valueOf(new File("images/enemyShip2.png").toURI().toURL())),
new Image(String.valueOf(new File("images/enemyShip4.png").toURI().toURL())),
new Image(String.valueOf(new File("images/enemyShip5.png").toURI().toURL())),
new Image(String.valueOf(new File("images/enemyShip1.png").toURI().toURL()))
};
private Random random = new Random(); //This class help to randomly generate position of
ships.

Enemies(double posX, double posY, double height, double width) throws MalformedURLExcep-
tion {
this.setImage(images[random.nextInt(5)]);
this.setFitWidth(width);
this.setFitHeight(height);
this.setTranslateX(posX);
this.setTranslateY(posY);
}

public void move(double SPEED){ //Move the ship according to given speed.
this.setTranslateY(this.getTranslateY()+SPEED);
}

public Enemies show(){


return this;
}
public double getPosY(){ //Shows the Y axis position of Enemy Ship.
return this.getTranslateY();
}
public boolean collide(Hero hero){ //Return true when Ship collide with Hero Ship.
boolean isCollide = false;
if (hero.getBoundsInParent().intersects(this.getBoundsInParent())) {
isCollide = true;
}
return isCollide;
}

30
8.2.6 Creating Bullets

We used Rectangle class from JavaFX library. Whenever player press Space bar key from keyboard, new
object of HeroBullets class.
package game;

import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

public class HeroBullets extends Rectangle {


HeroBullets(Hero hero){
this.setHeight(3);
this.setWidth(3);
this.setFill(Color.RED);
this.setTranslateX(hero.getTranslateX()+(hero.getFitWidth()/2));
this.setTranslateY(hero.getTranslateY()-10);
}
public void move(){ //move bullet in verticle direction.
this.setTranslateY(this.getTranslateY()-5);
}
public boolean collide(Enemies enemies){ //Return true if enemy collide with bullet.
boolean isCollide = false;
if (enemies.getBoundsInParent().intersects(this.getBoundsInParent())){
isCollide = true;
}
return isCollide;
}
public void shipCase(int x){ //Change colour of bullet according to skin Hero Ship.
switch (x){
case 1:
this.setFill(Color.GREEN);
break;
case 2:
this.setFill(Color.WHITE);
break;
case 3:
this.setFill(Color.RED);
break;
case 4:
this.setFill(Color.YELLOW);
break;
case 5:
this.setFill(Color.ORANGE);
break;
case 6:
this.setFill(Color.CYAN);
break;
}
}
}

31
8.2.7 Creating Start Menu

Start Menu is created using AnchorPane from JavaFX

package game;

//all used classes imported here from javaFX library

public class StartMenu extends AnchorPane {

//variable to set heigth and width of window


StartMenu(StackPane stackPane, GameScene gameScene, Pane pane, Hero hero, VFXSound vfxSound){

this.setTranslateX((SCENE_WIDTH/2)-150);
this.setTranslateY((SCENE_HEIGHT/2)-150);

Text logo = new Text("SPACE WAR");

//setting all values and attributes of logo here.

Text newGame = new Text("New Game");

//setting all values and attributes of ‘New Game’ button here.

Text option = new Text("Options");

//setting all values and attributes of ‘Options’ button here.

newGame.setOnMouseClicked(e ->{

//trigger all statements under braces when ‘New Game’ Button is pressed.

});

option.setOnMouseClicked(e->{

//trigger all statements under braces when ‘Options’ Button is pressed.

});
this.getChildren().addAll(logo,newGame, option);
stackPane.getChildren().add(this);
}
}

8.2.8 Creating Pause Screen


package game;

//Importing all usefull classes here

public class PauseScreen extends StackPane {


private int SCENE_HEIGHT = 720;
private int SCENE_WIDTH = 1080;
private Rectangle rectangle;
PauseScreen(){
this.setHeight(SCENE_HEIGHT-100);
this.setWidth(SCENE_WIDTH -100);
rectangle = new Rectangle(this.getWidth(), this.getHeight(), Color.rgb(255,255,255,0.2));
Text head = new Text("PAUSED");
head.setFont(new Font(25));
this.getChildren().addAll(rectangle,head);
}
}

32
8.2.9 Creating Option Menu

We created Option menu in same way as we created Start Menu

package game;

//Importing all usefull classes

public class OptionMenu extends AnchorPane {


//defining width and height of Menu
private Text selectShip;
private CheckBox vfxBox;
private CheckBox backgroundSound;
OptionMenu(StackPane stackPane, Hero hero, Pane pane, AnchorPane anchorPane, GameScene
gameScene, VFXSound vfxSound){
this.setTranslateX((SCENE_WIDTH/2)-150);
this.setTranslateY((SCENE_HEIGHT/2)-150);

selectShip = new Text("Select Ship");


//setting all attributes of selectShip here.
selectShip.setOnMouseEntered(e->{
selectShip.setFill(Color.RED);
});
selectShip.setOnMouseExited(e->{
selectShip.setFill(Color.WHITE);
});
selectShip.setOnMouseClicked(e->{
//trigerring all statements inside this arrow function.
});

vfxBox = new CheckBox("VFX Sound");


//setting all attributes of vfxBox here.
vfxBox.setOnMouseEntered(e->{
vfxBox.setTextFill(Color.RED);
});
vfxBox.setOnMouseExited(e->{
vfxBox.setTextFill(Color.WHITE);
});
vfxBox.setOnMouseClicked(e->{
//trigerring all statements inside this arrow function.
});

backgroundSound = new CheckBox("Background Sound");


//setting all attributes of backgroundSound here.
backgroundSound.setTextFill(Color.RED);
});
backgroundSound.setOnMouseExited(e->{
backgroundSound.setTextFill(Color.WHITE);
});
backgroundSound.setOnMouseClicked(e->{
//trigerring all statements inside this arrow function.
});

this.getChildren().addAll(selectShip, vfxBox, backgroundSound);


}
}

33
8.2.10 Creating Select Ship Menu
package game;

/*all important classes


imported here */

import java.io.File;
import java.net.MalformedURLException;

public class SelectShip extends AnchorPane {


//declaring varibale for height and width of screen here.
ImageView ship1, ship2, ship3, ship4, ship5, ship6;
//declaring varibale for height and width for enemy ship

SelectShip(Hero hero, Pane pane, StackPane stackPane, AnchorPane anchorPane, GameScene


gameScene) throws MalformedURLException {

this.setTranslateX((SCENE_WIDTH/2)-150);
this.setTranslateY((SCENE_HEIGHT/2)-150);

GridPane gridPane = new GridPane();


//designing gridpane here for enemy ship layout.
ship1 = new ImageView();
//setting ship1 postion, height, width and postion here.
ship1.setOnMouseClicked(e->{
//statements which will run when player will click on ship1.
});

ship2 = new ImageView();


//setting ship2 postion, height, width and postion here.
ship2.setOnMouseClicked(e->{
//statements which will run when player will click on ship2.
});

ship3 = new ImageView();


//setting ship3 postion, height, width and postion here.
ship3.setOnMouseClicked(e->{
//statements which will run when player will click on ship3.
});

ship4 = new ImageView();


//setting ship4 postion, height, width and postion here.
ship4.setOnMouseClicked(e->{
//statements which will run when player will click on ship4.
});

ship5 = new ImageView();


//setting ship5 postion, height, width and postion here.
ship5.setOnMouseClicked(e->{
//statements which will run when player will click on ship5.
});

ship6 = new ImageView();


//setting ship6 postion, height, width and postion here.
ship6.setOnMouseClicked(e->{
//statements which will run when player will click on ship6.
});

/*setting all ships in grid here


using Grid Object */

this.getChildren().add(gridPane);
}
}

34
8.2.11 VFX and Background Sound

We used wav format for background music and for VFX sound.

package game;

import javafx.scene.media.AudioClip;
import java.io.File;

public class VFXSound {


private AudioClip fireClip;
private AudioClip bombClip;
private AudioClip background;
VFXSound() throws Exception{
fireClip = new AudioClip(String.valueOf(new File("sounds/fire.wav").toURI().toURL()));
bombClip = new AudioClip(String.valueOf(new File("sounds/bomb.wav").toURI().toURL()));
background = new AudioClip(String.valueOf(new File("sounds/background-
Music.wav").toURI().toURL()));
background.play(); //Play background Music.
}
public void fireSound(){ //Play Sound when player fire bullets.
if (!fireClip.isPlaying()){
fireClip.play();
}
}
public void bombSound(){ //Play Sound when player enemy ship get hit by bullet.
if (!bombClip.isPlaying()){
bombClip.play();
}
}
public void muteAll(){ //Mute all VFX sound when player disable it from option.
fireClip.setVolume(0.0);
bombClip.setVolume(0.0);
}
public void unmuteAll(){ //Unmute all VFX sound when player enable VFX sound.
fireClip.setVolume(1.0);
bombClip.setVolume(1.0);
}
public void muteBgMusic(){ //Mute Background Music.
background.stop();

}
public void unmuteBgMusic(){ //Unmute Background Music.
background.play();
}
}

35
Chapter 9 – FUTURE PLANS

This Chapter will talk about future plans for our game project. We can make it more interesting in future
by adding many features.

9.1 Removing Errors and Bugs

Even after completing our project we still have some errors and bugs left in our game which are minor
but still may cause issue for some players.

• We get run time error sometime when player fire bullets. Sometime it doesn’t even play gun firing
sound when player fire bullets.
• Random position of enemy ship cause overlap of ships, which we can fix by checking positon of
other enemy ships.
• All elements of space get removed when player press ‘New Game’ after game over.
• Hero get killed even when enemy ship is little far from hero ship, we can fix this issue by changing
intersection values of enemy ship and hero ship.
• Right now we don’t have back button on every menu which make difficult for player to return to
main menu, we can fix this issue by adding back button on every menu screen.

We can remove these bugs and errors in our next update.

9.2 Adding New Bullets for Hero Ship

We can add more bullets in our future update so that player can enjoy our game more.

Right now we have feature of upgradation of bullet when player complete score of 20. We can add more
bullets when score get incremented by 20.

In future update, Player can even select his own bullet from option menu when new bullet get unlocked.

9.3 Adding New Levels

We will add new levels in our game. New levels with new enemies, new boss, new background sound,
new hero ships and new weapons which player can change from option menu.

Player can change levels from options.

36
9.4 Adding Public Score Board

We can add public score board in our game which will show high score of whoever play this game in
world.

For this we will add login functionality in this through which player can register his name in game and
whenever he will get high score, this high score will be uploaded on public score board with his name or
email id.

37
CONCLUSION

It was an exciting project to work on and there is a lot I learnt from it, above and beyond its original scope.
I was able to study and train myself on development in an environment that was almost completely
foreign to me, which I believe I have been reasonably successful with.

Although I was not able to complete some of the proposed functionality, the functionality related to the
core purpose of the application is working as desired. I believe there is still a lot of potential for this
application, and will continue development in the future.

You might also like