protected override void Initialize() { Main.Set_Game_Location(this); location = new LocationHandler(Content, player); Dialogue = new DialogueHandler(); WoodChopper_NPC = new WoodChopper(new Vector2(100, 300)); shop = new ShopKeeper(new Vector2(510, 300), player); enemy = new Enemy(new Vector2(480, 512), player, 3); combatHandler = new CombatHandler(); base.Initialize(); // Main.game.player.Change_Location("Varrock", false); }
public Enemy(Vector2 position, Player play, int MapID) : base(position, "Enemy") { FramesPerSecond = 10; //Adds all the players animations AddAnimation(12, 0, 0, "Down", 50, 50, new Vector2(0, 0)); AddAnimation(1, 0, 0, "IdleDown", 50, 50, new Vector2(0, 0)); AddAnimation(12, 50, 0, "Up", 50, 50, new Vector2(0, 0)); AddAnimation(1, 50, 0, "IdleUp", 50, 50, new Vector2(0, 0)); AddAnimation(8, 100, 0, "Left", 50, 50, new Vector2(0, 0)); AddAnimation(1, 100, 0, "IdleLeft", 50, 50, new Vector2(0, 0)); AddAnimation(8, 100, 8, "Right", 50, 50, new Vector2(0, 0)); AddAnimation(1, 100, 8, "IdleRight", 50, 50, new Vector2(0, 0)); AddAnimation(9, 150, 0, "AttackDown", 70, 80, new Vector2(0, 0)); AddAnimation(9, 230, 0, "AttackUp", 70, 80, new Vector2(-13, -27)); AddAnimation(9, 310, 0, "AttackLeft", 70, 70, new Vector2(-30, -5)); AddAnimation(9, 380, 0, "AttackRight", 70, 70, new Vector2(+15, -5)); //Plays our start animation PlayAnimation("IdleDown"); player = play; HitBox = new Rectangle((int)sPostion.X - 45, (int)sPostion.Y - 45, 90, 90); Map = MapID; combatHandler = Main.game.combatHandler; // }
public override void Update(GameTime gameTime) { if (walkable) { if (!AtX) { if (Path[Path.Length - currentTile].X * 32 == sPostion.X) { AtX = true; currentDir = myDirection.none; } else if (sPostion.X < Path[Path.Length - currentTile].X * 32) { //Move char Right sDirection += new Vector2(1, 0); sPostion += new Vector2(1, 0); PlayAnimation("Right"); currentDir = myDirection.right; HitBox = new Rectangle((int)sPostion.X - 45, (int)sPostion.Y - 45, 90, 90); } else if (sPostion.X > Path[Path.Length - currentTile].X * 32) { sDirection += new Vector2(-1, 0); sPostion += new Vector2(-1, 0); PlayAnimation("Left"); currentDir = myDirection.left; HitBox = new Rectangle((int)sPostion.X - 45, (int)sPostion.Y - 45, 90, 90); } base.Update(gameTime); return; } else if (!AtY) { // Console.WriteLine(sPostion.Y + " " + Path[Path.Length - currentTile].Y * 32); if (Path[Path.Length - currentTile].Y * 32 == sPostion.Y) { AtY = true; currentDir = myDirection.none; } else if (sPostion.Y < Path[Path.Length - currentTile].Y * 32) { //Move char Down sDirection += new Vector2(0, 1); sPostion += new Vector2(0, 1); PlayAnimation("Down"); currentDir = myDirection.down; HitBox = new Rectangle((int)sPostion.X - 45, (int)sPostion.Y - 45, 90, 90); } else if (sPostion.Y > Path[Path.Length - currentTile].Y * 32) { sDirection += new Vector2(0, -1); sPostion += new Vector2(0, -1); PlayAnimation("Up"); currentDir = myDirection.up; HitBox = new Rectangle((int)sPostion.X - 45, (int)sPostion.Y - 45, 90, 90); } base.Update(gameTime); return; } else { if (currentTile < Path_Length) { currentTile += 1; AtX = false; AtY = false; return; } else if (currentTile == Path_Length) { walkable = false; } } } else { if (currentAnimation.Contains("Left")) { PlayAnimation("IdleLeft"); } if (currentAnimation.Contains("Right")) { PlayAnimation("IdleRight"); } if (currentAnimation.Contains("Up")) { PlayAnimation("IdleUp"); } if (currentAnimation.Contains("Down")) { PlayAnimation("IdleDown"); } currentDir = myDirection.none; base.Update(gameTime); } newState = Mouse.GetState(); if (newState.RightButton == ButtonState.Pressed && oldState.RightButton == ButtonState.Released) { if (HitBox.Contains(newState.X, newState.Y)) { Right_Click = true; RightClick_Menu = new Rectangle(newState.X - 30, newState.Y, 100, 60); } } if (Right_Click) { if (new Rectangle(RightClick_Menu.X, RightClick_Menu.Y - 10, 75, 75).Contains(newState.X, newState.Y)) { Main.game.spriteBatch.Draw(Main.game.chat.Chat_Log_Texture, RightClick_Menu, Color.White); Rectangle rect1 = new Rectangle(RightClick_Menu.X, RightClick_Menu.Y + 0, 75, 20); Rectangle rect2 = new Rectangle(RightClick_Menu.X, RightClick_Menu.Y + 25, 75, 20); Main.game.spriteBatch.DrawString(Main.game.chat.Font, "Attack", new Vector2(rect1.X, rect1.Y), Color.White); if (rect1.Contains(newState.X, newState.Y)) { Main.game.spriteBatch.DrawString(Main.game.chat.Font, "Attack", new Vector2(rect1.X, rect1.Y), Color.Blue); newState = Mouse.GetState(); if (newState.LeftButton == ButtonState.Pressed && oldState.LeftButton == ButtonState.Released) { combatHandler = Main.game.combatHandler; combatHandler.Setup_Combat(this); isAttacking = true; Right_Click = false; } } Main.game.spriteBatch.DrawString(Main.game.chat.Font, "Cancel", new Vector2(rect2.X, rect2.Y), Color.White); if (rect2.Contains(newState.X, newState.Y)) { Main.game.spriteBatch.DrawString(Main.game.chat.Font, "Cancel", new Vector2(rect2.X, rect2.Y), Color.Blue); newState = Mouse.GetState(); if (newState.LeftButton == ButtonState.Pressed && oldState.LeftButton == ButtonState.Released) { Right_Click = false; } } } else { Right_Click = false; } } oldState = newState; // this reassigns the old state so that it is ready for next time }