Пример #1
0
        public void Update(Viking viking, GameTime time, int modifySpeed)
        {
            if (bloodspatters.Count > 0)
            {
                drawblood = 1;
                for (int b = 0; b < bloodspatters.Count; b++)
                {
                    bloodspatters[b].Update(time, modifySpeed);
                    if (!bloodspatters[b].Active)
                    {
                        bloodspatters.RemoveAt(b);
                    }
                }
            }
            else
            {
                drawblood = 0;
            }

            if (!Dead)
            {
                currenthealth.Width = (int)(0.5 * health);

                if (hit)
                {
                    hittimer -= (float)time.ElapsedGameTime.TotalMilliseconds;

                    if (hittimer < 0)
                    {
                        this.hit      = false;
                        this.hittimer = 50f;
                    }
                }

                if (attacking)
                {
                    if (hitting)
                    {
                        bodyPos.X      -= modifySpeed;
                        attackRotation += MathHelper.ToRadians(25);

                        if (!(bodyPos.X - viking.Position.X < 150 && bodyPos.X - viking.Position.X > -120))
                        {
                            this.hitting   = false;
                            attackRotation = 0;
                        }
                    }
                    else
                    {
                        if (bodyPos.X - viking.Position.X < 150 && bodyPos.X - viking.Position.X > -120)
                        {
                            bodyPos.X   -= modifySpeed;
                            this.hitting = true;
                        }
                        else
                        {
                            if (bodyPos.X > viking.Position.X)
                            {
                                bodyPos.X     -= (int)(enemyMoveSpeed * time.ElapsedGameTime.TotalSeconds) + modifySpeed;
                                enemyDirection = false;
                            }
                            else
                            {
                                bodyPos.X     += (int)(enemyMoveSpeed * time.ElapsedGameTime.TotalSeconds) - modifySpeed;
                                enemyDirection = true;
                            }
                        }
                    }
                }
                else
                {
                    bodyPos.X -= modifySpeed;
                    if (bodyPos.X < 2000)
                    {
                        attacking = true;
                    }
                }
                currenthealth.X = bodyPos.X + 60;
                fullhealth.X    = bodyPos.X + 60;


                bullets = viking.getBullets();

                for (int i = 0; i < bullets.Count; i++)
                {
                    if (bullets[i].Position.Intersects(bodyPos) || bullets[i].Position.Intersects(leftLegPos) || bullets[i].Position.Intersects(rightLegPos))
                    {
                        if (bullets[i].Position.Intersects(leftLegPos) || bullets[i].Position.Intersects(rightLegPos))
                        {
                            if (!this.jumping)
                            {
                                this.falling = false;
                                this.jumping = true;
                            }
                        }

                        this.health -= bullets[i].Damage;

                        angle = bullets[i].angle;

                        addSpatter(bullets[i].Position);

                        bullets[i].Active = false;

                        if (!hit)
                        {
                            hit = true;
                        }

                        if (enemyDirection)
                        {
                            bodyPos.X -= 5;
                        }
                        else
                        {
                            bodyPos.X += 5;
                        }
                    }
                }
            }

            if (this.health <= 0)
            {
                this.Dead = true;
            }
            if (Dead && drawblood == 0)
            {
                this.Active = false;
            }

            //Positions for other bodyparts
            leftArmPos  = new Rectangle(bodyPos.X + 136, bodyPos.Y + 80, 59, 148);
            rightArmPos = new Rectangle(bodyPos.X + 34, bodyPos.Y + 80, 51, 150);
            leftLegPos  = new Rectangle(bodyPos.X + 115, bodyPos.Y + 160, 104, 157);
            rightLegPos = new Rectangle(bodyPos.X + 55, bodyPos.Y + 170, 116, 158);


            //Arm rotation
            if (!rot1)
            {
                Rotation = Rotation + MathHelper.ToRadians(4);
                if (MathHelper.ToDegrees(Rotation) >= 45)
                {
                    rot1 = true;
                }
            }
            else if (rot1)
            {
                Rotation = Rotation - MathHelper.ToRadians(4);
                if (MathHelper.ToDegrees(Rotation) <= -45)
                {
                    rot1 = false;
                }
            }

            if (rot2)
            {
                Rotation2 = Rotation2 + MathHelper.ToRadians(4);
                if (MathHelper.ToDegrees(Rotation2) >= 45)
                {
                    rot2 = false;
                }
            }
            else if (!rot2)
            {
                Rotation2 = Rotation2 - MathHelper.ToRadians(4);
                if (MathHelper.ToDegrees(Rotation2) <= -45)
                {
                    rot2 = true;
                }
            }


            if (jumping && bodyPos.Y > 517 && !falling)
            {
                if (bodyPos.Y > groundLevel - 150)
                {
                    bodyPos.Y -= 10;
                }
                else if (bodyPos.Y > groundLevel - 200 && bodyPos.Y <= groundLevel - 150)
                {
                    bodyPos.Y -= 6;
                }
            }
            else if (bodyPos.Y < groundLevel)
            {
                falling = true;
                if (bodyPos.Y < groundLevel - 100)
                {
                    bodyPos.Y += 6;
                }
                else if (bodyPos.Y > groundLevel - 100 && bodyPos.Y < groundLevel)
                {
                    bodyPos.Y += 9;
                }
            }
            else
            {
                jumping = false;
            }
        }