public void OnStart() { Hero hero1 = new Hero(Hero.x, Hero.y, heroSize); StartRoom(); }
private void gameTimer_Tick(object sender, EventArgs e) { Rectangle heroRec = new Rectangle(Hero.x, Hero.y, heroSize, heroSize); Rectangle enemyRec = new Rectangle(Enemy.x, Enemy.y, heroSize, heroSize); Rectangle enemyRec2 = new Rectangle(Enemy.x2, Enemy.y2, heroSize, heroSize); Rectangle objectiveRec = new Rectangle(600, 600, 20, 20); Hero.Move(heroSpeed, wKeyDown, sKeyDown, aKeyDown, dKeyDown); counter++; if (heroRec.IntersectsWith(enemyRec) || heroRec.IntersectsWith(enemyRec2)) { if (counter > 50) { playerHealth--; healthLabel.Text = $"{playerHealth}"; counter = 0; } } if (playerHealth == 0) { gameTimer.Stop(); lossLabel.Visible = true; } if (enemyList.Count == 0) { Rectangle arrowRec = new Rectangle(900, 500, 30, 30); Rectangle arrowRec2 = new Rectangle(100, 500, 30, 30); Rectangle arrowRec3 = new Rectangle(550, 100, 30, 30); Rectangle arrowRec4 = new Rectangle(550, 900, 30, 30); if (heroRec.IntersectsWith(arrowRec) && enemyList.Count == 0) { if (room == 0) { //set new room and reset character position room = 1; Hero.x = 600; Hero.y = 100; //spawns new enemies Enemy enemy1 = new Enemy(Enemy.x, Enemy.y, heroSize); Enemy enemy2 = new Enemy(Enemy.x2, Enemy.y2, heroSize); enemyList.Add(enemy1); enemyList.Add(enemy2); Enemy.x = 400; Enemy.y = 800; Enemy.x2 = 200; Enemy.y2 = 700; } else if (room == 1) { //set new room and reset character position room = 2; Hero.x = 600; Hero.y = 100; //spawns new enemies Enemy enemy1 = new Enemy(Enemy.x, Enemy.y, heroSize); Enemy enemy2 = new Enemy(Enemy.x2, Enemy.y2, heroSize); Enemy enemy3 = new Enemy(Enemy.x3, Enemy.y3, heroSize); enemyList.Add(enemy1); enemyList.Add(enemy2); enemyList.Add(enemy3); Enemy.x = 200; Enemy.y = 400; Enemy.x2 = 900; Enemy.y2 = 700; Enemy.x3 = 500; Enemy.y3 = 600; } else if (room == 2) { //set new room and reset character position room = 3; Hero.x = 600; Hero.y = 100; //spawns new enemies Enemy enemy1 = new Enemy(Enemy.x, Enemy.y, heroSize); Enemy enemy2 = new Enemy(Enemy.x2, Enemy.y2, heroSize); enemyList.Add(enemy1); enemyList.Add(enemy2); Enemy.x = 300; Enemy.y = 500; Enemy.x2 = 800; Enemy.y2 = 600; } } if (heroRec.IntersectsWith(arrowRec2) && enemyList.Count == 0 && room < 0) { if (room == 1) { //set new room and reset character position room = 0; Hero.x = 850; Hero.y = 500; } if (room == 2) { //set new room and reset character position room = 1; Hero.x = 850; Hero.y = 500; } if (room == 3) { //set new room and reset character position room = 2; Hero.x = 850; Hero.y = 500; } } if (heroRec.IntersectsWith(arrowRec3) && enemyList.Count == 0 && room == 2) { room = 4; //set new room and reset character position room = 3; Hero.x = 600; Hero.y = 100; Enemy enemy1 = new Enemy(Enemy.x, Enemy.y, heroSize); Enemy enemy2 = new Enemy(Enemy.x2, Enemy.y2, heroSize); enemyList.Add(enemy1); enemyList.Add(enemy2); Enemy.x = 600; Enemy.y = 600; Enemy.x2 = 700; Enemy.y2 = 600; } if (heroRec.IntersectsWith(arrowRec4) && enemyList.Count == 0 && room == 4) { room = 2; //set new room and reset character position room = 3; Hero.x = 600; Hero.y = 100; } } if (heroRec.IntersectsWith(objectiveRec) && enemyList.Count == 0) { gameTimer.Stop(); winLabel.Visible = true; } if (spaceKeyDown == true) { if (Form1.wildWestMode == true) { Bullet bullet1 = new Bullet(Bullet.bulletX, Bullet.bulletY, bulletSize); bulletList.Add(bullet1); Bullet.WildWestShoot(bulletSpeed); } //else if (Form1.futureMode == true) //{ // Bullet.FutureShoot(); //} //else if (Form1.pirateMode == true) //{ // Bullet.PirateShoot(); //} } if (Bullet.bulletMoveUp == true) { Bullet.bulletY = Bullet.bulletY - bulletSpeed; } else if (Bullet.bulletMoveUp == false) { Bullet.bulletY = Bullet.bulletY + bulletSpeed; } else if (Bullet.bulletMoveRight == true) { Bullet.bulletX = Bullet.bulletX + bulletSpeed; } else if (Bullet.bulletMoveRight == false) { Bullet.bulletX = Bullet.bulletX - bulletSpeed; } Refresh(); }