This repository has been archived by the owner on Oct 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Swarm.cs
104 lines (82 loc) · 2.44 KB
/
Swarm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
namespace Oodles
{
public class Swarm
{
private List<SwarmMember> members = new List<SwarmMember>();
private Random r = new Random();
private PointF position;
private Color color;
private bool playerControlled = false;
private float thrust = 2.5f;
private float radius = 0;
public Swarm(int size, PointF position, Color color)
{
this.position = position;
this.color = color;
AddMembers(size);
}
public void Update()
{
for (int i = 0; i < members.Count; i++)
{
if (members[i].LifePercentage < 0.1f)
{
members.RemoveAt(i);
break;
}
members[i].Update(position);
radius = position.X - members[i].X;
}
}
public void AddMembers(int amount)
{
thrust += 0.0025f;
for (int i = 0; i < amount; i++)
{
SwarmMember member = new SwarmMember();
member.X = position.X + r.Next(0, 500);
member.Y = position.Y + r.Next(0, 500);
float angle = (float)(r.NextDouble() * (Math.PI * 2));
member.VelocityX = (float)(Math.Sin(angle) * 1.5f);
member.VelocityY = (float)(Math.Cos(angle) * 1.5f);
member.thrust = thrust;
member.LifePercentage = r.Next(0, 4); // difficulty really
members.Add(member);
}
}
public void RemoveMembers(int amount)
{
thrust -= 0.0002f;
members.RemoveRange(0, amount);
}
public float Radius
{
get { return radius; }
set { radius = value; }
}
public PointF Position
{
get { return position; }
set { position = value; }
}
public List<SwarmMember> Members
{
get { return members; }
set { members = value; }
}
public Color Color
{
get { return color; }
set { color = value; }
}
public bool PlayerControlled
{
get { return playerControlled; }
set { playerControlled = value; }
}
}
}