示例#1
0
        //runs every time update is called in the main program
        //this will handle any changes to the obj
        public override void update()
        {
            //resets the x and the y
            rect.X = x;
            rect.Y = y;
            //checks if the player is dead
            if (health < 1)
            {
                kill = true;
            }
            //knocks back the enemy
            if (this.knockBack == true)
            {
                ObjectsList.knockBack(this);
            }

            //checks if the player is the same x as enemy and if so do nothing

            if (ObjectsList.playerx == x)
            {
                ;
            }
            //checks if its greater and if so try to go right
            else if (ObjectsList.playerx > x)
            {
                //checks if i am going to hit a wall and if i dont move
                rect.X += 2;
                if (!ObjectsList.collision(this))
                {
                    x += 2;
                }
                rect.X -= 2;
            }
            //trys to go left
            else
            {
                //checks if I would hit a wall
                rect.X -= 2;
                if (!ObjectsList.collision(this))
                {
                    x -= 2;
                }
                rect.X += 2;
            }
            //trys to move up or down and if i hit a wall change dirrects

            rect.Y += (int)slope;
            if (!ObjectsList.collision(this))
            {
                y += (int)slope;
            }
            else
            {
                slope *= -1;
            }
        }
示例#2
0
 public override void update()
 {
     //adds the x
     this.x += movementx;
     //this will find the new y
     this.y      = (double)(((((double)slope) / ((double)xdir))) * (this.x - this.startX) + this.yInt);
     this.rect.Y = (int)y;
     this.rect.X = (int)x;
     //this will kill the bullet after being in the air for so long
     if (x - startX > 1000 || x - startX < -1000)
     {
         this.kill = true;
     }
     //if it collides kill it
     if (ObjectsList.collision(this))
     {
         this.kill = true;
     }
 }
示例#3
0
        //this will be called every frame do things that i want to run every time
        public override void update()
        {
            //this refreshs the rect for the hit boxs
            rect.X = x;
            rect.Y = y;
            //this will be used for enemys so they know where the player is
            ObjectsList.playerx = x;
            ObjectsList.playery = y;
            //this will check if the player is dead
            if (health <= 0)
            {
                ;
                //do death screen here
            }
            //this will be used for
            walkingTimer++;
            //This will display the first frame
            if (walkingTimer < 15)
            {
                walkAnimation = 0;
                //display the second frame
            }
            else
            {
                walkAnimation = 1;
                //resets the walk timer
                if (walkingTimer >= 30)
                {
                    walkingTimer = 0;
                }
            }
            //this will check if the button is getting pressed
            if (LarrysAngelWarfare.mouseState.LeftButton == ButtonState.Pressed)
            {
                //this will add one to the CD timer
                gunTimer++;
                //this will checks if it can run
                if (gunTimer == gunSpeed)
                {
                    //resets the gun timer
                    gunTimer = 0;
                    //creates a new bullet
                    Objects bullet = new Bullets();
                    //sets the x and why of the bullet based on your x and y
                    bullet.setx(x + 32);
                    bullet.sety(y + 16);
                    //finding if the bullet should go left or right
                    if (x - moveScreenX - LarrysAngelWarfare.mouseState.X > 0)
                    {
                        bullet.moveX = -1;
                    }
                    else
                    {
                        bullet.moveX = 1;
                    }
                    //finds the x direction (the run of the slope)
                    bullet.xdir = (x - moveScreenX - LarrysAngelWarfare.mouseState.X);

                    //finds the rise of the slope
                    bullet.slope = (y - moveScreenY - LarrysAngelWarfare.mouseState.Y);


                    //this will init the bullet making
                    bullet.init(this.spriteBatch, this.Content);
                    //this will add the bullet to the obj list
                    ObjectsList.addBullet(bullet);
                    //dels the old bullet obj
                    bullet = null;
                }
            }



            //this will move the plaeyer right
            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                //this will check if the player can move up
                rect.Y -= 8;
                //this will change the animation side for example this will show the right frame
                walkAnimationSide = 0;
                //this will check if i collide with the wall
                if (!ObjectsList.collision(this))
                {
                    //if i dont i move the player

                    if (screenY >= -192 + 16)
                    {
                        screenY -= 8;
                    }
                    else
                    {
                        moveScreenY -= 8;
                    }

                    y -= 8;
                }
                //move back the rect
                rect.Y += 8;
            }
            //checks if the player can move down
            if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                //change the animation
                walkAnimationSide = 0;
                //moves the rect obj
                rect.Y += 8;

                if (!ObjectsList.collision(this))
                {
                    if (screenY <= 192)
                    {
                        screenY += 8;
                    }
                    else
                    {
                        moveScreenY += 8;
                    }
                    y += 8;
                }
                rect.Y -= 8;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                walkAnimationSide = 2;
                rect.X           -= 8;
                if (!ObjectsList.collision(this))
                {
                    if (screenX >= 200)
                    {
                        screenX -= 8;
                    }
                    else
                    {
                        moveScreenX -= 8;
                    }
                    x -= 8;
                }
                rect.X += 8;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                walkAnimationSide = 1;
                rect.X           += 8;
                if (!ObjectsList.collision(this))
                {
                    //this is used to move the screen when the player moves in a box
                    if (screenX <= 300)
                    {
                        screenX += 8;
                    }
                    else
                    {
                        moveScreenX += 8;
                    }
                    x += 8;
                }
            }
            rect.X -= 8;
        }
示例#4
0
 /// <summary>
 /// this will be called for ever tick
 /// </summary>
 public override void update()
 {
     //resets the x and y
     rect.X = x;
     rect.Y = y;
     //add one to the walktimer
     walkingTimer++;
     //this will find what sprite they are on
     if (walkingTimer < 15)
     {
         walkAnimation = 0;
     }
     else
     {
         walkAnimation = 1;
         if (walkingTimer >= 30)
         {
             walkingTimer = 0;
         }
     }
     //this will only move if its near the player
     if (x - 600 < ObjectsList.playerx && x + 600 > ObjectsList.playerx && y - 300 < ObjectsList.playerx && y + 300 > ObjectsList.playery)
     {
         if (x != ObjectsList.playerx)
         {
             if (x > ObjectsList.playerx)
             {
                 // this will move the rect and see if the can move
                 rect.X           -= 8;
                 walkAnimationSide = 2;
                 if (!ObjectsList.collision(this))
                 {
                     x -= 8;
                 }
                 rect.X += 8;
             }
             else
             {// this will move the rect and see if the can move
                 rect.X           += 8;
                 walkAnimationSide = 1;
                 if (!ObjectsList.collision(this))
                 {
                     x += 8;
                 }
                 rect.X -= 8;
             }
         }// this will move the rect and see if the can move
     }
     if (y != ObjectsList.playery)
     {
         if (y < ObjectsList.playery)
         {
             walkAnimationSide = 0;
             rect.Y           += 8;
             if (!ObjectsList.collision(this))
             {
                 y += 8;
             }
             rect.Y -= 8;
         }// this will move the rect and see if the can move
         else
         {
             rect.Y           -= 8;
             walkAnimationSide = 0;
             if (!ObjectsList.collision(this))
             {
                 y -= 8;
             }
             rect.Y += 8;
         }
     }
     if (health < 1)
     {
         //this will check if they are dead and if kill them if they are dead
         this.kill = true;
     }
     //do knock back if its true
     if (this.knockBack == true)
     {
         ObjectsList.knockBack(this);
     }
 }