Frumpy the (Ninja) pig – Unity 3D

Frumpy was the first project that I had worked on that seemed like an actual project and not a university assignment.

Intricate detail when into the planning process by way of a design document which allowed a concise development. The game took around 6 weeks to complete from planning to the final product, during which time I was working on other projects and assignments. During the development process I was asked to write a learning journal, however as I was dealing with a visual medium I was granted permission to create a development video journal which can be seen below.

Frumpy was made using Unity 3D and was the first major project I had undertaken using Unity 3D. At first the majority of scripts I had coded were using JavaScript, however towards the end of the project I felt the need to convert all my scripts to C#, this also helped when I wrote my A Star (A*) algorithm, which I used Edsger Dijkstra graph search algorithm’s pseudo code to create my A* for the non-player characters.

Code Snippet:

```using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class DijkstraAlg
{
public static Stack Dijkstra(GameObject[] graph, GameObject source, GameObject target)
{
Dictionary<GameObject, float> dist = new Dictionary<GameObject, float>();
Dictionary<GameObject, GameObject> previous = new Dictionary<GameObject, GameObject>();
List q = new List();
foreach (GameObject v in graph)
{
dist[v] = Mathf.Infinity;
previous[v] = null;

}
dist[source] = 0;

while(q.Count > 0)
{
float shortestDistance = Mathf.Infinity;
GameObject shortestDistanceNode = null;
foreach(GameObject obj in q)
{
if (dist[obj] < shortestDistance)
{
shortestDistance = dist[obj];
shortestDistanceNode = obj;
}
}
GameObject u = shortestDistanceNode;

q.Remove(u);

if (u == target)
{
Stack s = new Stack();
while (previous[u] != null)
{
s.Push (u);
u = previous[u];
}
return s;
}

if (dist[u] == Mathf.Infinity)
{
break;
}
foreach(GameObject v in u.GetComponent().neighbors)
{
float alt = dist[u] + (u.transform.position - v.transform.position).magnitude;

if (alt < dist[v])
{
dist[v] = alt;
previous[v] = u;
}
}
}
return null;
}
}```