コード例 #1
0
 public void Update(GameTime gameTime)
 {
     if (LinearVelocity.LengthSquared() >= 1e-7)
     {
         var  step    = LinearVelocity * World.TimeScale * (float)gameTime.ElapsedGameTime.TotalSeconds;
         bool stopped = false;
         var  rf      = this;
         World.Physics.RayCast((Fixture arg1, Vector2 arg2, Vector2 arg3, float arg4) =>
         {
             if (arg1.Body.Tag is TerrainComponent)
             {
                 Position       = arg2 * 64f;
                 LinearVelocity = Vector2.Zero;
                 stopped        = true;
             }
             else if (arg1.Body.Tag is Entity)
             {
                 var ent = arg1.Body.Tag as Entity;
                 if (ent.Tags.Any(t => TargetedTags.Contains(t)))
                 {
                     var ch = ent.GetComponent <CharacterComponent>();
                     if (ch != null)
                     {
                         ch.Damage(World.GetEntity(OwnerID), Damage);
                         Position       = arg2 * 64f;
                         LinearVelocity = Vector2.Zero;
                         stopped        = true;
                         Parent.AddComponent(new BindedBodyComponent().BindTo(ent, Position, Rotation));
                         rf.Remove = true;
                         return(0);
                     }
                 }
             }
             return(arg4);
         }, Position / 64f, (Position + step) / 64f);
         if (!stopped)
         {
             Position += step;
         }
         else
         {
             Gravity = false;
         }
     }
     if (Gravity)
     {
         LinearVelocity += new Vector2(0, World.Physics.Gravity.Y * 64f *
                                       (float)gameTime.ElapsedGameTime.TotalSeconds * World.TimeScale);
     }
     if (Friction > 0)
     {
         LinearVelocity /= Friction;
     }
 }
コード例 #2
0
        public override EntityComponent Clone()
        {
            List <string> tags = new List <string>();

            TargetedTags.ForEach(t => tags.Add(t));
            return(new ProjectileBody()
            {
                Rotation = Rotation,
                Position = Position,
                Gravity = Gravity,
                Friction = Friction,
                TargetedTags = tags
            });
        }
コード例 #3
0
ファイル: PlayerComponent.cs プロジェクト: RisaI/mff-totem
        public override EntityComponent Clone()
        {
            List <string> tags = new List <string>();

            TargetedTags.ForEach(t => tags.Add(t));
            return(new PlayerComponent()
            {
                _hp = _hp,
                _stamina = _stamina,
                _baseMaxHp = _baseMaxHp,
                _baseMaxStamina = _baseMaxStamina,
                _baseSpeed = _baseSpeed,
                _expReward = _expReward,
                TargetedTags = tags,
                TechnologyLevel = TechnologyLevel,
                _techExp = _techExp,
                MagicLevel = MagicLevel,
                _magExp = _magExp,
            });
        }