public Obstaculo gerarObstaculo()
        {
            Obstaculo obst = null;
            int       i    = 0;

            while ((i < lista.Count) && (obst == null))
            {
                if (lista[i].ativo == false)
                {
                    lista[i].ativo    = true;
                    lista[i].atingido = false;
                    obst = lista[i];
                    if (tipoObstaculo.AviaoInimigo == obst.tipo)
                    {
                        obst.pos = new Rectangle(410 - rnd.Next(1, 5) * 60, 0 - rnd.Next(1, 7) * 70, 60, 60);
                    }
                    else if (tipoObstaculo.Missil == obst.tipo)
                    {
                        obst.pos = new Rectangle(1000 - rnd.Next(1, 3) * 70, 600 - rnd.Next(1, 7) * 60, 60, 60);
                    }
                    else if (tipoObstaculo.Cloud == obst.tipo)
                    {
                        obst.pos = new Rectangle(410 - rnd.Next(1, 5) * 60, -60, 60, 60);
                    }
                    obstaculosAtivos++;
                }

                i++;
            }

            return(obst);
        }
Example #2
0
        public bool verificarColisao(Obstaculo obs)
        {
            Tiro[] t = lista.ToArray();
            int    i = 0;

            while ((i < t.Length) && (obs != null))
            {
                if (t[i].vivo)
                {
                    if (obs.ativo)
                    {
                        /*if ((obs.pos.Y >= t[i].pos.Y) && (obs.pos.Y <= t[i].pos.Y + t[i].altura) &&
                         *  (obs.pos.X >= t[i].pos.X) && (obs.pos.X <= t[i].pos.X + t[i].largura)
                         *  )*/
                        if ((t[i].pos.Y + (t[i].altura / 2) >= obs.pos.Y) && (t[i].pos.Y - (t[i].altura / 2) <= obs.pos.Y + (obs.altura / 2)) &&
                            (t[i].pos.X + (t[i].largura / 2) >= obs.pos.X) && (t[i].pos.X - (t[i].largura / 2) <= obs.pos.X + (obs.largura / 2))
                            )

                        {
                            //lista.Remove(t[i]);
                            t[i].vivo = false;
                            return(true);
                        }
                    }
                }
                i++;
            }
            return(false);
        }
Example #3
0
        public static void draw(Obstaculo obs, SpriteBatch spriteBatch, Texture2D texture)
        {
            Rectangle r = new Rectangle((int)obs.pos.X, (int)obs.pos.Y, obs.largura, obs.altura);

            if (obs.atingido == false)
            {
                spriteBatch.Draw(texture, r, Color.White);
            }
        }
Example #4
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }



            tempoTiro--;

            posY1 = posY1 + 4;

            if (posY1 > 600)
            {
                posY1 = 0;
            }

            int rand = rnd.Next(-1000, 1000);

            if ((Math.Abs(rand) <= 0) || (go.obstaculosAtivos == 0))
            {
                obstaculo = go.gerarObstaculo();
            }

            Obstaculo[] obstaculos = go.toArray();

            for (int i = 0; i < obstaculos.Length; i++)
            {
                if (gt.verificarColisao(obstaculos[i]))
                {
                    obstaculos[i].atingido = true;
                    pontos += 1;
                }
            }



            aviao.Colisaodoavisao(obstaculos, aviao);
            Clickdomouse(mousestate.X, mousestate.Y);



            avaliarJogada();
            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Example #5
0
 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 protected override void Initialize()
 {
     // TODO: Add your initialization logic here
     aviao          = new Aviao();
     tiro           = null;
     obstaculo      = null;
     tiroPreparado  = false;
     tempoTiro      = 0;
     gt             = new GerenciadorTiro();
     go             = new GerenciadorObstaculo();
     rnd            = new Random();
     IsMouseVisible = true;
     posbutton      = new Rectangle(250, 400, 300, 100);
     posButton2     = new Rectangle(250, 200, 300, 100);
     posButton3     = new Rectangle(250, 300, 300, 100);
     base.Initialize();
 }
        private Obstaculo fabricarObstaculo()
        {
            Obstaculo obstac = null;

            int i = rnd.Next(0, 3);


            switch (i)
            {
            case 0: obstac = new Obstaculo(tipoObstaculo.Cloud, 0, 0);
                break;

            case 1: obstac = new Obstaculo(tipoObstaculo.Missil, 0, 0);
                break;

            case 2: obstac = new Obstaculo(tipoObstaculo.AviaoInimigo, 0, 0);
                break;
            }

            return(obstac);
        }
 public void Add(Obstaculo t)
 {
     lista.Add(t);
 }