Beispiel #1
0
        public ByteMap CombineWith(ByteMap otherByteMap)
        {
            Byte[,] newBytes;
            Byte[,] otherBytes;
            ByteMap newByteMap;

            if ((this.Width != otherByteMap.Width) || (this.Height != otherByteMap.Height))
            {
                return(null);
            }

            newByteMap = new ByteMap(width, height);

            newBytes   = newByteMap.Bytes;
            otherBytes = otherByteMap.Bytes;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    newBytes[i, j] = (byte)(otherBytes[i, j] | map[i, j]);
                }
            }

            return(newByteMap);
        }
Beispiel #2
0
        public Terrain(int width, int height)
        {
            bool test = false;

            this.width  = width;
            this.height = height;

            tiles        = new Tile[this.width, this.height];
            collisionMap = new ByteMap(this.width, this.height);

            if (test)
            {
                int n = 0;

                for (int i = 0; i < tiles.GetLength(0); i++)
                {
                    for (int j = 0; j < tiles.GetLength(1); j++)
                    {
                        switch (n % 4)
                        {
                        case 0:
                            tiles[i, j] = new FloorTile();
                            break;

                        case 1:
                            tiles[i, j] = new LightRubblePile();
                            break;

                        case 2:
                            tiles[i, j] = new MediumRubblePile();
                            break;

                        case 3:
                            tiles[i, j] = new HeavyRubblePile();
                            break;
                        }

                        n++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < tiles.GetLength(0); i++)
                {
                    for (int j = 0; j < tiles.GetLength(1); j++)
                    {
                        tiles[i, j] = new FloorTile();
                    }
                }
            }

            GenerateCollisionMap();
        }
Beispiel #3
0
        public Terrain(int width, int height)
        {
            bool test = false;
            this.width = width;
            this.height = height;

            tiles = new Tile[this.width, this.height];
            collisionMap = new ByteMap(this.width, this.height);

            if (test)
            {
                int n = 0;

                for (int i = 0; i < tiles.GetLength(0); i++)
                {
                    for (int j = 0; j < tiles.GetLength(1); j++)
                    {
                        switch (n % 4)
                        {
                            case 0:
                                tiles[i, j] = new FloorTile();
                                break;

                            case 1:
                                tiles[i, j] = new LightRubblePile();
                                break;

                            case 2:
                                tiles[i, j] = new MediumRubblePile();
                                break;

                            case 3:
                                tiles[i, j] = new HeavyRubblePile();
                                break;
                        }

                        n++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < tiles.GetLength(0); i++)
                {
                    for (int j = 0; j < tiles.GetLength(1); j++)
                    {
                        tiles[i, j] = new FloorTile();
                    }
                }
            }

            GenerateCollisionMap();
        }
Beispiel #4
0
        public ByteMap CombineWith(ByteMap otherByteMap)
        {
            Byte[,] newBytes;
            Byte[,] otherBytes;
            ByteMap newByteMap;

            if ((this.Width != otherByteMap.Width) || (this.Height != otherByteMap.Height))
                return null;

            newByteMap = new ByteMap(width, height);

            newBytes = newByteMap.Bytes;
            otherBytes = otherByteMap.Bytes;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    newBytes[i, j] = (byte) (otherBytes[i, j] | map[i, j]);
                }
            }

            return newByteMap;
        }
Beispiel #5
0
        public override void PerformActions(Action actions)
        {
            float x, y;
            float angle;
            bool  active;
            float prevX;
            float prevY;

            float[] position;
            float[] prevPosition;
            bool    cancelMove = false;

            if (!attached)
            {
                return;
            }

            active = ((actions & Action.ACTIVE) != 0);

            if ((actions & Action.TOGGLE_LIGHT) != 0)
            {
                robot.ToggleLight();
            }

            if ((actions & Action.MOVE_UP) != 0)
            {
                MoveUp();
            }
            if ((actions & Action.MOVE_DOWN) != 0)
            {
                MoveDown();
            }
            if ((actions & Action.MOVE_LEFT) != 0)
            {
                MoveLeft();
            }
            if ((actions & Action.MOVE_RIGHT) != 0)
            {
                MoveRight();
            }

            if ((actions & Action.ROTATE_RIGHT) != 0)
            {
                RotateRight();
            }
            if ((actions & Action.ROTATE_LEFT) != 0)
            {
                RotateLeft();
            }

            if ((actions & Action.TILT_LEFT) != 0)
            {
                tiltLeft = active;
            }
            if ((actions & Action.TILT_RIGHT) != 0)
            {
                tiltRight = active;
            }
            if ((actions & Action.TILT_UP) != 0)
            {
                tiltUp = active;
            }
            if ((actions & Action.TILT_DOWN) != 0)
            {
                tiltDown = active;
            }

            prevPosition = GetPosition();
            prevX        = prevPosition[0];
            prevY        = prevPosition[2];

            position = GetPosition();
            x        = position[0];
            y        = -position[2];

            angle = GetXZViewAngle();

            if (x < 0.0f)
            {
                x = 0.0f;
            }

            if (x > map.GetWidth())
            {
                x = map.GetWidth();
            }

            if (y < 0.0f)
            {
                y = 0.0f;
            }

            if (y > map.GetHeight())
            {
                y = map.GetHeight();
            }

            Console.WriteLine("Robot(" + x + "," + y + ") (" + Math.Floor(x) + "," + Math.Ceiling(y) + ")");

            ByteMap bMap = map.Terrain.CollisionMap;

            bMap.Bytes[(int)x, (int)y] = ByteMap.FALSE;             //Disable testing your own collision area before testing others

            cancelMove = robot.RobotCollisionTest(map, x, y);

            bMap.Bytes[(int)x, (int)y] = ByteMap.TRUE;                  //Re-enable your own collision after the test
            //if (map.IsColliding((int)Math.Ceiling(x), (int)Math.Ceiling(y)))
            //    cancelMove = true;
            //if (map.IsColliding((int)Math.Floor(x), (int)Math.Floor(y)))
            //    cancelMove = true;

            //if (map.IsColliding(x, y))
            //    cancelMove = true;

            if (cancelMove)
            {
                if ((actions & Action.MOVE_UP) != 0)
                {
                    MoveDown();
                }
                if ((actions & Action.MOVE_DOWN) != 0)
                {
                    MoveUp();
                }
                if ((actions & Action.MOVE_LEFT) != 0)
                {
                    MoveRight();
                }
                if ((actions & Action.MOVE_RIGHT) != 0)
                {
                    MoveLeft();
                }
            }
            else
            {
                //Console.WriteLine("Robot(" + x + "," + y + " @ " + angle + ")");

                robot.PosX = x;
                robot.PosY = -y;
            }

            robot.Angle = -angle;
        }