Ejemplo n.º 1
0
        public GameObject(Vector2 pos, Vector2 size, Texture2D sprite, Color4 color, Vector2 velocity)
        {
            this.Position = pos;
            this.Size = size;
            this.Sprite = sprite;
            this.Color = color;
            this.Velocity = velocity;

            this.IsSolid = false;
            this.IsDestroyed = false;
        }
Ejemplo n.º 2
0
        public void DrawSprite(Texture2D texture, Vector2 position, Vector2 size, float rotation, Color4 color)
        {
            //Prepare Transforms
            this.shader.Use();

            Matrix4 model =
                Matrix4.CreateScale(size.X, size.Y, 1.0f) *
                Matrix4.CreateTranslation(-0.5f * size.X, -0.5f * size.Y, 0.0f) *
                Matrix4.CreateFromAxisAngle(new Vector3(0.0f, 0.0f, 1.0f), rotation) *
                Matrix4.CreateTranslation(0.5f * size.X, 0.5f * size.Y, 0.0f) *
                Matrix4.CreateTranslation(position.X, position.Y, 0.0f);

            this.shader.SetMatrix4("model", model);
            this.shader.SetVector3("spriteColor", color.R, color.G, color.B);

            GL.ActiveTexture(TextureUnit.Texture0);
            texture.Bind();

            GL.BindVertexArray(this.quadVAO);
            GL.DrawArrays(PrimitiveType.Triangles, 0, 6);
            GL.BindVertexArray(0); //Unbind VAO
        }
Ejemplo n.º 3
0
        public GameLevel(string filePath)
        {
            this.Bricks = new List<GameObject>();
            this.brickTexture = new Texture2D(@"Textures/block.bmp");
            this.solidBrickTexture = new Texture2D(@"Textures/solidblock.bmp");

            if (String.IsNullOrEmpty(filePath) || !File.Exists(filePath))
                throw new FileNotFoundException(String.Format("Could not find level data. ('{0}')", filePath));

            int levelWidth = 0;
            int levelHeight = 0;

            List<int> tileData = new List<int>();

            //Extract level data from text file
            string[] fileLines = File.ReadAllLines(filePath);
            levelHeight = fileLines.Length;

            for (int i = 0; i < fileLines.Length; i++)
            {
                string[] line = fileLines[i].Split(' '); //Row

                if (line.Length > levelWidth)
                    levelWidth = line.Length;

                for (int j = 0; j < line.Length; j++)
                {
                    int data;

                    if (Int32.TryParse(line[j].Trim(), out data))
                        tileData.Add(data);
                }
            }

            this.initLevel(tileData, levelWidth, levelHeight);
        }
Ejemplo n.º 4
0
 public void DrawSprite(Texture2D texture, Vector2 position, Vector2 size, float rotation)
 {
     this.DrawSprite(texture, position, size, rotation, Color.White);
 }
Ejemplo n.º 5
0
 public void DrawSprite(Texture2D texture, Vector2 position, Vector2 size)
 {
     this.DrawSprite(texture, position, size, 0f);
 }
Ejemplo n.º 6
0
 public void DrawSprite(Texture2D texture, Vector2 position)
 {
     this.DrawSprite(texture, position, new Vector2(10, 10));
 }
Ejemplo n.º 7
0
 public BallObject(Vector2 pos, float radius, Vector2 velocity, Texture2D sprite)
     : base(pos, new Vector2(radius * 2, radius * 2), sprite, System.Drawing.Color.Red, velocity)
 {
     this.IsStuck = true;
     this.Radius = radius;
 }
Ejemplo n.º 8
0
        public void Init()
        {
            //Initialize game timer
            this.gameTime = new GameTime();

            //OpenGL Config
            GL.ClearColor(Color.Black);
            //GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            //GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);

            //Initialize our game state
            this.activeState = GameStates.Active;

            //Load Shaders
            Shader shader = new Shader(@"Shaders/vertex.glsl", @"Shaders/fragment.glsl");

            //Configure Shaders
            Matrix4 projection = Matrix4.CreateOrthographic(gameWindow.Width, gameWindow.Height, -1.0f, 1.0f) * Matrix4.CreateTranslation(-1f, -1f, 0f) * Matrix4.CreateScale(1f, -1f, 1f);

            shader.Use();
            shader.SetInteger("image", 0);
            shader.SetMatrix4("proj", projection);

            this.renderer = new SpriteRenderer(shader);

            //Init Game Logic
            this.gameLevels = new List<GameLevel>();
            this.gameLevels.Add(new GameLevel(@"Levels/level_01.level"));
            this.currentLevelIndex = 0;

            Texture2D playerTexture = new Texture2D(@"Textures/paddle.png");
            Vector2 playerSize = new Vector2(100, 20);
            Vector2 playerPos = new Vector2(gameWindow.Width / 2 - playerSize.X / 2, gameWindow.Height - playerSize.Y);

            //Player
            this.player = new GameObject(playerPos, playerSize, playerTexture, Color.White, Vector2.Zero);

            //Ball
            float ballRadius = 12.5f;
            this.ball = new BallObject(
                new Vector2(player.Position.X + (playerSize.X / 2 - ballRadius), player.Position.Y - ballRadius * 2f - 1),
                ballRadius, new Vector2(RNG.NextFloat(-250.0f, 250.0f), -350f), new Texture2D(@"Textures/ball.png"));
        }