コード例 #1
0
ファイル: Form1.cs プロジェクト: huzaifazia17/SpaceInvaders
 private void StartBtn_Click(object sender, EventArgs e)
 {
     // will allow the background music to contunially play
     backMusic.playLooping();
     //will start the timer
     refresh.Start();
     // hide the help button when the start button is clicked
     helpBtn.Hide();
     // hide the exit button when the start button is clicked
     exitBtn.Hide();
     // hide the start button when the start button is clicked
     startBtn.Hide();
     //change the background image
     BackgroundImage = Image.FromFile(Application.StartupPath + @"\background.jpg", true);
     // set the coordinates for player
     player = new Rectangle((this.ClientSize.Width / 2 - 40), (this.ClientSize.Height - 100), 100, 100);
 }
コード例 #2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     //double buffered
     this.DoubleBuffered = true;
     //set sprite timer interval
     spriteTimer.Interval = 250;
     //set refresh timer interval
     refreshTimer.Interval = (1000 / 60);
     //set reload timer interval
     reloadTimer.Interval = 500;
     //start sprite timer
     spriteTimer.Start();
     //start refresh timer
     refreshTimer.Start();
     //create reload timer tick
     reloadTimer.Tick += ReloadTimer_Tick;
     //set form location
     this.Location = new Point(0, 0);
     //set form size
     this.MinimumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
     //set form size
     this.MaximumSize = this.MinimumSize;
     //prevent minimizing window
     this.MinimizeBox = false;
     //prevent maximizing window
     this.MaximizeBox = false;
     //set horizontal location of start button
     startBtn.Left = this.ClientSize.Width / 2 - 100;
     //set vertical location of start button
     startBtn.Top = this.ClientSize.Height / 2 - 50;
     //make start button visible
     startBtn.Visible = true;
     //set start button size
     startBtn.Width = 200;
     //set start button size
     startBtn.Height = 100;
     //set start button text
     startBtn.Text = "Start";
     //set horizontal location of how to play button
     howToPlayBtn.Left = this.ClientSize.Width / 2 - 100;
     //set vertical location of how to play button
     howToPlayBtn.Top = this.ClientSize.Height / 3 - 50;
     //make start button visible
     howToPlayBtn.Visible = true;
     //set start button size
     howToPlayBtn.Width = 200;
     //set start button size
     howToPlayBtn.Height = 100;
     //set start button text
     howToPlayBtn.Text = "How To Play";
     //create how to play button method
     howToPlayBtn.Click += HowToPlayBtn_Click;
     //add how to play button to form
     this.Controls.Add(howToPlayBtn);
     //set horizontal location of how to play button
     MenuBtn.Left = 0;
     //set vertical location of how to play button
     MenuBtn.Top = 0;
     //make start button visible
     MenuBtn.Visible = true;
     //set start button size
     MenuBtn.Width = 50;
     //set start button size
     MenuBtn.Height = 50;
     //set start button text
     MenuBtn.Text = "Menu";
     //create how to play button method
     MenuBtn.Click += MenuBtn_Click;
     //create form 1 paint
     this.Paint += Form1_Paint;
     //create mouse click mehtod
     MouseClick += Form1_MouseClick;
     //create refresh tick
     refreshTimer.Tick += RefreshTimer_Tick;
     //create sprite timer tick method
     spriteTimer.Tick += SpriteTimer_Tick;
     //add button to form
     this.Controls.Add(startBtn);
     //start button method
     startBtn.Click += StartBtn_Click;
     //declare values for backgroundrect
     backgroundRect = new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height);
     //assign value to ground
     ground = this.ClientSize.Height * 0.6;
     //add duck sprites to ducksprite right
     duckSpriteRight[0] = Image.FromFile(Application.StartupPath + @"\DuckRight0.png", true);
     duckSpriteRight[1] = Image.FromFile(Application.StartupPath + @"\DuckRight1.png", true);
     duckSpriteRight[2] = Image.FromFile(Application.StartupPath + @"\DuckRight2.png", true);
     duckSpriteRight[3] = Image.FromFile(Application.StartupPath + @"\DuckRight1.png", true);
     //add duck sprites to ducksprite left
     duckSpriteLeft[0] = Image.FromFile(Application.StartupPath + @"\DuckLeft0.png", true);
     duckSpriteLeft[1] = Image.FromFile(Application.StartupPath + @"\DuckLeft1.png", true);
     duckSpriteLeft[2] = Image.FromFile(Application.StartupPath + @"\DuckLeft2.png", true);
     duckSpriteLeft[3] = Image.FromFile(Application.StartupPath + @"\DuckLeft1.png", true);
     //add duck sprites to ducksprite falling
     duckSpriteFalling[0] = Image.FromFile(Application.StartupPath + @"\DuckDeadRight.png", true);
     duckSpriteFalling[1] = Image.FromFile(Application.StartupPath + @"\DuckDeadLeft.png", true);
     //add ammo box images to array
     ammoSprite[0] = Image.FromFile(Application.StartupPath + @"\Ammo0.png", true);
     ammoSprite[1] = Image.FromFile(Application.StartupPath + @"\Ammo1.png", true);
     ammoSprite[2] = Image.FromFile(Application.StartupPath + @"\Ammo2.png", true);
     ammoSprite[3] = Image.FromFile(Application.StartupPath + @"\Ammo3.png", true);
     //setup font
     fontCollection = new PrivateFontCollection();
     fontCollection.AddFontFile(Application.StartupPath + @"\Font.TTF");
     customFont = new Font(fontCollection.Families[0], 16);
     //add values to HTPRect
     HTPRect = new Rectangle(this.ClientSize.Width / 3, this.ClientSize.Height, this.ClientSize.Width / 3, this.ClientSize.Height);
     //setup music audio player
     Music = new AudioFilePlayer();
     Music.setAudioFile(Application.StartupPath + @"\DuckHuntMedley.mp3");
     //play music on loop
     Music.playLooping();
     //set up shootSound player
     shootSound = new AudioFilePlayer();
     shootSound.setAudioFile(Application.StartupPath + @"\ShootingSound.wav");
     //place ammo display rect on form
     ammoDisplayRect = new Rectangle(Convert.ToInt32(this.ClientSize.Width * (1.0 / 8.0)), Convert.ToInt32(this.ClientSize.Height * (5.0 / 6.0)), ammoSprite[0].Width * 5, ammoSprite[0].Height * 5);
     //place score display rect on form
     playerScoreDisplayRect = new Rectangle(Convert.ToInt32(this.ClientSize.Width * (3.0 / 4.0)), Convert.ToInt32(this.ClientSize.Height * (5.0 / 6.0)), scoreDisplaySprite.Width * 5, scoreDisplaySprite.Height * 5);
     //place game over rect on form
     gameOverRect = new Rectangle((this.ClientSize.Width / 2) - Convert.ToInt32(gameOverSprite.Width * (5.0 / 2.0)), this.ClientSize.Height / 2, gameOverSprite.Width * 5, gameOverSprite.Height * 5);
     //place score rect on form
     scoreRect = new Rectangle(Convert.ToInt32(this.ClientSize.Width * (3.0 / 4.0)) + scoreDisplaySprite.Width, Convert.ToInt32(this.ClientSize.Height * (5.0 / 6.0) + scoreDisplaySprite.Height), scoreDisplaySprite.Width * 5, scoreDisplaySprite.Height * 5);
 }