Пример #1
0
        public void Draw(IntVector2D pos, Color color)
        {
            if (texture == null)
            {
                return;
            }

            spriteBatch.Draw(texture, new Rectangle(pos.X, pos.Y, width, height), color);
        }
Пример #2
0
Файл: Room.cs Проект: Milun/VWA
        public void InitRoom()
        {
            // Maybe have a parent class for ALL ACTORS which has a common draw and
            // check collision function which returns a vector.
            // This way the ACTORS can check the type of thing they're colliding with (you pass the other actor to them).


            //// TO DO LIST!!!
            // Make it sort the collisions from top left to bottom right.
            // Do an int for down and right. First go DOWN (if possible) then add 1 to down, then go right and check.
            // Remove as you go. At the end just add a collision for the amount of down and right you have x 24.


            List <IntVector2D> temp = new List <IntVector2D>();

            foreach (KeyValuePair <IntVector2D, Tile> e in tiles)
            {
                temp.Add(e.Key);

                e.Value.SetNeighbours(tiles.ContainsKey(new IntVector2D(e.Key.X, e.Key.Y - 1)),
                                      tiles.ContainsKey(new IntVector2D(e.Key.X + 1, e.Key.Y)),
                                      tiles.ContainsKey(new IntVector2D(e.Key.X, e.Key.Y + 1)),
                                      tiles.ContainsKey(new IntVector2D(e.Key.X - 1, e.Key.Y)));
            }

            while (temp.Count > 0)
            {
                Vector2 pos  = new Vector2(temp[0].X, temp[0].Y);
                Vector2 size = new Vector2(1f, 1f);

                bool horizontal = true;
                bool vertical   = true;

                IntVector2D start = temp[0] + new IntVector2D(1, 0);
                temp.RemoveAt(0);

                while (temp.Contains(start))
                {
                    size += new Vector2(1f, 0f);
                    temp.Remove(start);
                    start += new IntVector2D(1, 0);
                }

                cols.Add(new ColSquare(pos,
                                       Vector2.Zero,
                                       size));
            }


            //foreach (IntVector2D e in temp)
            {
                /*cols.Add(new ColSquare(new Vector2(e.Key.X * 24, e.Key.Y * 24),
                 *                     Vector2.Zero,
                 *                     new Vector2(24, 24)));*/
            }
        }
Пример #3
0
Файл: Room.cs Проект: Milun/VWA
 public void SetTile(IntVector2D v, Tile tile)
 {
     if (tile != null)
     {
         tiles[v] = tile;
     }
     else
     {
         tiles.Remove(v);
     }
 }
Пример #4
0
        public bool Equals(IntVector2D v)
        {
            // If parameter is null return false:
            if ((object)v == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return((X == v.X) && (Y == v.Y));
        }
Пример #5
0
        public void InitGame(ref Room _room, IntVector2D startPos)
        {
            room = _room;
            room.InitRoom();

            // AHA! You're the bug causer!
            room.SetActor(new IntVector2D(-1, -1), ball);

            ball.SetPos(startPos);
            Global.viewZoom = 2f;
        }
Пример #6
0
Файл: Room.cs Проект: Milun/VWA
 public void SetActor(IntVector2D v, Actor actor)
 {
     if (actor != null)
     {
         actors[v] = actor;
     }
     else
     {
         actors.Remove(v);
     }
 }
Пример #7
0
        public void Draw(IntVector2D pos, IntVector2D size, Color color)
        {
            if (texture == null)
            {
                return;
            }

            spriteBatch.Draw(texture, new Rectangle(pos.X,
                                                    pos.Y,
                                                    size.X,
                                                    size.Y), color);
        }
Пример #8
0
        /*public void Draw3D(Vector2 pos, Color color, float z)
         * {
         *  if (texture == null) return;
         *
         *  spriteBatch.Draw(texture, new Rectangle((int)(pos.X * Global.viewZoom - Global.viewCenter.X * Global.viewZoom + Global.Get3DRatio(pos).X * z * 500f - (width - width * z) / 2f),
         *                                          (int)(pos.Y * Global.viewZoom - Global.viewCenter.Y * Global.viewZoom + Global.Get3DRatio(pos).Y * z * 500f - (height - height * z) / 2f),
         *                                          (int)((width -width *z) * Global.viewZoom),
         *                                          (int)((height-height*z) * Global.viewZoom)), color);
         * }*/

        public void DrawView(Vector2 pos, IntVector2D size, Color color)
        {
            if (texture == null)
            {
                return;
            }

            spriteBatch.Draw(texture, new Rectangle((int)(pos.X * Global.viewZoom - Global.viewCenter.X * Global.viewZoom),
                                                    (int)(pos.Y * Global.viewZoom - Global.viewCenter.Y * Global.viewZoom),
                                                    (int)(size.X * Global.viewZoom),
                                                    (int)(size.Y * Global.viewZoom)), color);
        }
Пример #9
0
        public Border(SpriteBatch sb,
                      Texture2D tex,
                      IntVector2D _point1,
                      IntVector2D _point2,
                      IntVector2D _topLeft,
                      IntVector2D _bottomRight)
        {
            point1      = _point1;
            point2      = _point2;
            topLeft     = _topLeft;
            bottomRight = _bottomRight;

            spriteBatch = sb;
            texBrowser  = tex;
        }
Пример #10
0
        private void SelectTileMap()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.LeftAlt))
            {
                return;
            }

            if (Mouse.GetState().X >= 696 || Mouse.GetState().Y >= 528)
            {
                return;
            }

            IntVector2D mouse = GetMouseMenuPos();

            if (mouse == new IntVector2D(-1, -1))
            {
                return;
            }

            // Delete tile
            if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                rooms[currentRoom.X, currentRoom.Y].SetTile(mouse, null);
                rooms[currentRoom.X, currentRoom.Y].SetActor(mouse, null);
                return;
            }
            // Create tile
            if (Mouse.GetState().LeftButton == ButtonState.Pressed && Keyboard.GetState().IsKeyDown(Keys.LeftControl))
            {
                Tile other = new Tile(sprMap, new Vector2(random.Next(0, 4),
                                                          random.Next(0, 4)),
                                      new Vector2(mouse.X, mouse.Y));
                other.setPos(new Vector2(mouse.X, mouse.Y));

                rooms[currentRoom.X, currentRoom.Y].SetTile(mouse, other);
                return;
            }
            // Create block
            if (placingActor || Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                placingActor = true;
                CreateActor(new Vector2(mouse.X, mouse.Y));

                return;
            }
        }
Пример #11
0
Файл: Room.cs Проект: Milun/VWA
        public void Draw3D(IntVector2D _pos)
        {
            foreach (KeyValuePair <IntVector2D, Tile> e in tiles)
            {
                e.Value.Draw3D();
            }

            foreach (Col e in cols)
            {
                e.DrawDebug(Editor.colorDebug);
            }

            foreach (KeyValuePair <IntVector2D, Actor> e in actors)
            {
                e.Value.Draw();
            }
        }
Пример #12
0
Файл: Tile.cs Проект: Milun/VWA
        public void Draw(IntVector2D _pos)
        {
            Texture2D tex = spr.GetTexture();

            // Get offset.
            Vector2 temp = new Vector2
                           (
                (int)(tex.Width / 4 * off.X),
                (int)(tex.Height / 4 * off.Y)
                           );


            spr.DrawView(new Vector2(pos.X, pos.Y) * Global.gridSize,
                         Vector2.One * Global.gridSize,
                         temp,
                         new Vector2(tex.Width / 4, tex.Height / 4),
                         Color.White);
        }
Пример #13
0
        public override bool Equals(System.Object other)
        {
            // If parameter is null return false.
            if (other == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            IntVector2D v = other as IntVector2D;

            if ((System.Object)v == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return((X == v.X) && (Y == v.Y));
        }
Пример #14
0
        private void SelectColorMenu()
        {
            if (Mouse.GetState().LeftButton != ButtonState.Pressed)
            {
                return;
            }

            int x = Mouse.GetState().X - COLORSMENU_X;
            int y = Mouse.GetState().Y - COLORSMENU_Y;

            x = x / Global.gridSize;
            y = y / Global.gridSize;

            if (x < 0 || x >= 8 || y < 0 || y >= 2)
            {
                return;
            }

            currentCOLORSelect = new IntVector2D(x, y);
        }
Пример #15
0
        private void SelectTileMenu()
        {
            if (Mouse.GetState().LeftButton != ButtonState.Pressed)
            {
                return;
            }

            int x = Mouse.GetState().X;
            int y = Mouse.GetState().Y - TOOLS_Y;

            x = x / Global.gridSize;
            y = y / Global.gridSize;

            if (x < 0 || x > 7 || y < 0 || y > 15)
            {
                return;
            }

            currentActorSelect = new IntVector2D(x, y);
            //currentTile = tilesMenu[x, y];
        }
Пример #16
0
        public void MoveRoom()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.LeftAlt) && Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                // Set initial location the mouse was.
                if (roomPosLastMouse.X == 0 && roomPosLastMouse.Y == 0)
                {
                    roomPosLastMouse = new IntVector2D(Mouse.GetState().X, Mouse.GetState().Y);
                }

                // Move room
                roomPos = roomPosLast + roomPosLastMouse - new IntVector2D(Mouse.GetState().X, Mouse.GetState().Y);

                Global.viewCenter = new Vector2(roomPos.X, roomPos.Y);
            }
            else
            {
                roomPosLastMouse.X = 0;
                roomPosLastMouse.Y = 0;
                roomPosLast        = roomPos;
            }
        }
Пример #17
0
        public Billboard(Texture2D _tex,
                         Vector3 _pos,
                         Vector2 _origin,
                         Vector2 _size,
                         int _frame,
                         Vector2 _uvSize)
        {
            tex  = _tex;
            pos  = _pos;
            size = _size;

            sizeUV = _uvSize;

            tileMap = new IntVector2D((int)Math.Floor(1f / _uvSize.X),
                                      (int)Math.Floor(1f / _uvSize.Y));

            origin = new Vector3(size.X * _origin.X, size.Y * _origin.Y, 0.0f);

            quad = new Classes.Quad
                   (
                pos + origin,
                Vector3.Backward,
                Vector3.Down,
                size.X,
                size.Y,
                Vector2.Zero * sizeUV,
                sizeUV,
                tex
                   );

            // LOOK OVER THIS LATER
            quad.Z     = pos.Z;
            quad.Order = (int)(pos.Z * 100f);

            FrameToUV(_frame);
            frame = _frame;
        }
Пример #18
0
        public void Draw(bool isActive)
        {
            actorMode = Mouse.GetState().ScrollWheelValue / 180;

            if (!gameRunning)
            {
                LaunchGame();
                DrawTileMap();

                //rooms[currentRoom.X, currentRoom.Y].DrawShadow(roomPos);
                //rooms[currentRoom.X, currentRoom.Y].Draw(roomPos);

                DrawColorMenu();

                DrawCurrentTile();


                spriteBatch.Draw(texTools, new Rectangle(0, TOOLS_Y, 384, 96), new Rectangle(0, 0, 384, 96), Color.White);

                DrawSelect();

                if (isActive)
                {
                    SelectTileMenu();
                    SelectTileMap();
                    SelectColorMenu();

                    SaveCurrentMap();
                    ToggleGrid();

                    MoveRoom();
                }
            }
            else
            {
                mainGame.Draw();
                ToggleDebug();
                //sprDebug.Draw(new IntVector2D(696, 0), new IntVector2D(400, 700), Color.Black);
                //sprDebug.Draw(new IntVector2D(0, 528), new IntVector2D(696, 200), Color.Black);

                if (Keyboard.GetState().IsKeyDown(Keys.Escape) || rooms[currentRoom.X, currentRoom.Y].IsLevelComplete())
                {
                    roomPos = new IntVector2D((int)Global.viewCenter.X, (int)Global.viewCenter.Y);
                    MainGame.StopGame();
                    gameRunning = false;
                }
            }



            if (Keyboard.GetState().IsKeyDown(Keys.P))
            {
                spriteBatch.Draw(texBall, new Rectangle(Mouse.GetState().X - 12,
                                                        Mouse.GetState().Y - 12,
                                                        24,
                                                        24), Color.White);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.LeftAlt))
            {
                spriteBatch.Draw(texCursor, new Rectangle(Mouse.GetState().X,
                                                          Mouse.GetState().Y,
                                                          17,
                                                          32),
                                 new Rectangle(12,
                                               0,
                                               17,
                                               32), Color.White);
            }
            else
            {
                spriteBatch.Draw(texCursor, new Rectangle(Mouse.GetState().X,
                                                          Mouse.GetState().Y,
                                                          12,
                                                          32),
                                 new Rectangle(0,
                                               0,
                                               12,
                                               32), Color.White);
            }

            sprDebug.DrawView(Global.viewCenter, Color.White);

            string hd = "Disabled";

            if (MainGame.HD)
            {
                hd = "Enabled";
            }
            spriteBatch.DrawString(font,
                                   "HD: " + hd,
                                   new Vector2(20, 20),
                                   Color.White);

            spriteBatch.DrawString(font,
                                   "ySpeed: " + MainGame.ball.GetYspeed(),
                                   new Vector2(20, 40),
                                   Color.White);
        }
Пример #19
0
        // Constructor
        public Editor(SpriteBatch _spriteBatch, ContentManager Content)
        {
            random = new Random();

            roomPos          = new IntVector2D();
            roomPosLast      = new IntVector2D();
            roomPosLastMouse = new IntVector2D();

            font = Content.Load <SpriteFont>("Arial");


            spriteBatch = _spriteBatch;

            mainGame = new MainGame(_spriteBatch, Content);

            sprMap = new Sprite(Content.Load <Texture2D>("Sprites/spr_wall_1"),
                                ref spriteBatch,
                                8, 8);

            sprBlock = new Sprite(Content.Load <Texture2D>("Sprites/spr_burger"),
                                  ref spriteBatch);

            texBall   = Content.Load <Texture2D>("Sprites/spr_ball");
            texLine   = Content.Load <Texture2D>("Sprites/spr_line");
            texBlack  = Content.Load <Texture2D>("Sprites/spr_black");
            texWhite  = Content.Load <Texture2D>("Sprites/spr_white");
            texCursor = Content.Load <Texture2D>("Sprites/spr_cursor");
            texSelect = Content.Load <Texture2D>("Sprites/spr_select");
            texTools  = Content.Load <Texture2D>("Sprites/spr_tools");

            Color[] data = new Color[texWhite.Width * texWhite.Height];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = Color.White;
            }
            texWhite.SetData <Color>(data);

            colorDebug  = new Color(255, 0, 0, 80);
            colorDebug2 = new Color(0, 255, 0, 80);
            colorDebug3 = new Color(255, 255, 255, 80);
            sprDebug    = new Sprite(texWhite,
                                     ref spriteBatch);
            sprCircle = new Sprite(Content.Load <Texture2D>("Sprites/spr_circle"),
                                   ref spriteBatch);

            currentRoom = new IntVector2D(11, 11);
            rooms       = new Room[ROOMSMAP, ROOMSMAP];
            for (int i = 0; i < ROOMSMAP; i++)
            {
                for (int j = 0; j < ROOMSMAP; j++)
                {
                    rooms[i, j] = new Room();
                }
            }

            tilesMenu = new Tile[8, 16];
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    tilesMenu[i, j] = new Tile(sprMap,
                                               new Vector2(i, j),
                                               new Vector2(i + mapWidth + 2,
                                                           j + 1));
                }
            }

            tilesMap = new Tile[mapWidth, mapHeight];
            for (int i = 0; i < mapWidth; i++)
            {
                for (int j = 0; j < mapHeight; j++)
                {
                    /*tilesMap[i,j] = new Tile(sprMap,
                     *                       Vector2.Zero,
                     *                       new Vector2(i * tileScale*(tileSize) + TILESMAP_X,
                     *                                   j * tileScale*(tileSize) + TILESMAP_Y));*/
                    tilesMap[i, j] = null;
                }
            }

            currentTile = tilesMenu[0, 0];


            COLORS     = new Color[16];
            COLORS[0]  = new Color(255, 255, 255);
            COLORS[1]  = new Color(170, 116, 73);
            COLORS[2]  = new Color(120, 41, 34);
            COLORS[3]  = new Color(135, 214, 221);
            COLORS[4]  = new Color(170, 95, 182);
            COLORS[5]  = new Color(85, 160, 73);
            COLORS[6]  = new Color(64, 49, 141);
            COLORS[7]  = new Color(191, 206, 114);
            COLORS[8]  = new Color(40, 40, 40);
            COLORS[9]  = new Color(234, 180, 137);
            COLORS[10] = new Color(184, 105, 98);
            COLORS[11] = new Color(199, 255, 255);
            COLORS[12] = new Color(234, 159, 246);
            COLORS[13] = new Color(148, 224, 137);
            COLORS[14] = new Color(128, 113, 204);
            COLORS[15] = new Color(255, 255, 178);

            currentCOLORSelect = new IntVector2D(0, 0);
            currentTileSelect  = new IntVector2D(0, 0);


            sprStatue = new Sprite(Content.Load <Texture2D>("Sprites/spr_statue"), ref spriteBatch);
            sprHead   = new Sprite(Content.Load <Texture2D>("Sprites/spr_head"), ref spriteBatch);
            sprEarth  = new Sprite(Content.Load <Texture2D>("Sprites/spr_earth"), ref spriteBatch);

            sprBlockTape        = new Sprite(Content.Load <Texture2D>("Sprites/spr_vhs"), ref spriteBatch);
            sprBlockTapeSticker = new Sprite(Content.Load <Texture2D>("Sprites/spr_vhs_sticker"), ref spriteBatch);

            sprDoom = new Sprite(Content.Load <Texture2D>("Sprites/spr_doom"), ref spriteBatch);

            LoadMap();

            /*
             * rooms[currentRoom.X, currentRoom.Y].SetActor(new IntVector2D(5,5), new Enemy(new Vector2(2f,5f), new Sprite(Content.Load<Texture2D>("Sprites/spr_statue"),
             *                     ref spriteBatch, 48, 48), -1f));
             *
             * rooms[currentRoom.X, currentRoom.Y].SetActor(new IntVector2D(5, 6), new Enemy(new Vector2(2f, 4f), new Sprite(Content.Load<Texture2D>("Sprites/spr_statue"),
             *                     ref spriteBatch, 48, 48), 1f));
             */


            currentActorSelect = new IntVector2D(0, 0);

            /*rooms[currentRoom.X, currentRoom.Y].SetActor(new IntVector2D(9, 9),
             *                                           new EnemyCursor(Vector2.Zero*9f,
             *                                                           new Sprite(texCursor, ref spriteBatch)));*/
        }
Пример #20
0
Файл: Ball.cs Проект: Milun/VWA
 public void SetPos(IntVector2D _pos)
 {
     pos = new Vector3(_pos.X, _pos.Y, 0f);
     UpdateCol(new Vector2(pos.X, pos.Y));
     startPos = pos;
 }