public Character(Vector2 newLoc, CharDef newCharDef, int newID, int newTeam)
        {
            script = new Script(this);

            Ai = null;

            Loc        = newLoc;
            ID         = newID;
            Trajectory = new Vector2();

            Team = newTeam;

            Face    = CharDir.Right;
            Scale   = 0.5f;
            charDef = newCharDef;

            NoLifty = false;

            InitScript();

            AnimName = "";
            SetAnim("fly");
            ethereal = false;

            State = CharState.Air;
        }
        public Loc GetFront()
        {
            DirH horiz;
            DirV vert;

            CharDir.Separate(out horiz, out vert);

            Loc resultLoc = Bounds.Center;

            if (horiz == DirH.Left)
            {
                resultLoc.X = Bounds.Left;
            }
            if (horiz == DirH.Right)
            {
                resultLoc.X = Bounds.Right;
            }

            if (vert == DirV.Up)
            {
                resultLoc.Y = Bounds.Top;
            }
            if (vert == DirV.Down)
            {
                resultLoc.Y = Bounds.Bottom;
            }

            return(resultLoc);
        }
        public void SetAnim(String newAnim)
        {
            if (AnimName != newAnim)
            {
                for (int i = 0; i < charDef.GetAnimationArray().Length; i++)
                {
                    if (charDef.GetAnimation(i).name == newAnim)
                    {
                        for (int t = 0; t < GotoGoal.Length; t++)
                        {
                            GotoGoal[t] = -1;
                        }


                        Floating  = false;
                        Anim      = i;
                        AnimFrame = 0;
                        frame     = 0f;
                        AnimName  = newAnim;
                        CanCancel = false;
                        ethereal  = false;

                        if (KeyLeft)
                        {
                            Face = CharDir.Left;
                        }
                        if (KeyRight)
                        {
                            Face = CharDir.Right;
                        }
                    }
                }
            }
        }
Exemple #4
0
 private bool FriendInWay(Character[] c, int id, CharDir face)
 {
     for (var i = 0; i < c.Length; i++)
     {
         if (i != id && c[i] != null)
         {
             if (Me.Team == c[i].Team)
             {
                 if (Me.Location.Y > c[i].Location.Y - 100f && Me.Location.Y < c[i].Location.Y + 10f)
                 {
                     if (face == CharDir.Right)
                     {
                         if (c[i].Location.X > Me.Location.X && c[i].Location.X < Me.Location.X + 70f)
                         {
                             return(true);
                         }
                     }
                     else
                     {
                         if (c[i].Location.X <Me.Location.X && c[i].Location.X> Me.Location.X - 70f)
                         {
                             return(true);
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
Exemple #5
0
        protected override void UpdateFrameInternal()
        {
            MapLoc = AnimLoc * GraphicsManager.TileSize;

            int farthest_distance = GraphicsManager.TileSize * (FallShort ? 1 : 2) / 3;
            Loc toOffset          = CharDir.GetLoc() * farthest_distance;

            if (ActionTime < AnimRushTime)
            {
                //dont do anything; the animation itself will take care of pull-back
            }
            else if (ActionTime < AnimHitTime)
            {
                double intb   = (double)(ActionTime - AnimRushTime).FractionOf(AnimHitTime - AnimRushTime);
                Loc    newLoc = new Loc(AnimMath.Lerp(0, toOffset.X, intb), AnimMath.Lerp(0, toOffset.Y, intb));
                drawOffset = newLoc;
            }
            else if (ActionTime < AnimReturnTime)
            {
                drawOffset = toOffset;
            }
            else
            {
                double intb   = (double)(ActionTime - AnimReturnTime).FractionOf(AnimTotalTime - AnimReturnTime);
                Loc    newLoc = new Loc(AnimMath.Lerp(toOffset.X, 0, intb), AnimMath.Lerp(toOffset.Y, 0, intb));
                drawOffset = newLoc;
            }
        }
Exemple #6
0
 protected override void UpdateFrameInternal()
 {
     MapLoc = AnimLoc * GraphicsManager.TileSize;
     if (ActionTime.FractionOf(2, ANIM_TIME) % 2 == 0)
     {
         drawOffset = drawOffset + CharDir.Reverse().GetLoc();
     }
 }
Exemple #7
0
 protected override void UpdateFrameInternal()
 {
     if (ActionTime.DivOf(10) % 2 == 0)
     {
         drawOffset = drawOffset + CharDir.Reverse().GetLoc();
     }
     if (ActionTime.FractionOf(4, AnimTime) > 0)
     {
         opacity = 128;
     }
     MapLoc = AnimLoc * GraphicsManager.TileSize;
 }
 public void MakeBullet(Vector2 loc, Vector2 traj, CharDir face, int owner)
 {
     switch (face)
     {
         case CharDir.Left:
             AddParticle(new Bullet(loc,
                 new Vector2(-traj.X, traj.Y) + Rand.GetRandomVector2(-90f, 90f, -90f, 90f), owner));
             MakeMuzzleFlash(loc, new Vector2(-traj.X, traj.Y));
             break;
         case CharDir.Right:
             AddParticle(new Bullet(loc, traj + Rand.GetRandomVector2(-90f, 90f, -90f, 90f), owner));
             MakeMuzzleFlash(loc, traj);
             break;
     }
 }
        public void MakeBullet(Vector2 loc, Vector2 traj, CharDir face, int owner)
        {
            switch (face)
            {
            case CharDir.Left:
                AddParticle(new Bullet(loc,
                                       new Vector2(-traj.X, traj.Y) + Rand.GetRandomVector2(-90f, 90f, -90f, 90f), owner));
                MakeMuzzleFlash(loc, new Vector2(-traj.X, traj.Y));
                break;

            case CharDir.Right:
                AddParticle(new Bullet(loc, traj + Rand.GetRandomVector2(-90f, 90f, -90f, 90f), owner));
                MakeMuzzleFlash(loc, traj);
                break;
            }
        }
Exemple #10
0
 /// <summary>
 /// Make a bullet with muzzle flash.
 /// </summary>
 /// <param name="loc">Location to create the bullet from.</param>
 /// <param name="traj">Bullet trajectory</param>
 /// <param name="face">Facing of owner</param>
 /// <param name="owner">Owner of bullet</param>
 public void MakeBullet(Vector2 loc, Vector2 traj, CharDir face, int owner)
 {
     if (face == CharDir.Left)
     {
         AddParticle(new Bullet(loc, new Vector2(-traj.X, traj.Y)
                                + Rand.GetRandomVector2(-90f, 90f, -90f, 90f),
                                owner));
         MakeMuzzleFlash(loc, new Vector2(-traj.X, traj.Y));
     }
     else
     {
         AddParticle(new Bullet(loc, traj
                                + Rand.GetRandomVector2(-90f, 90f, -90f, 90f),
                                owner));
         MakeMuzzleFlash(loc, traj);
     }
 }
Exemple #11
0
        public Character(Vector2 newLoc, CharDef newCharDef, int newId, int newTeam)
        {
            Location   = newLoc;
            Trajectory = Vector2.Zero;

            Face     = CharDir.Right;
            Scale    = 0.5f;
            _charDef = newCharDef;
            Id       = newId;
            Team     = newTeam;
            _script  = new Script(this);

            Ai = null;
            InitScript();
            Ethereal = false;
            AnimName = "";
            State    = CharState.Air;
            SetAnim("fly");
        }
        public void ReadFromNet(PacketReader reader)
        {
            Loc.X = NetPacker.ShortToBigFloat(reader.ReadInt16());
            Loc.Y = NetPacker.ShortToBigFloat(reader.ReadInt16());

            Anim      = NetPacker.ShortToInt(reader.ReadInt16());
            AnimFrame = NetPacker.ShortToInt(reader.ReadInt16());
            AnimName  = charDef.GetAnimation(Anim).name;
            frame     = NetPacker.ShortToMidFloat(reader.ReadInt16());

            if (reader.ReadBoolean())
            {
                State = CharState.Air;
            }
            else
            {
                State = CharState.Grounded;
            }

            if (reader.ReadBoolean())
            {
                Face = CharDir.Right;
            }
            else
            {
                Face = CharDir.Left;
            }

            Trajectory.X = NetPacker.ShortToBigFloat(reader.ReadInt16());
            Trajectory.Y = NetPacker.ShortToBigFloat(reader.ReadInt16());

            KeyRight = reader.ReadBoolean();
            KeyLeft  = reader.ReadBoolean();

            HP = NetPacker.ShortToInt(reader.ReadInt16());

            ReceivedNetUpdate = true;
        }
Exemple #13
0
 private bool FriendInWay(Character[] c, int ID, CharDir face)
 {
     for (int i = 0; i < c.Length; i++)
     {
         if (i != ID)
         {
             if (c[i] != null)
             {
                 if (me.Team == c[i].Team)
                 {
                     if (me.Loc.Y > c[i].Loc.Y - 100f &&
                         me.Loc.Y < c[i].Loc.Y + 10f)
                     {
                         if (face == CharDir.Right)
                         {
                             if (c[i].Loc.X > me.Loc.X &&
                                 c[i].Loc.X < me.Loc.X + 70f)
                             {
                                 return(true);
                             }
                         }
                         else
                         {
                             if (c[i].Loc.X <me.Loc.X &&
                                             c[i].Loc.X> me.Loc.X - 70f)
                             {
                                 return(true);
                             }
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
Exemple #14
0
 public virtual void SetDir(CharDir dir)
 {
 }
        public Character(Vector2 newLoc, CharDef newCharDef, int newId, int newTeam)
        {
            Location = newLoc;
            Trajectory = Vector2.Zero;

            Face = CharDir.Right;
            Scale = 0.5f;
            _charDef = newCharDef;
            Id = newId;
            Team = newTeam;
            _script = new Script(this);

            Ai = null;
            InitScript();
            Ethereal = false;
            AnimName = "";
            State = CharState.Air;
            SetAnim("fly");
        }
Exemple #16
0
 public virtual void Move(CharDir dir, float speed)
 {
 }
Exemple #17
0
 private bool FriendInWay(Character[] c, int id, CharDir face)
 {
     for (var i = 0; i < c.Length; i++)
     {
         if (i != id && c[i] != null)
         {
             if (Me.Team == c[i].Team)
             {
                 if (Me.Location.Y > c[i].Location.Y - 100f && Me.Location.Y < c[i].Location.Y + 10f)
                 {
                     if (face == CharDir.Right)
                     {
                         if (c[i].Location.X > Me.Location.X && c[i].Location.X < Me.Location.X + 70f)
                             return true;
                     }
                     else
                     {
                         if (c[i].Location.X < Me.Location.X && c[i].Location.X > Me.Location.X - 70f)
                             return true;
                     }
                 }
             }
         }
     }
     return false;
 }
        public void Update(ParticleManager pMan, Character[] c)
        {
            #region Update AI

            if (Ai != null)
                Ai.Update(c, Id, Map);

            #endregion

            #region Update Dying

            if (DyingFrame > -1)
                DyingFrame += Game1.FrameTime;

            #endregion

            #region Update animation

            if (DyingFrame < 0)
            {
                var animation = _charDef.Animations[Anim];
                var keyFrame = animation.KeyFrames[AnimFrame];

                _frame += Game1.FrameTime * 30;

                if (_frame > keyFrame.Duration)
                {
                    var pFrame = AnimFrame;
                    _script.DoScript(Anim, AnimFrame);
                    CheckTrig(pMan);

                    _frame -= keyFrame.Duration;

                    if (AnimFrame == pFrame)
                        AnimFrame++;

                    if (AnimFrame >= animation.KeyFrames.Length)
                        AnimFrame = 0;

                    keyFrame = animation.KeyFrames[AnimFrame];

                    if (keyFrame.FrameRef < 0)
                        AnimFrame = 0;
                }
            }

            #endregion

            #region Collison w/ other characters

            for (var i = 0; i < c.Length; i++)
            {
                if (i != Id)
                {
                    if (c[i] != null)
                    {
                        if (!Ethereal && !c[i].Ethereal)
                        {
                            if (Location.X > c[i].Location.X - 90f * c[i].Scale &&
                                Location.X < c[i].Location.X + 90f * c[i].Scale &&
                                Location.Y > c[i].Location.Y - 120f * c[i].Scale &&
                                Location.Y < c[i].Location.Y + 10f * c[i].Scale)
                            {
                                var dif = Math.Abs(Location.X - c[i].Location.X);
                                dif = 180f * c[i].Scale - dif;
                                dif *= 2f;
                                if (Location.X < c[i].Location.X)
                                {
                                    ColMove = -dif;
                                    c[i].ColMove = dif;
                                }
                                else
                                {
                                    ColMove = dif;
                                    c[i].ColMove = -dif;
                                }
                            }
                        }
                    }
                }
            }

            if (ColMove > 0f)
            {
                ColMove -= 400f * Game1.FrameTime;
                if (ColMove < 0f) ColMove = 0f;
            }
            else if (ColMove < 0f)
            {
                ColMove += 400f * Game1.FrameTime;
                if (ColMove > 0f) ColMove = 0f;
            }

            #endregion

            #region Update location by trajectory

            var pLoc = Location;

            if (State == CharState.Grounded)
            {
                if (Trajectory.X > 0)
                {
                    Trajectory.X -= Game1.Friction * Game1.FrameTime;
                    if (Trajectory.X < 0)
                        Trajectory.X = 0;
                }

                if (Trajectory.X < 0)
                {
                    Trajectory.X += Game1.Friction * Game1.FrameTime;
                    if (Trajectory.X > 0)
                        Trajectory.X = 0;
                }
            }

            Location.X += Trajectory.X * Game1.FrameTime;
            Location.X += ColMove * Game1.FrameTime;

            if (State == CharState.Air)
            {
                Location.Y += Trajectory.Y * Game1.FrameTime;
                Trajectory.Y += Game1.FrameTime * Game1.Gravity;
            }

            #endregion

            #region Colision detection

            if (State == CharState.Air)
            {
                CheckXCol(pLoc);

                #region Land on ledge

                if (Trajectory.Y > 0)
                {
                    for (var i = 0; i < 16; i++)
                    {
                        if (Map.Ledges[i].TotalNodes > 1)
                        {
                            var ts = Map.GetLedgeSec(i, pLoc.X);
                            var s = Map.GetLedgeSec(i, Location.X);

                            if (s > -1 && ts > -1)
                            {
                                var tfy = Map.GetLedgeYLoc(i, s, pLoc.X);
                                var fy = Map.GetLedgeYLoc(i, s, Location.X);

                                if (pLoc.Y <= tfy && Location.Y >= fy)
                                {
                                    if (Trajectory.Y > 0)
                                    {
                                        Location.Y = fy;
                                        _ledgeAttach = i;
                                        Land();
                                    }
                                }
                                else
                                {
                                    if (Map.Ledges[i].Flags == (int)LedgeFlags.Solid && Location.Y >= fy)
                                    {
                                        Location.Y = fy;
                                        _ledgeAttach = i;
                                        Land();
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion

                #region Land on col

                if (State == CharState.Air && Trajectory.Y > 0)
                {
                    if (Map.CheckCol(new Vector2(Location.X, Location.Y + 15)))
                    {
                        Location.Y = (int)(Location.Y + 15) / 64 * 64;
                        Land();
                    }
                }

                #endregion
            }
            else if (State == CharState.Grounded)
            {
                #region Grounded state

                if (_ledgeAttach > -1)
                {
                    if (Map.GetLedgeSec(_ledgeAttach, Location.X) == -1)
                    {
                        FallOff();
                    }
                    else
                    {
                        Location.Y = Map.GetLedgeYLoc(_ledgeAttach, Map.GetLedgeSec(_ledgeAttach, Location.X),
                            Location.X);
                    }
                }
                else
                {
                    if (!Map.CheckCol(new Vector2(Location.X, Location.Y + 15)))
                        FallOff();
                }

                CheckXCol(pLoc);

                #endregion
            }

            #endregion

            #region UpdateKey input

            if (AnimName == "idle" || AnimName == "run")
            {
                if (KeyLeft)
                {
                    SetAnim("run");
                    Trajectory.X = -200;
                    Face = CharDir.Left;
                }
                else if (KeyRight)
                {
                    SetAnim("run");
                    Trajectory.X = 200;
                    Face = CharDir.Right;
                }
                else
                {
                    SetAnim("idle");
                }

                if (KeyAttack)
                {
                    SetAnim("attack");
                }

                if (KeySecondary)
                {
                    SetAnim("second");
                }

                if (KeyJump)
                {
                    SetAnim("fly");
                    Trajectory.Y = -600;
                    State = CharState.Air;
                    _ledgeAttach = -1;
                    if (KeyRight) Trajectory.X = 200;
                    else if (KeyLeft) Trajectory.X = -200;
                }
            }

            if (AnimName == "fly")
            {
                if (KeyLeft)
                {
                    Face = CharDir.Left;
                    if (Trajectory.X > -200)
                        Trajectory.X -= 500 * Game1.FrameTime;
                }
                else if (KeyRight)
                {
                    Face = CharDir.Right;
                    if (Trajectory.X < 200)
                        Trajectory.X += 500 * Game1.FrameTime;
                }
            }

            PressedKey = PressedKeys.None;

            if (KeyAttack)
                PressedKey = KeyUp ? PressedKeys.Lower : KeyDown ? PressedKeys.Upper : PressedKeys.Attack;

            if (KeySecondary)
                PressedKey = KeyUp ? PressedKeys.SecUp : KeyDown ? PressedKeys.SecDown : PressedKeys.Secondary;

            if (PressedKey != PressedKeys.None)
            {
                if (GotoGoal[(int)PressedKey] > -1)
                {
                    AnimFrame = GotoGoal[(int)PressedKey];

                    if (KeyLeft)
                        Face = CharDir.Left;
                    else if (KeyRight)
                        Face = CharDir.Right;

                    PressedKey = PressedKeys.None;

                    for (var i = 0; i < GotoGoal.Length; i++)
                        GotoGoal[i] = -1;

                    _frame = 0;
                    _script.DoScript(Anim, AnimFrame);
                }
            }

            #endregion
        }
Exemple #19
0
        public void Update(Map map, ParticleManager pMan, Character[] c)
        {
            if (Ai != null)
                Ai.Update(c, ID, map);

            PressedKey = PressedKeys.None;
            if (KeyAttack)
            {
                PressedKey = PressedKeys.Attack;
                if (KeyUp) PressedKey = PressedKeys.Lower;
                if (KeyDown) PressedKey = PressedKeys.Upper;
            }
            if (KeySecondary)
            {
                PressedKey = PressedKeys.Secondary;
                if (KeyUp) PressedKey = PressedKeys.SecUp;
                if (KeyDown) PressedKey = PressedKeys.SecDown;
            }
            if (PressedKey > PressedKeys.None)
            {
                if (GotoGoal[(int)PressedKey] > -1)
                {
                    SetFrame(GotoGoal[(int)PressedKey]);

                    if (KeyLeft)
                        Face = CharDir.Left;
                    if (KeyRight)
                        Face = CharDir.Right;

                    PressedKey = PressedKeys.None;

                    for (int i = 0; i < GotoGoal.Length; i++)
                        GotoGoal[i] = -1;

                    frame = 0f;
                }
            }

            if (StunFrame > 0f)
                StunFrame -= Game1.FrameTime;

            #region Update Dying
            if (DyingFrame > -1f)
            {
                DyingFrame += Game1.FrameTime;

            }
            #endregion

            #region Update Animation
            if (DyingFrame < 0f)
            {
                Animation animation = charDef.GetAnimation(Anim);
                KeyFrame keyframe = animation.GetKeyFrame(AnimFrame);

                frame += Game1.FrameTime * 30.0f;

                if (frame > (float)keyframe.Duration)
                {
                    int pframe = AnimFrame;

                    script.DoScript(Anim, AnimFrame);
                    CheckTrig(pMan);

                    frame -= (float)keyframe.Duration;
                    if (AnimFrame == pframe)
                        AnimFrame++;

                    keyframe = animation.GetKeyFrame(AnimFrame);

                    if (AnimFrame >=
                        animation.getKeyFrameArray().Length)
                        AnimFrame = 0;

                }

                if (keyframe.FrameRef < 0)
                    AnimFrame = 0;

                if (AnimName == "jhit")
                {
                    if (Trajectory.Y > -100f)
                        SetAnim("jmid");
                }
            }
            #endregion

            #region Collison w/ other characters
            for (int i = 0; i < c.Length; i++)
            {
                if (i != ID)
                {
                    if (c[i] != null)
                    {
                        if (!ethereal && !c[i].ethereal)
                        {
                            if (Loc.X > c[i].Loc.X - 90f * c[i].Scale &&
                                Loc.X < c[i].Loc.X + 90f * c[i].Scale &&
                                Loc.Y > c[i].Loc.Y - 120f * c[i].Scale &&
                                Loc.Y < c[i].Loc.Y + 10f * c[i].Scale)
                            {
                                float dif = (float)Math.Abs(Loc.X - c[i].Loc.X);
                                dif = 180f * c[i].Scale - dif;
                                dif *= 2f;
                                if (Loc.X < c[i].Loc.X)
                                {
                                    ColMove = -dif;
                                    c[i].ColMove = dif;
                                }
                                else
                                {
                                    ColMove = dif;
                                    c[i].ColMove = -dif;
                                }
                            }
                        }
                    }
                }
            }
            if (ColMove > 0f)
            {
                ColMove -= 400f * Game1.FrameTime;
                if (ColMove < 0f) ColMove = 0f;
            }
            if (ColMove < 0f)
            {
                ColMove += 400f * Game1.FrameTime;
                if (ColMove > 0f) ColMove = 0f;
            }
            #endregion

            #region Update loc by trajectory

            Vector2 pLoc = new Vector2(Loc.X, Loc.Y);

            if (State == CharState.Grounded || (State == CharState.Air && Floating))
            {
                if (Trajectory.X > 0f)
                {
                    Trajectory.X -= Game1.Friction * Game1.FrameTime;
                    if (Trajectory.X < 0f) Trajectory.X = 0f;
                }
                if (Trajectory.X < 0f)
                {
                    Trajectory.X += Game1.Friction * Game1.FrameTime;
                    if (Trajectory.X > 0f) Trajectory.X = 0f;
                }
            }
            Loc.X += Trajectory.X * Game1.FrameTime;
            Loc.X += ColMove * Game1.FrameTime;
            if (State == CharState.Air)
            {
                Loc.Y += Trajectory.Y * Game1.FrameTime;
            }
            #endregion

            #region Collision detection
            if (State == CharState.Air)
            {
                #region Air State
                if (Floating)
                {
                    Trajectory.Y += Game1.FrameTime * Game1.Gravity * 0.5f;
                    if (Trajectory.Y > 100f) Trajectory.Y = 100f;
                    if (Trajectory.Y < -100f) Trajectory.Y = -100f;

                }
                else
                    Trajectory.Y += Game1.FrameTime * Game1.Gravity;

                CheckXCol(map, pLoc);

                #region Land on ledge
                if (Trajectory.Y > 0.0f)
                {
                    for (int i = 0; i < 16; i++)
                    {
                        if (map.GetLedgeTotalNodes(i) > 1)
                        {

                            int ts = map.GetLedgeSec(i, pLoc.X);
                            int s = map.GetLedgeSec(i, Loc.X);
                            float fY;
                            float tfY;
                            if (s > -1 && ts > -1)
                            {

                                tfY = map.GetLedgeYLoc(i, s, pLoc.X);
                                fY = map.GetLedgeYLoc(i, s, Loc.X);
                                if (pLoc.Y <= tfY && Loc.Y >= fY)
                                {
                                    if (Trajectory.Y > 0.0f)
                                    {

                                        Loc.Y = fY;
                                        ledgeAttach = i;
                                        Land();
                                    }
                                }
                                else

                                    if (map.GetLedgeFlags(i) == (int)LedgeFlags.Solid
                                        &&
                                        Loc.Y >= fY)
                                    {
                                        Loc.Y = fY;
                                        ledgeAttach = i;
                                        Land();
                                    }
                            }

                        }
                    }
                }
                #endregion

                #region Land on col
                if (State == CharState.Air)
                {
                    if (Trajectory.Y > 0f)
                    {
                        if (map.CheckCol(new Vector2(Loc.X, Loc.Y + 15f)))
                        {
                            Loc.Y = (float)((int)((Loc.Y + 15f) / 64f) * 64);
                            Land();
                        }
                    }
                }
                #endregion

                #endregion
            }
            else if (State == CharState.Grounded)
            {
                #region Grounded State

                if (ledgeAttach > -1)
                {
                    if (map.GetLedgeSec(ledgeAttach, Loc.X) == -1)
                    {
                        FallOff();
                    }
                    else
                    {
                        Loc.Y = map.GetLedgeYLoc(ledgeAttach,
                            map.GetLedgeSec(ledgeAttach, Loc.X), Loc.X);
                    }
                }
                else
                {
                    if (!map.CheckCol(new Vector2(Loc.X, Loc.Y + 15f)))
                        FallOff();
                }

                CheckXCol(map, pLoc);

                #endregion
            }
            #endregion

            #region Key input
            if (AnimName == "idle" || AnimName == "run" ||
                (State == CharState.Grounded && CanCancel))
            {
                if (AnimName == "idle" || AnimName == "run")
                {
                    if (KeyLeft)
                    {
                        SetAnim("run");
                        Trajectory.X = -Speed;
                        Face = CharDir.Left;
                    }
                    else if (KeyRight)
                    {
                        SetAnim("run");
                        Trajectory.X = Speed;
                        Face = CharDir.Right;
                    }
                    else
                    {
                        SetAnim("idle");
                    }
                }
                if (KeyAttack)
                {
                    SetAnim("attack");
                }
                if (KeySecondary)
                {
                    SetAnim("second");
                }
                if (KeyJump)
                {
                    SetAnim("jump");
                }
                if (RightAnalog.X > 0.2f || RightAnalog.X < -0.2f)
                {
                    SetAnim("roll");
                    if (AnimName == "roll")
                    {
                        if (RightAnalog.X > 0f)
                            Face = CharDir.Right;
                        else
                            Face = CharDir.Left;
                    }
                }
            }

            if (AnimName == "fly" ||
                (State == CharState.Air && CanCancel))
            {
                if (KeyLeft)
                {
                    Face = CharDir.Left;
                    if (Trajectory.X > -Speed)
                        Trajectory.X -= 500f * Game1.FrameTime;
                }
                if (KeyRight)
                {
                    Face = CharDir.Right;
                    if (Trajectory.X < Speed)
                        Trajectory.X += 500f * Game1.FrameTime;
                }
                if (KeySecondary)
                {
                    SetAnim("fsecond");
                }
                if (KeyAttack)
                {
                    SetAnim("fattack");
                }
            }

            #endregion
        }
Exemple #20
0
        public void SetAnim(String newAnim)
        {
            if (AnimName != newAnim)
            {
                for (int i = 0; i < charDef.GetAnimationArray().Length; i++)
                {
                    if (charDef.GetAnimation(i).name == newAnim)
                    {
                        for (int t = 0; t < GotoGoal.Length; t++)
                            GotoGoal[t] = -1;

                        Floating = false;
                        Anim = i;
                        AnimFrame = 0;
                        frame = 0f;
                        AnimName = newAnim;
                        CanCancel = false;
                        ethereal = false;

                        if (KeyLeft)
                            Face = CharDir.Left;
                        if (KeyRight)
                            Face = CharDir.Right;

                    }

                }
            }
        }
Exemple #21
0
        public void Update(ParticleManager pMan, Character[] c)
        {
            #region Update AI

            if (Ai != null)
            {
                Ai.Update(c, Id, Map);
            }

            #endregion

            #region Update Dying

            if (DyingFrame > -1)
            {
                DyingFrame += Game1.FrameTime;
            }

            #endregion

            #region Update animation

            if (DyingFrame < 0)
            {
                var animation = _charDef.Animations[Anim];
                var keyFrame  = animation.KeyFrames[AnimFrame];

                _frame += Game1.FrameTime * 30;

                if (_frame > keyFrame.Duration)
                {
                    var pFrame = AnimFrame;
                    _script.DoScript(Anim, AnimFrame);
                    CheckTrig(pMan);

                    _frame -= keyFrame.Duration;

                    if (AnimFrame == pFrame)
                    {
                        AnimFrame++;
                    }

                    if (AnimFrame >= animation.KeyFrames.Length)
                    {
                        AnimFrame = 0;
                    }

                    keyFrame = animation.KeyFrames[AnimFrame];

                    if (keyFrame.FrameRef < 0)
                    {
                        AnimFrame = 0;
                    }
                }
            }

            #endregion

            #region Collison w/ other characters

            for (var i = 0; i < c.Length; i++)
            {
                if (i != Id)
                {
                    if (c[i] != null)
                    {
                        if (!Ethereal && !c[i].Ethereal)
                        {
                            if (Location.X > c[i].Location.X - 90f * c[i].Scale &&
                                Location.X <c[i].Location.X + 90f * c[i].Scale &&
                                            Location.Y> c[i].Location.Y - 120f * c[i].Scale &&
                                Location.Y < c[i].Location.Y + 10f * c[i].Scale)
                            {
                                var dif = Math.Abs(Location.X - c[i].Location.X);
                                dif  = 180f * c[i].Scale - dif;
                                dif *= 2f;
                                if (Location.X < c[i].Location.X)
                                {
                                    ColMove      = -dif;
                                    c[i].ColMove = dif;
                                }
                                else
                                {
                                    ColMove      = dif;
                                    c[i].ColMove = -dif;
                                }
                            }
                        }
                    }
                }
            }

            if (ColMove > 0f)
            {
                ColMove -= 400f * Game1.FrameTime;
                if (ColMove < 0f)
                {
                    ColMove = 0f;
                }
            }
            else if (ColMove < 0f)
            {
                ColMove += 400f * Game1.FrameTime;
                if (ColMove > 0f)
                {
                    ColMove = 0f;
                }
            }

            #endregion

            #region Update location by trajectory

            var pLoc = Location;

            if (State == CharState.Grounded)
            {
                if (Trajectory.X > 0)
                {
                    Trajectory.X -= Game1.Friction * Game1.FrameTime;
                    if (Trajectory.X < 0)
                    {
                        Trajectory.X = 0;
                    }
                }

                if (Trajectory.X < 0)
                {
                    Trajectory.X += Game1.Friction * Game1.FrameTime;
                    if (Trajectory.X > 0)
                    {
                        Trajectory.X = 0;
                    }
                }
            }

            Location.X += Trajectory.X * Game1.FrameTime;
            Location.X += ColMove * Game1.FrameTime;

            if (State == CharState.Air)
            {
                Location.Y   += Trajectory.Y * Game1.FrameTime;
                Trajectory.Y += Game1.FrameTime * Game1.Gravity;
            }

            #endregion

            #region Colision detection

            if (State == CharState.Air)
            {
                CheckXCol(pLoc);

                #region Land on ledge

                if (Trajectory.Y > 0)
                {
                    for (var i = 0; i < 16; i++)
                    {
                        if (Map.Ledges[i].TotalNodes > 1)
                        {
                            var ts = Map.GetLedgeSec(i, pLoc.X);
                            var s  = Map.GetLedgeSec(i, Location.X);

                            if (s > -1 && ts > -1)
                            {
                                var tfy = Map.GetLedgeYLoc(i, s, pLoc.X);
                                var fy  = Map.GetLedgeYLoc(i, s, Location.X);

                                if (pLoc.Y <= tfy && Location.Y >= fy)
                                {
                                    if (Trajectory.Y > 0)
                                    {
                                        Location.Y   = fy;
                                        _ledgeAttach = i;
                                        Land();
                                    }
                                }
                                else
                                {
                                    if (Map.Ledges[i].Flags == (int)LedgeFlags.Solid && Location.Y >= fy)
                                    {
                                        Location.Y   = fy;
                                        _ledgeAttach = i;
                                        Land();
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion

                #region Land on col

                if (State == CharState.Air && Trajectory.Y > 0)
                {
                    if (Map.CheckCol(new Vector2(Location.X, Location.Y + 15)))
                    {
                        Location.Y = (int)(Location.Y + 15) / 64 * 64;
                        Land();
                    }
                }

                #endregion
            }
            else if (State == CharState.Grounded)
            {
                #region Grounded state

                if (_ledgeAttach > -1)
                {
                    if (Map.GetLedgeSec(_ledgeAttach, Location.X) == -1)
                    {
                        FallOff();
                    }
                    else
                    {
                        Location.Y = Map.GetLedgeYLoc(_ledgeAttach, Map.GetLedgeSec(_ledgeAttach, Location.X),
                                                      Location.X);
                    }
                }
                else
                {
                    if (!Map.CheckCol(new Vector2(Location.X, Location.Y + 15)))
                    {
                        FallOff();
                    }
                }

                CheckXCol(pLoc);

                #endregion
            }

            #endregion

            #region UpdateKey input

            if (AnimName == "idle" || AnimName == "run")
            {
                if (KeyLeft)
                {
                    SetAnim("run");
                    Trajectory.X = -200;
                    Face         = CharDir.Left;
                }
                else if (KeyRight)
                {
                    SetAnim("run");
                    Trajectory.X = 200;
                    Face         = CharDir.Right;
                }
                else
                {
                    SetAnim("idle");
                }

                if (KeyAttack)
                {
                    SetAnim("attack");
                }

                if (KeySecondary)
                {
                    SetAnim("second");
                }

                if (KeyJump)
                {
                    SetAnim("fly");
                    Trajectory.Y = -600;
                    State        = CharState.Air;
                    _ledgeAttach = -1;
                    if (KeyRight)
                    {
                        Trajectory.X = 200;
                    }
                    else if (KeyLeft)
                    {
                        Trajectory.X = -200;
                    }
                }
            }

            if (AnimName == "fly")
            {
                if (KeyLeft)
                {
                    Face = CharDir.Left;
                    if (Trajectory.X > -200)
                    {
                        Trajectory.X -= 500 * Game1.FrameTime;
                    }
                }
                else if (KeyRight)
                {
                    Face = CharDir.Right;
                    if (Trajectory.X < 200)
                    {
                        Trajectory.X += 500 * Game1.FrameTime;
                    }
                }
            }

            PressedKey = PressedKeys.None;

            if (KeyAttack)
            {
                PressedKey = KeyUp ? PressedKeys.Lower : KeyDown ? PressedKeys.Upper : PressedKeys.Attack;
            }

            if (KeySecondary)
            {
                PressedKey = KeyUp ? PressedKeys.SecUp : KeyDown ? PressedKeys.SecDown : PressedKeys.Secondary;
            }

            if (PressedKey != PressedKeys.None)
            {
                if (GotoGoal[(int)PressedKey] > -1)
                {
                    AnimFrame = GotoGoal[(int)PressedKey];

                    if (KeyLeft)
                    {
                        Face = CharDir.Left;
                    }
                    else if (KeyRight)
                    {
                        Face = CharDir.Right;
                    }

                    PressedKey = PressedKeys.None;

                    for (var i = 0; i < GotoGoal.Length; i++)
                    {
                        GotoGoal[i] = -1;
                    }

                    _frame = 0;
                    _script.DoScript(Anim, AnimFrame);
                }
            }

            #endregion
        }
        public void Update(Map map, ParticleManager pMan, Character[] c)
        {
            if (Ai != null)
            {
                Ai.Update(c, ID, map);
            }

            PressedKey = PressedKeys.None;
            if (KeyAttack)
            {
                PressedKey = PressedKeys.Attack;
                if (KeyUp)
                {
                    PressedKey = PressedKeys.Lower;
                }
                if (KeyDown)
                {
                    PressedKey = PressedKeys.Upper;
                }
            }
            if (KeySecondary)
            {
                PressedKey = PressedKeys.Secondary;
                if (KeyUp)
                {
                    PressedKey = PressedKeys.SecUp;
                }
                if (KeyDown)
                {
                    PressedKey = PressedKeys.SecDown;
                }
            }
            if (PressedKey > PressedKeys.None)
            {
                if (GotoGoal[(int)PressedKey] > -1)
                {
                    SetFrame(GotoGoal[(int)PressedKey]);

                    if (KeyLeft)
                    {
                        Face = CharDir.Left;
                    }
                    if (KeyRight)
                    {
                        Face = CharDir.Right;
                    }

                    PressedKey = PressedKeys.None;

                    for (int i = 0; i < GotoGoal.Length; i++)
                    {
                        GotoGoal[i] = -1;
                    }

                    frame = 0f;
                }
            }

            if (StunFrame > 0f)
            {
                StunFrame -= Game1.FrameTime;
            }

            #region Update Dying
            if (DyingFrame > -1f)
            {
                DyingFrame += Game1.FrameTime;
            }
            #endregion

            #region Update Animation
            if (DyingFrame < 0f)
            {
                Animation animation = charDef.GetAnimation(Anim);
                KeyFrame  keyframe  = animation.GetKeyFrame(AnimFrame);



                frame += Game1.FrameTime * 30.0f;

                if (frame > (float)keyframe.Duration)
                {
                    int pframe = AnimFrame;

                    script.DoScript(Anim, AnimFrame);
                    CheckTrig(pMan);

                    frame -= (float)keyframe.Duration;
                    if (AnimFrame == pframe)
                    {
                        AnimFrame++;
                    }

                    keyframe = animation.GetKeyFrame(AnimFrame);

                    if (AnimFrame >=
                        animation.getKeyFrameArray().Length)
                    {
                        AnimFrame = 0;
                    }
                }


                if (keyframe.FrameRef < 0)
                {
                    AnimFrame = 0;
                }

                if (AnimName == "jhit")
                {
                    if (Trajectory.Y > -100f)
                    {
                        SetAnim("jmid");
                    }
                }
            }
            #endregion


            #region Collison w/ other characters
            for (int i = 0; i < c.Length; i++)
            {
                if (i != ID)
                {
                    if (c[i] != null)
                    {
                        if (!ethereal && !c[i].ethereal)
                        {
                            if (Loc.X > c[i].Loc.X - 90f * c[i].Scale &&
                                Loc.X <c[i].Loc.X + 90f * c[i].Scale &&
                                       Loc.Y> c[i].Loc.Y - 120f * c[i].Scale &&
                                Loc.Y < c[i].Loc.Y + 10f * c[i].Scale)
                            {
                                float dif = (float)Math.Abs(Loc.X - c[i].Loc.X);
                                dif  = 180f * c[i].Scale - dif;
                                dif *= 2f;
                                if (Loc.X < c[i].Loc.X)
                                {
                                    ColMove      = -dif;
                                    c[i].ColMove = dif;
                                }
                                else
                                {
                                    ColMove      = dif;
                                    c[i].ColMove = -dif;
                                }
                            }
                        }
                    }
                }
            }
            if (ColMove > 0f)
            {
                ColMove -= 400f * Game1.FrameTime;
                if (ColMove < 0f)
                {
                    ColMove = 0f;
                }
            }
            if (ColMove < 0f)
            {
                ColMove += 400f * Game1.FrameTime;
                if (ColMove > 0f)
                {
                    ColMove = 0f;
                }
            }
            #endregion

            #region Update loc by trajectory

            Vector2 pLoc = new Vector2(Loc.X, Loc.Y);

            if (State == CharState.Grounded || (State == CharState.Air && Floating))
            {
                if (Trajectory.X > 0f)
                {
                    Trajectory.X -= Game1.Friction * Game1.FrameTime;
                    if (Trajectory.X < 0f)
                    {
                        Trajectory.X = 0f;
                    }
                }
                if (Trajectory.X < 0f)
                {
                    Trajectory.X += Game1.Friction * Game1.FrameTime;
                    if (Trajectory.X > 0f)
                    {
                        Trajectory.X = 0f;
                    }
                }
            }
            Loc.X += Trajectory.X * Game1.FrameTime;
            Loc.X += ColMove * Game1.FrameTime;
            if (State == CharState.Air)
            {
                Loc.Y += Trajectory.Y * Game1.FrameTime;
            }
            #endregion



            #region Collision detection
            if (State == CharState.Air)
            {
                #region Air State
                if (Floating)
                {
                    Trajectory.Y += Game1.FrameTime * Game1.Gravity * 0.5f;
                    if (Trajectory.Y > 100f)
                    {
                        Trajectory.Y = 100f;
                    }
                    if (Trajectory.Y < -100f)
                    {
                        Trajectory.Y = -100f;
                    }
                }
                else
                {
                    Trajectory.Y += Game1.FrameTime * Game1.Gravity;
                }

                CheckXCol(map, pLoc);

                #region Land on ledge
                if (Trajectory.Y > 0.0f)
                {
                    for (int i = 0; i < 16; i++)
                    {
                        if (map.GetLedgeTotalNodes(i) > 1)
                        {
                            int   ts = map.GetLedgeSec(i, pLoc.X);
                            int   s  = map.GetLedgeSec(i, Loc.X);
                            float fY;
                            float tfY;
                            if (s > -1 && ts > -1)
                            {
                                tfY = map.GetLedgeYLoc(i, s, pLoc.X);
                                fY  = map.GetLedgeYLoc(i, s, Loc.X);
                                if (pLoc.Y <= tfY && Loc.Y >= fY)
                                {
                                    if (Trajectory.Y > 0.0f)
                                    {
                                        Loc.Y       = fY;
                                        ledgeAttach = i;
                                        Land();
                                    }
                                }
                                else

                                if (map.GetLedgeFlags(i) == (int)LedgeFlags.Solid
                                    &&
                                    Loc.Y >= fY)
                                {
                                    Loc.Y       = fY;
                                    ledgeAttach = i;
                                    Land();
                                }
                            }
                        }
                    }
                }
                #endregion

                #region Land on col
                if (State == CharState.Air)
                {
                    if (Trajectory.Y > 0f)
                    {
                        if (map.CheckCol(new Vector2(Loc.X, Loc.Y + 15f)))
                        {
                            Loc.Y = (float)((int)((Loc.Y + 15f) / 64f) * 64);
                            Land();
                        }
                    }
                }
                #endregion

                #endregion
            }
            else if (State == CharState.Grounded)
            {
                #region Grounded State

                if (ledgeAttach > -1)
                {
                    if (map.GetLedgeSec(ledgeAttach, Loc.X) == -1)
                    {
                        FallOff();
                    }
                    else
                    {
                        Loc.Y = map.GetLedgeYLoc(ledgeAttach,
                                                 map.GetLedgeSec(ledgeAttach, Loc.X), Loc.X);
                    }
                }
                else
                {
                    if (!map.CheckCol(new Vector2(Loc.X, Loc.Y + 15f)))
                    {
                        FallOff();
                    }
                }

                CheckXCol(map, pLoc);


                #endregion
            }
            #endregion

            #region Key input
            if (AnimName == "idle" || AnimName == "run" ||
                (State == CharState.Grounded && CanCancel))
            {
                if (AnimName == "idle" || AnimName == "run")
                {
                    if (KeyLeft)
                    {
                        SetAnim("run");
                        Trajectory.X = -Speed;
                        Face         = CharDir.Left;
                    }
                    else if (KeyRight)
                    {
                        SetAnim("run");
                        Trajectory.X = Speed;
                        Face         = CharDir.Right;
                    }
                    else
                    {
                        SetAnim("idle");
                    }
                }
                if (KeyAttack)
                {
                    SetAnim("attack");
                }
                if (KeySecondary)
                {
                    SetAnim("second");
                }
                if (KeyJump)
                {
                    SetAnim("jump");
                }
                if (RightAnalog.X > 0.2f || RightAnalog.X < -0.2f)
                {
                    SetAnim("roll");
                    if (AnimName == "roll")
                    {
                        if (RightAnalog.X > 0f)
                        {
                            Face = CharDir.Right;
                        }
                        else
                        {
                            Face = CharDir.Left;
                        }
                    }
                }
            }

            if (AnimName == "fly" ||
                (State == CharState.Air && CanCancel))
            {
                if (KeyLeft)
                {
                    Face = CharDir.Left;
                    if (Trajectory.X > -Speed)
                    {
                        Trajectory.X -= 500f * Game1.FrameTime;
                    }
                }
                if (KeyRight)
                {
                    Face = CharDir.Right;
                    if (Trajectory.X < Speed)
                    {
                        Trajectory.X += 500f * Game1.FrameTime;
                    }
                }
                if (KeySecondary)
                {
                    SetAnim("fsecond");
                }
                if (KeyAttack)
                {
                    SetAnim("fattack");
                }
            }

            #endregion
        }
Exemple #23
0
        public override void Update(GameTime gameTime)
        {
            timer.Update();

            elapsed = gameTime.ElapsedGameTime.Milliseconds;

            background.Update();

            tweener.Update();

            if (Input.KeyPressed(Key.Escape))
            {
                Game.Quit();
            }


            if (Input.KeyPressed(Key.F11))
            {
                Game.ToggleFullscreen();
            }
            else if (Input.KeyPressed(Key.D1))
            {
                Game.ScreenSize = new Size(size.W, size.H);
            }
            else if (Input.KeyPressed(Key.D2))
            {
                Game.ScreenSize = new Size(size.W * 2, size.H * 2);
            }
            else if (Input.KeyPressed(Key.D3))
            {
                Game.ScreenSize = new Size(size.W * 3, size.H * 3);
            }

            if (Input.KeyDown(Key.Left))
            {
                particle_dx -= speed;
            }

            if (Input.KeyDown(Key.Right))
            {
                particle_dx += speed;
            }

            if (Input.KeyDown(Key.Up))
            {
                particle_dy -= speed;
            }

            if (Input.KeyDown(Key.Down))
            {
                particle_dy += speed;
            }

            particle_dx *= friction;
            particle_dy *= friction;

            if (particle_dx > 0.05f && particle_dx < 0.05f || particle_dx < 0 && particle_dx > -0.05f)
            {
                particle_dx = 0;
            }

            if (particle_dy > 0.05f && particle_dy < 0.05f || particle_dy < 0.05f && particle_dy > -0.05f)
            {
                particle_dy = 0;
            }

            particle_x += particle_dx;
            particle_y += particle_dy;

            if (particle_x > Canvas.Width - 16)
            {
                particle_x  = Canvas.Width - 16;
                particle_dx = -particle_dx;
                PlayBump();
            }
            else if (particle_x < 16)
            {
                particle_x  = 16;
                particle_dx = -particle_dx;
                PlayBump();
            }

            if (particle_y > Canvas.Height - 16)
            {
                particle_y  = Canvas.Height - 16;
                particle_dy = -particle_dy;
                PlayBump();
            }
            else if (particle_y < 16)
            {
                particle_y  = 16;
                particle_dy = -particle_dy;
                PlayBump();
            }

            bool up    = Input.KeyDown(Key.W);
            bool down  = Input.KeyDown(Key.S);
            bool left  = Input.KeyDown(Key.A);
            bool right = Input.KeyDown(Key.D);

            if (left)
            {
                if (!up && !down)
                {
                    char_sx  = -5.0f;
                    char_dir = CharDir.Left;
                }
                else
                {
                    char_sx = -4.0f;
                }
            }
            else if (right)
            {
                if (!up && !down)
                {
                    char_sx  = 5.0f;
                    char_dir = CharDir.Right;
                }
                else
                {
                    char_sx = 4.0f;
                }
            }

            if (up)
            {
                if (!left && !right)
                {
                    char_sy  = -5.0f;
                    char_dir = CharDir.Up;
                }
                else
                {
                    char_sy = -4.0f;
                }
            }
            else if (down)
            {
                if (!left && !right)
                {
                    char_sy  = 5.0f;
                    char_dir = CharDir.Down;
                }
                else
                {
                    char_sy = 4.0f;
                }
            }

            switch (char_dir)
            {
            case CharDir.Left:
                animated_sprite.SetAnimation("walk_horiz");
                animated_sprite.SetFlipH(true);
                break;

            case CharDir.Right:
                animated_sprite.SetAnimation("walk_horiz");
                animated_sprite.SetFlipH(false);
                break;

            case CharDir.Up:
                animated_sprite.SetAnimation("walk_up");
                animated_sprite.SetFlipH(false);
                break;

            case CharDir.Down:
                animated_sprite.SetAnimation("walk_down");
                animated_sprite.SetFlipH(false);
                break;
            }


            if (!left && !right)
            {
                char_sx = 0.0f;
            }

            if (!up && !down)
            {
                char_sy = 0.0f;
            }

            char_x += char_sx;
            char_y += char_sy;

            if (char_sx == 0.0f && char_sy == 0.0f)
            {
                switch (char_dir)
                {
                case CharDir.Left:
                case CharDir.Right:
                    animated_sprite.SetAnimation("idle_horiz");
                    break;

                case CharDir.Up:
                    animated_sprite.SetAnimation("idle_up");
                    break;

                case CharDir.Down:
                    animated_sprite.SetAnimation("idle_down");
                    break;
                }
            }

            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            animated_sprite.Update();

            _trail.MoveTo(particle_x, particle_y);
            _trail.Update(dt);
            _explosion.Update(dt);


            if (Input.MousePressed(MouseButton.Left))
            {
                _explosion.FireAt(Input.MousePos.X, Input.MousePos.Y);
            }
        }
Exemple #24
0
 public override void Update(FrameTick elapsedTime)
 {
     //set the character's projected movement
     Move = CharDir.GetLoc() * (run ? 5 : 2);
 }
Exemple #25
0
        public void ReadFromNet(PacketReader reader)
        {
            Loc.X = NetPacker.ShortToBigFloat(reader.ReadInt16());
            Loc.Y = NetPacker.ShortToBigFloat(reader.ReadInt16());

            Anim = NetPacker.ShortToInt(reader.ReadInt16());
            AnimFrame = NetPacker.ShortToInt(reader.ReadInt16());
            AnimName = charDef.GetAnimation(Anim).name;
            frame = NetPacker.ShortToMidFloat(reader.ReadInt16());

            if (reader.ReadBoolean())
                State = CharState.Air;
            else
                State = CharState.Grounded;

            if (reader.ReadBoolean())
                Face = CharDir.Right;
            else
                Face = CharDir.Left;

            Trajectory.X = NetPacker.ShortToBigFloat(reader.ReadInt16());
            Trajectory.Y = NetPacker.ShortToBigFloat(reader.ReadInt16());

            KeyRight = reader.ReadBoolean();
            KeyLeft = reader.ReadBoolean();

            HP = NetPacker.ShortToInt(reader.ReadInt16());

            ReceivedNetUpdate = true;
        }
Exemple #26
0
 private bool FriendInWay(Character[] c, int ID, CharDir face)
 {
     for (int i = 0; i < c.Length; i++)
     {
         if (i != ID)
         {
             if (c[i] != null)
             {
                 if (me.Team == c[i].Team)
                 {
                     if (me.Loc.Y > c[i].Loc.Y - 100f &&
                         me.Loc.Y < c[i].Loc.Y + 10f)
                     {
                         if (face == CharDir.Right)
                         {
                             if (c[i].Loc.X > me.Loc.X &&
                                 c[i].Loc.X < me.Loc.X + 70f)
                                 return true;
                         }
                         else
                         {
                             if (c[i].Loc.X < me.Loc.X &&
                                 c[i].Loc.X > me.Loc.X - 70f)
                                 return true;
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
        public static bool CheckHit(Particle p, Character[] c,
                                    ParticleManager pMan)
        {
            bool r = false;

            CharDir tFace = GetFaceFromTraj(p.GetTraj());

            for (int i = 0; i < c.Length; i++)
            {
                if (i != p.Owner)
                {
                    if (c[i] != null)
                    {
                        if (c[i].DyingFrame < 0f &&
                            !c[i].ethereal)
                        {
                            if (c[i].InHitBounds(p.GetLoc()))
                            {
                                float hVal = 1f;

                                c[i].LastHitBy = p.Owner;
                                CharState pState = c[i].State;
                                Vector2   pLoc   = c[i].Loc;

                                bool noAnim = false;
                                if (c[i].StunFrame > 0f &&
                                    c[i].StunFrame < 3f)
                                {
                                    noAnim = true;
                                }
                                if (c[i].NoLifty)
                                {
                                    if (c[i].StunFrame <= 0f ||
                                        c[i].StunFrame > 5.2f)
                                    {
                                        c[i].StunFrame = 5.5f;
                                    }
                                }

                                if (typeof(Bullet).Equals(p.GetType()))
                                {
                                    if (!r)
                                    {
                                        hVal *= 4f;

                                        c[i].Face = 1 - tFace;

                                        c[i].SetAnim("idle");
                                        if (!noAnim)
                                        {
                                            c[i].SetAnim("hit");
                                            c[i].Slide(-100f);
                                        }
                                        Sound.PlayCue("bullethit");

                                        Vector2 v = new Vector2(c[i].Loc.X,
                                                                p.GetLoc().Y);
                                        pMan.MakeBulletBlood(v, p.GetTraj() / 2f);
                                        pMan.MakeBulletBlood(v, -p.GetTraj());
                                        pMan.MakeBulletDust(v, p.GetTraj());
                                        Game1.SlowTime = 0.05f;



                                        r = true;
                                    }
                                }
                                else if (typeof(Rocket).Equals(p.GetType()))
                                {
                                    pMan.MakeExplosion(p.GetLoc(), 1f);
                                    hVal *= 5f;
                                    if (!noAnim)
                                    {
                                        c[i].Trajectory.X = (p.GetTraj().X > 0f ? 600f : -600f);
                                        c[i].SetAnim("jhit");
                                        c[i].SetJump(300f);
                                    }
                                    Game1.SlowTime = 0.25f;
                                    r = true;
                                }
                                else if (typeof(Hit).Equals(p.GetType()))
                                {
                                    c[i].Face = 1 - tFace;
                                    float tX = 1f;
                                    if (tFace == CharDir.Left)
                                    {
                                        tX = -1f;
                                    }
                                    if (!noAnim)
                                    {
                                        c[i].SetAnim("idle");
                                        c[i].SetAnim("hit");
                                    }
                                    Sound.PlayCue("zomhit");

                                    if (c[i].State == CharState.Grounded)
                                    {
                                        c[i].Slide(-200f);
                                    }
                                    else
                                    {
                                        c[i].Slide(-50f);
                                    }



                                    switch (p.GetFlag())
                                    {
                                    case Character.TRIG_ZOMBIE_HIT:
                                        hVal *= 5f;
                                        pMan.MakeBloodSplash(p.GetLoc(),
                                                             new Vector2(50f * tX, 100f));

                                        break;

                                    case Character.TRIG_WRENCH_DIAG_DOWN:
                                        hVal *= 5f;
                                        pMan.MakeBloodSplash(p.GetLoc(),
                                                             new Vector2(50f * tX, 100f));

                                        Game1.SlowTime = 0.1f;

                                        break;

                                    case Character.TRIG_WRENCH_DIAG_UP:
                                        hVal *= 5f;
                                        pMan.MakeBloodSplash(p.GetLoc(),
                                                             new Vector2(-50f * tX, -100f));

                                        Game1.SlowTime = 0.1f;

                                        break;

                                    case Character.TRIG_WRENCH_UP:
                                        hVal *= 5f;
                                        pMan.MakeBloodSplash(p.GetLoc(),
                                                             new Vector2(30f * tX, -100f));
                                        Game1.SlowTime = 0.1f;

                                        break;

                                    case Character.TRIG_WRENCH_DOWN:
                                        hVal *= 5f;
                                        pMan.MakeBloodSplash(p.GetLoc(),
                                                             new Vector2(-50f * tX, 100f));

                                        Game1.SlowTime = 0.1f;
                                        Sound.PlayCue("zomhit");

                                        break;

                                    case Character.TRIG_WRENCH_UPPERCUT:
                                    case Character.TRIG_CHAINSAW_UPPER:
                                        hVal *= 15f;
                                        pMan.MakeBloodSplash(p.GetLoc(),
                                                             new Vector2(-50f * tX, -150f));
                                        c[i].Trajectory.X = 100f * tX;

                                        c[i].SetAnim("jhit");
                                        c[i].SetJump(700f);
                                        Game1.SlowTime = 0.125f;
                                        QuakeManager.SetQuake(.5f);
                                        QuakeManager.SetBlast(.5f, p.GetLoc());
                                        break;

                                    case Character.TRIG_WRENCH_SMACKDOWN:
                                    case Character.TRIG_CHAINSAW_DOWN:
                                        hVal *= 15f;
                                        pMan.MakeBloodSplash(p.GetLoc(),
                                                             new Vector2(-50f * tX, 150f));
                                        c[i].SetAnim("jfall");
                                        c[i].SetJump(-900f);


                                        Game1.SlowTime = 0.125f;
                                        QuakeManager.SetQuake(.5f);
                                        QuakeManager.SetBlast(.5f, p.GetLoc());
                                        break;

                                    case Character.TRIG_KICK:
                                        hVal *= 15f;
                                        pMan.MakeBloodSplash(p.GetLoc(),
                                                             new Vector2(300f * tX, 0f));

                                        c[i].Trajectory.X = 1000f * tX;

                                        c[i].SetAnim("jhit");
                                        c[i].SetJump(300f);

                                        Game1.SlowTime = 0.25f;
                                        QuakeManager.SetQuake(.5f);
                                        QuakeManager.SetBlast(.75f, p.GetLoc());
                                        break;
                                    }
                                }
                                if (c[i].State == CharState.Air)
                                {
                                    if (c[i].AnimName == "hit")
                                    {
                                        c[i].SetAnim("jmid");
                                        c[i].SetJump(300f);
                                        if (typeof(Hit).Equals(p.GetType()))
                                        {
                                            if (c[p.Owner].Team ==
                                                Character.TEAM_GOOD_GUYS)
                                            {
                                                c[i].Loc.Y =
                                                    c[p.Owner].Loc.Y;
                                            }
                                        }
                                    }
                                    if (c[i].NoLifty)
                                    {
                                        if (pState == CharState.Grounded)
                                        {
                                            c[i].Loc   = pLoc;
                                            c[i].State = pState;
                                            c[i].SetAnim("hit");
                                        }
                                        if (c[i].Trajectory.X > 300f)
                                        {
                                            c[i].Trajectory.X = 300f;
                                        }
                                        if (c[i].Trajectory.X < -300f)
                                        {
                                            c[i].Trajectory.X = -300f;
                                        }
                                    }
                                }

                                c[i].HP -= (int)hVal;

                                if (c[i].LastHitBy == 0)
                                {
                                    Game1.Score += (int)hVal * 50;
                                }


                                if (c[i].HP < 0)
                                {
                                    if (c[i].AnimName == "hit")
                                    {
                                        c[i].SetAnim("diehit");
                                    }
                                    if (i == 0)
                                    {
                                        if (c[i].AnimName == "hit")
                                        {
                                            c[i].SetAnim("jmid");
                                            c[i].SetJump(300f);
                                        }
                                        Game1.Menu.Die();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(r);
        }
 /// <summary>
 /// Make a bullet with muzzle flash.
 /// </summary>
 /// <param name="loc">Location to create the bullet from.</param>
 /// <param name="traj">Bullet trajectory</param>
 /// <param name="face">Facing of owner</param>
 /// <param name="owner">Owner of bullet</param>
 public void MakeBullet(Vector2 loc, Vector2 traj, CharDir face, int owner)
 {
     if (face == CharDir.Left)
     {
         AddParticle(new Bullet(loc, new Vector2(-traj.X, traj.Y)
             + Rand.GetRandomVector2(-90f, 90f, -90f, 90f),
             owner));
         MakeMuzzleFlash(loc, new Vector2(-traj.X, traj.Y));
     }
     else
     {
         AddParticle(new Bullet(loc, traj
             + Rand.GetRandomVector2(-90f, 90f, -90f, 90f),
             owner));
         MakeMuzzleFlash(loc, traj);
     }
 }
Exemple #29
0
        public Character(Vector2 newLoc, CharDef newCharDef, int newID, int newTeam)
        {
            script = new Script(this);

            Ai = null;

            Loc = newLoc;
            ID = newID;
            Trajectory = new Vector2();

            Team = newTeam;

            Face = CharDir.Right;
            Scale = 0.5f;
            charDef = newCharDef;

            NoLifty = false;

            InitScript();

            AnimName = "";
            SetAnim("fly");
            ethereal = false;

            State = CharState.Air;
        }