private void gameTimer_Tick(object sender, EventArgs e) { //rotate left if (leftArrowDown) { if (hero.angle > -80) { hero.Turn("left"); } } //rotate right if (rightArrowDown) { if (hero.angle < 80) { hero.Turn("right"); } } //spawn missile every 60 ticks if (counter == Form1.difficulty) { //missile object requires float values to draw on screen Missile m = new Missile(randGen.Next(10, this.Width - 10), 0, missileSize, missileSpeed); missiles.Add(m); //reset counter counter = 0; } else { counter++; } //fire bullet if (spaceDown && ammo > 0 && firecounter == 0) { //theta measure for angle of fire, (float uses less memory) float thetaAngle = (90 - hero.angle); // determine the end point for each hand (result must be a double) double xStep = Math.Cos(thetaAngle * Math.PI / 180.0); double yStep = Math.Sin(thetaAngle * Math.PI / 180.0); //bullet object requires float values to draw on screen Bullet b = new Bullet(hero.x, hero.y, bulletSize, bulletSpeed, (float)xStep, (float)-yStep); bullets.Add(b); //remove ammo ammo--; ammoLabel.Text = "Ammo: " + ammo.ToString(); //reset firecounter firecounter = 0; } //move bullet foreach (Bullet b in bullets) { b.Move(); } //move missile foreach (Missile m in missiles) { m.MissileMove(); } if (bullets.Count > 0) { //Use the OffScreen method from the first bullet since we know it exists. //bullets[0].OffScreen(bullets, this); } //remove missile and health when missile hits bottom of screen foreach (Missile m in missiles) { if (m.y > this.Height) { lives--; livesLabel.Text = lives.ToString(); missiles.RemoveAt(missiles.IndexOf(m)); break; } } if (missiles.Count > 0) { //Use the OffScreen method from the first bullet since we know it exists. missiles[0].OffScreen(missiles, this); } BulletsMissilesCollision(); //paint the screen Refresh(); }