protected GameObject(MatrixCoords topLeft, char[,] body)
        {
            this.TopLeft = topLeft;

            int imageRows = body.GetLength(0);
            int imageCols = body.GetLength(1);

            this.body = this.CopyBodyMatrix(body);

            this.IsDestroyed = false;
        }
        public void EnqueueForRendering(IRenderable obj)
        {
            char[,] objImage = obj.GetImage();

            int imageRows = objImage.GetLength(0);
            int imageCols = objImage.GetLength(1);

            MatrixCoords objTopLeft = obj.GetTopLeft();

            int lastRow = Math.Min(objTopLeft.Row + imageRows, this.renderContextMatrixRows);
            int lastCol = Math.Min(objTopLeft.Col + imageCols, this.renderContextMatrixCols);

            for (int row = obj.GetTopLeft().Row; row < lastRow; row++)
            {
                for (int col = obj.GetTopLeft().Col; col < lastCol; col++)
                {
                    if (row >= 0 && row < renderContextMatrixRows &&
                        col >= 0 && col < renderContextMatrixCols)
                    {
                        renderContextMatrix[row, col] = objImage[row - obj.GetTopLeft().Row, col - obj.GetTopLeft().Col];
                    }
                }
            }
        }
Beispiel #3
0
 public Missle(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, new char[, ] {
     { '^' }
 }, speed)
 {
 }
 public MeteoriteBall(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, speed)
 {
 }
        private static void HandleMovingWithStaticCollisions(List<MovingObject> movingObjects, List<GameObject> staticObjects)
        {
            foreach (var movingObject in movingObjects)
            {
                int verticalIndex = VerticalCollisionIndex(movingObject, staticObjects);
                int horizontalIndex = HorizontalCollisionIndex(movingObject, staticObjects);

                MatrixCoords movingCollisionForceDirection = new MatrixCoords(0, 0);

                if (verticalIndex != -1)
                {
                    movingCollisionForceDirection.Row = -movingObject.Speed.Row;
                    staticObjects[verticalIndex].RespondToCollision(
                        new CollisionData(new MatrixCoords(movingObject.Speed.Row, 0),
                            movingObject.GetCollisionGroupString())
                            );
                }

                if (horizontalIndex != -1)
                {
                    movingCollisionForceDirection.Col = -movingObject.Speed.Col;
                    staticObjects[horizontalIndex].RespondToCollision(
                        new CollisionData(new MatrixCoords(0, movingObject.Speed.Col),
                            movingObject.GetCollisionGroupString())
                            );
                }

                int diagonalIndex = -1;
                if (horizontalIndex == -1 && verticalIndex == -1)
                {
                    diagonalIndex = DiagonalCollisionIndex(movingObject, staticObjects);
                    if (diagonalIndex != -1)
                    {
                        movingCollisionForceDirection.Row = -movingObject.Speed.Row;
                        movingCollisionForceDirection.Col = -movingObject.Speed.Col;

                        staticObjects[diagonalIndex].RespondToCollision(
                        new CollisionData(new MatrixCoords(movingObject.Speed.Row, 0),
                            movingObject.GetCollisionGroupString())
                            );
                    }
                }

                List<string> hitByMovingCollisionGroups = new List<string>();

                if(verticalIndex != -1)
                {
                    hitByMovingCollisionGroups.Add(staticObjects[verticalIndex].GetCollisionGroupString());
                }

                if(horizontalIndex != -1)
                {
                    hitByMovingCollisionGroups.Add(staticObjects[horizontalIndex].GetCollisionGroupString());
                }

                if(diagonalIndex != -1)
                {
                    hitByMovingCollisionGroups.Add(staticObjects[diagonalIndex].GetCollisionGroupString());
                }

                if (verticalIndex != -1 || horizontalIndex != -1 || diagonalIndex != -1)
                {
                    movingObject.RespondToCollision(
                        new CollisionData(movingCollisionForceDirection,
                            hitByMovingCollisionGroups)
                            );
                }
            }
        }
 public UnstoppableBall(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, speed)
 {
     this.body[0, 0] = UnstoppableBall.Symbol;
 }
Beispiel #7
0
 public Ball(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, new char[,] { { 'o' } }, speed)
 {
 }
Beispiel #8
0
 public Gift(MatrixCoords topLeft)
     : base(topLeft, new char[, ] {
     { Symbol }
 }, new MatrixCoords(1, 0))
 {
 }
 public ExplodingBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
     this.body[0, 0] = ExplodingBlock.Symbol;
 }
 public MovingObject(MatrixCoords topLeft, char[,] body, MatrixCoords speed)
     : base(topLeft, body)
 {
     this.Speed = speed;
 }
 public TrailObject(MatrixCoords topLeft, uint lifetime)
     : base(topLeft, new char[,] { { Symbol } })
 {
     this.lifetime = lifetime;
 }
Beispiel #12
0
 public Racket(MatrixCoords topLeft, int width)
     : base(topLeft, new char[,]{{'='}})
 {
     this.Width = width;
     this.body = GetRacketBody(this.Width);
 }
        private static void HandleMovingWithStaticCollisions(List <MovingObject> movingObjects, List <GameObject> staticObjects)
        {
            foreach (var movingObject in movingObjects)
            {
                int verticalIndex   = VerticalCollisionIndex(movingObject, staticObjects);
                int horizontalIndex = HorizontalCollisionIndex(movingObject, staticObjects);

                MatrixCoords movingCollisionForceDirection = new MatrixCoords(0, 0);

                if (verticalIndex != -1)
                {
                    movingCollisionForceDirection.Row = -movingObject.Speed.Row;
                    staticObjects[verticalIndex].RespondToCollision(
                        new CollisionData(new MatrixCoords(movingObject.Speed.Row, 0),
                                          movingObject.GetCollisionGroupString())
                        );
                }

                if (horizontalIndex != -1)
                {
                    movingCollisionForceDirection.Col = -movingObject.Speed.Col;
                    staticObjects[horizontalIndex].RespondToCollision(
                        new CollisionData(new MatrixCoords(0, movingObject.Speed.Col),
                                          movingObject.GetCollisionGroupString())
                        );
                }

                int diagonalIndex = -1;
                if (horizontalIndex == -1 && verticalIndex == -1)
                {
                    diagonalIndex = DiagonalCollisionIndex(movingObject, staticObjects);
                    if (diagonalIndex != -1)
                    {
                        movingCollisionForceDirection.Row = -movingObject.Speed.Row;
                        movingCollisionForceDirection.Col = -movingObject.Speed.Col;

                        staticObjects[diagonalIndex].RespondToCollision(
                            new CollisionData(new MatrixCoords(movingObject.Speed.Row, 0),
                                              movingObject.GetCollisionGroupString())
                            );
                    }
                }

                List <string> hitByMovingCollisionGroups = new List <string>();

                if (verticalIndex != -1)
                {
                    hitByMovingCollisionGroups.Add(staticObjects[verticalIndex].GetCollisionGroupString());
                }

                if (horizontalIndex != -1)
                {
                    hitByMovingCollisionGroups.Add(staticObjects[horizontalIndex].GetCollisionGroupString());
                }

                if (diagonalIndex != -1)
                {
                    hitByMovingCollisionGroups.Add(staticObjects[diagonalIndex].GetCollisionGroupString());
                }

                if (verticalIndex != -1 || horizontalIndex != -1 || diagonalIndex != -1)
                {
                    movingObject.RespondToCollision(
                        new CollisionData(movingCollisionForceDirection,
                                          hitByMovingCollisionGroups)
                        );
                }
            }
        }
 public ExplodingBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
     this.body[0, 0] = ExplodingBlock.Symbol;
 }
Beispiel #15
0
 public Block(MatrixCoords topLeft)
     : base(topLeft, new char[,] { { '#' } })
 {
 }
 public ImpassableBlock(MatrixCoords upperLeft)
     : base(upperLeft)
 {
     this.body[0, 0] = ImpassableBlock.Symbol;
 }
Beispiel #17
0
 public Gift(MatrixCoords topLeft)
     : base(topLeft, new char[,]{{Symbol}}, new MatrixCoords(1, 0))
 {
 }
Beispiel #18
0
 public MeteoriteBall(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, speed)
 {
 }
Beispiel #19
0
 public IndestructibleBlock(MatrixCoords upperLeft)
     : base(upperLeft)
 {
     this.body[0, 0] = IndestructibleBlock.Symbol;
 }
Beispiel #20
0
 public GiftBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
     this.body[0, 0] = GiftBlock.Symbol;
 }
Beispiel #21
0
 public CollisionData(MatrixCoords collisionForceDirection, string objectCollisionGroupString)
 {
     this.CollisionForceDirection         = collisionForceDirection;
     this.hitObjectsCollisionGroupStrings = new List <string>();
     this.hitObjectsCollisionGroupStrings.Add(objectCollisionGroupString);
 }
Beispiel #22
0
 public Missle(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, new char[,] { { '^' } }, speed)
 {
 }
Beispiel #23
0
        public CollisionData(MatrixCoords collisionForceDirection, List <string> hitObjectsCollisionGroupStrings)
        {
            this.CollisionForceDirection = collisionForceDirection;

            this.hitObjectsCollisionGroupStrings = new List <string>(hitObjectsCollisionGroupStrings);
        }
Beispiel #24
0
 public Block(MatrixCoords topLeft)
     : base(topLeft, new char[, ] {
     { '#' }
 })
 {
 }
Beispiel #25
0
 public Ball(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, new char[, ] {
     { 'o' }
 }, speed)
 {
 }
 public UnstoppableBall(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, speed)
 {
     this.body[0, 0] = UnstoppableBall.Symbol;
 }
Beispiel #27
0
        public override bool Equals(object obj)
        {
            MatrixCoords objAsMatrixCoords = obj as MatrixCoords;

            return(objAsMatrixCoords.Row == this.Row && objAsMatrixCoords.Col == this.Col);
        }
 public IndestructibleBlock(MatrixCoords upperLeft)
     : base(upperLeft)
 {
     this.body[0, 0] = IndestructibleBlock.Symbol;
 }
 public CollisionData(MatrixCoords collisionForceDirection, string objectCollisionGroupString)
 {
     this.CollisionForceDirection = collisionForceDirection;
     this.hitObjectsCollisionGroupStrings = new List<string>();
     this.hitObjectsCollisionGroupStrings.Add(objectCollisionGroupString);
 }
Beispiel #30
0
 public ImpassableBlock(MatrixCoords upperLeft)
     : base(upperLeft)
 {
     this.body[0, 0] = ImpassableBlock.Symbol;
 }
        public CollisionData(MatrixCoords collisionForceDirection, List<string> hitObjectsCollisionGroupStrings)
        {
            this.CollisionForceDirection = collisionForceDirection;

            this.hitObjectsCollisionGroupStrings = new List<string>(hitObjectsCollisionGroupStrings);
        }
Beispiel #32
0
 public GiftBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
     this.body[0, 0] = GiftBlock.Symbol;
 }
 public MovingObject(MatrixCoords topLeft, char[,] body, MatrixCoords speed)
     : base(topLeft, body)
 {
     this.Speed = speed;
 }