public void Update(Player player) { old_position = position; int r = rand.Next(0, 2); int r2; if (r == 0) { r2 = player.position.X - position.X; bool is_straight_line = false; if (r2 == 0) is_straight_line = true; r2 = Math.Sign(r2); if (!grid.IsGridSpotFull(position.X + r2, position.Y) && !is_straight_line) position.X += r2; else if (!grid.IsGridSpotFull(position.X, position.Y + r2)) position.Y += r2; } else { r2 = player.position.Y - position.Y; bool is_straight_line = false; if (r2 == 0) is_straight_line = true; r2 = Math.Sign(r2); if (!grid.IsGridSpotFull(position.X, position.Y + r2) && !is_straight_line) position.Y += r2; else if (!grid.IsGridSpotFull(position.X + r2, position.Y)) position.X += r2; } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here grid = new Grid(); inventory = new Inventory(); player = new Player(grid, inventory); // Whew, avoided circular dependencies! inventory.SetPlayer(player); Creature.grid_position wand_pos = new Creature.grid_position(); wand_pos.X = 8; wand_pos.Y = 8; wand = new TeleportWand(grid, wand_pos, player); //creature = new Creature(grid); wall = new Wall(grid); room_gen = new RoomGen(); room_gen.Initialize(); base.Initialize(); }