public Bullet(Vector position, Vector velocity, Int32 damage) { Position = position; Velocity = velocity; Damage = damage; Dim = new Size(5, 5); }
public void Build() { Alive = true; HP = 100; Dim = new Size(20, 20); Position = new Vector(300, 300); List<IRobot> Enemies = new List<IRobot>(); calcRect(); }
public void GoTo(Vector pos) { Vector delta = pos - Position; float p = 0.5f; float length = (int)delta.Length(); float k = length / 50; if (length > 0.5) { if (k < p) { k = p; } Vector velocity = (pos - Position).GetNormalize() * k; Position = Position + velocity; calcRect(); } }
public Vector(Vector a) { x = a.x; y = a.y; }
public Vector GetNormalize() { Vector vec = new Vector(this); vec.Normalize(); return vec; }
public bool Equals(Vector a, float epsilon) { if (Math.Abs(x - a.x) > epsilon) return false; if (Math.Abs(y - a.y) > epsilon) return false; return true; }
/* public unsafe float this[int index] { get { if (index < 0 || index > 1) throw new ArgumentOutOfRangeException("index"); fixed (float* v = &this.x) { return v[index]; } } set { if (index < 0 || index > 1) throw new ArgumentOutOfRangeException("index"); fixed (float* v = &this.x) { v[index] = value; } } }*/ public float Dot(Vector v) { return x * v.x + y * v.y; }
public Vector Cross(Vector v) { return new Vector((y * v.x) - (x * v.y), (x * v.y) - (y * v.x)); }
public void Clamp(Vector min, Vector max) { if (x < min.x) x = min.x; else if (x > max.x) x = max.x; if (y < min.y) y = min.y; else if (y > max.y) y = max.y; }
public static Vector Normalize(Vector v) { return v.GetNormalize(); }
public static float Dot(Vector a, Vector b) { return a.Dot(b); }
public static Vector Cross(Vector a, Vector b) { return a.Cross(b); }
public void FireTo(Vector pos) { RobotEventArgs e = new RobotEventArgs(); e.Bullet = new Bullet(Position + (pos - Position).GetNormalize() * 20, (pos - Position).GetNormalize()*50, 5); FireEvent(this, e); }