Top Down Shooter
bij dit project heb ik samen met een mede student een shooter game gemaakt waarin je in een legerbasis zombies moet dood schieten om de game te winnen!!
https://topdownshooter.galaxystudio.tech/
samen gemaakt met https://github.com/sjempotje
we hebben unity gebruikt om het spel te maken en het is voornamelijk geschreven met C#. je kan er voor kiezen om met muis en keyboard of met een controller te spelen.
// zombie logic
void Start()
{
//targetIndex = 0;
hp = Random.Range(3, 10);
//make speed random between 2, 4
speed = Random.Range(2, 4);
// Define the three sets of patrol points
Vector2[][] patrolSets = new Vector2[][] {
//new Vector2[] { new Vector2(0, 0), new Vector2(0, 12), new Vector2(12, 12), new Vector2(18, 0) },
new Vector2[] { new Vector2(-6, 2), new Vector2(-5.5f, 12.7f), new Vector2(14.3f, 13), new Vector2(14, 9), new Vector2(1, 9), new Vector2(-2, 2) },
new Vector2[] { new Vector2(66, 15), new Vector2(98, 15.5f), new Vector2(98, 3), new Vector2(66, 6) },
new Vector2[] { new Vector2(-9, -7.5f), new Vector2(-8, -6.5f), new Vector2(-7, -12), new Vector2(-9, -12) }
};
min_threshold = -arrivalThreshold;
random_plusminius_pos = Random.Range(min_threshold, arrivalThreshold);
random_plusminus_pos_y = Random.Range(min_threshold*2, arrivalThreshold*2);
// Calculate distances to each set of patrol points and choose the closest one
float closestDistance = float.MaxValue;
for (int i = 0; i < patrolSets.Length; i++)
{
float totalDistance = 0f;
foreach (Vector2 point in patrolSets[i])
{
totalDistance += Vector2.Distance(transform.position, point);
}
if (totalDistance < closestDistance)
{
closestDistance = totalDistance;
patrolIndex = i;
}
////set random target index
//targetIndex = Random.Range(0, patrolSets[patrolIndex].Length);
//set target index using the closest vector from the patrol set
targetIndex = GetClosestVectorIndex(patrolSets[patrolIndex], transform.position);
}
// Assign move spots based on the chosen index
moveSpots = patrolSets[patrolIndex];
//get Damage_Hue from canvas
}
// Add a method to find the closest vector index
private int GetClosestVectorIndex(Vector2[] vectors, Vector2 position)
{
float closestDistance = float.MaxValue;
int closestIndex = 0;
for (int i = 0; i < vectors.Length; i++)
{
float distance = Vector2.Distance(vectors[i], position);
if (distance < closestDistance)
{
closestDistance = distance;
closestIndex = i;
}
}
return closestIndex;
}