Exemplo n.º 1
0
        private void Juego_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 40) // down
            {
                pressDown        = true;
                jugador.selected = 1;
            }

            if (e.KeyValue == 39) // right
            {
                pressRight       = true;
                jugador.selected = 2;
            }

            if (e.KeyValue == 37) //lefth
            {
                pressLefth       = true;
                jugador.selected = 3;
            }

            if (e.KeyValue == 38) //up
            {
                pressUp          = true;
                jugador.selected = 4;
            }

            if (e.KeyValue == 32) //space
            {
                //aqui va la bomba simple
                bomba      = new Bomba();
                bomba.x    = jugador.x;
                bomba.y    = jugador.y;
                bomba.tipo = 1;
                bombas.Add(bomba);
                bandBomb = true;
            }

            if (e.KeyValue == 81) //q
            {
                //aqui va la bomba remota
                bomba      = new Bomba();    //*****
                bomba.x    = jugador.x + 25; //*****
                bomba.y    = jugador.y;      //*****
                bomba.tipo = 6;
                bombas.Add(bomba);
                bandBomb    = true;
                bombaRemota = true;
                Colision colision = new Colision();

                colision.x    = bomba.x - 25;
                colision.y    = bomba.y;
                colision.tipo = 2;
                colisiones.Add(colision);
                //xes.Add(bomba.x - 25);
                //yes.Add(bomba.y);
                //Console.WriteLine(bomba.x - 25);
                //Console.WriteLine(bomba.y);
                int h = 0;

                /*for (int i = 0; i < colisiones.Count; i++)
                 * {
                 *  if (colisiones[i].tipo == 2)
                 *      h++;
                 *
                 * }
                 * Console.WriteLine("colision 2 " + h);*/
            }

            if (e.KeyValue == 87) //w
            {
                //bomba de gran alcance
                bomba      = new Bomba();
                bomba.x    = jugador.x;
                bomba.y    = jugador.y;
                bomba.tipo = 3;
                bombas.Add(bomba);
                bandBomb = true;
            }

            if (e.KeyValue == 69) //e
            {
                //aqui va la bomba apestosa
                bomba      = new Bomba();
                bomba.x    = jugador.x;
                bomba.y    = jugador.y;
                bomba.tipo = 4;
                bombas.Add(bomba);
                bandBomb = true;
            }

            if (e.KeyValue == 82) //r
            {
                //aqui van las minas
                bomba      = new Bomba();
                bomba.x    = jugador.x;
                bomba.y    = jugador.y;
                bomba.tipo = 5;
                bombas.Add(bomba);
                bandBomb = true;
            }

            if (e.KeyValue == 84) //t
            {
                if (bombaRemota)
                {
                    for (int i = 0; i < bombas.Count; i++)
                    {
                        if (bombas[i].tipo == 6)
                        {
                            explosion      = new Explosion();
                            explosion.x    = bombas[i].x - 45;
                            explosion.y    = bombas[i].y - 45;
                            explosion.tipo = 4;
                            explosionesRemotas.Add(explosion);
                        }
                    }
                    bombaRemota = false;
                }
            }
            //******************************************************************************
            if (e.KeyValue == 75) //down jugadorD
            {
                pressDown2        = true;
                jugadorD.selected = 1;
            }

            if (e.KeyValue == 73) //up jugadorD
            {
                pressUp2          = true;
                jugadorD.selected = 4;
            }

            if (e.KeyValue == 76) //right jugadorD
            {
                pressRight2       = true;
                jugadorD.selected = 2;
            }

            if (e.KeyValue == 74)  //lefht jugadorD
            {
                pressLefth2       = true;
                jugadorD.selected = 3;
            }

            if (e.KeyValue == 88) //x
            {
                //aqui va la bomba remota
                if (band2 == 0)
                {
                    bomba      = new Bomba();
                    bomba.x    = jugadorD.x;
                    bomba.y    = jugadorD.y;
                    bomb1X2    = bomba.x - 45;
                    bomb2Y2    = bomba.y - 45;
                    bomba.tipo = 2;
                    bombas.Add(bomba);
                    bandBomb = true;
                    band2    = 1;
                    bom2     = true;
                }
            }

            if (e.KeyValue == 67) //c
            {
                //bomba de gran alcance
                bomba      = new Bomba();
                bomba.x    = jugadorD.x;
                bomba.y    = jugadorD.y;
                bomba.tipo = 3;
                bombas.Add(bomba);
                bandBomb = true;
            }

            if (e.KeyValue == 86) //v
            {
                //aqui va la bomba apestosa
                bomba      = new Bomba();
                bomba.x    = jugadorD.x;
                bomba.y    = jugadorD.y;
                bomba.tipo = 4;
                bombas.Add(bomba);
                bandBomb = true;
            }

            if (e.KeyValue == 66) //b
            {
                //aqui van las minas
                bomba      = new Bomba();
                bomba.x    = jugadorD.x;
                bomba.y    = jugadorD.y;
                bomba.tipo = 5;
                bombas.Add(bomba);
                bandBomb = true;
            }

            if (e.KeyValue == 78) //n
            {
                //aqui va la bomba simple
                bomba      = new Bomba();
                bomba.x    = jugadorD.x;
                bomba.y    = jugadorD.y;
                bomba.tipo = 1;
                bombas.Add(bomba);
                bandBomb = true;
            }

            if (e.KeyValue == 77) //m
            {
                if (bom2)
                {
                    explosion      = new Explosion();
                    explosion.x    = bomb1X2;
                    explosion.y    = bomb2Y2;
                    explosion.tipo = 1;
                    explosiones.Add(explosion);
                    bandExplo = true;
                    band2     = 0;
                    bom2      = false;
                }
            }
        }
Exemplo n.º 2
0
        private void Juego_Paint(object sender, PaintEventArgs e)
        {
            Graphics g;

            g         = null;
            g         = e.Graphics;
            jugador.y = y;
            jugador.x = x;

            jugadorD.x = x2;
            jugadorD.y = y2;

            g.DrawImage(jugador.getCurFrame(), jugador.x, jugador.y);
            g.DrawImage(jugadorD.getCurFrame(), jugadorD.x, jugadorD.y);

            if (explosionesRemotas.Count != 0)
            {
                for (int i = 0; i < explosionesRemotas.Count; i++)
                {
                    if (contBb < 20)
                    {
                        xExplo = explosionesRemotas[i].x - 30;
                        yExplo = explosionesRemotas[i].y - 40;

                        g.DrawImage(explosionesRemotas[i].getImage(), explosionesRemotas[i].x, explosionesRemotas[i].y);
                        for (int w = 0; w < bombas.Count; w++)
                        {
                            if (bombas[w].x == explosionesRemotas[i].x + 45 && bombas[w].y == explosionesRemotas[i].y + 45)
                            {
                                //Console.WriteLine(bombas[w].x - 25);
                                //Console.WriteLine(bombas[w].y);
                                //xes.Remove(bombas[w].x - 25);
                                //yes.Remove(bombas[w].y);
                                bombas.RemoveAt(w);
                            }
                        }
                        contBb++;
                    }
                    else
                    {
                        int incY = 155;
                        int incX = 145;

                        explosionesRemotas.RemoveAt(i);
                        contBb = 0;
                        if ((y + 3 >= yExplo + 10 && y + 3 <= yExplo + incY) && (x >= xExplo + 10 && x <= xExplo + incX))
                        {
                            this.Close();
                        }
                        if ((y2 + 3 >= yExplo && y2 + 3 <= yExplo + incY) && (x2 >= xExplo && x2 <= xExplo + incX))
                        {
                            this.Close();
                        }
                    }
                }
            }


            if (bandBomb)
            {
                for (int i = 0; i < bombas.Count; i++)
                {
                    if (bombas[i].tipo == 1)
                    {
                        g.DrawImage(bombas[i].getImage(), bombas[i].x, bombas[i].y);
                        bombas[i].cont++;
                        if (bombas[i].cont > 60)
                        {
                            //bombas.RemoveAt(i);
                            explosion      = new Explosion();
                            explosion.x    = bombas[i].x - 45;
                            explosion.y    = bombas[i].y - 45;
                            explosion.tipo = 1;
                            explosiones.Add(explosion);
                            bandExplo = true;
                            band      = 0;
                        }
                    }
                }

                for (int y = 0; y < bombas.Count; y++)
                {
                    if (bombas[y].tipo == 2)
                    {
                        g.DrawImage(bombas[y].getImage(), bombas[y].x, bombas[y].y);
                    }
                }

                for (int w = 0; w < bombas.Count; w++)
                {
                    if (bombas[w].tipo == 3)
                    {
                        g.DrawImage(bombas[w].getImage(), bombas[w].x, bombas[w].y);
                        bombas[w].cont++;
                        if (bombas[w].cont > 50)
                        {
                            //bombas.RemoveAt(w);
                            explosion      = new Explosion();
                            explosion.x    = bombas[w].x - 65;
                            explosion.y    = bombas[w].y - 65;
                            explosion.tipo = 2;
                            explosiones.Add(explosion);
                            bandExplo = true;
                            band      = 0;
                        }
                    }
                }

                for (int z = 0; z < bombas.Count; z++)
                {
                    if (bombas[z].tipo == 4)
                    {
                        g.DrawImage(bombas[z].getImage(), bombas[z].x, bombas[z].y);
                        bombas[z].cont++;
                        if (bombas[z].cont > 70)
                        {
                            //bombas.RemoveAt(z);
                            explosion      = new Explosion();
                            explosion.x    = bombas[z].x - 45;
                            explosion.y    = bombas[z].y - 45;
                            explosion.tipo = 3;
                            explosiones.Add(explosion);
                            bandExplo = true;
                            band      = 0;
                        }
                    }
                }

                for (int z = 0; z < bombas.Count; z++)
                {
                    if (bombas[z].tipo == 5)
                    {
                        g.DrawImage(bombas[z].getImage(), bombas[z].x, bombas[z].y);
                    }
                }

                for (int i = 0; i < bombas.Count; i++)
                {
                    if (bombas[i].tipo == 6)
                    {
                        g.DrawImage(bombas[i].getImage(), bombas[i].x, bombas[i].y);
                    }
                }

                if (bandExplo)
                {
                    for (int i = 0; i < explosiones.Count; i++)
                    {
                        if (explosiones[i].tipo == 1)
                        {
                            if (contBUno < 20)
                            {
                                xExplo = explosiones[i].x - 30;
                                yExplo = explosiones[i].y - 40;

                                //Pen p = new Pen(Color.Black);
                                //g.DrawRectangle(p, xExplo, yExplo, incX, incY);

                                g.DrawImage(explosiones[i].getImage(), explosiones[i].x, explosiones[i].y);
                                for (int w = 0; w < bombas.Count; w++)
                                {
                                    if (bombas[w].x == explosiones[i].x + 45 && bombas[w].y == explosiones[i].y + 45)
                                    {
                                        bombas.RemoveAt(w);
                                    }
                                }


                                contBUno++;
                            }
                            else
                            {
                                int incY = 155;
                                int incX = 145;

                                explosiones.RemoveAt(i);
                                contBUno = 0;
                                if ((y + 3 >= yExplo + 10 && y + 3 <= yExplo + incY) && (x >= xExplo + 10 && x <= xExplo + incX))
                                {
                                    this.Close();
                                }

                                /*if (!((y + 3 >= yExplo && y + 3 <= yExplo + (incY/2)) && (x >= xExplo && x <= xExplo + (incX/2) - 3)))
                                 *  if (!((y + 3 >= yExplo && y + 3 <= yExplo + (incY/2)) && (x >= xExplo + (incX/2) && x <= xExplo + incX)))
                                 *      if (!((y + 3 >= yExplo + (incY/2) && y + 3 <= yExplo + incY) && (x >= xExplo && x <= xExplo + (incX / 2) + 3)))*/
                                if ((y2 + 3 >= yExplo && y2 + 3 <= yExplo + incY) && (x2 >= xExplo && x2 <= xExplo + incX))
                                {
                                    this.Close();
                                }
                            }
                        }
                        else
                        {
                            if (explosiones[i].tipo == 2)
                            {
                                if (contBUno < 30)
                                {
                                    xExplo = explosiones[i].x - 60;
                                    yExplo = explosiones[i].y - 80;

                                    g.DrawImage(explosiones[i].getImage(), explosiones[i].x, explosiones[i].y);
                                    for (int w = 0; w < bombas.Count; w++)
                                    {
                                        if (bombas[w].x == explosiones[i].x + 65 && bombas[w].y == explosiones[i].y + 65)
                                        {
                                            bombas.RemoveAt(w);
                                        }
                                    }

                                    contBUno++;
                                }
                                else
                                {
                                    int incY = 310;
                                    int incX = 290;

                                    explosiones.RemoveAt(i);
                                    contBUno = 0;

                                    if ((y + 3 >= yExplo + 20 && y + 3 <= yExplo + incY) && (x >= xExplo + 20 && x <= xExplo + incX))
                                    {
                                        this.Close();
                                    }

                                    /*if (!((y + 3 >= yExplo && y + 3 <= yExplo + (incY/2)) && (x >= xExplo && x <= xExplo + (incX/2) - 3)))
                                     *  if (!((y + 3 >= yExplo && y + 3 <= yExplo + (incY/2)) && (x >= xExplo + (incX/2) && x <= xExplo + incX)))
                                     *      if (!((y + 3 >= yExplo + (incY/2) && y + 3 <= yExplo + incY) && (x >= xExplo && x <= xExplo + (incX / 2) + 3)))*/
                                    if ((y + 3 >= yExplo + 20 && y + 3 <= yExplo + incY) && (x >= xExplo + 20 && x <= xExplo + incX))
                                    {
                                        this.Close();
                                    }
                                }
                            }
                            else
                            {
                                if (explosiones[i].tipo == 3)
                                {
                                    if (contBDos < 30)
                                    {
                                        xExplo = explosiones[i].x;
                                        yExplo = explosiones[i].y;

                                        g.DrawImage(explosiones[i].getImage(), explosiones[i].x, explosiones[i].y);
                                        for (int w = 0; w < bombas.Count; w++)
                                        {
                                            if (bombas[w].x == explosiones[i].x + 45 && bombas[w].y == explosiones[i].y + 45)
                                            {
                                                bombas.RemoveAt(w);
                                            }
                                        }
                                        contBDos++;
                                    }
                                    else
                                    {
                                        int incY = 155;
                                        int incX = 145;

                                        explosiones.RemoveAt(i);
                                        contBDos = 0;
                                        if ((y + 3 >= yExplo + 10 && y + 3 <= yExplo + incY) && (x >= xExplo + 10 && x <= xExplo + incX))
                                        {
                                            this.Close();
                                        }

                                        /*if (!((y + 3 >= yExplo && y + 3 <= yExplo + (incY/2)) && (x >= xExplo && x <= xExplo + (incX/2) - 3)))
                                         *  if (!((y + 3 >= yExplo && y + 3 <= yExplo + (incY/2)) && (x >= xExplo + (incX/2) && x <= xExplo + incX)))
                                         *      if (!((y + 3 >= yExplo + (incY/2) && y + 3 <= yExplo + incY) && (x >= xExplo && x <= xExplo + (incX / 2) + 3)))*/
                                        if ((y2 + 3 >= yExplo && y2 + 3 <= yExplo + incY) && (x2 >= xExplo && x2 <= xExplo + incX))
                                        {
                                            this.Close();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (b == 0)
            {
                for (int i = 0; i < bloques.Count; i++)
                {
                    if (bloques[i].tipo == 1)
                    {
                        Colision colision = new Colision();
                        //xes.Add(bloques[i].x - 25);
                        //yes.Add(bloques[i].y - 43);
                        colision.x    = bloques[i].x - 25;
                        colision.y    = bloques[i].y - 43;
                        colision.tipo = 1;
                        colisiones.Add(colision);
                    }
                }
                b = 1;
            }

            for (int i = 0; i < bloques.Count; i++)
            {
                if (bloques[i].tipo == 0)
                {
                    g.DrawImage(bloques[i].concreto, bloques[i].x, bloques[i].y);
                }
                if (bloques[i].tipo == 1)
                {
                    g.DrawImage(bloques[i].ladrillo, bloques[i].x, bloques[i].y);
                }
            }
        }