//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; } }
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; } }
//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; }
/// <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); } }
//this will load the level in public void load(string levelImg, SpriteBatch spriteBatch, ContentManager Content) { //this will find the map image image = Content.Load <Texture2D>(levelImg); //this will make a colour array MapColours = new Color[image.Width * image.Height]; //get all the data for the image image.GetData <Color>(MapColours); //shift 2 to the right so i lines up the colours correctly int coloumCounter = -2; int rowCounter = 0; //do a foreach loop of all the colours in the colour map foreach (Color colour in MapColours) { //adds one the colour coloumCounter += 1; //this will change rows if (coloumCounter == image.Width - 1) { rowCounter += 1; coloumCounter = -1; } if (colour == new Color(0, 0, 0)) { //this will add a background dungeon Objects background = new BackWallStone(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background = null; } //this will check the colour of the obj and based on it add a wall else if (colour == new Color(255, 94, 139)) { Objects wall = new Wall(); wall.sety(rowCounter * 64); wall.setx(coloumCounter * 64); wall.init(spriteBatch, Content); ObjectsList.addObject(wall); wall = null; } else if (colour == new Color(77, 77, 77)) { Objects torch = new Torch(); torch.sety(rowCounter * 64); torch.setx(coloumCounter * 64); torch.init(spriteBatch, Content); ObjectsList.addObject(torch); ObjectsList.addLight(torch); torch = null; //this will add a background dungeon Objects background = new BackWallStone(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background = null; } //this will check the colour of the obj and based on it add a player else if (colour == new Color(94, 94, 255)) { Objects player = new Player(); ObjectsList.addLight(player); player.sety(rowCounter * 64); player.setx(coloumCounter * 64); player.init(spriteBatch, Content); ObjectsList.addObject(player); player = null; //this will add a background dungeon Objects background = new BackWallStone(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background = null; } //this will check the colour of the obj and based on it add a demon else if (colour == new Color(140, 0, 0)) { Objects demon = new Demon(); demon.sety(rowCounter * 64); demon.setx(coloumCounter * 64); demon.init(spriteBatch, Content); ObjectsList.addObject(demon); demon = null; //this will add a background dungeon Objects background = new BackWallStone(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background = null; } //this will check the colour of the obj and based on it add a bloodFountain else if (colour == new Color(127, 255, 197)) { Objects bloodFountain = new BloodFountianSmall(); bloodFountain.sety(rowCounter * 64); bloodFountain.setx(coloumCounter * 64); bloodFountain.init(spriteBatch, Content); ObjectsList.addObject(bloodFountain); //do this to save memory bloodFountain = null; //this will add a background dungeon Objects background = new BackWallStone(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background = null; } //this will check the colour of the obj and based on it add a bloodfountain else if (colour == new Color(255, 255, 255)) { Objects bloodFountain = new BloodFountianBig(); bloodFountain.sety(rowCounter * 64); bloodFountain.setx(coloumCounter * 64); bloodFountain.init(spriteBatch, Content); ObjectsList.addObject(bloodFountain); bloodFountain = null; //this will add a background dungeon Objects background = new BackWallStone(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background = null; } //this will check the colour of the obj and based on it add a wall dark else if (colour == new Color(44, 44, 44)) { Objects wall = new Wall(); wall.sety(rowCounter * 64); wall.setx(coloumCounter * 64); wall.init(spriteBatch, Content); wall.image = Images.darkWall; ObjectsList.addObject(wall); wall = null; } else if (colour == new Color(6, 12, 33)) //this will check the colour of the obj and based on it add a wall blood { Objects wall = new Wall(); wall.sety(rowCounter * 64); wall.setx(coloumCounter * 64); wall.init(spriteBatch, Content); wall.image = Images.stoneWall; ObjectsList.addObject(wall); wall = null; } //this will be for the blob enemy else if (colour == new Color(126, 32, 44)) { Objects blob = new Blob(); blob.sety(rowCounter * 64); blob.setx(coloumCounter * 64); blob.init(spriteBatch, Content); ObjectsList.addObject(blob); blob = null; //this will add a background dungeon Objects background = new BackWallStone(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background = null; } //this will be used for water else if (colour == new Color(0, 38, 255)) { Objects background = new Backgrounds(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background.weather = 2; background = null; } //this is rain else if (colour == new Color(64, 64, 64)) { Objects background = new Backgrounds(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background.weather = 0; background = null; } //this will be used for snow else if (colour == new Color(128, 128, 128)) { Objects background = new Backgrounds(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background.weather = 1; background = null; } //this will be used for the night sky else if (colour == new Color(0, 255, 255)) { Objects background = new Backgrounds(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background.weather = 3; background = null; } //this will be used for the night stars else if (colour == new Color(244, 244, 244)) { Objects background = new Backgrounds(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background.weather = 4; background = null; } //this will be used to spawn player with water background else if (colour == new Color(81, 38, 255)) { Objects background = new Backgrounds(); background.sety(rowCounter * 64); background.setx(coloumCounter * 64); background.init(spriteBatch, Content); ObjectsList.addObject(background); background.weather = 2; background = null; Objects player = new Player(); ObjectsList.addLight(player); player.sety(rowCounter * 64); player.setx(coloumCounter * 64); player.init(spriteBatch, Content); ObjectsList.addObject(player); player = null; } } }