public MoveableObject(Region region, ProChar symbol, string objectType, string[] obstacles) { this.region = region; this.Symbol = symbol; this.objectType = objectType; this.obstacle = obstacles; standingTile = new Tile( Char.Parse(region.mapConfig[0, 4]), region.mapConfig[0, 7], symbol.X, symbol.Y, (ConsoleColor)Enum.Parse(typeof(ConsoleColor), ((region.mapConfig[0, 5] == "None") ? region.ForeColor.ToString() : region.mapConfig[0, 5])), (ConsoleColor)Enum.Parse(typeof(ConsoleColor), ((region.mapConfig[0, 6] == "None") ? region.BackColor.ToString() : region.mapConfig[0, 7]))); oldStandingTile = Region.GetTile((Tile)standingTile); }
public virtual void LoadMap() { string path = Environment.CurrentDirectory; path += @"\Resources\" + mapPath; Bitmap loadedMap = (Bitmap)Bitmap.FromFile(path); Color pixel; this.width = loadedMap.Width; this.height = loadedMap.Height; map = new GameObject[Width, Height]; ProChar[,] tScreen = new ProChar[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < Height; y++) { for (int i = 0; i <= mapConfig.GetUpperBound(0); i++) { pixel = loadedMap.GetPixel(x, y); if (pixel == Color.FromArgb( Int32.Parse(mapConfig[i, 1]), /* RED */ Int32.Parse(mapConfig[i, 2]), /* GREEN */ Int32.Parse(mapConfig[i, 3]))) /* BLUE */ { map[x, y] = new Tile(Char.Parse(mapConfig[i, 4]), mapConfig[i, 7], x, y, (ConsoleColor)Enum.Parse(typeof(ConsoleColor), ((mapConfig[i, 5] == "None") ? ForeColor.ToString() : mapConfig[i, 5])), (ConsoleColor)Enum.Parse(typeof(ConsoleColor), ((mapConfig[i, 6] == "None") ? BackColor.ToString() : mapConfig[i, 6]))); } else if (i == mapConfig.Length / 7 - 1 && map[x, y] == null) { map[x, y] = new Tile('?', "Air", x, y, ConsoleColor.Black, ConsoleColor.White); } } tScreen[x, y] = map[x, y].Symbol; } } screen.Set(tScreen); }
static bool projectile_CollisionAction(MoveableObject sender, CollisionEventArgs e) { bool allow = true; try { if (e.CollidingObject.Name.StartsWith("MO_Enemy")) { int index = Int32.Parse(e.CollidingObject.Name.Split('y')[1]); e.CollidingObject.ChangeBackColor(ProChar.GetInvertedColor(e.CollidingObject.Symbol.ForeColor)); e.CollidingObject.ChangeBackColor(ProChar.GetInvertedColor(e.CollidingObject.Symbol.BackColor)); region.SetDrawObject(((MoveableObject)e.CollidingObject).StandingTile); nonfixObject[index].Name = ""; allow = false; } } catch { return(allow); } return(allow); }
static bool Enemy_CollisionAction(MoveableObject sender, CollisionEventArgs e) { bool allow = true; if (e.CollidingObject.ObjectType == "Player") { if (health > 1) { health--; UpdateHealth(); } else { health--; Alive = false; UpdateHealth(); int width = 13, height = 5; int x = region.Width / 2 - width, y = (region.Height / 2 - height / 2) - 5; Window gameOver = new Window(screen, x, y, width, height, "Game", "YOU LOOSE", ConsoleColor.White, ConsoleColor.Black, ConsoleColor.Yellow, ConsoleColor.Red); gameOver.Show(); Console.ReadKey(true); } allow = false; } else if (e.CollidingObject.ObjectType == "projectile") { MoveableObject currentEnemy = sender as MoveableObject; int index = Int32.Parse(currentEnemy.Name.Split('y')[1]); currentEnemy.ChangeBackColor(ProChar.GetInvertedColor(e.CollidingObject.Symbol.ForeColor)); currentEnemy.ChangeBackColor(ProChar.GetInvertedColor(e.CollidingObject.Symbol.BackColor)); region.SetDrawObject(currentEnemy.StandingTile); nonfixObject[index].Name = ""; allow = false; } return(allow); }