private void DrawMap(PaintEventArgs e) { if (!game.IsGameFinished && animationCycles <= 39) { e.Graphics.DrawImage(mapImage, coordinates.X, coordinates.Y, game.MapImage.Width, game.MapImage.Height); if (!pauseGame) { animationCycles++; } if (animationCycles % 10 == 0) { mapImage = GameMethods.GetImageByName($"{animationCycles / 10}_"); } } else if (game.IsGameFinished && animationCycles > -1) { if (animationCycles > 0 && !pauseGame) { animationCycles--; } if (animationCycles % 10 == 9) { mapImage = GameMethods.GetImageByName($"{animationCycles / 10}_"); } e.Graphics.DrawImage(mapImage, coordinates.X, coordinates.Y, game.MapImage.Width, game.MapImage.Height); } else { e.Graphics.DrawImage(game.MapImage, coordinates.X, coordinates.Y, game.MapImage.Width, game.MapImage.Height); } }
private void PausePress() { pauseGame = !pauseGame; if (pauseGame) { pauseButton.Image = GameMethods.GetImageByName("PAUSE_PRESSED_ACTIVE"); } else { pauseButton.Image = GameMethods.GetImageByName("PAUSE"); } menuButton.Enabled = !menuButton.Enabled; menuButton.Visible = !menuButton.Visible; }
private void OnFrameChanged(object sender, EventArgs e) { if (animationCycles < 12) { if (animationCycles % 3 == 0 && animationCycles != 0) { image = GameMethods.GetImageByName($"menu_{animationCycles / 3}"); } animationCycles++; } else { animationCycles = 0; image = GameMethods.GetImageByName($"menu_0"); } Invalidate(); }
public KeyboardSaga(Menu menuF) { //Form Initialization InitializeComponent(); Icon = Properties.Resources.logo; animationCycles = 0; gameOverCycles = 0; mapImage = GameMethods.GetImageByName("0_"); menuForm = menuF; Font = new Font(menuForm.FontCollection.Families[0], 20F); gameOverFont = new Font(menuForm.FontCollection.Families[0], 40F); game = new Game(); pauseGame = false; gameOverSoundPlayed = false; #region Sounds Initialization var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); healRechargeSound = new WindowsMediaPlayer(); healRechargeSound.URL = Path.Combine(currentDirectory, @"sounds\heal_recharge.wav"); healRechargeSound.settings.volume = 15; healRechargeSound.controls.stop(); healSound = new WindowsMediaPlayer(); healSound.URL = Path.Combine(currentDirectory, @"sounds\heal.wav"); healSound.settings.volume = 15; healSound.controls.stop(); hitSound = new WindowsMediaPlayer(); hitSound.URL = Path.Combine(currentDirectory, @"sounds\hit.wav"); hitSound.settings.volume = 10; hitSound.controls.stop(); gameOverSound = new WindowsMediaPlayer(); gameOverSound.URL = Path.Combine(currentDirectory, @"sounds\game_over.wav"); gameOverSound.settings.volume = 100; gameOverSound.controls.stop(); #endregion AutoScaleMode = AutoScaleMode.Dpi; AutoValidate = AutoValidate.Disable; DoubleBuffered = true; Name = "KeyboardSaga"; Text = "eyboardSaga"; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ClientSize = new Size(1280, 720); coordinates = new Point((ClientSize.Width - game.MapImage.Width) / 2, (ClientSize.Height - game.MapImage.Height) / 2); BackColor = Color.FromArgb(47, 40, 58); Paint += new PaintEventHandler(OnPaint); KeyDown += new KeyEventHandler(OnKeyPress); SizeChanged += new EventHandler((sender, args) => { coordinates = new Point((ClientSize.Width - game.MapImage.Width) / 2, (ClientSize.Height - game.MapImage.Height) / 2); pauseButton.Location = new Point((ClientSize.Width - pauseButton.Image.Width - 30), 30); restartButton.Location = new Point( (coordinates.X + game.MapImage.Width / 2 - restartButton.Image.Width / 2), (ClientSize.Height / 2 - restartButton.Image.Height)); menuButton.Location = new Point((coordinates.X + game.MapImage.Width / 2 - menuButton.Image.Width / 2), (restartButton.Location.Y + 15 + restartButton.Image.Height)); Invalidate(); }); //Timer timer = new Timer(components) { Enabled = true, Interval = 20 }; timer.Tick += new EventHandler(OnFrameChanged); #region Pause Button pauseButton = new PictureBox(); pauseButton.Image = GameMethods.GetImageByName("PAUSE"); pauseButton.Size = new Size(pauseButton.Image.Width, pauseButton.Image.Height); pauseButton.Location = new Point((ClientSize.Width - pauseButton.Image.Width - 40), 20); pauseButton.MouseUp += new MouseEventHandler((sender, args) => { if (!pauseGame) { pauseButton.Image = GameMethods.GetImageByName("PAUSE_ACTIVE"); } }); pauseButton.MouseDown += new MouseEventHandler((sender, args) => pauseButton.Image = GameMethods.GetImageByName("PAUSE_PRESSED_ACTIVE")); pauseButton.MouseClick += new MouseEventHandler((sender, args) => { menuForm.PlayClickSound(); pauseGame = !pauseGame; restartButton.Enabled = !restartButton.Enabled; restartButton.Visible = !restartButton.Visible; menuButton.Enabled = !menuButton.Enabled; menuButton.Visible = !menuButton.Visible; }); pauseButton.MouseEnter += new EventHandler((sender, args) => { if (!pauseGame) { pauseButton.Image = GameMethods.GetImageByName("PAUSE_ACTIVE"); } }); pauseButton.MouseLeave += new EventHandler((sender, args) => { if (!pauseGame) { pauseButton.Image = GameMethods.GetImageByName("PAUSE"); } }); pauseButton.BackColor = Color.Transparent; #endregion Controls.Add(pauseButton); #region Restart Button restartButton = new PictureBox(); restartButton.Image = GameMethods.GetImageByName("RESTART"); restartButton.Size = new Size(restartButton.Image.Width, restartButton.Image.Height); restartButton.Location = new Point((coordinates.X + game.MapImage.Width / 2 - restartButton.Image.Width / 2), (ClientSize.Height / 2 - restartButton.Image.Height)); restartButton.MouseUp += new MouseEventHandler((sender, args) => restartButton.Image = GameMethods.GetImageByName("RESTART_ACTIVE")); restartButton.MouseDown += new MouseEventHandler((sender, args) => restartButton.Image = GameMethods.GetImageByName("RESTART_PRESSED")); restartButton.MouseClick += new MouseEventHandler((sender, args) => { menuForm.PlayClickSound(); game.Reset(); animationCycles = 0; gameOverCycles = 0; gameOverSound.controls.stop(); gameOverSoundPlayed = false; mapImage = GameMethods.GetImageByName("0_"); PausePress(); }); restartButton.MouseEnter += new EventHandler((sender, args) => restartButton.Image = GameMethods.GetImageByName("RESTART_ACTIVE")); restartButton.MouseLeave += new EventHandler((sender, args) => restartButton.Image = GameMethods.GetImageByName("RESTART")); restartButton.BackColor = Color.Transparent; restartButton.Enabled = false; restartButton.Visible = false; #endregion Controls.Add(restartButton); #region Exit To Menu Button menuButton = new PictureBox(); menuButton.Image = GameMethods.GetImageByName("EXIT"); menuButton.Size = new Size(menuButton.Image.Width, menuButton.Image.Height); menuButton.Location = new Point((coordinates.X + game.MapImage.Width / 2 - menuButton.Image.Width / 2), (restartButton.Location.Y + 15 + restartButton.Image.Height)); menuButton.MouseUp += new MouseEventHandler((sender, args) => menuButton.Image = GameMethods.GetImageByName("EXIT_ACTIVE")); menuButton.MouseDown += new MouseEventHandler((sender, args) => menuButton.Image = GameMethods.GetImageByName("EXIT_PRESSED")); menuButton.MouseClick += new MouseEventHandler((sender, args) => { menuForm.PlayClickSound(); menuForm.Open(this); }); menuButton.MouseEnter += new EventHandler((sender, args) => menuButton.Image = GameMethods.GetImageByName("EXIT_ACTIVE")); menuButton.MouseLeave += new EventHandler((sender, args) => menuButton.Image = GameMethods.GetImageByName("EXIT")); menuButton.BackColor = Color.Transparent; menuButton.Enabled = false; menuButton.Visible = false; #endregion Controls.Add(menuButton); Invalidate(); }
public Tutorial(Menu menuF) { //Form Initialization InitializeComponent(); Icon = Properties.Resources.logo; menuForm = menuF; hitSound = new WindowsMediaPlayer(); hitSound.URL = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"sounds\hit.wav"); hitSound.settings.volume = 10; hitSound.controls.stop(); mapImage = GameMethods.GetImageByName("0_"); tutorialFinished = false; arrow = GameMethods.GetImageByName("arrow"); exclamationMark = GameMethods.GetImageByName("exclamation_mark"); game = new Game(); pauseGame = false; animationCycles = 0; markAnimationCycles = 0; AutoScaleMode = AutoScaleMode.Dpi; AutoValidate = AutoValidate.Disable; DoubleBuffered = true; Name = "KeyboardSaga"; Text = "eyboardSaga"; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ClientSize = new Size(1280, 720); coordinates = new Point( (ClientSize.Width - game.MapImage.Width) / 2, (ClientSize.Height - game.MapImage.Height) / 2); BackColor = Color.FromArgb(47, 40, 58); Paint += new PaintEventHandler(OnPaint); KeyDown += new KeyEventHandler(OnKeyPress); SizeChanged += new EventHandler((sender, args) => { coordinates = new Point( (ClientSize.Width - game.MapImage.Width) / 2, (ClientSize.Height - game.MapImage.Height) / 2); pauseButton.Location = new Point((ClientSize.Width - pauseButton.Image.Width - 30), 30); menuButton.Location = menuButton.Location = new Point( (coordinates.X + game.MapImage.Width / 2 - menuButton.Image.Width / 2), (ClientSize.Height / 2 - menuButton.Image.Height)); Invalidate(); }); //Timer timer = new Timer(components) { Enabled = true, Interval = 20 }; timer.Tick += new EventHandler(OnFrameChanged); #region Pause Button pauseButton = new PictureBox(); pauseButton.Image = GameMethods.GetImageByName("PAUSE"); pauseButton.Size = new Size(pauseButton.Image.Width, pauseButton.Image.Height); pauseButton.Location = new Point((ClientSize.Width - pauseButton.Image.Width - 40), 20); pauseButton.MouseUp += new MouseEventHandler((sender, args) => { if (!pauseGame) { pauseButton.Image = GameMethods.GetImageByName("PAUSE_ACTIVE"); } }); pauseButton.MouseDown += new MouseEventHandler((sender, args) => { pauseButton.Image = GameMethods.GetImageByName("PAUSE_PRESSED_ACTIVE"); }); pauseButton.MouseClick += new MouseEventHandler((sender, args) => { menuForm.PlayClickSound(); PausePress(); }); pauseButton.MouseEnter += new EventHandler((sender, args) => { if (!pauseGame) { pauseButton.Image = GameMethods.GetImageByName("PAUSE_ACTIVE"); } }); pauseButton.MouseLeave += new EventHandler((sender, args) => { if (!pauseGame) { pauseButton.Image = GameMethods.GetImageByName("PAUSE"); } }); pauseButton.BackColor = Color.Transparent; #endregion Controls.Add(pauseButton); #region Menu Button menuButton = new PictureBox(); menuButton.Image = GameMethods.GetImageByName("EXIT"); menuButton.Size = new Size(menuButton.Image.Width, menuButton.Image.Height); menuButton.Location = new Point( (coordinates.X + game.MapImage.Width / 2 - menuButton.Image.Width / 2), (ClientSize.Height / 2 - menuButton.Image.Height)); menuButton.MouseUp += new MouseEventHandler((sender, args) => menuButton.Image = GameMethods.GetImageByName("EXIT_ACTIVE")); menuButton.MouseDown += new MouseEventHandler((sender, args) => { menuButton.Image = GameMethods.GetImageByName("EXIT_PRESSED"); }); menuButton.MouseClick += new MouseEventHandler((sender, args) => { menuForm.PlayClickSound(); menuForm.Open(this); }); menuButton.MouseEnter += new EventHandler((sender, args) => menuButton.Image = GameMethods.GetImageByName("EXIT_ACTIVE")); menuButton.MouseLeave += new EventHandler((sender, args) => menuButton.Image = GameMethods.GetImageByName("EXIT")); menuButton.BackColor = Color.Transparent; menuButton.Enabled = false; menuButton.Visible = false; #endregion Controls.Add(menuButton); Invalidate(); }
public Menu() { SoundOn = true; var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); #region Sound Files Initialization var soundsFolder = Path.Combine(currentDirectory, @"sounds"); if (!Directory.Exists(soundsFolder)) { Directory.CreateDirectory(soundsFolder); } string musicFile = Path.Combine(currentDirectory, @"sounds\music.wav"); FileInitialize(musicFile, Properties.Resources.music); string clickSoundFile = Path.Combine(currentDirectory, @"sounds\click.wav"); FileInitialize(clickSoundFile, Properties.Resources.menu_select); FileInitialize(Path.Combine(currentDirectory, @"sounds\heal.wav"), Properties.Resources.heal); FileInitialize(Path.Combine(currentDirectory, @"sounds\heal_recharge.wav"), Properties.Resources.heal_recharge); FileInitialize(Path.Combine(currentDirectory, @"sounds\hit.wav"), Properties.Resources.hit); FileInitialize(Path.Combine(currentDirectory, @"sounds\game_over.wav"), Properties.Resources.game_over); //Music Player Creation music = new WindowsMediaPlayer(); music.URL = musicFile; music.controls.stop(); music.settings.setMode("loop", true); music.settings.volume = 10; if (SoundOn) { music.controls.play(); } //Click Sound Player Creation clickSound = new WindowsMediaPlayer(); clickSound.URL = clickSoundFile; clickSound.settings.volume = 10; clickSound.controls.stop(); #endregion #region Font File Initialization string fontFile = Path.Combine(currentDirectory, @"fontFile.tmp"); FileInitialize(fontFile, Properties.Resources.Main_Font); //Font Creation FontCollection = new PrivateFontCollection(); FontCollection.AddFontFile(fontFile); #endregion //Form Initialization InitializeComponent(); Icon = Properties.Resources.logo; image = GameMethods.GetImageByName("menu_0"); FormBorderStyle = FormBorderStyle.None; AutoScaleMode = AutoScaleMode.Dpi; AutoValidate = AutoValidate.Disable; Name = "KeyboardSaga"; Text = "eyboardSaga"; WindowState = FormWindowState.Maximized; DoubleBuffered = true; ClientSize = new Size(1280, 720); BackColor = Color.FromArgb(47, 40, 58); coordinates = new Point((ClientSize.Width - image.Width) / 2, (ClientSize.Height - image.Height) / 2); SizeChanged += new EventHandler((sender, args) => { coordinates = new Point((ClientSize.Width - image.Width) / 2, (ClientSize.Height - image.Height) / 2); playButton.Location = new Point((coordinates.X + image.Width / 2 - playButton.Image.Width / 2), (ClientSize.Height / 2 - playButton.Image.Height)); tutorialButton.Location = new Point(playButton.Location.X, playButton.Location.Y + 15 + playButton.Image.Height); exitButton.Location = new Point(tutorialButton.Location.X, tutorialButton.Location.Y + 15 + tutorialButton.Image.Height); soundToggleButton.Location = new Point((coordinates.X + 41), (coordinates.Y + image.Height - 41 - soundToggleButton.Image.Height)); Invalidate(); }); Paint += new PaintEventHandler(OnPaint); //Timer timer = new Timer(components) { Enabled = true, Interval = 100 }; timer.Tick += new EventHandler(OnFrameChanged); animationCycles = 0; #region Play Button playButton = new PictureBox(); playButton.Image = GameMethods.GetImageByName("MENU_PLAY"); playButton.Size = new Size(playButton.Image.Width, playButton.Image.Height); playButton.Location = new Point((coordinates.X + image.Width / 2 - playButton.Image.Width / 2), (ClientSize.Height / 2 - playButton.Image.Height)); playButton.MouseUp += new MouseEventHandler((sender, args) => playButton.Image = GameMethods.GetImageByName("MENU_PLAY_ACTIVE")); playButton.MouseDown += new MouseEventHandler((sender, args) => playButton.Image = GameMethods.GetImageByName("MENU_PLAY_PRESSED")); playButton.MouseClick += new MouseEventHandler((sender, args) => { PlayClickSound(); gameForm = new KeyboardSaga(this); gameForm.Show(); }); playButton.MouseEnter += new EventHandler((sender, args) => playButton.Image = GameMethods.GetImageByName("MENU_PLAY_ACTIVE")); playButton.MouseLeave += new EventHandler((sender, args) => playButton.Image = GameMethods.GetImageByName("MENU_PLAY")); playButton.BackColor = Color.Transparent; #endregion Controls.Add(playButton); #region Tutorial Button tutorialButton = new PictureBox(); tutorialButton.Image = GameMethods.GetImageByName("MENU_TUTORIAL"); tutorialButton.Size = new Size(tutorialButton.Image.Width, tutorialButton.Image.Height); tutorialButton.Location = new Point(playButton.Location.X, playButton.Location.Y + 15 + playButton.Image.Height); tutorialButton.MouseUp += new MouseEventHandler((sender, args) => tutorialButton.Image = GameMethods.GetImageByName("MENU_TUTORIAL_ACTIVE")); tutorialButton.MouseDown += new MouseEventHandler((sender, args) => tutorialButton.Image = GameMethods.GetImageByName("MENU_TUTORIAL_PRESSED")); tutorialButton.MouseClick += new MouseEventHandler((sender, args) => { PlayClickSound(); tutorialForm = new Tutorial(this); tutorialForm.Show(); }); tutorialButton.MouseEnter += new EventHandler((sender, args) => tutorialButton.Image = GameMethods.GetImageByName("MENU_TUTORIAL_ACTIVE")); tutorialButton.MouseLeave += new EventHandler((sender, args) => tutorialButton.Image = GameMethods.GetImageByName("MENU_TUTORIAL")); tutorialButton.BackColor = Color.Transparent; #endregion Controls.Add(tutorialButton); #region Exit Game Button exitButton = new PictureBox(); exitButton.Image = GameMethods.GetImageByName("MENU_EXIT"); exitButton.Size = new Size(exitButton.Image.Width, exitButton.Image.Height); exitButton.Location = new Point(tutorialButton.Location.X, tutorialButton.Location.Y + 15 + tutorialButton.Image.Height); exitButton.MouseUp += new MouseEventHandler((sender, ars) => exitButton.Image = GameMethods.GetImageByName("MENU_EXIT_ACTIVE")); exitButton.MouseDown += new MouseEventHandler((sender, args) => exitButton.Image = GameMethods.GetImageByName("MENU_EXIT_PRESSED")); exitButton.MouseClick += new MouseEventHandler((sender, args) => { Application.Exit(); }); exitButton.MouseEnter += new EventHandler((sender, args) => exitButton.Image = GameMethods.GetImageByName("MENU_EXIT_ACTIVE")); exitButton.MouseLeave += new EventHandler((sender, args) => exitButton.Image = GameMethods.GetImageByName("MENU_EXIT")); exitButton.BackColor = Color.Transparent; #endregion Controls.Add(exitButton); #region Sound Toggle Button soundToggleButton = new PictureBox(); soundToggleButton.Image = SoundOn ? GameMethods.GetImageByName("SOUND_ON") : GameMethods.GetImageByName("SOUND_OFF"); soundToggleButton.Size = new Size(soundToggleButton.Image.Width, soundToggleButton.Image.Height); soundToggleButton.Location = new Point((coordinates.X + 41), (coordinates.Y + image.Height - 41 - soundToggleButton.Image.Height)); soundToggleButton.MouseUp += new MouseEventHandler((sender, args) => soundToggleButton.Image = SoundOn ? GameMethods.GetImageByName("SOUND_ON_ACTIVE") : GameMethods.GetImageByName("SOUND_OFF_ACTIVE")); soundToggleButton.MouseDown += new MouseEventHandler((sender, args) => soundToggleButton.Image = SoundOn ? GameMethods.GetImageByName("SOUND_ON_PRESSED") : GameMethods.GetImageByName("SOUND_OFF_PRESSED")); soundToggleButton.MouseClick += new MouseEventHandler((sender, args) => { PlayClickSound(); SoundOn = !SoundOn; if (SoundOn) { music.controls.play(); } else { music.controls.pause(); } }); soundToggleButton.MouseEnter += new EventHandler((sender, args) => soundToggleButton.Image = SoundOn ? GameMethods.GetImageByName("SOUND_ON_ACTIVE") : GameMethods.GetImageByName("SOUND_OFF_ACTIVE")); soundToggleButton.MouseLeave += new EventHandler((sender, args) => soundToggleButton.Image = SoundOn ? GameMethods.GetImageByName("SOUND_ON") : GameMethods.GetImageByName("SOUND_OFF")); soundToggleButton.BackColor = Color.Transparent; #endregion Controls.Add(soundToggleButton); Invalidate(); }