Пример #1
0
        public override bool CheckCollision(GameObject two, out Directions direction, out Vector2 diffVector)
        {
            direction = Directions.Up; //Default direction value
            diffVector = Vector2.Zero; //Default vector value

            //Get the center point circle
            Vector2 center = new Vector2(this.Position.X + this.Radius, this.Position.Y + this.Radius);

            //Calculate AABB info (center, half-extents)
            Vector2 aabbHalf = new Vector2(two.Size.X / 2, two.Size.Y / 2);
            Vector2 aabbCenter = two.Position + aabbHalf;

            //Get difference vector between both centers
            Vector2 diff = center - aabbCenter;
            Vector2 clamped = new Vector2(clamp(diff.X, -aabbHalf.X, aabbHalf.X), clamp(diff.Y, -aabbHalf.Y, aabbHalf.Y));

            //Add clamped value to AABB Center and get the value of point closest to cirlce
            Vector2 closest = aabbCenter + clamped;

            diff = closest - center;

            if (diff.Length <= this.Radius)
            {
                direction = VectorDirection(diff);
                diffVector = diff;
                return true;
            }

            return false;
        }
Пример #2
0
        public virtual bool CheckCollision(GameObject two)
        {
            //Check X-Collision
            bool collisionX = this.Position.X + this.Size.X >= two.Position.X &&
                two.Position.X + two.Size.X >= this.Position.X;

            //Check Y-Collision
            bool collisionY = this.Position.Y + this.Size.Y >= two.Position.Y &&
                two.Position.Y + two.Size.Y >= this.Position.Y;

            return collisionX && collisionY;
        }
Пример #3
0
 public virtual bool CheckCollision(GameObject two, out Directions direction, out Vector2 diffVector)
 {
     direction = Directions.Up; //Default direction
     diffVector = Vector2.Zero; //Default vector value
     return this.CheckCollision(two);
 }
Пример #4
0
        private void initLevel(List<int> tileData, int levelWidth, int levelHeight)
        {
            //Process TileData and transfer it to GameObject Bricks
            int index = 0;
            for (int y = 0; y < levelHeight; y++)
            {
                for (int x = 0; x < levelWidth && index < tileData.Count; x++, index++)
                {
                    if (tileData[index] == 0) //Empty Space
                        continue;

                    //Calculate Brick Dimensions
                    float height = 32.0f;
                    float width = 800 / (float)levelWidth;
                    GameObject brick = new GameObject()
                    {
                        Position = new Vector2(width * x, height * y),
                        Color = this.getBrickColor(tileData[index]),
                        Size = new Vector2(width, height),
                        Rotation = 0f,

                        IsSolid = (tileData[index] == 1),
                        IsDestroyed = false,

                        Velocity = Vector2.Zero,
                    };

                    if (brick.IsSolid)
                        brick.Sprite = solidBrickTexture;
                    else
                        brick.Sprite = brickTexture;

                    this.Bricks.Add(brick);
                }
            }
        }
Пример #5
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"));
        }