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

Visvesvaraya Technological University

Belagavi-590 018, Karnataka

Assignment on

“Space Shooter”
Assignment submitted in partial fulfillment of the requirement for the
Computer Graphics and Visualization[18CS62]
Bachelor of Engineering
in
Computer Science and Engineering

Submitted by Team:
Akash S S [1JT18CS004] Maruthi M N [1JT18CS035]
Amogh B S [1JT18CS006] Rakshith Hegde K S [1JT18CS046]
Harish R Kulkarni [1JT18CS019] Shashank Lokesh [1JT18CS049]
Kushal M U [1JT18CS032] Syed Nahid [1JT18CS058]

Department of Computer Science and Engineering


Accredit by NBA, New Delhi
Jyothy Institute of Technology
Tataguni, Bengaluru-560082

1
Jyothy Institute of Technology
Tataguni, Bengaluru-560082
Department of Computer Science and Engineering

CERTIFICATE
This is to certify that the Unity assignment on the topic “Space Shooter”
carried out by Team: Sentinels Bonafide students of Jyothy Institute of
Technology have successfully completed the Unity Assignment under the
subject Computer Graphics[18CS62]. The students have successfully applied
the concepts and completed the assignment, as per the course outcome number
5 of the Computer Graphics subject, in the year 2020-2021. It is certified that
all corrections/suggestions indicated for Internal Assessment have been
incorporated in the assignment deposited in the department library. The
assignment has been approved as it satisfies the academic requirements in
respect of Assignment word prescribed for the said degree.

Mr. Vallabh Mahale Dr. Prabhanjan S


Guide, Asst. Professor Professor & HOD
Dept. of CSE Dept. of CSE

Mr. Srinidhi Kulkarni V


Guide, Asst. Professor
Dept. of CSE

2
ACKNOWLEDGEMENT
Firstly, we are very grateful to this esteemed institution “Jyothy Institute of Technology”
for providing us an opportunity to complete our project.

We express our sincere thanks to our Principal Dr. Gopalakrishna K for providing us with
adequate facilities to undertake this project.

We would like to thank Dr. Prabhanjan S, Professor and Head of Computer Science and
Engineering Department for providing his valuable support.

We would like to thank our guide Mr. Vallabh Mahale, Assistant Professor, Mr. Srinidhi
Kulkarni, Assistant Professor for their keen interest and guidance in preparing this work.

Finally, we would thank all our friends who have helped us directly or indirectly in this
project.

Akash S S [1JT18CS004]
Amogh B S [1JT18CS006]
Harish R Kulkarni [1JT18CS019]
Kushal M U [1JT18CS032]
Maruthi M N [1JT18CS035]
Rakshith Hegde K S [1JT18CS046]
Shashank Lokesh [1JT18CS049]
Syed Nahid [1JT18CS058]

3
ABSTRACT

Title of project: Space Shooter

Aim: To implement a simple shooting game using Unity.

Software requirement specifications:

Platform used:
• Windows

Software used:
• Unity

About the game:

Space Shooter is a game where the player can use the keyboard keys to control the
movement of the spaceship. Initially the player is given three lives, on hitting an enemy ship
the player loses a life. On losing all three lives the game ends. The player should move the
ship in such a way that he dodges and shoots the enemy ships. The player should see to that
the ship and make sure he does not hit the enemy ships as it will end the game. As the player
progresses further in the game the difficulty of the game and the frequency of the enemy
ships increase gradually.

4
Table of Contents

SL No Description Page No.


1 INTRODUCTION 6
2 UNITY ARCHITECTURE 10
3 IMPLEMENTATION 12
4 RESULTS AND SNAPSHOTS 18
5 CONCLUSION 22

5
CHAPTER 1
INTRODUCTION

6
1.INTRODUCTION
1.1 Introduction to CG

Graphics is defined as any sketch or a drawing or a special network that pictorially


represents some meaningful information. Computer Graphics is used where a set of image
needs to be manipulated or the creation of the image in the form of pixels and is drawn on
the computer. Computer Graphics can be used in digital photography, film,
entertainment, electronic gadgets and all other core technologies which are required. It is
a vast subject and area in the field of computer science. Computer Graphics can be used
in UI design, rendering, geometric object, animation and many more. In most area,
computer graphics is an abbreviation of CG. There are several tools used for
implementation of Computer Graphics.

Computer Graphics refers to several things:

• The manipulation and the representation of the image or the data in a graphical
manner.
• Various technologies required for the creation and manipulation.
• Digital synthesis and its manipulation.

Applications

• Computer Graphics are used for aided design for engineering and architectural
system- These are used in electrical automobile, electro-mechanical, mechanical,
electronic devices. For example: gears and bolts.
• Computer Art – MS Paint, Adobe Photoshop.
• Presentation Graphics – It is used to summarize financial statistical scientific or
economic data. For example- Bar chart, Line chart.
• Entertainment- It is used in motion picture, music video, television gaming.
• Education and training- It is used to understand operations of complex system. It is
also used for specialized system such for framing for captains, pilots and so on.
• Visualization- To study trends and patterns. For example- Analyzing satellite photo
of earth.

7
1.2 Introduction to Unity

Unity is a cross-platform game engine developed by Unity Technologies, first announced


and released in June 2005 at Apple Inc.’s Worldwide Developers Conference as a Mac OS
X-exclusive game engine. The engine has since been gradually extended to support a variety
of desktop, mobile, console and virtual reality platforms. It is particularly popular
for iOS and Android mobile game development and used for games such as Pokémon
Go, Monument Valley, Call of Duty: Mobile, Beat Saber and Cuphead. It is cited to be easy
to use for beginner developers and is popular for indie game development.
The engine can be used to create three-dimensional (3D) and two-dimensional (2D) games,
as well as interactive simulations and other experiences. The engine has been adopted by
industries outside video gaming, such
as film, automotive, architecture, engineering and construction.
Unity gives users the ability to create games and experiences in both 2D and 3D, and the
engine offers a primary scripting API in C#, for both the Unity editor in the form of plugins,
and games themselves, as well as drag and drop functionality. Prior to C# being the primary
programming language used for the engine, it previously supported Boo, which was
removed with the release of Unity 5, and a version of JavaScript called Unity Script, which
was deprecated in August 2017, after the release of Unity 2017.1, in favour of C#.

Overview:

Within 2D games, Unity allows importation of sprites and an advanced 2D world renderer.
For 3D games, Unity allows specification of texture compression, mipmaps, and resolution
settings for each platform that the game engine supports, and provides support for bump
mapping, reflection mapping, parallax mapping, screen space ambient occlusion (SSAO),
dynamic shadows using shadow maps, render-to-texture and full-screen post-processing
effects.

Supported platforms:

Unity is a cross-platform engine. The Unity editor is supported on Windows, macOS, and
the Linux platform, while the engine itself currently supports building games for more than
19 different platforms, including mobile, desktop, consoles, and virtual reality. Officially
supported platforms as of Unity 2020 LTS are:
• Mobile platforms: iOS, Android, TvOS;
• Desktop platforms: Windows, Linux, Mac;
• Console platforms: PlayStation, Xbox, Nintendo Switch, Stadia;
• Virtual/Extended reality platforms: Oculus, PlayStation VR, Google’s ARCore,
Windows Mixed Reality.

Licensing model:

During its first ten years as a product, the paid versions of Unity were sold outright; in 2016,
the corporation changed to a subscription model. Unity has free and paid licensing options.

8
The free license is for personal use or smaller companies generating less than $100,000
annually, and the subscriptions are based on revenues generated by the games using Unity.

Unity Asset Store:

Creators can develop and sell user-generated assets to other game makers via the Unity
Asset Store. This includes 3D and 2D assets and environments for developers to buy and
sell. Unity Asset Store launched in 2010. By 2018, there had been approximately 40 million
downloads through the digital store.

Non-gaming industries uses:

In the 2010s, Unity Technologies used its game engine to transition into other industries
using the real-time 3D platform, including film and automotive. Unity first experimented in
filmmaking with Adam, a short film about a robot escaping from prison. Later, Unity
partnered with filmmaker Neill Blomkamp, whose Oats Studios used the engine's tools,
including real-time rendering and Cinemachine, to create two computer-generated short
films, Adam: The Mirror and Adam: The Prophet. At the 2017 Unite Europe conference in
Amsterdam, Unity focused on filmmaking with Unity 2017.1's new Cinemachine tool. In
2018, Disney Television Animation launched three shorts, called Baymax Dreams, that were
created using the Unity engine. The Unity engine was also used by Disney to create
backgrounds for the 2019 film The Lion King.
Automakers use Unity's technology to create full-scale models of new vehicles in virtual
reality, build virtual assembly lines, and train workers. Unity's engine is used by DeepMind,
an Alphabet Inc. company, to train artificial intelligence. Other uses being pursued by Unity
Technologies include architecture, engineering, and construction.

9
CHAPTER 2
Unity Architecture

10
 Unity Architecture

The Unity engine is built with native C/C++ internally, however it has a C# wrapper that
you use to interact with it. As such, you need to be familiar with some of the key concepts of
scripting in C#. This section of the User Manual contains information on how Unity
implements .NET and C#, and any exceptions you might encounter as you code.

Unity uses the open-source .NET platform in order to ensure that applications you make
with Unity can run on a wide variety of different hardware configurations. .NET supports a
range of languages and API libraries.

Unity has two scripting backends: Mono and IL2CPP


(Intermediate Language To C++), each of which uses a different compilation technique:

• Mono uses just-in-time (JIT) compilation and compiles code on demand at runtime.
• IL2CPP uses ahead-of-time (AOT) compilation and compiles your entire application before
it is run.
The benefit of using a JIT-based scripting backend is that the compilation time is typically
much faster than AOT and it’s platform-independent.

When you build your application, Unity scans the compiled assemblies (.DLLs) to detect
and remove unused code. This process reduces the final binary size of your build, but
increases build time.

Unity uses the Boehm garbage collector for both the Mono and IL2CPP backends. Unity
uses the Incremental mode by default. You can disable the Incremental mode to use “stop
the world” garbage collection, although Unity recommends use of Incremental mode.

Unity supports many platforms and might use different scripting backends depending on the
platform. The .NET system libraries require platform-specific implementations to work
correctly in some cases. While Unity tries its best to support as much of the .NET ecosystem
as possible, there are some exceptions to parts of the .NET system libraries that Unity
explicitly does not support.

Unity makes no performance nor allocation guarantees of the .NET system libraries across
Unity versions. As a general rule of thumb, Unity does not fix any performance regressions
in the .NET system libraries.

A JIT scripting backend allows you to emit dynamic C#/.NET Intermediate Language (IL)
code generation during the runtime of your application, whereas an AOT scripting backend
does not support dynamic code generation. This is important to consider when you use third-
party libraries, because they might have different code paths for JIT and AOT, or they might
use code paths that rely on dynamically generated code. For more information on how to
generate code at runtime, see Microsoft’s ModuleBuilder documentation.

11
CHAPTER 3
IMPLEMENTATION

12
Code section:

Player.cs :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
//PUBLIC OR PRIVATE REFERENCE
//DATA TYPE (INT,FLOAT,BOOL,STRING)
//every variable has a name
//optional value assigned
[SerializeField]
private float _speed = 3.5f;
[SerializeField]
private GameObject _laserPrefab;
[SerializeField]
private GameObject _tripleShotPrefab;
[SerializeField]
private float _firerate = 0.5f;
[SerializeField]
private float _canfire = -1f;
[SerializeField]
private int _lives = 3;
private Spawn_manager _spawnmanager;
[SerializeField]
private bool _isTripleShotActive = false;
// Start is called before the first frame update
void Start()
{
//Take the current position = new position (0, 0, 0)
transform.position = new Vector3(0, 0, 0);
_spawnmanager =
GameObject.Find("Spawn_manager").GetComponent<Spawn_manager>();

if(_spawnmanager == null)
{
Debug.LogError("The spawn is null");
}
}

// Update is called once per frame


void Update()
{ CalculateMovement();

if(Input.GetKeyDown(KeyCode.Space) && Time.time > _canfire)


{

13
FireLaser();
}
}
void CalculateMovement()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
//New Vector3(1,0,0)
// transform.Translate(Vector3.right * horizontalInput * _speed * Time.deltaTime);
//transform.Translate(Vector3.up * verticalInput * _speed * Time.deltaTime);

Vector3 direction = new Vector3(horizontalInput,verticalInput,0);


transform.Translate( direction * _speed * Time.deltaTime)
if (transform.position.y >=0)
{
transform.position = new Vector3(transform.position.x ,0 ,0);
}
else if(transform.position.y <= -3.8f)
{
transform.position = new Vector3(transform.position.x,-3.8f,0);
}
//transform.position = new
Vector3(transform.position.x,Mathf.Clamp(transform.position.y,-3.8f,0),0);

if(transform.position.x > 11)


{
transform.position = new Vector3(-11,transform.position.y,0);
}
else if(transform.position.x < -11)
{
transform.position = new Vector3(11,transform.position.y,0);
}

}
void FireLaser()
{
//if space key is pressed
//spawn object
_canfire = Time.time + _firerate;

if(_isTripleShotActive == true)
{
//instantiate triple shot
Instantiate(_tripleShotPrefab,transform.position,Quaternion.identity);
}
else {
Instantiate(_laserPrefab, transform.position + new Vector3(0,1.05f,0),
Quaternion.identity);
}
}

14
public void Damage()
{
_lives -= 1;
//_lives = _lives - 1;
//_lives--;
if(_lives < 1)
{ //communicate spawn manager to stop spawning
_spawnmanager.onplayerDeath();
Destroy(this.gameObject);
}
}
}

Enemy.cs :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour


{
[SerializeField]
private float _speed = 4f;
// Start is called before the first frame update
void Start()
{

// Update is called once per frame


void Update()
{
transform.Translate(Vector3.down * _speed * Time.deltaTime);

if(transform.position.y < -5f)


{
float randomX = Random.Range(-8f,8f);
transform.position = new Vector3(randomX,7,0);
}
}
private void OnTriggerEnter2D(Collider2D other)
{
//Debug.Log("Hit:"+other.transform.name);
if (other.tag == "player")
{
Player player = other.transform.GetComponent<Player>();
if(player != null)
{
player.Damage();

15
}
Destroy(this.gameObject);
}

if(other.tag == "Laser")
{
Destroy(other.gameObject);
Destroy(this.gameObject);
}
}
}

Laser.cs :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Laser : MonoBehaviour


{
// Start is called before the first frame update
[SerializeField]
private float _speed = 8.0f;

void Update()
{
transform.Translate(Vector3.up * _speed * Time.deltaTime);

if(transform.position.y > 8.0f)


{
Destroy(this.gameObject);
}
}
}

Spawn manager.cs :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spawn_manager : MonoBehaviour


{
[SerializeField]
private GameObject _enemyPrefab;
[SerializeField]
private GameObject _enemyContainer;

16
private bool _stopspawning = false;
// Start is called before the first frame update
void Start()
{
StartCoroutine(SpawnRoutine());
}

// Update is called once per frame


void Update()
{

//spawn game object every 5sec


//create a coroutine of type IENUMERATOR -- yeild events
//while
IEnumerator SpawnRoutine()
{
while(_stopspawning == false)
{
Vector3 postospawn = new Vector3(Random.Range(-8f,8f),7,0);
GameObject newEnemy =
Instantiate(_enemyPrefab,postospawn,Quaternion.identity);
newEnemy.transform.parent = _enemyContainer.transform;
yield return new WaitForSeconds(5.0f);
}
//wait one frame and then this is called
//we wont get here

//while loop
//Instantiate enemy prefab
//yield wait for 5 secs
}
public void onplayerDeath()
{
_stopspawning = true;
}
}

17
CHAPTER 4
RESULTS AND SNAPSHOTS

18
Design preview:

Fig 1: Game Board Layout

Fig 2: Initial position

19
Fig 3: Player dodging enemy ship

Fig 4: Player shooting laser

20
CHAPTER 5
CONCLUSION

21
CONCLUSION
The aim of this project was to create a 3D game which was the spaces shooter game with
the Unity game engine. A game engine is the core of creating a game. The integration of
model design, level design and script design is the game engine, which is complex and
powerful. The Unity game engine supports visualized design, thus it is a strong game engine
which is suitable for a beginner.

We have designed this game using Unity and C#. The objective of the game is to shoot and
dodge enemy ships. To enable the player to control the movement of the ship inside the play
area and try avoiding enemy ships, we will use the arrow keys (the up, down, left, and right
keys) on the keyboard.

The Unity 3D game engine provides us with an incredibly powerful and versatile tool for
project development. Unity’s simple interface, a friendly development environment and
cross platform framework support, all contribute to its prolonged success in the industry.

22
REFERENCES

[1] https://www.youtube.com/watch?v=XCOTK-a-1cc

[2] http://udemy.com

[3] https://unity.com

23

You might also like