Exemplo n.º 1
0
        public Vector2 Move(GameTime gameTime, int windowWidth)
        {
            if (!this.IsStuck)
            {
                //Update Position based on the ball's velocity
                this.Position.X += this.Velocity.X * (float)gameTime.ElapsedTime.TotalSeconds;
                this.Position.Y += this.Velocity.Y * (float)gameTime.ElapsedTime.TotalSeconds;

                //Check screen bounds
                if (this.Position.X <= 0.0f)
                {
                    this.Velocity.X *= -1; //Reflect
                    this.Position.X = 0.0f; //Set
                }
                else if (this.Position.X + this.Size.X >= windowWidth)
                {
                    this.Velocity.X *= -1; //Reflect
                    this.Position.X = windowWidth - this.Size.X; //Set
                }

                if (this.Position.Y <= 0.0f)
                {
                    this.Velocity.Y *= -1; //Reflect
                    this.Position.Y = 0.0f; //Set
                }
            }

            return this.Position;
        }
Exemplo n.º 2
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"));
        }
Exemplo n.º 3
0
        public virtual void UpdateFrame(GameTime gameTime)
        {
            gameTime.Update();

            this.processInput();
            this.ball.Move(gameTime, gameWindow.Width);

            this.checkCollisions();
        }
Exemplo n.º 4
0
        public virtual void RenderFrame(GameTime gameTime)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);

            CurrentLevel.Draw(renderer);
            player.Draw(renderer);
            ball.Draw(renderer);

            this.gameWindow.SwapBuffers();
        }