Ejemplo n.º 1
0
        public void randomPosition(object source, ElapsedEventArgs e)
        {
            bool foodOcupado = true;
            bool obstOcupado = true;

            while (foodOcupado == true)
            {
                int newValueX = rndNumber.Next(1, fieldSize);
                int newValueY = rndNumber.Next(1, fieldSize);

                if (foodMatrix[newValueX, newValueY] != 1 && obstaclesMatrix[newValueX, newValueY] != 1)
                {
                    Modelo comida = new Modelo();
                    comida.LerFicheiro("..\\..\\loadModelos\\maça.obj");
                    comida.Translacao(newValueX, 0.5, newValueY);
                    foodMatrix[newValueX, newValueY] = 1;
                    Matriz["food"].Add(comida);
                    foodOcupado = false;
                }
            }

            while (obstOcupado == true)
            {
                int newValueX = rndNumber.Next(1, fieldSize);
                int newValueY = rndNumber.Next(1, fieldSize);

                if (obstaclesMatrix[newValueX, newValueY] != 1 && foodMatrix[newValueX, newValueY] != 1)
                {
                    Modelo obstaculo = new Modelo();
                    obstaculo.LerFicheiro("..\\..\\loadModelos\\cubo.obj");
                    obstaculo.Translacao(newValueX, 0.5, newValueY);
                    obstaclesMatrix[newValueX, newValueY] = 1;
                    Matriz["obstaculos"].Add(obstaculo);
                    obstOcupado = false;
                }
            }
        }
Ejemplo n.º 2
0
        private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
        {
            //  Get the OpenGL object.
            OpenGL gl = openGLControl.OpenGL;

            //  Clear the color and depth buffer.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //  Load the identity matrix.
            gl.LoadIdentity();

            gl.Color(1.0, 1.0, 1.0);
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            VT[0].Bind(gl);
            DesenharFundo(gl, true);
            gl.Disable(OpenGL.GL_TEXTURE_2D);



            //Verificar se Existe Colisão
            if (colisao == false && playing == true)
            {
                foreach (Modelo obs in Obstaculo)
                {
                    if (obs.Ymin <= Jogador.Ymax && Jogador.Ymax <= obs.Ymax && Jogador.pos1 == obs.pos1 ||
                        obs.Ymin <= Jogador.Ymin && Jogador.Ymin <= obs.Ymax && Jogador.pos1 == obs.pos1)
                    {
                        colisao = true;
                    }
                }
            }

            //Verificar Melhor Pontuação
            if (MelhorPontuacao < Pontuacao)
            {
                MelhorPontuacao = Pontuacao;
            }

            //Perdeu
            if (colisao == true && playing == true)
            {
                playing = false;

                if (PontuacaoFinal == false)
                {
                    txtStart.Visible = true;
                    txtStart.Text    = "Pressione a tecla ESPAÇO para recomeçar";

                    TeclasText.Visible = true;


                    txtPontFinal.Visible = true;
                    txtPontFinal.Text    = "A sua pontuação foi: " + Pontuacao;
                    PontuacaoFinal       = true;

                    Pontuacao  = 0;
                    Velocidade = 0.8f;
                }

                //Gravar Melhor Resultado em Ficheiro
                if (MelhorPontuacao > MelhorResultadoTxt)
                {
                    StreamWriter NewBestScore = new StreamWriter("..\\..\\..\\files\\bestscore.txt");
                    NewBestScore.WriteLine(MelhorPontuacao);
                    NewBestScore.Close();
                }
            }


            //Desenhar Cones

            foreach (Modelo M in Obstaculo)
            {
                M.Desenhar(gl, M.Color, false);
            }


            //Desenhar Bola
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            VT[1].Bind(gl);
            foreach (Modelo M in LModelos)
            {
                M.Desenhar(gl, M.Color, true);
            }
            gl.Disable(OpenGL.GL_TEXTURE_2D);

            //Alterar Resultado
            txtPontuacao.Text = "Pontuação: " + Pontuacao;
            txtBestScore.Text = "Melhor Resultado: " + MelhorPontuacao;

            //Adicionar Obstáculos às Pistas(Cone)
            if (playing == true && Obstaculo.Count() < 3)
            {
                Random randNobjects  = new Random();
                int    indexNobjects = randNobjects.Next(1, 2);

                for (int i = 0; i < indexNobjects; i++)
                {
                    //Determina a Pista
                    Random rand  = new Random();
                    int    index = rand.Next(XPista.Length);

                    //Determina a Cor
                    Random Cor = new Random();
                    int    c   = Cor.Next(0, 3);

                    Modelo X = (Modelo)ObstaculoObj.Clone();
                    X.Posicionar(XPista[index], YPista, 0, c);
                    Obstaculo.Add(X);
                }

                //Distancia entre cones
                YPista += 8;
            }

            //-----------------------------------------------------
            if (playing == true)
            {
                //Aumentar Pontuação
                Pontuacao++;

                //Movimentar Jogador
                Jogador.Movimentar(0, Velocidade, 0);

                //Movimentar Câmera
                YCamera    += Velocidade;
                YViewPoint += Velocidade;

                //Apagar Objetos
                for (int i = 0; i < Obstaculo.Count(); i++)
                {
                    if (Obstaculo[i].Ymax < Jogador.Ymin - 5)
                    {
                        Obstaculo.Remove(Obstaculo[i]);
                    }
                }
            }

            //Movimentar Câmera
            MoveCamera();

            //Aumentar Dificuldade
            if (Pontuacao == 100)
            {
                Velocidade = 1.0f;
            }
            else if (Pontuacao == 200)
            {
                Velocidade = 1.2f;
            }
            else if (Pontuacao == 400)
            {
                Velocidade = 1.4f;
            }
            else if (Pontuacao == 600)
            {
                Velocidade = 1.5f;
            }
            else if (Pontuacao == 1000)
            {
                Velocidade = 1.7f;
            }
            else if (Pontuacao == 1300)
            {
                Velocidade = 1.8f;
            }
            else if (Pontuacao == 1500)
            {
                Velocidade = 2.0f;
            }
        }
Ejemplo n.º 3
0
        public SharpGLForm()
        {
            InitializeComponent();

            TextArray = new Texture[5];

            gl = openGLControl.OpenGL;

            for (int i = 1; i <= 4; i++)
            {
                TextArray[i - 1] = new Texture();
                TextArray[i - 1].Create(gl, "..\\..\\Texturas\\Text" + i + ".bmp");
            }

            TextArray[4] = new Texture();
            TextArray[4].Create(gl, "..\\..\\Texturas\\Terrain.bmp");

            this.KeyDown += new KeyEventHandler(keyPress);

            TX                = 0;
            TY                = 0;
            TZ                = 0;
            Escala            = 1.0;
            Incremento_Escala = 0.1;
            Sentido           = 2;
            Em_Movimento      = true;

            Cobra            = new Modelo();
            cobraLength      = 1;
            CobraFull        = new List <Modelo>();
            directionHistory = new List <int>();
            directionHistory.Add(1);

            direcaoCobra = 1;   //1: X+  2: Z+  3: X-  4: Z-

            LModelos   = new List <Modelo>();
            Comida     = new List <Modelo>();
            Obstaculos = new List <Modelo>();

            Cobra.LerFicheiro("..\\..\\loadModelos\\cubo.obj");
            Cobra.Translacao(0, 0.5f, 0);

            fieldSize = 100;

            currentPont = 0;
            maxPont     = 0;

            pontLabel.TextChanged += new System.EventHandler(this.updateScreenPont);

            foodMatrix      = new int[fieldSize, fieldSize];
            obstaclesMatrix = new int[fieldSize, fieldSize];

            timer          = new System.Timers.Timer();
            timer.Elapsed += new ElapsedEventHandler(timerMovement);
            timer.Interval = 100;
            timer.Enabled  = true;

            extrasTimer           = new System.Timers.Timer();
            extrasTimer.Elapsed  += new ElapsedEventHandler(randomPosition);
            extrasTimer.Interval  = 6000;
            extrasTimer.Enabled   = true;
            extrasTimer.AutoReset = true;

            rotatetimer          = new System.Timers.Timer();
            rotatetimer.Elapsed += new ElapsedEventHandler(rotateFunction);
            rotatetimer.Interval = 100;
            rotatetimer.Enabled  = true;

            Matriz               = new Dictionary <string, List <Modelo> >();
            Matriz["food"]       = new List <Modelo>();
            Matriz["obstaculos"] = new List <Modelo>();

            rndNumber = new Random();
        }