Beispiel #1
0
 //Shoot method, used to set starting position of our bullets
 public void shoot_bullet()
 {
     //shoot only if the bullet delay is set. particle originates in center of player
     if (bulletDelay >= firerate) {
         Bullet b = new Bullet(bulletTexture,bulletspeed);
         b.position = new Vector2(position.X + texture.Width / 2 - b.texture.Width / 2, position.Y + texture.Height / 2 - b.texture.Height / 2);
         b.isVisible = true;
         if (bullets.Count() < 20) bullets.Add(b);
         bulletDelay = 0;
         sm.playerShootSound.Play(.1f,0,0);
     }
 }
Beispiel #2
0
        //shoot bullets helper function
        private void shoot_bullets(Vector2 playerpos)
        {
            //shoot only if the bullet delay is set - Determine bullet texture, and bullet position
            if (bulletDelay >= firerate) {
                bulletDelay = 0;

                //small fighter type. does not shoot lasers
                if (shiptype == 4) {

                }

                //Defualt, medium fighter type - one laser from center
                else if (shiptype == 0) {
                    Bullet b = new Bullet(bulletTexture, bulletvelocity);
                    b.position = new Vector2(position.X + texture.Width / 2 - b.texture.Width / 2, position.Y + texture.Height / 2 - b.texture.Height / 2);
                    bullets.Add(b); //add bullet
                }

                //Large fighter type - three lasers fanned out
                else if (shiptype == 1) {
                    Bullet b1 = new Bullet(bulletTexture, bulletvelocity);
                    b1.position = new Vector2(position.X + texture.Width / 2 - b1.texture.Width / 2, position.Y + texture.Height / 2 - b1.texture.Height / 2);
                    Bullet b2 = new Bullet(bulletTexture, bulletvelocity);
                    b2.position = new Vector2(position.X - b1.texture.Width / 2, position.Y + texture.Height / 2 - b1.texture.Height / 2);
                    b2.rotation = 45; b2.speedX = -1 * bulletvelocity / 4; b2.speedY = bulletvelocity * .75f;
                    Bullet b3 = new Bullet(bulletTexture, bulletvelocity);
                    b3.position = new Vector2(position.X + texture.Width - b1.texture.Width / 2, position.Y + texture.Height / 2 - b1.texture.Height / 2);
                    b3.rotation = -45; b3.speedX = bulletvelocity / 4; b3.speedY = bulletvelocity * .75f;
                    bullets.Add(b1); //add bullet
                    bullets.Add(b2);
                    bullets.Add(b3);
                }

                //Large fighter type#2 - laser in general direction of player
                else if (shiptype == 2) {
                    Bullet b = new Bullet(bulletTexture, bulletvelocity);
                    b.position = new Vector2(position.X + texture.Width / 2 - b.texture.Width / 2, position.Y + texture.Height / 2 - b.texture.Height / 2);
                    b.speedX = (float)(Math.Atan2((playerpos.X - b.position.X), (playerpos.Y - b.position.Y)));
                    bullets.Add(b); //add bullet
                }

                //cruiser - big fire ball to player's location
                else if (shiptype == 3) {
                    Bullet b1 = new Bullet(bulletTexture, bulletvelocity);
                    b1.position = new Vector2(position.X + texture.Width / 2f - b1.texture.Width / 2, position.Y + texture.Height - b1.texture.Height / 2);
                    b1.speedX = (playerpos.X - b1.position.X) / (bulletvelocity * 15);
                    b1.speedY = (playerpos.Y - b1.position.Y) / (bulletvelocity * 15);
                    b1.rotation = (float)(Math.Atan2((b1.position.X - playerpos.X), (playerpos.Y - b1.position.Y)));
                    bullets.Add(b1); //add bullet
                }

                //Cruiser - 8 downward dumb bullets
                else if (shiptype == 5) {
                    for (int i = 0; i < 6; i++) {
                        Bullet b = new Bullet(bulletTexture, bulletvelocity);
                        b.position = new Vector2(position.X  + ((i* .16f)* texture.Width) - b.texture.Width / 2, position.Y + texture.Height / 2 - b.texture.Height / 2);
                        bullets.Add(b); //add bullet
                    }
                }
            }
        }