public EnemySpawner(GameWindow gameWindow, EnemyPicture enemyPicture) { this.gameWindow = gameWindow ?? throw new ArgumentNullException(nameof(gameWindow)); this.enemyPicture = enemyPicture ?? throw new ArgumentNullException(nameof(enemyPicture)); gameWindow.masterTimer.Tick += (sender, e) => SpawnEnemyEvent(); }
private void SpawnEnemyEvent() { if (spawnCounter > 10) { int spawnSide = gameWindow.RandomNumber; if (spawnSide == 0) { SpawnPoint = new Point(1, gameWindow.RandomCoordinateNumber * 50); var newEnemy = new EnemyPicture(gameWindow); gameWindow.Controls.Add(newEnemy); listOfEnemies.Add(newEnemy); listOfEnemiesMovingRight.Add(newEnemy); spawnCounter = 0; } else if (spawnSide == 1) { SpawnPoint = new Point(gameWindow.RandomCoordinateNumber * 50, 1); var newEnemy = new EnemyPicture(gameWindow); gameWindow.Controls.Add(newEnemy); listOfEnemies.Add(newEnemy); listOfEnemiesMovingDown.Add(newEnemy); spawnCounter = 0; } else if (spawnSide == 2) { SpawnPoint = new Point(899, gameWindow.RandomCoordinateNumber * 50); var newEnemy = new EnemyPicture(gameWindow); gameWindow.Controls.Add(newEnemy); listOfEnemies.Add(newEnemy); listOfEnemiesMovingLeft.Add(newEnemy); spawnCounter = 0; } } else { spawnCounter++; } }
public GameWindow() { InitializeComponent(); var enemy = new Enemy(this); var player = new Player(); var gold = new Gold(this); var goldSpawner = new GoldSpawner(this, gold); this.MaximumSize = new Size(900, 900); masterTimer.Interval = 1; masterTimer.Enabled = true; var playerSprite = new PlayerSprite(); Controls.Add(playerSprite); var PlayerController = new PlayerContoller(this, playerSprite); var enemyPicture = new EnemyPicture(this); var enemySpawner = new EnemySpawner(this, enemyPicture); var enemyController = new EnemyController(this); masterTimer.Tick += (sender, e) => SetRandomNumberEveryTick(); masterTimer.Tick += (sender, e) => CheckIfGameShouldRun(); }