Example #1
0
 /// <summary>Applies force to two objects based on their weight and angle between them</summary>
 /// <param name="g1"></param>
 /// <param name="g2"></param>
 public static void Handle(GameObj g1, GameObj g2)
 {
     Vector2 v = g1.pos - g2.pos;
     v.Normalize();
     v *= 2;
     g1.fce += v * g2.GetWeight() / g1.GetWeight();
     g2.fce -= v * g1.GetWeight() / g2.GetWeight();
 }
Example #2
0
 /// <summary>Determines whenever this object intersects with another</summary>
 /// <param name="go">The another object</param>
 public bool Intersects(GameObj go)
 {
     int r = go.Radius + Radius;
     return DistanceSq(go) < r * r;
 }
Example #3
0
 /// <summary>Checks distance to another object</summary>
 /// <param name="go">The another object</param>
 /// <returns>The squared distance</returns>
 public float DistanceSq(GameObj go)
 {
     return (go.pos - pos).LengthSquared();
 }
Example #4
0
 /// <summary>Writes data of a single game object into a packet</summary>
 /// <param name="data">The output packet</param>
 /// <param name="go">A game object to extract data from</param>
 private void WriteData(NetPacket.Factory data, GameObj go)
 {
     data.WriteUInt(go.ID);
     data.WriteString(go.GetType().FullName);
     data.WriteShort(go.hp);
     data.WriteShort(go.mp);
     data.WriteByte(go.state);
     data.WriteByte(go.frame);
     data.WriteFloat(go.dir);
     data.WriteFloat(go.ang.X);
     data.WriteFloat(go.ang.Y);
     data.WriteFloat(go.spd.X);
     data.WriteFloat(go.spd.Y);
     data.WriteFloat(go.pos.X);
     data.WriteFloat(go.pos.Y);
     data.WriteFloat(go.fce.X);
     data.WriteFloat(go.fce.Y);
     // TODO: Add a member method into GameObj for writing/reading?
     if (go is GEC)
     {
         GEC g = (GEC)go;
         data.WriteString(g.gfx.Name);
         data.WriteByte(g.GetPrefs());
     }
     else if (go is GPChain)
     {
         GPChain g = (GPChain)go;
         data.WriteFloat(g.GetBoltDest().X);
         data.WriteFloat(g.GetBoltDest().Y);
     }
 }