Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

“JNANA SANGAMA”, BELGAUM-590018.

A
Mini Project Report
On

SPACE SHOOTER GAME


SUBMITTED IN FULFILLMENT OF THE REQUIREMENT IN
6TH SEMESTER MOBILE APPLICATION DEVELOPMENT MINI PROJECT WORK OF BACHELOR OF
ENGINEERING
IN

COMPUTER SCIENCE AND ENGINEERING


By

Nikitha D [1JB20CS071]
Nischitha B[1JB20CS073]

UNDER THE GUIDANCE OF

Mrs. Rajatha
Assistant Professor
Dept. of CSE

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

SJB INSTITUTE OF TECHNOLOGY


No. 67, BGS HEALTH AND EDUCATION CITY,
Dr. Vishnuvardhana Road, Kengeri, Bangalore-560060.
2022-2023
||Jai Sri Gurudev||
Sri Adichunchanagiri Shikshana Trust ®
SJB INSTITUTE OF TECHNOLOGY
No.67, BGS Health & Education City, Dr. Vishnuvardhana Road,
Kengeri, Bangalore-560060.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CERTIFICATE

This is to certify that the mini project report entitled “Space Shooter Game” is a
bonafied work carried out Nikitha D [1JB20CS071], Nischitha B [1JB20CS073] in partial
fulfillment of mini project of 6th semester Mobile Application Development Laboratory
(18CSMP68) in COMPUTER SCIENCE AND ENGINEERING of VISVESVARAYA
TECHNOLOGICAL UNIVERSITY, BELGAUM, during the academic year 2022-2023. It is
certified that all corrections/suggestions have been incorporated in the report deposited in the
department library. The mini project report has been approved as it satisfies the academic
requirements.

___________________ ___________________
Signature of the guide Signature of the HOD
Mrs. Rajatha Dr. Krishna A N
Asst. Professor Professor & Head
Dept. of CSE Dept. of CSE

Name of the Examiner: Signature of the Examiner:

1. _______________________ __________________________

2. _______________________ __________________________
ACKNOWLEDGEMENT

We would like to express our profound gratefulness to His Divine Soul Jagadguru
Padmabhushana Sri Sri Sri Dr. Balagangadharanatha Mahaswamiji and His Holiness
Jagadguru Sri Sri Sri Dr. Nirmalanandanatha Mahaswamiji for providing me with an
opportunity to study in this esteemed Institution.

We would like to express our profound thanks to Reverend Sri Sri Dr. Prakashnath Swamiji,
Managing Director, SJB Institute of Technology, for his continuous support in providing
amenities to carry out this mini project in this admired institution.

We express our gratitude to Dr. K V Mahendra Prashanth, Principal, SJB Institute of


Technology, for providing me with excellent facilities and academic ambience; which have
helped me in satisfactory completion of this mini project.

We extend our sincere thanks to Dr. Krishna A N, Head of the Department of Computer Science
and Engineering, for providing me with invaluable support throughout the period of my mini
project.

We wish to express our heartfelt gratitude to our guides, Mrs. Rajatha, Assistant professor,
Dept. of CSE for their valuable guidance, suggestions and cheerful encouragement during the
entire period of this min project work.

Finally, We take this opportunity to extend our earnest gratitude and respect to our parents,
Teaching & Non-teaching staffs of the department, the library staff and all our friends, who have
directly or indirectly supported me during the period of our mini project work.

Regards,

Nikitha D [1JB20CS071]
Nischitha B [1JB20CS073]
ABSTRACT

The rapid evolution of mobile technology has transformed the way we consume and
interact with game. Mobile games are now a way of relaxing and have indeed become a part of
our daily lives. ”Space Shooter is a simple, yet addictive, space shooter game developed in
Android Studio." The proposed approach is designed to make space shooter games more
accessible to a wider audience. By simplifying the controls and relaxing the pace, the game can
be enjoyed by players of all skill levels. The game is a single-player game that is played from a
top-down perspective. The player controls a spaceship that can move left, right, up, and down.
The player can also shoot bullets at enemies. The goal of the game is to survive as long as
possible by destroying enemy ships. The game is easy and simple to play. It has intuitive controls
that are easy to learn and straightforward gameplay that is easy to follow. This makes it a great
game for beginners and casual gamers who are looking for a fun and relaxing experience.

ii
TABLE OF CONTENTS

Acknowledgement i

Abstract ii

Table of Contents iii

List of Figures v

List of Tables vi

Chapter 1 INTRODUCTION

1.1 Mobile Application Development 1

1.2 Android Studio 2

1.3 Java 2

1.4 Xml 3

1.5 About Mini Project 3

1.6 Scope of Project 3

1.7 Objective of the Project 3

1.8 Advantages 4

Chapter 2 SYSTEM REQUIREMENTS

2.1 Introduction 5

2.2 Hardware Requirements 5

2.3 Software Requirements 5

2.4 Functional Requirements 5

2.5 Android Studio Emulator 5

2.6 Platform 6

Chapter 3 SYSTEM DESIGN

3.1 Flowchart 7

3.2 Algorithm 8

3.3 Description Function 9

Chapter 4 IMPLEMENATION

4.1 Java 10
4.2 Implementation Code 10
4.3 Code Snippet 11
4.3.1 MainActivity.java 11

4.3.2 OurSpaceShip.java 11

4.3.3 Shot.java 12

iii
4.3.4 SpaceShooter.java 13

4.3.5 Explosion.java 19

4.3.6 GameOver.java 20

4.3.7 StartUp.java 21

4.3.8 Manifest.xml 22

Chapter 5 SNAPSHOTS 23

Chapter 6 CONCLUSION 26

REFERENCES 27

iv
List Of Figures

3.1 Flowchart of the project 7

5.1 Starting Page 23

5.2 Game Screen 23

5.3 Game in Process 24

5.4 Protecting ship and exploding enemy ship 24

5.5 Game Over 25

v
List of Tables

3.1 Description of Function 9

vi
Space Shooter Game

CHAPTER 1

INTRODUCTION
” Space Shooter is a simple, yet addictive, space shooter game developed in Android
Studio." The proposed approach is designed to make space shooter games more accessible to a
wider audience. By simplifying the controls and relaxing the pace, the game can be enjoyed by
players of all skill levels. The game is a single-player game that is played from a top-down
perspective. The player controls a spaceship that can move left, right, up, and down. The player
can also shoot bullets at enemies. The goal of the game is to survive as long as possible by
destroying enemy ships. The game is easy and simple to play. It has intuitive controls that are easy
to learn and straightforward gameplay that is easy to follow.

1.1 Mobile Application development

Mobile application development is a term used to denote the act or process by which
application software is developed for handheld devices, such as personal digital assistants,
enterprise digital assistants or mobile phones. These applications can be pre- installed on phones
during manufacturing platforms or delivered as web applications using server-side or User
interface design (UI) or user interface engineering is the design of user interfaces for machines
and software, such as computers, home appliances, mobile devices, and other electronic devices,
with the focus on maximizing the user experience. The goal of user interface design is to make
the user's interaction as simple and efficient as possible; in terms of accomplishing user goals
(user-centered design). Good user interface design facilitates finishing the task at hand without
drawing unnecessary attention to it. Graphic design and typography are utilized to support its
usability, influencing how the user performs certain interactions and improving the aesthetic
appeal of the design.

ADVANTAGES:
• Improves Efficiency.
• Offers High Scalability.
• Secures the App Data.
• Easy to Maintain.
• Improves Customer Relationship
• Facilitates New Client Data Retrieval.
• Provides Real-time Project Access.
• Ease in Project Management.

Dept of CSE,SJBIT 2022-2023 Page | 1


Space Shooter Game

1.2 Android Studio

Android Studio is the official Integrated Development Environment (IDE) for Android
app development, based on IntelliJ IDEA software. It provides the fastest tools for building apps
on every type of android device. It is a purpose-built for android to accelerate the development
and helps to build the highest-quality apps for every android device.

FEATURES:
• A flexible Gradle-based build system.
• A unified environment where one can develop for all Android devices.
• Apply Changes to push code and resource changes to the running app without restarting the
app.
• Extensive testing tools and frameworks.
• Lint tools to catch performance, usability, version compatibility, and other problems C++
and NDK support.
• Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud
Messaging and App Engine.

1.3 Java

Java is an object-oriented programming language created by James Gosling, Mike


Sheridan, and Patrick Naughton in 1991. It is a high-level, class-based language that is designed
to have a few implementation dependencies as possible. It is a general- purpose programming
language intended to let android developers run the compiled Java code on all platforms that
support Java without any need for recompilation.

FEATURES OF JAVA:

• Simple: Java is designed to be easy to learn.


• Secure: With Java’s secure feature it enables to develop virus-free, tamper-free systems.
Authentication techniques are based on public-key encryption.
• Architecture-neutral: Java compiler generates an architecture-neutral object file format,
which makes the compiled code executable on many processors, with the presence of Java
runtime system.
• Portable: Being architecture-neutral and having no implementation dependent aspects of the
specification makes Java portable. The compiler in Java is written in ANSI C with a clean
portability boundary, which is a POSIX subset.

Dept of CSE,SJBIT 2022-2023 Page | 2


Space Shooter Game

• Robust: Java makes an effort to eliminate error-prone situations by emphasizing mainly on


compile time error checking and runtime checking.

1.4 XML

Extensible Markup Language (XML) is a markup language that defines a set of rules for
encoding documents in a format that is both human-readable and machine- readable. The design
goals of XML focus on simplicity, generality, and usability across the Internet. It is a textual data
format with strong support via Unicode for different human languages. Although the design of
XML focuses on documents, the language is widely used for the representation of arbitrary data
structures such as those used in web services.

FEATURES OF XML:

• XML focuses on data rather than how it looks.


• Easy and efficient data sharing.
• Compatibility with other markup language HTML.
• Supports platform transition.
• Allows XML validation.
• Adapts technology advancements.
• supports Unicode.

1.5 About mini project

This is a complete project of a simple 2D space shooter game . The game contains all the
"ingredients" needed to learn the paradigms underlying videogames development including (but
not limited to) player-enemies interaction, How the invaders & attacker shoots, GUI ,explosion
animation, game start/end proceed and How to calculate points and many more.

1.6 Scope of Project

The scope of the project includes followings


• Functional specification document to describe the complete system in low level
• User interface design for website and mobile phone for both iOS and Android.
• Development of all functional requirements as proposed for the web and mobile application.
• Setting up the system on live server in ready for use condition
1.7 Objective of the Project

Dept of CSE,SJBIT 2022-2023 Page | 3


Space Shooter Game

The objective of a space shooter game is to control a spacecraft or a character and engage
in combat with enemy spaceships or other hostile entities in a space-themed environment. The
primary goal is usually to destroy enemies while avoiding or surviving their attacks. space
shooter game is to provide an exciting and immersive experience, combining skillful shooting,
reflexes, and strategic decision-making to overcome challenges and emerge victorious in the
vastness of space.

1.8 Advantages

• User Interface
• Easy maintenance
• Best User Experience
• People can enjoy the news anytime and anywhere
• Frequent news updates
• Provide diverse content

Dept of CSE,SJBIT 2022-2023 Page | 4


Space Shooter Game

CHAPTER 2

SYSTEM REQUIREMENTS
2.1 Introduction
Requirements are during early stages of a system development as a specification of what
should be implemented or as a constraint of some kind of on the system. They may be a user
level facility descript -ion, a detailed specification of expected system behavior, a general
system property, a specific contai -nt on the system, and information on how to carry out some
computation or a constraint on the devel -opment of the system. System requirements are more
detailed descriptions of the user requirements. They are used by software engineers as the
starting point of system design. In principle, the system requirements should state what the
system should do and not how it should be implemented.

2.2 Hardware Requirements


• Processor: Intel core Duo 2.0GHz or more.
• RAM: 6GB or more.
• Hard disk: 80GB or more
• Monitor: 15” CRT or LCD monitor
• Keyboard: Normal or Multimedia
• Mouse: Compatible mouse

2.3 Software Requirements


• Android Studio Flamingo 2022.2.1
• Java Development Kit (JDK) 8
• Java
• Operating system-Windows OS, Linux or Mac

2.4 Functional Requirements


The functional requirements are the statement of services the system should provide,
how system reacts to particular inputs and how system should behave in particular situation. It
describes the functionality that the system provides.
Our app requires:
• Active internet connection.
• A firebase console to store the data.

Dept of CSE,SJBIT 2022-2023 Page | 5


Space Shooter Game

2.5 Android Studio Emulator


Android Studio is the default development platform for Android application. It comes
with collections of tools that help developers to make their apps and games specifically for
Android devices. It also provides a built-in emulator which is used to test your app takes a few
minutes to start.

2.6 Platform

The platform organizations need to develop, deploy and manage mobile applications is made
from many components, and tools allow a developer to write, test and deploy.

Front-end development tools

Front-end development tools are focused on the user interface and user experience (UI/UX)
and provide the following capabilities:
• UI design tools
• SDKs to access device features
• Cross-platform accommodations/support

Back-end servers

Back-end tools pick up where the front-end tools leave off, and provide a set of reusable
services that are centrally managed and controlled and provide the following capabilities:
• Integration with back-end systems
• User authentication/authorization
• Data services
• Reusable business logic

Security add-on layers

The security is more important within more enterprises, IT departments often need stopgap,
tactical solutions that layer on top of existing apps, phones, and platform component.
• App wrapping for security.
• Data encryption
• Client actions
• Reporting and statistics

Dept of CSE,SJBIT 2022-2023 Page | 6


Space Shooter Game

CHAPTER 3

SYSTEM DESIGN

3.1 Flow Chart of the Project

Fig 3.1 Flow chart of the project


Once the app is installed in the android mobile phone, the user will be able to view main menu
where play button is displayed when the user clicks on the play button game screen is displayed
with points = 0 and life= 3 at the starting of the game then when user keeps playing the game
simultaneously points get updated each attack gains 1 points and if the enemy ship attack the user
,user will loose one life ,once all the life of user is over points screen is displayed and user can press
exit button to close the game and retry button to restart the game .

Dept of CSE,SJBIT 2022-2023 Page | 7


Space Shooter Game

3.2 Algorithm
Initialize the game:
● Set up the game screen, player ship, and score.
● Display the main menu.
Handle user input:
● Listen for user input to choose options from the main menu (play or exit) and level selection.
● Handle input for player ship movement and shooting during gameplay.
Start the game:
● If the player chooses to play:
1. Initialize the chosen level with appropriate enemy configurations and level settings.
2. Display the level selection screen.
Game loop:
● While the player ship is alive and enemies exist:
1. Update the player ship's position and handle shooting.
2. Update enemy positions and behavior.
3. Detect collisions between the player ship and enemies.
4. Update the score and destroy enemies upon collision.

● If all enemies are destroyed:


1. Display the victory screen.
2. Wait for the player to choose to proceed to the next level or return to the main menu.
Handle user choices:
● If the player chooses to play again:
1. Go back to the level selection screen.
● If the player chooses to return to the main menu:
1. Go back to the main menu screen.
Exit the game:
● If the player chooses to exit:
● Terminate the game.

Dept of CSE,SJBIT 2022-2023 Page | 8


Space Shooter Game

3.2 Description Function

Table no 3.1 shows function used in project and its description.

Table no 3.1:

SL NO. FUNCTION DESCRIPTION

1. Text View
A TextView displays text to the user and optionally
allows them to edit it. A TextView is a complete text
editor, however the basic class is configured to not
allow editing.

2. Edit Text
A EditText is an overlay over TextView that
configures itself to be editable. It is the predefined
subclass of TextView that includes rich editing
capabilities.

3. Button
In Android, Button represents a push button. A Push
buttons can be clicked, or pressed by the user to
perform an action.

4. Image View Displays image resources, for example Bitmap or


Drawable resources. Image View is also commonly
used to apply tints to an image and handle image
scaling.
5. Menu Common user interface components which is used to
handle common functionalitie around the application

6. Toast A toast providessimple feedback about an operation in


a small popup. It only fills the amount of space
required for the message and the current activity
remains visible and interactive. Toasts automatically
disappear after a timeout.

Dept of CSE,SJBIT 2022-2023 Page | 9


Space Shooter Game

CHAPTER 4
IMPLEMENTATION
4.1. Java
There are several ways to create apps for Android devices, but their commended method
for most developers is to write native apps using Java and the Android SDK. Java for Android
apps is both similar and quite different from other types of Java applications. If you have
experience with Java (or a similar language) then you’ll probably feel comfortable diving right
into the code and learning how to use the Android SDK to make your app run. But if you’re new
to programming or object- oriented languages then you’ll probably want to get familiar with the
syntax of the Java language and how to accomplish basic programming tasks before learning
how to use the Android SDK.

4.2. Implementation Code

Fig 4.1: Overview of files in app

Fig 4.1 shows the overview of the files in the application. Which contains many modules like
MainActivity, EnemySpaceship, Explosion, GameOver, OurSpaceship ,Shot, SpaceShooter
StartUp and many other.

Dept of CSE,SJBIT 2022-2023 Page | 10


Space Shooter Game

4.3 Code Snippet

4.3.1 Main Activity

package com.example.spaceshooters;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SpaceShooter(this));
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void onPause() {
super.onPause();
}
}

4.3.2 OurSpaceship.java

package com.example.spaceshooters;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.util.Random;
public class OurSpaceship {
Context context;
Bitmap ourSpaceship;
int ox, oy;
Random random;
public OurSpaceship(Context context) {
this.context = context;

Dept of CSE,SJBIT 2022-2023 Page | 11


Space Shooter Game

ourSpaceship = BitmapFactory.decodeResource(context.getResources(), R.drawable.rocket1);


random = new Random();
ox = random.nextInt(SpaceShooter.screenWidth);
oy = SpaceShooter.screenHeight - ourSpaceship.getHeight();
}
public Bitmap getOurSpaceship(){
return ourSpaceship;
}
int getOurSpaceshipWidth(){
return ourSpaceship.getWidth();
}
}

4.3.3 Shot.java

package com.example.spaceshooters;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class Shot {
Bitmap shot;
Context context;
int shx, shy;
public Shot(Context context, int shx, int shy) {
this.context = context;
shot = BitmapFactory.decodeResource(context.getResources(),
R.drawable.shot);
this.shx = shx;
this.shy = shy;
}
public Bitmap getShot(){
return shot;
}
public int getShotWidth() {
return shot.getWidth();

Dept of CSE,SJBIT 2022-2023 Page | 12


Space Shooter Game

}
public int getShotHeight() {
return shot.getHeight();
}
}
4.3.4 SpaceShooter.java

package com.example.spaceshooters;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.os.Handler;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;

import java.util.ArrayList;
import java.util.Random;

public class SpaceShooter extends View {


Context context;
Bitmap background, lifeImage;
Handler handler;
long UPDATE_MILLIS = 30;
static int screenWidth, screenHeight;
int points = 0;
int life = 3;
Paint scorePaint;
int TEXT_SIZE = 80;

Dept of CSE,SJBIT 2022-2023 Page | 13


Space Shooter Game

boolean paused = false;


OurSpaceship ourSpaceship;
EnemySpaceship enemySpaceship;
Random random;
ArrayList<Shot> enemyShots, ourShots;
Explosion explosion;
ArrayList<Explosion> explosions;
boolean enemyShotAction = false;
final Runnable runnable = new Runnable() {
@Override
public void run() {
invalidate();
}
};
public SpaceShooter(Context context) {
super(context);
this.context = context;
Display display = ((Activity) getContext()).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
screenHeight = size.y;
random = new Random();
enemyShots = new ArrayList<>();
ourShots = new ArrayList<>();
explosions = new ArrayList<>();
ourSpaceship = new OurSpaceship(context);
enemySpaceship = new EnemySpaceship(context);
handler = new Handler();
background = BitmapFactory.decodeResource(context.getResources(), R.drawable.bg);
lifeImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.life);
scorePaint = new Paint();
scorePaint.setColor(Color.RED);
scorePaint.setTextSize(TEXT_SIZE);
scorePaint.setTextAlign(Paint.Align.LEFT);

Dept of CSE,SJBIT 2022-2023 Page | 14


Space Shooter Game

@Override
protected void onDraw(Canvas canvas) {
// Draw background, Points and life on Canvas
canvas.drawBitmap(background, 0, 0, null);
canvas.drawText("Pt: " + points, 0, TEXT_SIZE, scorePaint);
for(int i=life; i>=1; i--){
canvas.drawBitmap(lifeImage, screenWidth - lifeImage.getWidth() * i, 0, null);
}
// When life becomes 0, stop game and launch GameOver Activity with points
if(life == 0){
paused = true;
handler = null;
Intent intent = new Intent(context, GameOver.class);
intent.putExtra("points", points);
context.startActivity(intent);
((Activity) context).finish();
}
// Move enemySpaceship
enemySpaceship.ex += enemySpaceship.enemyVelocity;
// If enemySpaceship collides with right wall, reverse enemyVelocity
if(enemySpaceship.ex + enemySpaceship.getEnemySpaceshipWidth() >= screenWidth){
enemySpaceship.enemyVelocity *= -1;
}
// If enemySpaceship collides with left wall, again reverse enemyVelocity
if(enemySpaceship.ex <=0){
enemySpaceship.enemyVelocity *= -1;
}
// Till enemyShotAction is false, enemy should fire shots from random travelled distance
if(enemyShotAction == false){
if(enemySpaceship.ex >= 200 + random.nextInt(400)){
Shot enemyShot = new Shot(context, enemySpaceship.ex +
enemySpaceship.getEnemySpaceshipWidth() / 2, enemySpaceship.ey );
enemyShots.add(enemyShot);

Dept of CSE,SJBIT 2022-2023 Page | 15


Space Shooter Game

// We're making enemyShotAction to true so that enemy can take a short at a time
enemyShotAction = true;
}
if(enemySpaceship.ex >= 400 + random.nextInt(800)){
Shot enemyShot = new Shot(context, enemySpaceship.ex +
enemySpaceship.getEnemySpaceshipWidth() / 2, enemySpaceship.ey );
enemyShots.add(enemyShot);
// We're making enemyShotAction to true so that enemy can take a short at a time
enemyShotAction = true;
}
else{
Shot enemyShot = new Shot(context, enemySpaceship.ex +
enemySpaceship.getEnemySpaceshipWidth() / 2, enemySpaceship.ey );
enemyShots.add(enemyShot);
// We're making enemyShotAction to true so that enemy can take a short at a time
enemyShotAction = true;
}
}
// Draw the enemy Spaceship
canvas.drawBitmap(enemySpaceship.getEnemySpaceship(), enemySpaceship.ex,
enemySpaceship.ey, null);
// Draw our spaceship between the left and right edge of the screen
if(ourSpaceship.ox > screenWidth - ourSpaceship.getOurSpaceshipWidth()){
ourSpaceship.ox = screenWidth - ourSpaceship.getOurSpaceshipWidth();
}else if(ourSpaceship.ox < 0){
ourSpaceship.ox = 0;
}
// Draw our Spaceship
canvas.drawBitmap(ourSpaceship.getOurSpaceship(), ourSpaceship.ox, ourSpaceship.oy,
null);
// Draw the enemy shot downwards our spaceship and if it's being hit, decrement life,
remove
// the shot object from enemyShots ArrayList and show an explosion.
// Else if, it goes away through the bottom edge of the screen also remove
// the shot object from enemyShots.

Dept of CSE,SJBIT 2022-2023 Page | 16


Space Shooter Game

// When there is no enemyShots no the screen, change enemyShotAction to false, so that


enemy
// can shot.
for(int i=0; i < enemyShots.size(); i++){
enemyShots.get(i).shy += 15;
canvas.drawBitmap(enemyShots.get(i).getShot(), enemyShots.get(i).shx,
enemyShots.get(i).shy, null);
if((enemyShots.get(i).shx >= ourSpaceship.ox)
&& enemyShots.get(i).shx <= ourSpaceship.ox +
ourSpaceship.getOurSpaceshipWidth()
&& enemyShots.get(i).shy >= ourSpaceship.oy
&& enemyShots.get(i).shy <= screenHeight){
life--;
enemyShots.remove(i);
explosion = new Explosion(context, ourSpaceship.ox, ourSpaceship.oy);
explosions.add(explosion);
}else if(enemyShots.get(i).shy >= screenHeight){
enemyShots.remove(i);
}
if(enemyShots.size() < 1){
enemyShotAction = false;
}
}
// Draw our spaceship shots towards the enemy. If there is a collision between our shot
and enemy
// spaceship, increment points, remove the shot from ourShots and create a new Explosion
object.
// Else if, our shot goes away through the top edge of the screen also remove
// the shot object from enemyShots ArrayList.
for(int i=0; i < ourShots.size(); i++){
ourShots.get(i).shy -= 15;
canvas.drawBitmap(ourShots.get(i).getShot(), ourShots.get(i).shx, ourShots.get(i).shy,
null);
if((ourShots.get(i).shx >= enemySpaceship.ex)
&& ourShots.get(i).shx <= enemySpaceship.ex +

Dept of CSE,SJBIT 2022-2023 Page | 17


Space Shooter Game

enemySpaceship.getEnemySpaceshipWidth()
&& ourShots.get(i).shy <= enemySpaceship.getEnemySpaceshipWidth()
&& ourShots.get(i).shy >= enemySpaceship.ey){
points++;
ourShots.remove(i);
explosion = new Explosion(context, enemySpaceship.ex, enemySpaceship.ey);
explosions.add(explosion);
}else if(ourShots.get(i).shy <=0){
ourShots.remove(i);
}
}
// Do the explosion
for(int i=0; i < explosions.size(); i++){
canvas.drawBitmap(explosions.get(i).getExplosion(explosions.get(i).explosionFrame),
explosions.get(i).eX, explosions.get(i).eY, null);
explosions.get(i).explosionFrame++;
if(explosions.get(i).explosionFrame > 8){
explosions.remove(i);
}
}
// If not paused, we’ll call the postDelayed() method on handler object
// run method inside Runnable to be executed after 30 milliseconds, that is the value inside
// UPDATE_MILLIS.
if(!paused)
handler.postDelayed(runnable, UPDATE_MILLIS);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
int touchX = (int)event.getX();
// When event.getAction() is MotionEvent.ACTION_UP, if ourShots arraylist size < 1,
// create a new Shot.
// This way we restrict ourselves of making just one shot at a time, on the screen.
if(event.getAction() == MotionEvent.ACTION_UP){
if(ourShots.size() < 1){

Dept of CSE,SJBIT 2022-2023 Page | 18


Space Shooter Game

Shot ourShot = new Shot(context, ourSpaceship.ox +


ourSpaceship.getOurSpaceshipWidth() / 2, ourSpaceship.oy);
ourShots.add(ourShot);
}
}
// When event.getAction() is MotionEvent.ACTION_DOWN, control ourSpaceship
if(event.getAction() == MotionEvent.ACTION_DOWN){
ourSpaceship.ox = touchX;
}
// When event.getAction() is MotionEvent.ACTION_MOVE, control ourSpaceship
// along with the touch.
if(event.getAction() == MotionEvent.ACTION_MOVE){
ourSpaceship.ox = touchX;
}
// Returning true in an onTouchEvent() tells Android system that you already handled
// the touch event and no further handling is required.
return true;
}
}

4.3.5 Explosion.java

package com.example.spaceshooters;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class Explosion {
Bitmap explosion[] = new Bitmap[9];
int explosionFrame;
int eX, eY;

public Explosion(Context context, int eX, int eY) {


explosion[0] = BitmapFactory.decodeResource(context.getResources(),
R.drawable.explosion0);
explosion[1] = BitmapFactory.decodeResource(context.getResources(),

Dept of CSE,SJBIT 2022-2023 Page | 19


Space Shooter Game

R.drawable.explosion1);
explosion[2] = BitmapFactory.decodeResource(context.getResources(),
R.drawable.explosion2);
explosion[3] = BitmapFactory.decodeResource(context.getResources(),
R.drawable.explosion3);
explosion[4] = BitmapFactory.decodeResource(context.getResources(),
R.drawable.explosion4);
explosion[5] = BitmapFactory.decodeResource(context.getResources(),
R.drawable.explosion5);
explosion[6] = BitmapFactory.decodeResource(context.getResources(),
R.drawable.explosion6);
explosion[7] = BitmapFactory.decodeResource(context.getResources(),
R.drawable.explosion7);
explosion[8] = BitmapFactory.decodeResource(context.getResources(),
R.drawable.explosion8);
explosionFrame = 0;
this.eX = eX;
this.eY = eY;
}

public Bitmap getExplosion(int explosionFrame){


return explosion[explosionFrame];
}
}

4.3.6 GameOver.java

package com.example.spaceshooters;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class GameOver extends AppCompatActivity {
TextView tvPoints;

Dept of CSE,SJBIT 2022-2023 Page | 20


Space Shooter Game

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game_over);
int points = getIntent().getExtras().getInt("points");
tvPoints = findViewById(R.id.tvPoints);
tvPoints.setText("" + points);
}
public void restart(View view) {
Intent intent = new Intent(GameOver.this, StartUp.class);
startActivity(intent);
finish();
}
public void exit(View view) {
finish();
}
}

4.3.7 StartUp.java

package com.example.spaceshooters;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class StartUp extends AppCompatActivity {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.startup);
}
public void startGame(View view) {
startActivity(new Intent(this, MainActivity.class));
finish();
}

Dept of CSE,SJBIT 2022-2023 Page | 21


Space Shooter Game

4.3.8 Manifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.spaceshooters">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<activity android:name=".StartUp"
android:exported="true"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:screenOrientation="landscape">
</activity>
<activity android:name=".GameOver"
android:screenOrientation="landscape">
</activity>
</application>

</manifest>

Dept of CSE,SJBIT 2022-2023 Page | 22


Space Shooter Game

CHAPTER 5
SNAPSHOTS

Fig 5.1 Starting page


Fig 5.1 shows starting screen of space shooter game, user who wishes to play this game can click
on the pay button in the middle of the screen to start the game and next display game screen will
get opened.

Fig 5.2 Game Screen


Fig 5.2 shows that once the user clicks on play button game screen is displayed where a rocket
and enemy space ship is present ,user can move the rocket left and right by dragging them around
the screen ,at beginning score Pt is set to zero and the life is set to three chances.

Dept of CSE,SJBIT 2022-2023 Page | 23


Space Shooter Game

Fig 5.3 Game in process


Fig 5.3 shows the view of game while playing the points gets updated when user ship bullet hits
the enemy space ship and when enemy space ships bullets hits the user rocket a life gets reduced
by losing one life.

Fig 5.4 Protecting the rocket and exploding enemy ship.

Fig 5.4 Once the game starts we can see that the player should protect his space rocket from
being shot by the enemy ship. you can also see the explosion once bullet is shot to the enemy
ship.

Dept of CSE,SJBIT 2022-2023 Page | 24


Space Shooter Game

Fig 5.5 GameOver page


Fig 5.5 Once the game finishes the points scored by the player will be displayed on the screen.
Along with retry button at top left corner and exit button at top right corner , if the player wishes
to play another retry button can be press or else to exit exit button can be pressed to terminate
the game.

Dept of CSE,SJBIT 2022-2023 Page | 25


Space Shooter Game

CONCLUSION
The space shooter project is an Android game that offers thrilling shooting action in a space-
themed setting. It includes features like player ship movement, shooting mechanics, enemy
generation, scoring, and game over conditions. The game aims to provide an immersive and
enjoyable gaming experience with responsive controls and smooth performance. Through
testing, the project ensures the accuracy of internal mechanisms and verifies user experience
aspects such as controls, level progression, and stability. Overall, the space shooter project aims
to deliver an engaging and polished Android game for players to enjoy.

Dept of CSE,SJBIT 2022-2023 Page | 26


REFERENCES

REFERENCE BOOKS

[1].“Programming Android Java Programming for the New Generation of


Mobile Devices” by Zigurd Mennieks.
[2].“Android Cookbook” by Ian F Darwin.
[3].“Headfirst Android Development: A Brain-Friendly Guide” by David Griffiths.

WEBSITE LINKS

[1]. https://youtu.be/YNq6B_VEvRI
[2]. https://www.udemy.com/course/android -game-development-tutorial-in-android-studio/
[3]. https://developer.android.com/docs
[4]. https://app.diagrams.net

You might also like