Final_2D_Platformer_Dev_Project_with_Definitions
Final_2D_Platformer_Dev_Project_with_Definitions
This document details the full development lifecycle of a 2D platformer game titled 'Shadow
Leap' using Unity. It includes conceptualization, design, programming stages, C# code
examples, testing, and deployment strategies. The content is aimed at postgraduate-level
learners exploring professional game development workflows.
Create a Game Design Document (GDD) with storyline, levels, and characters.
C# Code Example:
```csharp
public class PlayerMovement : MonoBehaviour {
public float moveSpeed = 5f;
private Rigidbody2D rb;
private Vector2 movement;
void Start() {
rb = GetComponent<Rigidbody2D>();
}
void Update() {
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
}
void FixedUpdate() {
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
}
```
void Update() {
isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.1f, groundLayer);
if (Input.GetButtonDown("Jump") && isGrounded) {
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
}
```
C# Code Example:
```csharp
public class EnemyPatrol : MonoBehaviour {
public Transform pointA, pointB;
public float speed = 2f;
private Vector3 target;
void Start() {
target = pointB.position;
}
void Update() {
transform.position = Vector3.MoveTowards(transform.position, target, speed *
Time.deltaTime);
if (transform.position == pointB.position) target = pointA.position;
else if (transform.position == pointA.position) target = pointB.position;
}
}
```
C# Code Example:
```csharp
public class Collectible : MonoBehaviour {
void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("Player")) {
ScoreManager.instance.AddScore(10);
Destroy(gameObject);
}
}
}
```
C# Code Example:
```csharp
public class ScoreManager : MonoBehaviour {
public static ScoreManager instance;
public Text scoreText;
private int score = 0;
void Awake() {
instance = this;
}
Level Design
Use Unity Tilemap system to design multiple platformer levels with obstacles and hazards.
Rigidbody2D
Rigidbody2D is a Unity component that allows a game object to respond to physics-based
behaviors such as gravity, force, and collisions. It is essential in 2D games to simulate
natural movement, such as jumping and falling.
Tilemap
Unity’s Tilemap system allows developers to paint 2D game levels using grid-based tiles.
This improves level creation speed and keeps asset management efficient, especially in
platformers.
Collider2D
A Collider2D defines the shape of a GameObject for physical collisions in 2D space. It doesn’t
render visibly in-game but allows the object to interact with other colliders, such as
triggering events or blocking movement.
LayerMask
LayerMask helps specify which layers should be considered during a physics check, such as
raycasting or overlap detection, making interaction checks more efficient.
Game Loop
The game loop is the core structure of a game engine where logic updates and rendering
happen repeatedly. In Unity, this is controlled through functions like Update(),
FixedUpdate(), and LateUpdate().
Prefab
A Prefab is a reusable GameObject stored as a template in Unity. Common uses include
enemies, items, and platforms that can be dynamically instantiated during gameplay.
OnTriggerEnter2D
This Unity method detects when one collider enters another marked as a trigger. It’s useful
for handling events like collecting items or entering new areas.