Ejemplo n.º 1
0
 public BasicWeapon(Mob owner, RangedStats ranged, MeleeStats melee, Texture2D pTexture, Texture2D mTexture, SoundEffect soundEffect)
     : base(owner, ranged, melee, pTexture, mTexture, soundEffect)
 {
 }
Ejemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            oldAnim = currAnim;
            Vector2       vel    = Vector2.Zero;
            KeyboardState currKb = Keyboard.GetState();

            if (!knockBacked)
            {
                //input
                Vector2 dir = Vector2.Zero;
                if (currKb.IsKeyDown(controls.keyUp))
                {
                    dir.Y += 1;
                }
                if (currKb.IsKeyDown(controls.keyDown))
                {
                    dir.Y -= 1;
                }
                if (currKb.IsKeyDown(controls.keyLeft))
                {
                    dir.X -= 1;
                }
                if (currKb.IsKeyDown(controls.keyRight))
                {
                    dir.X += 1;
                }
                vel = new Vector2(dir.X, -dir.Y) * speed;
                if (vel == Vector2.Zero)
                {
                    currAnim = AnimationState.Idle;
                }
                else
                {
                    currAnim = AnimationState.Walking;
                }
                if (currKb.IsKeyDown(controls.keyFireUp))
                {
                    Weapon.FireProjectile(loc, Vector2.Zero, Direction.Up);
                    bodyDirecton = Direction.Up;
                    currAnim     = AnimationState.Firing;
                }
                else if (currKb.IsKeyDown(controls.keyFireDown))
                {
                    Weapon.FireProjectile(loc, Vector2.Zero, Direction.Down);
                    bodyDirecton = Direction.Down;
                    currAnim     = AnimationState.Firing;
                }
                else if (currKb.IsKeyDown(controls.keyFireLeft))
                {
                    Weapon.FireProjectile(loc, Vector2.Zero / 2, Direction.Left);
                    bodyDirecton = Direction.Left;
                    currAnim     = AnimationState.Firing;
                }
                else if (currKb.IsKeyDown(controls.keyFireRight))
                {
                    Weapon.FireProjectile(loc, Vector2.Zero / 2, Direction.Right);
                    bodyDirecton = Direction.Right;
                    currAnim     = AnimationState.Firing;
                }
                if (currKb.IsKeyDown(controls.melee))
                {
                    Mob mob = Game1.GetClosestMonsterAround(this.loc, Weapon.meleeStats.Range);
                    if (mob != null)
                    {
                        //Weapon.FireMelee(loc, dir);
                    }
                }

                //staying in arena
                Vector2   tempLoc = loc + vel * (float)gameTime.ElapsedGameTime.TotalSeconds;
                Rectangle arena   = Game1.Arena_Bounds;

                if (tempLoc.X < arena.X)
                {
                    loc.X = arena.X;
                }
                else if (tempLoc.X + Width > arena.Width + arena.X)
                {
                    loc.X = arena.Width + arena.X - Width;
                }
                else
                {
                    loc.X = tempLoc.X;
                }
                if (tempLoc.Y < arena.Y)
                {
                    loc.Y = arena.Y;
                }
                else if (tempLoc.Y + Height > arena.Height + arena.Y)
                {
                    loc.Y = arena.Height + arena.Y - Height;
                }
                else
                {
                    loc.Y = tempLoc.Y;
                }
            }
            else
            {
                //knockBacked
                Vector2   tempLoc = loc + knockBackDir * (float)gameTime.ElapsedGameTime.TotalSeconds * knockBackSpeed;
                Rectangle arena   = Game1.Arena_Bounds;

                if (tempLoc.X < arena.X)
                {
                    loc.X       = arena.X;
                    knockBacked = false;
                }
                else if (tempLoc.X + Width > arena.Width + arena.X)
                {
                    loc.X       = arena.Width + arena.X - Width;
                    knockBacked = false;
                }
                else
                {
                    loc.X = tempLoc.X;
                }
                if (tempLoc.Y < arena.Y)
                {
                    loc.Y       = arena.Y;
                    knockBacked = false;
                }
                else if (tempLoc.Y + Height > arena.Height + arena.Y)
                {
                    loc.Y       = arena.Height + arena.Y - Height;
                    knockBacked = false;
                }
                else
                {
                    loc.Y = tempLoc.Y;
                }
            }
            oldKb = currKb;
            if (oldAnim != currAnim)
            {
                animTimer = 0;
                switch (currAnim)
                {
                case AnimationState.Firing:
                    switch (bodyDirecton)
                    {
                    case Direction.Up:
                        srcRect = new Rectangle(Width * 2, 0, Width, Height);
                        break;

                    case Direction.Down:
                        srcRect = new Rectangle(0, 0, Width, Height);
                        break;

                    case Direction.Left:
                        srcRect = new Rectangle(Width * 3, 0, Width, Height);
                        break;

                    case Direction.Right:
                        srcRect = new Rectangle(Width, 0, Width, Height);
                        break;
                    }
                    break;

                case AnimationState.Walking:
                    srcRect = new Rectangle(0, Height, Width, Height);
                    break;

                case AnimationState.Idle:
                    srcRect = new Rectangle(0, Height, Width, Height);
                    break;
                }
            }
            base.Update(gameTime);
            if (currAnim == AnimationState.Firing && animTimer >= FIRE_ANIM_DURATION_MS)
            {
                if (vel == Vector2.Zero)
                {
                    currAnim = AnimationState.Idle;
                }
                else
                {
                    currAnim = AnimationState.Walking;
                }
            }
        }
Ejemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            oldAnim = currAnim;
            boostedMobs.Clear();
            float   updateSpeed = tempSpeedInc + speed;
            Vector2 dir         = (player.Location + new Vector2(player.Width / 2, player.Height / 2) - loc - new Vector2(Width / 2, Height / 2));
            float   dist        = dir.Length();

            tempSpeedInc = 0;
            if (!knockBacked)
            {
                dir.Normalize();
                if (dist > STOP_RANGE)
                {
                    Vector2 tempLoc = new Vector2(loc.X + dir.X * updateSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds,
                                                  loc.Y + dir.Y * updateSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
                    Mob mob = Game1.IsSpaceOcupied(this, tempLoc);
                    if (mob == null)
                    {
                        loc += dir * updateSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    else
                    {
                        if (mob.GetType() != typeof(Player))
                        {
                            loc += dir * updateSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;

                            if (!mob.boostedMobs.Contains(this))
                            {
                                mob.AddSpeedForUpdate(speed / 2);
                                this.boostedMobs.Add(mob);
                            }
                        }
                    }
                }
                else if (dist < STOP_RANGE)
                {
                    if (dist > STOP_RANGE)
                    {
                        Vector2 tempLoc = new Vector2(loc.X + dir.X * updateSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds,
                                                      loc.Y + dir.Y * updateSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
                        Mob mob = Game1.IsSpaceOcupied(this, tempLoc);
                        if (mob == null)
                        {
                            loc -= dir * updateSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        }
                        else
                        {
                            if (mob.GetType() != typeof(Player))
                            {
                                loc -= dir * updateSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;

                                if (!mob.boostedMobs.Contains(this))
                                {
                                    mob.AddSpeedForUpdate(speed / 2);
                                    this.boostedMobs.Add(mob);
                                }
                            }
                        }
                    }
                }
                Vector2 vec   = player.Location - loc;
                float   angle = (float)Math.Atan2(vec.Y, vec.X);
                angle  = MathHelper.ToDegrees(angle);
                angle += 180;
                vec.Normalize();
                if (angle >= 0 && angle < 45 || angle > 315 && angle <= 360)
                {
                    bodyDirecton = Direction.Left;
                }
                else if (angle >= 45 && angle < 135)
                {
                    bodyDirecton = Direction.Up;
                }
                else if (angle >= 135 && angle < 225)
                {
                    bodyDirecton = Direction.Right;
                }
                else if (angle >= 225 && angle < 315)
                {
                    bodyDirecton = Direction.Down;
                }
                if (Weapon.canFire)
                {
                    currAnim = AnimationState.Firing;
                    Weapon.FireProjectile(loc, vec, bodyDirecton);
                    animTimer = 0;
                }
            }
            else
            {
                Vector2   tempLoc = loc + knockBackDir * (float)gameTime.ElapsedGameTime.TotalSeconds * knockBackSpeed;
                Rectangle arena   = Game1.Arena_Bounds;

                if (tempLoc.X < arena.X)
                {
                    loc.X       = arena.X;
                    knockBacked = false;
                }
                else if (tempLoc.X + Width > arena.Width + arena.X)
                {
                    loc.X       = arena.Width + arena.X - Width;
                    knockBacked = false;
                }
                else
                {
                    loc.X = tempLoc.X;
                }
                if (tempLoc.Y < arena.Y)
                {
                    loc.Y       = arena.Y;
                    knockBacked = false;
                }
                else if (tempLoc.Y + Height > arena.Height + arena.Y)
                {
                    loc.Y       = arena.Height + arena.Y - Height;
                    knockBacked = false;
                }
                else
                {
                    loc.Y = tempLoc.Y;
                }
            }

            base.Update(gameTime);
            if (currAnim == AnimationState.Firing && animTimer >= FIRE_ANIM_DURATION_MS)
            {
                if (dist > STOP_RANGE)
                {
                    currAnim = AnimationState.Idle;
                }
                else
                {
                    currAnim = AnimationState.Walking;
                }
            }
            if (oldAnim != currAnim)
            {
                animTimer = 0;
                switch (currAnim)
                {
                case AnimationState.Firing:
                    switch (bodyDirecton)
                    {
                    case Direction.Up:
                        srcRect = new Rectangle(Width * 2, 0, Width, Height);
                        break;

                    case Direction.Down:
                        srcRect = new Rectangle(0, 0, Width, Height);
                        break;

                    case Direction.Left:
                        srcRect = new Rectangle(Width * 3, 0, Width, Height);
                        break;

                    case Direction.Right:
                        srcRect = new Rectangle(Width, 0, Width, Height);
                        break;
                    }
                    break;

                case AnimationState.Walking:
                    srcRect = new Rectangle(0, Height, Width, Height);
                    break;

                case AnimationState.Idle:
                    srcRect = new Rectangle(0, Height, Width, Height);
                    break;
                }
            }
        }