private void SeekPlayer(Player player) { Image.IsActive = true; directionToPlayer = player.Image.Position - Image.Position; directionToPlayer.Normalize(); if (directionToPlayer.X > 0) { if (directionToPlayer.X > directionToPlayer.Y) { directionToPlayer.Y = 0; } else { directionToPlayer.X = 0; } } else if (directionToPlayer.X < 0) { if (directionToPlayer.X < directionToPlayer.Y) { directionToPlayer.Y = 0; } else { directionToPlayer.X = 0; } } else if (directionToPlayer.Y > 0) { if (directionToPlayer.Y > directionToPlayer.X) { directionToPlayer.Y = 0; } else { directionToPlayer.X = 0; } } else if (directionToPlayer.Y < 0) { if (directionToPlayer.Y < directionToPlayer.X) { directionToPlayer.Y = 0; } else { directionToPlayer.X = 0; } } Velocity = directionToPlayer; Image.Position += Velocity; UpdateFOV(); }
public void Update(GameTime gameTime, ref Player player) { foreach (Layer l in Layer) { l.Update(gameTime, ref player, ref NPC); } foreach (NPC npc in NPC) { npc.Update(gameTime, ref player); } }
public void Update(GameTime gameTime, ref Player player, ref List<NPC> npcList) { Rectangle tileRect = new Rectangle((int)position.X, (int)position.Y, sourceRect.Width, sourceRect.Height); Rectangle playerRect = new Rectangle((int)player.Image.Position.X, (int)player.Image.Position.Y, player.Image.SourceRect.Width, player.Image.SourceRect.Height); Rectangle npcRect; if (state == "Solid") { if(playerRect.Intersects(tileRect)) { if (player.Velocity.X < 0) player.Image.Position.X = tileRect.Right; else if (player.Velocity.X > 0) player.Image.Position.X = tileRect.Left - player.Image.SourceRect.Width; else if (player.Velocity.Y < 0) player.Image.Position.Y = tileRect.Bottom; else player.Image.Position.Y = tileRect.Top - player.Image.SourceRect.Height; player.Velocity = Vector2.Zero; } foreach (NPC npc in npcList) { npcRect = new Rectangle((int)npc.Image.Position.X, (int)npc.Image.Position.Y, npc.Image.SourceRect.Width, npc.Image.SourceRect.Height); if (npcRect.Intersects(tileRect)) { if (npc.Velocity.X < 0) npc.Image.Position.X = tileRect.Right; else if (npc.Velocity.X > 0) npc.Image.Position.X = tileRect.Left - npc.Image.SourceRect.Width; else if (npc.Velocity.Y < 0) npc.Image.Position.Y = tileRect.Bottom; else if (npc.Velocity.Y > 0) npc.Image.Position.Y = tileRect.Top - npc.Image.SourceRect.Height; npc.Velocity = Vector2.Zero; } } return; } }
public override void LoadContent() { base.LoadContent(); XmlManager<Player> playerLoader = new XmlManager<Player>(); XmlManager<Map> mapLoader = new XmlManager<Map>(); map = mapLoader.Load("Load/Gameplay/Maps/Map1.xml"); player = playerLoader.Load("Load/Gameplay/Player.xml"); player.LoadContent(); map.LoadContent(); font = content.Load<SpriteFont>("Fonts/MorrisRoman"); music = content.Load<Song>("Sound/CitySound"); arrowSound = content.Load<SoundEffect>("Sound/Arrow"); MediaPlayer.Play(music); MediaPlayer.IsRepeating = true; showPlayerInfo = false; }
private bool PlayerInFOV(Player player) { Rectangle playerRect = new Rectangle((int)player.Image.Position.X, (int)player.Image.Position.Y, player.Image.SourceRect.Width, player.Image.SourceRect.Height); return (FOV.Intersects(playerRect)); }
public virtual void Update(GameTime gameTime, ref Player player) { switch (NPCType) { case "Aggressive": //if (!PlayerInFOV(player)) // Wander(gameTime); //else SeekPlayer(player); break; case "Passive": break; default: break; } Image.Update(gameTime); }
public void Update(GameTime gameTime, ref Player player, ref List<NPC> npc) { foreach (Tile tile in underlayTiles) tile.Update(gameTime, ref player, ref npc); foreach (Tile tile in overlayTiles) tile.Update(gameTime, ref player, ref npc); }