private void Collider2D_Tick(object sender, EventArgs e) { //Bricks collider if (GameData.gameInitiated) { int xAxis = 10; int yAxis = 4; for (int j = yAxis - 1; j >= 0; j--) { for (int i = 0; i < xAxis; i++) { if (bricksMatrix[i, j] != null) { if (mario.Bounds.IntersectsWith(bricksMatrix[i, j].Bounds)) { bricksMatrix[i, j].hits--; if (bricksMatrix[i, j].hits == 1) { bricksMatrix[i, j].BackgroundImage = Image.FromFile("../../Resources/Bricks/brokenBrick.png"); player.score = Convert.ToString($"Score: {Convert.ToInt32(player.score.Substring(6)) + 100}"); } else { Controls.Remove(bricksMatrix[i, j]); bricksMatrix[i, j] = null; player.score = Convert.ToString($"Score: {Convert.ToInt32(player.score.Substring(6)) + 100}"); number_of_bricks--; if (number_of_bricks == 0) { StaticAttributes.finished = true; var NewScore = (Convert.ToInt32(player.time.Substring(5)) + Convert.ToInt32(player.score.Substring(6))) * (Convert.ToInt32(player.lives.Substring(1)) + 1); if (!StaticAttributes.nicknameRepeated) { ControllerPlayer.AddNickname(player.nickname); } ControllerPlayer.AddScore(player.nickname, NewScore); Congratulations congratulations = new Congratulations(player); congratulations.Show(); Hide(); } } GameData.dirY *= -1; return; } } } } } }
private void clockTimer_Tick(object sender, EventArgs e) { //if the star has been acquired if (Star.time != 0) { Star.time--; //When the star runs out if (Star.time == 0) { if (GameData.dirX > 0) { GameData.dirX = 3; } else { GameData.dirX = -3; } if (GameData.dirY > 0) { GameData.dirY = 4; } else { GameData.dirY = -4; } music.PlayLooping(); Star.loseStar = true; } } //When the time has been Initiated if (StaticAttributes.timer) { player.time = Convert.ToString($"Time: {Convert.ToInt32(lblClockTimer.Text.Substring(5)) - 1}"); lblClockTimer.Text = player.time; lblScore.Text = player.score; lblLives.Text = player.lives; //Time out if (player.time.Equals("Time: 0")) { StaticAttributes.finished = true; if (!StaticAttributes.nicknameRepeated) { ControllerPlayer.AddNickname(player.nickname); } ControllerPlayer.AddScore(player.nickname, 0); GameOver gameOver = new GameOver(); gameOver.Show(); Hide(); } } //When the time has NOT been initiated else { try { if (NotStartedException()) { throw new NotStartedException("Press space to start"); } if (IdlePlayerException()) { throw new IdlePlayerException("IDLE player detected"); } } catch (NotStartedException exc) { MessageBox.Show(exc.Message); } catch (IdlePlayerException exc) { MessageBox.Show(exc.Message); } } }
private void MarioTimer_Tick_1(object sender, EventArgs e) { //movement of mario in timer int thickness = SystemInformation.BorderSize.Width; if (Convert.ToInt32(player.time.Substring(5)) == 700) { Star.starInitiated = true; Controls.Add(star); } if (GameData.gameInitiated) { //Movement of Mario mario.Left += GameData.dirX; mario.Top += GameData.dirY; } if (Star.starInitiated) { star.Left += Star.dirX; star.Top += Star.dirY; } if (mario.Bottom > Height) { int lives = Convert.ToInt16(player.lives.Substring(1)) - 1; if (lives < 0 && !StaticAttributes.finished) { StaticAttributes.finished = true; if (!StaticAttributes.nicknameRepeated) { ControllerPlayer.AddNickname(player.nickname); } ControllerPlayer.AddScore(player.nickname, 0); GameOver gameOver = new GameOver(); gameOver.Show(); Hide(); } else { //restart game if (Star.time != 0) { starMusic.Stop(); Star.time = 1; } if (GameData.gameInitiated) { int marioHeight = (Height - 2 * thickness) * 12 / 100; player.lives = $"x{lives}"; GameData.gameInitiated = false; mario.BackgroundImage = Image.FromFile("../../Resources/MarioSprites/StandingMario.png"); mario.Top = platform.Top - marioHeight; GameData.dirX = 3; GameData.dirY = -4; } } } else if (mario.Top < 0) { //Rebound with top screen GameData.dirY *= -1; } else if (mario.Left < 0 || mario.Right > Width - 2 * thickness) { //Rebound with walls GameData.dirX *= -1; if (GameData.dirX > 0) { if (Star.time != 0) { mario.BackgroundImage = Image.FromFile("../../Resources/MarioSprites/RightJumpingMarioStar.png"); } else { mario.BackgroundImage = Image.FromFile("../../Resources/MarioSprites/RightJumpingMario.png"); } } else { if (Star.time != 0) { mario.BackgroundImage = Image.FromFile("../../Resources/MarioSprites/LeftJumpingMarioStar.png"); } else { mario.BackgroundImage = Image.FromFile("../../Resources/MarioSprites/LeftJumpingMario.png"); } } } else if (mario.Bounds.IntersectsWith(platform.Bounds)) { //Rebound with platform GameData.dirY *= -1; } if (star.Bottom > Height) { star.Dispose(); } else if (star.Top < 0) { Star.dirY *= -1; } else if (star.Left < 0 || star.Right > Width - 2 * thickness) { Star.dirX *= -1; } else if (star.Bounds.IntersectsWith(platform.Bounds)) { Star.dirY *= -1; } if (mario.Bounds.IntersectsWith(star.Bounds) && GameData.gameInitiated && Star.starInitiated) { starMusic.PlayLooping(); Star.time = 60; if (GameData.dirX > 0) { GameData.dirX = 8; mario.BackgroundImage = Image.FromFile("../../Resources/MarioSprites/RightJumpingMarioStar.png"); } else { GameData.dirX = -8; mario.BackgroundImage = Image.FromFile("../../Resources/MarioSprites/LeftJumpingMarioStar.png"); } if (GameData.dirY > 0) { GameData.dirY = 8; } else { GameData.dirY = -8; } star.Dispose(); } if (Star.loseStar) { if (GameData.dirX > 0) { mario.BackgroundImage = Image.FromFile("../../Resources/MarioSprites/RightJumpingMario.png"); } else { mario.BackgroundImage = Image.FromFile("../../Resources/MarioSprites/LeftJumpingMario.png"); } Star.loseStar = false; } }