예제 #1
0
 protected override void OnRenderFrame(FrameEventArgs e)
 {
     GL.ClearColor(SColor.CornflowerBlue);
     GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
     if (Alive)
     {
         Graphics.Draw(Player.image, Player.transform);
         Graphics.Draw(FloorImage, Floor.ToArray());
         Graphics.Draw(CactoImage, Cactos.ToArray());
         Graphics.Draw(HowPlay, HowPlayPos, HowPlay.MeasureSize());
         Graphics.Draw(ScoreText, new Vector2(10, 10), ScoreText.MeasureSize());
     }
     else
     {
         Graphics.Draw(HowPlay, HowPlayPos, HowPlay.MeasureSize());
         Graphics.Draw(ScoreText, new Vector2(400 - ScoreText.MeasureSize().X / 2, HowPlayPos.Y + 100), ScoreText.MeasureSize());
     }
     Context.SwapBuffers();
 }
예제 #2
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.ClearColor(Color.CornflowerBlue);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            render.Draw(renderText, new Vector3(50, 50, 0), renderText.MeasureSize());
            render.Draw(renderColor, new Vector2(200, 200), new Vector2(100, 100));
            render.Draw(renderImage, new RectPosition(new Vector3(400, 200, 0), new Vector2(100, 100)));

            Context.SwapBuffers();
        }
예제 #3
0
    void StartGame()
    {
        Floor             = new List <RectPosition>();
        Cactos            = new List <RectPosition>(12);
        Player.transform  = new RectPosition(new Vector2(300, 540), new Vector2(50, 50));
        Alive             = true;
        Score             = 0;
        Jump              = false;
        OnFloor           = true;
        distLast          = 0;
        HowPlay           = new RenderText("Press any button to jump!", 35, Renderer.LoadFontFromFile("./fonts/Pulsar.otf"));
        HowPlay.TextColor = SColor.Yellow;
        HowPlayPos        = new Vector2(400 - HowPlay.MeasureSize().X / 2, 100);
        ScoreText         = new RenderText(Score.ToString(), 20, Renderer.LoadFontFromFile("./fonts/Pulsar.otf"));


        for (int i = 0; i < 20; i++)
        {
            Floor.Add(new RectPosition(new Vector2(i * 50, 590), new Vector2(50, 50)));
        }
    }
예제 #4
0
    protected override void OnUpdateFrame(FrameEventArgs e)
    {
        if (Alive)
        {
            Score         += (float)e.Time;
            ScoreText.Text = "Score: " + ((int)Score).ToString();

            if (Jump)
            {
                acel += 0.025f;
            }
            if (Jump == false && Player.transform.position.Y >= 540)
            {
                OnFloor = true;
                acel    = 0;
            }
            if (Jump == true && Player.transform.position.Y > 540 - JumpHeight)
            {
                Player.transform.position.Y -= 10;
            }
            if (Jump == true && Player.transform.position.Y <= 540 - JumpHeight)
            {
                Jump = false;
            }
            if (Jump == false && OnFloor == false)
            {
                Player.transform.position.Y += 4 + acel;
            }



            for (int i = 0; i < Floor.Count; i++)
            {
                var f = Floor[i];
                f.position.X -= velocidade;
                if (f.position.X <= -50)
                {
                    f.position.X = 19 * 50;
                }
                Floor[i] = f;
            }
            distLast += velocidade;

            if (distLast > 250)
            {
                distLast = 0;
                int n = new Random().Next() % 100;
                if (n < 15)
                {
                    Cactos.Add(new RectPosition(new Vector2(850, 540), new Vector2(50, 50)));
                }
                else if (n < 20)
                {
                    Cactos.Add(new RectPosition(new Vector2(850, 540), new Vector2(50, 50)));
                    Cactos.Add(new RectPosition(new Vector2(900, 540), new Vector2(50, 50)));
                    distLast -= 50;
                }
                else if (n < 23)
                {
                    Cactos.Add(new RectPosition(new Vector2(850, 540), new Vector2(50, 50)));
                    Cactos.Add(new RectPosition(new Vector2(900, 540), new Vector2(50, 50)));
                    Cactos.Add(new RectPosition(new Vector2(950, 540), new Vector2(50, 50)));
                    distLast -= 75;
                }
            }

            for (int i = 0; i < Cactos.Count; i++)
            {
                var f = Cactos[i];
                f.position.X -= velocidade;
                if (f.position.X <= -50)
                {
                    Cactos.Remove(f);
                }
                else
                {
                    Cactos[i] = f;
                }
            }


            foreach (var c in Cactos)
            {
                if (RectPosition.Hit(Player.transform, c))
                {
                    HowPlay.Text = "Press any button to restart!\n             You Loose!";
                    Alive        = false;
                    HowPlayPos.Y = 300;
                    HowPlayPos.X = 400 - HowPlay.MeasureSize().X / 2;
                }
            }
        }
    }