//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; } }
/// <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); } }