コード例 #1
0
ファイル: TelaJogo.cs プロジェクト: RenatoDrigoVieira/Jogo
        //Este é o evento que detecta quando o jogador apertou uma tecla
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right)
            {
                vaiparadireita = true;
                parado         = false;
            }

            if (e.KeyCode == Keys.Left)
            {
                vaiparaesquerda = true;
                parado          = false;
            }
            //esse atirar == false é o q limita a frequencia de tiro do jogo
            if (e.KeyCode == Keys.Space && atirar == false)
            {
                atirar = true;
                frequenciatiro.Start();
            }
            if (e.KeyCode == Keys.Up)
            {
                //o jogador só pode pular se ele não estiver pulando
                //A variavel alturadopulo sera melhor explicada no timer de pulo
                if (pular == false && alturadopulo >= 0)
                {
                    pular = true;
                    Pulo.Start();
                }
            }
        }
コード例 #2
0
    public void movimentacao(Vector3 direcaoAlvo)
    {
        if (pulo == null)
        {
            pulo = new Pulo(caracMov.caracPulo, elementos);
        }

        pulo.NaoEstouPulando();
        targetSpeed = Mathf.Min(direcaoAlvo.magnitude, 1.0f);


        if (elementos.transform.tag == "Player")
        {
            targetSpeed *= (Input.GetButton("Run")) ?
                           caracMov.velocidadeCorrendo :
                           caracMov.velocidadeAndando;
        }
        else
        {
            targetSpeed *= caracMov.velocidadeAndando;
        }

        if (direcaoAlvo != Vector3.zero)
        {
            if (elementos.controle.velocity.magnitude < caracMov.velocidadeAndando /*&& VerificaChao.noChao(elementos.controle, elementos.transform)*/)
            {
                direcaoMovimento = direcaoAlvo.normalized;
            }
            else
            {
                direcaoMovimento = Vector3.RotateTowards(direcaoMovimento, direcaoAlvo, 500 * Mathf.Deg2Rad * Time.deltaTime, 1000);

                direcaoMovimento = direcaoMovimento.normalized;
            }
        }
        else
        {
            direcaoMovimento = Vector3.Lerp(direcaoMovimento, Vector3.zero, 1);
        }


        if (direcaoAlvo.magnitude > 0.3f)
        {
            elementos.transform.rotation = Quaternion.LookRotation(new Vector3(direcaoMovimento.x, 0, direcaoMovimento.z));
        }

        //Fundamentador();

        elementos.controle.Move((direcaoMovimento * targetSpeed + velocidadeDescendo * Vector3.down) * Time.deltaTime);
        elementos.animador.AnimaAndar(targetSpeed);
    }
コード例 #3
0
 public MovimentacaoBasica(CaracteristicasDeMovimentacao caracMov, ElementosDeMovimentacao elementos)
 {
     this.caracMov  = caracMov;
     this.elementos = elementos;
     pulo           = new Pulo(caracMov.caracPulo, elementos);
 }
コード例 #4
0
ファイル: TelaJogo.cs プロジェクト: RenatoDrigoVieira/Jogo
        private void vidaescore_Tick(object sender, EventArgs e)
        {
            Bitmap cidade = Properties.Resources.Cidade;

            //aqui existe um label que mostra a vida do personagem
            vida.Text = "Vida: " + Convert.ToString(barradevida.Width / 3);
            //outro label que mostra os monstros mortos
            monstrosM.Text = "Monstros Mortos: " + Convert.ToString(monstrosmortos);

            if (monstrosmortos == 10 && trocademapa == 0)
            {
                trocademapa++;
                this.BackgroundImage = Properties.Resources.Cidade;
            }
            if (monstrosmortos == 20 && trocademapa == 1)
            {
                trocademapa++;
                this.BackgroundImage = Properties.Resources.neve;
            }
            //se a barra de vida zerar então o jogo acaba e aparece outra tela dizendo que voce morreu
            if (barradevida.Width == 0)
            {
                i += 1;
            }
            if (barradevida.Width == 0 && i == 1)
            {
                TelaMorte morte = new TelaMorte();
                Movimentos.Stop();
                tiros.Stop();
                frequenciatiro.Stop();
                Pulo.Stop();
                Monstros.Stop();
                SpawnMonstros.Stop();
                Colisoes.Stop();
                vidaescore.Stop();
                sons.controls.stop();
                tiro.controls.stop();
                highscore.Stop();
                monstrosmortos  = 0;
                monstroscriados = 0;
                vaiparadireita  = false;
                vaiparaesquerda = false;
                parado          = true;
                atirar          = false;
                pular           = false;
                if (File.Exists("pontuacao.txt"))
                {
                    bool     existe = false;
                    string[] linhas = File.ReadAllLines("pontuacao.txt");
                    for (int i = 0; i < linhas.Length; i++)
                    {
                        if (linhas[i].Contains(Variaveis.login))
                        {
                            existe = true;
                            string[] dados = linhas[i].Split('|');
                            if (Variaveis.highscore > Convert.ToInt32(dados[1]))
                            {
                                dados[1]  = Convert.ToString(Variaveis.highscore);
                                linhas[i] = dados[0] + '|' + dados[1];
                                existe    = true;
                                string texto = "";
                                for (int j = 0; j < linhas.Length; j++)
                                {
                                    texto += linhas[j] + Environment.NewLine;
                                }
                                File.WriteAllText("pontuacao.txt", texto);
                                MessageBox.Show("Pontuação Salva");
                            }
                        }
                    }
                    if (existe == false)
                    {
                        File.AppendAllText("pontuacao.txt", Variaveis.login + "|" +
                                           Convert.ToString(Variaveis.highscore) + Environment.NewLine);
                    }
                }
                else
                {
                    File.AppendAllText("pontuacao.txt", Variaveis.login + "|" +
                                       Convert.ToString(Variaveis.highscore) + Environment.NewLine);
                }
                this.Hide();
                morte.ShowDialog();
                i = 0;
                this.Close();
            }
        }
コード例 #5
0
ファイル: TelaJogo.cs プロジェクト: RenatoDrigoVieira/Jogo
        public void Colisoes_Tick(object sender, EventArgs e)
        {
            #region colisão tiro/monstro
            //aqui são utilizados dois foreachs com duas variaveis, y e j, quando y for uma bala e j for um monstro e eles se encostarem
            //essas duas picturebox são removidas
            foreach (Control y in this.Controls)
            {
                foreach (Control j in this.Controls)
                {
                    if (y is PictureBox && (y.Tag == "bulletD" || y.Tag == "bulletE"))
                    {
                        if (j is Monstros && (j.Tag == "monstros" || j.Tag == "monstrosinvertidos" || j.Tag == "mumia" || j.Tag == "mumiainvertida"))
                        {
                            //detecta se teve colisão entre as picturebox
                            if (y.Bounds.IntersectsWith(j.Bounds))
                            {
                                int dano = 1;
                                ((Monstros)this.Controls.Find(j.Name, false)[0]).Vida -= dano;
                                if (((Monstros)this.Controls.Find(j.Name, false)[0]).Vida == 0)
                                {
                                    monstrosmortos++;
                                    monstroscriados--;
                                    Random coracaodevida = new Random();
                                    int    a             = coracaodevida.Next(0, 5);
                                    if (a == 2)
                                    {
                                        PictureBox coracao = new PictureBox();
                                        Bitmap     imagem;
                                        imagem            = Properties.Resources.coracao;
                                        coracao.Image     = imagem;
                                        coracao.Size      = new Size(51, 51);
                                        coracao.SizeMode  = PictureBoxSizeMode.StretchImage;
                                        coracao.Tag       = "coracao";
                                        coracao.Location  = ((Monstros)this.Controls.Find(j.Name, false)[0]).Location;
                                        coracao.BackColor = Color.Transparent;
                                        this.Controls.Add(coracao);
                                        coracao.BringToFront();
                                    }
                                    this.Controls.Remove(j);
                                }
                                this.Controls.Remove(y);
                            }
                        }
                    }
                }
            }
            #endregion
            #region colisão jogador/monstro
            //essa parte do programa é o que faz o jogador tomar dano, e o monstro virar para o outro lado quando encosta no jogador
            foreach (Control y in this.Controls)
            {
                foreach (Control j in this.Controls)
                {
                    if (y is PictureBox && y.Tag == "jogador")
                    {
                        //perceba que aqui é se a tag do for "monstros",e mais abaixo é se a tag for "monstrosinvertidos"
                        //isso foi feito pois se o monstro esta vindo da direita e ele colide com o personagem,ele vira para a esquerda e vice-versa
                        if (j is Monstros && (j.Tag == "monstros"))
                        {
                            if (y.Bounds.IntersectsWith(j.Bounds))
                            {
                                if (jogador.Top > 535)
                                {
                                    Bitmap imagem;
                                    imagem = Properties.Resources.monstroinvertido;
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Image = imagem;
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Tag   = "monstrosinvertidos";
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Left  = j.Left + 15;
                                    barradevida.Width = barradevida.Width - 12;
                                }
                            }
                        }
                        if (j is Monstros && (j.Tag == "monstrosinvertidos"))
                        {
                            if (y.Bounds.IntersectsWith(j.Bounds))
                            {
                                if (jogador.Top > 535)
                                {
                                    Bitmap imagem;
                                    imagem = Properties.Resources.monstro;
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Image = imagem;
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Tag   = "monstros";
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Left  = j.Left - 15;

                                    barradevida.Width = barradevida.Width - 12;
                                }
                            }
                        }
                        if (j is Monstros && (j.Tag == "mumia"))
                        {
                            if (y.Bounds.IntersectsWith(j.Bounds))
                            {
                                if (jogador.Top > 535)
                                {
                                    Bitmap imagem;
                                    imagem = Properties.Resources.mumia;
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Image = imagem;
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Tag   = "mumiainvertida";
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Left  = j.Left + 15;

                                    barradevida.Width = barradevida.Width - 24;
                                }
                            }
                        }
                        if (j is Monstros && (j.Tag == "mumiainvertida"))
                        {
                            if (y.Bounds.IntersectsWith(j.Bounds))
                            {
                                if (jogador.Top > 535)
                                {
                                    Bitmap imagem;
                                    imagem = Properties.Resources.mumia_invertida;
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Image = imagem;
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Tag   = "mumia";
                                    ((Monstros)this.Controls.Find(j.Name, false)[0]).Left  = j.Left - 15;

                                    barradevida.Width = barradevida.Width - 24;
                                }
                            }
                        }
                    }
                }
            }
            #endregion
            #region colisão tiro/parede invisivel
            //existe duas paredes invisiveis nas bordas da tela, se o tiro encostar nessas paredes ele some
            foreach (Control y in this.Controls)
            {
                foreach (Control j in this.Controls)
                {
                    if (y is PictureBox && (y.Tag == "bulletD" || y.Tag == "bulletE"))
                    {
                        if (j is PictureBox && (j.Tag == "Parede"))
                        {
                            if (y.Bounds.IntersectsWith(j.Bounds))
                            {
                                this.Controls.Remove(y);
                            }
                        }
                    }
                }
            }
            #endregion
            #region personagem/chao
            //aqui,se o personagem estiver pulando e começar a cair, ele só para de cair quando encostar no chão
            foreach (Control y in this.Controls)
            {
                if (y is PictureBox && (y.Tag == "plataforma" || y.Tag == "chao"))
                {
                    if (jogador.Bounds.IntersectsWith(y.Bounds) == true)
                    {
                        if (pular == false)
                        {
                            //a altura do pulo é definida para 40 novamente e assim ele pode pular novamente
                            alturadopulo = 40;
                            //deixa o jogador exatamente em cima da picturebox do chão
                            jogador.Top = y.Top - jogador.Height;
                            //para o timer do pulo
                            Pulo.Stop();
                        }
                    }
                }
            }
            #endregion
            #region personagem/vida
            foreach (Control y in this.Controls)
            {
                foreach (Control j in this.Controls)
                {
                    if (y is PictureBox && y.Tag == "jogador")
                    {
                        if (j is PictureBox && (j.Tag == "coracao"))
                        {
                            if (barradevida.Width <= 270)
                            {
                                if (y.Bounds.IntersectsWith(j.Bounds))
                                {
                                    barradevida.Width += 30;
                                    this.Controls.Remove(j);
                                }
                            }
                        }
                    }
                }
            }
            #endregion
            #region monstros saindo da tela
            foreach (Control y in this.Controls)
            {
                if (y is Monstros && (y.Tag == "monstros" || y.Tag == "mumia"))
                {
                    if (((Monstros)this.Controls.Find(y.Name, false)[0]).Left < 0)
                    {
                        this.Controls.Remove(y);
                        monstroscriados--;
                    }
                }
                if (y is Monstros && (y.Tag == "monstrosinvertidos" || y.Tag == "mumiainvertida"))
                {
                    if (((Monstros)this.Controls.Find(y.Name, false)[0]).Left > 1024)
                    {
                        this.Controls.Remove(y);
                        monstroscriados--;
                    }
                }
            }
            #endregion
            #region personagem pulando/monstro
            foreach (Control y in this.Controls)
            {
                foreach (Control j in this.Controls)
                {
                    if (y is PictureBox && y.Tag == "jogador")
                    {
                        //perceba que aqui é se a tag do for "monstros",e mais abaixo é se a tag for "monstrosinvertidos"
                        //isso foi feito pois se o monstro esta vindo da direita e ele colide com o personagem,ele vira para a esquerda e vice-versa
                        if (j is Monstros && (j.Tag == "monstros" || j.Tag == "monstrosinvertidos" || j.Tag == "mumia" || j.Tag == "mumiainvertida"))
                        {
                            if (jogador.Top < 535)
                            {
                                if (y.Bounds.IntersectsWith(j.Bounds))
                                {
                                    this.Controls.Remove(j);
                                    barradevida.Width = barradevida.Width - 30;
                                    monstroscriados--;
                                }
                            }
                        }
                    }
                }
            }
            #endregion
        }