Exemplo n.º 1
0
        public override void Update(Character[] c, int id, Map map)
        {
            Me = c[id];
            if (JobFrame < 0f)
            {
                var r = Rand.GetRandomFloat(0f, 1f);
                if (r < 0.6f)
                {
                    Job = JobMeleeChase;
                    JobFrame = Rand.GetRandomFloat(2f, 4f);
                    Targ = FindTarg(c);
                }
                else if (r < 0.8f)
                {
                    Job = JobAvoid;
                    JobFrame = Rand.GetRandomFloat(1f, 2f);
                    Targ = FindTarg(c);
                }
                else
                {
                    Job = JobIdle;
                    JobFrame = Rand.GetRandomFloat(.5f, 1f);
                }
            }

            base.Update(c, id, map);
        }
Exemplo n.º 2
0
 public virtual void Update(float gameTime, Map map, ParticleManager pMan, Character[] c)
 {
     Location += Trajectory*gameTime;
     Frame -= gameTime;
     if (Frame < 0)
         KillMe();
 }
Exemplo n.º 3
0
 public Hud(SpriteBatch sprite, Texture2D spritesTex, Texture2D nullTex, Character[] character, Map map)
 {
     _sprite = sprite;
     _spritesTex = spritesTex;
     _character = character;
     _map = map;
     _nullTex = nullTex;
     _scoreDraw = new ScoreDraw(_sprite, _spritesTex);
 }
Exemplo n.º 4
0
        protected void DoJob(Character[] c, int id)
        {
            switch (Job)
            {
                case JobIdle: //do nothing!
                    break;
                case JobMeleeChase:
                    if (Targ > -1)
                    {
                        if (!ChaseTarg(c, 50f))
                        {
                            if (!FaceTarg(c))
                            {
                                Me.KeyAttack = true;
                            }
                        }
                    }
                    else Targ = FindTarg(c);
                    break;
                case JobAvoid:
                    if (Targ > -1)
                    {
                        AvoidTarg(c, 500f);
                    }
                    else Targ = FindTarg(c);
                    break;
                case JobShootChase:
                    if (Targ > -1)
                    {
                        if (!ChaseTarg(c, 150f))
                        {
                            if (!FaceTarg(c))
                            {
                                Me.KeySecondary = true;
                            }
                        }
                    }
                    else Targ = FindTarg(c);
                    break;
            }

            if (!Me.KeyAttack && !Me.KeySecondary)
            {
                if (Me.KeyLeft)
                {
                    if (FriendInWay(c, id, CharDir.Left))
                        Me.KeyLeft = false;
                }
                if (Me.KeyRight)
                {
                    if (FriendInWay(c, id, CharDir.Right))
                        Me.KeyRight = false;
                }
            }
        }
Exemplo n.º 5
0
        public override void Update(float gameTime, Map map, ParticleManager pMan, Character[] c)
        {
            Trajectory.Y += gameTime * 100f;

            if (Trajectory.X < -10f) Trajectory.X += gameTime * 200f;
            if (Trajectory.X > 10f) Trajectory.X -= gameTime * 200f;

            Rotation = GlobalFunctions.GetAngle(Vector2.Zero, Trajectory);

            base.Update(gameTime, map, pMan, c);
        }
Exemplo n.º 6
0
        public override void Update(float gameTime, Map map, ParticleManager pMan, Character[] c)
        {
            if (Frame < 0.5f)
            {
                if (Trajectory.Y < -10) Trajectory.Y += gameTime * 500;
                if (Trajectory.X < -10) Trajectory.X += gameTime * 150;
                if (Trajectory.X > 10) Trajectory.X -= gameTime * 150;
            }

            base.Update(gameTime, map, pMan, c);
        }
Exemplo n.º 7
0
        public override void Update(float gameTime, Map map, ParticleManager pMan, Character[] c)
        {
            if (HitManager.CheckHit(this, c, pMan))
                Frame = 0f;

            if (map.CheckParticleCol(Location))
            {
                Frame = 0f;
                pMan.MakeBulletDust(Location, Trajectory);
            }
            base.Update(gameTime, map, pMan, c);
        }
Exemplo n.º 8
0
 public virtual void Update(Character[] c, int id, Map map)
 {
     Me = c[id];
     Me.KeyLeft = false;
     Me.KeyRight = false;
     Me.KeyUp = false;
     Me.KeyDown = false;
     Me.KeyAttack = false;
     Me.KeySecondary = false;
     Me.KeyJump = false;
     JobFrame -= Game1.FrameTime;
     DoJob(c, id);
 }
Exemplo n.º 9
0
 protected bool ChaseTarg(Character[] c, float distance)
 {
     if (Me.Location.X > c[Targ].Location.X + distance)
     {
         Me.KeyLeft = true;
         return true;
     }
     if (Me.Location.X < c[Targ].Location.X - distance)
     {
         Me.KeyRight = true;
         return true;
     }
     return false;
 }
Exemplo n.º 10
0
        public void Update(Character[] c)
        {
            updateFrame -= Game1.FrameTime;

            if (updateFrame > 0f)
                return;

            updateFrame = 1f;
            var monsters = 0;

            for (var i = 0; i < c.Length; i++)
            {
                if (c[i] != null)
                    if (c[i].Team == Character.TeamBadGuys) monsters++;
            }

            if (monsters < Size)
            {
                for (var i = 0; i < bucketItem.Length; i++)
                {
                    if (bucketItem[i] != null)
                    {
                        for (var n = 0; n < c.Length; n++)
                        {
                            if (c[n] == null)
                            {
                                c[n] = new Character(bucketItem[i].Location, Game1.CharDefs[bucketItem[i].CharDef], n,
                                    Character.TeamBadGuys) { Map = _map };
                                bucketItem[i] = null;
                                return;
                            }
                        }
                    }
                }

                if (monsters == 0)
                    IsEmpty = true;
            }
        }
Exemplo n.º 11
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
        }
Exemplo n.º 12
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;
 }
Exemplo n.º 13
0
        protected int FindTarg(Character[] c)
        {
            var closest = -1;
            var d = 0f;

            for (var i = 0; i < c.Length; i++)
            {
                if (i != Me.Id)
                {
                    if (c[i] != null)
                    {
                        if (c[i].Team != Me.Team)
                        {
                            var newD = (Me.Location - c[i].Location).Length();
                            if (closest == -1 || newD < d)
                            {
                                d = newD;
                                closest = i;
                            }
                        }
                    }
                }
            }

            return closest;
        }
Exemplo n.º 14
0
        public void Update(ParticleManager pMan, Character[] c)
        {
            CheckTransitions(c);
            if (TransOutFrame > 0f)
            {
                TransOutFrame -= Game1.FrameTime * 3f;
                if (TransOutFrame <= 0f)
                {
                    Path = TransitionDestination[(int) TransDir];
                    Read();
                    TransInFrame = 1.1f;

                    for (var i = 1; i < c.Length; i++)
                        c[i] = null;

                    pMan.Reset();
                }
            }
            if (TransInFrame > 0f)
            {
                TransInFrame -= Game1.FrameTime * 3f;
            }

            if (MapScript.IsReading)
                MapScript.DoScript(c);

            if (Bucket != null)
            {
                if (!Bucket.IsEmpty)
                    Bucket.Update(c);
            }

            Frame += Game1.FrameTime;

            if (Fog)
            {
                if ((int)(PFrame * 10f) != (int)(Frame * 10f))
                    pMan.AddParticle(new Fog(Rand.GetRandomVector2(0f, 1280f, 600f, 1000f)));
            }

            for (var i = 0; i < 64; i++)
            {
                if (Segments[LayerMap, i] != null)
                {
                    if (SegmentDefinitions[Segments[LayerMap, i].Index].Flags == (int)SegmentFlags.Torch)
                    {
                        pMan.AddParticle(
                            new Smoke(
                                Segments[LayerMap, i].Location * 2f + new Vector2(20f, 13f),
                                Rand.GetRandomVector2(-50.0f, 50.0f, -300.0f, -200.0f),
                                1.0f, 0.8f, 0.6f, 1.0f,
                                Rand.GetRandomFloat(0.25f, 0.5f), Rand.GetRandomInt(0, 4)
                            ),
                            true
                        );
                        pMan.AddParticle(
                            new Fire(
                                Segments[LayerMap, i].Location * 2f + new Vector2(20f, 37f),
                                Rand.GetRandomVector2(-30.0f, 30.0f, -250.0f, -200.0f),
                                Rand.GetRandomFloat(0.25f, 0.75f),
                                Rand.GetRandomInt(0, 4)
                            ),
                            true
                        );
                    }
                }
            }
        }
Exemplo n.º 15
0
 public override void Update(float gameTime, Map map, ParticleManager pMan, Character[] c)
 {
     HitManager.CheckHit(this, c, pMan);
     KillMe();
 }
Exemplo n.º 16
0
        public void UpdateParticles(float frameTime, Map map, Character[] c)
        {
            for (var i = 0; i < _particles.Length; i++)
            {
                var particle = _particles[i];
                if (particle == null) continue;

                particle.Update(frameTime, map, this, c);
                if (!particle.Exists)
                    _particles[i] = null;
            }
        }
Exemplo n.º 17
0
 public Script(Character character)
 {
     _character = character;
 }
Exemplo n.º 18
0
        public void DoScript(Character[] c)
        {
            if (_waiting > 0f)
            {
                _waiting -= Game1.FrameTime;
            }
            else
            {
                var done = false;
                while (!done)
                {
                    _curLine++;
                    if (Lines[_curLine] != null)
                    {
                        switch (Lines[_curLine].Command)
                        {
                            case MapCommands.Fog:
                                _map.Fog = true;
                                break;
                            case MapCommands.Monster:
                                for (var i = 0; i < c.Length; i++)
                                {
                                    if (c[i] == null)
                                    {
                                        c[i] = new Character(Lines[_curLine].VParam,
                                            Game1.CharDefs[GetMonsterFromString(Lines[_curLine].SParam[1])], i,
                                            Character.TeamBadGuys) { Map = _map };

                                        if (Lines[_curLine].SParam.Length > 4)
                                            c[i].Name = Lines[_curLine].SParam[4];
                                        break;
                                    }
                                }
                                break;
                            case MapCommands.MakeBucket:
                                _map.Bucket = new Bucket(Lines[_curLine].IParam, _map);
                                break;
                            case MapCommands.AddBucket:
                                _map.Bucket.AddItem(Lines[_curLine].VParam, GetMonsterFromString(Lines[_curLine].SParam[1]));
                                break;
                            case MapCommands.IfNotBucketGoto:
                                if (_map.Bucket.IsEmpty) GotoTag(Lines[_curLine].SParam[1]);
                                break;
                            case MapCommands.Wait:
                                _waiting = Lines[_curLine].IParam / 100f;
                                done = true;
                                break;
                            case MapCommands.IfTrueGoto:
                                if (Flags.GetFlag(Lines[_curLine].SParam[1])) GotoTag(Lines[_curLine].SParam[2]);
                                break;
                            case MapCommands.IfFalseGoto:
                                if (!Flags.GetFlag(Lines[_curLine].SParam[1])) GotoTag(Lines[_curLine].SParam[2]);
                                break;
                            case MapCommands.SetGlobalFlag:
                                _map.GlobalFlags.SetFlag(Lines[_curLine].SParam[1]);
                                break;
                            case MapCommands.IfGlobalTrueGoto:
                                if (_map.GlobalFlags.GetFlag(Lines[_curLine].SParam[1]))
                                    GotoTag(Lines[_curLine].SParam[2]);
                                break;
                            case MapCommands.IfGlobalFalseGoto:
                                if (!_map.GlobalFlags.GetFlag(Lines[_curLine].SParam[1]))
                                    GotoTag(Lines[_curLine].SParam[2]);
                                break;
                            case MapCommands.Stop:
                                IsReading = false;
                                done = true;
                                break;
                            case MapCommands.Tag:
                                break;
                            case MapCommands.SetLeftExit:
                                _map.TransitionDestination[(int)TransitionDirection.Left] = Lines[_curLine].SParam[1];
                                break;
                            case MapCommands.SetRightExit:
                                _map.TransitionDestination[(int)TransitionDirection.Right] = Lines[_curLine].SParam[1];
                                break;
                            case MapCommands.SetLeftEntrance:
                                if (_map.TransDir == TransitionDirection.Right)
                                {
                                    c[0].Location = Lines[_curLine].VParam;
                                    c[0].Face = CharDir.Right;
                                    c[0].SetAnim("fly");
                                    c[0].State = CharState.Air;
                                    c[0].Trajectory = new Vector2(200f, 0f);
                                    _map.TransDir = TransitionDirection.None;
                                }
                                break;
                            case MapCommands.SetRightEntrance:
                                if (_map.TransDir == TransitionDirection.Left)
                                {
                                    c[0].Location = Lines[_curLine].VParam;
                                    c[0].Face = CharDir.Left;
                                    c[0].SetAnim("fly");
                                    c[0].State = CharState.Air;
                                    c[0].Trajectory = new Vector2(-200f, 0f);
                                    _map.TransDir = TransitionDirection.None;
                                }
                                break;
                            case MapCommands.SetIntroEntrance:
                                if (_map.TransDir == TransitionDirection.Intro)
                                {
                                    c[0].Location = Lines[_curLine].VParam;
                                    c[0].Face = CharDir.Right;
                                    c[0].SetAnim("fly");
                                    c[0].State = CharState.Air;
                                    c[0].Trajectory = new Vector2(0f, 0f);
                                    _map.TransDir = TransitionDirection.None;
                                }
                                break;
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
 protected bool FaceTarg(Character[] c)
 {
     if (Me.Location.X > c[Targ].Location.X && Me.Face == CharDir.Right)
     {
         Me.KeyLeft = true;
         return true;
     }
     if (Me.Location.X < c[Targ].Location.X && Me.Face == CharDir.Left)
     {
         Me.KeyRight = true;
         return true;
     }
     return false;
 }
Exemplo n.º 20
0
        public void CheckTransitions(Character[] c)
        {
            if (TransOutFrame <= 0f && TransInFrame <= 0f)
            {
                if (c[0].DyingFrame > 0f)
                    return;

                if (c[0].Location.X > XSize * 64f - 32f && c[0].Trajectory.X > 0f)
                {
                    if (TransitionDestination[(int)TransitionDirection.Right] != "")
                    {
                        TransOutFrame = 1f;
                        TransDir = TransitionDirection.Right;
                    }
                }
                if (c[0].Location.X < 64f + 16f && c[0].Trajectory.X < 0f)
                {
                    if (TransitionDestination[(int)TransitionDirection.Left] != "")
                    {
                        TransOutFrame = 1f;
                        TransDir = TransitionDirection.Left;
                    }
                }
            }
        }