Ejemplo n.º 1
0
        private void LoadBiomes()
        {
            XmlDocument xml = new XmlDocument();

            xml.Load("Content/XML/Biomes.xml");
            foreach (XmlNode node in xml.SelectNodes("Biomes/Biome"))
            {
                string uid  = node.Attributes.GetNamedItem("UID").Value;
                string file = node.Attributes.GetNamedItem("File").Value;
                string name = node.Attributes.GetNamedItem("Name").Value;
                try
                {
                    using (Texture2D texture = TextureUtility.LoadTexture(GraphicsDevice, "Content/Graphics/Biomes/" + file))
                    {
                        Texture2D[,] variants = TextureUtility.Split(GraphicsDevice, texture, 64, 64);
                        BasicSprite[] sprites = new BasicSprite[variants.Length];
                        int           i = 0, maxY = variants.GetLength(1), maxX = variants.GetLength(0);
                        for (int y = 0; y < maxY; y++)
                        {
                            for (int x = 0; x < maxX; x++)
                            {
                                sprites[i] = Textures.Copy(variants[x, y]);
                                i++;
                            }
                        }
                        Biome biome = new Biome(uid, name, sprites);
                        Data.Biomes.Add(uid, biome);
                    }
                }
                catch
                {
                }
            }
            Textures.ApplyChanges();
        }
Ejemplo n.º 2
0
        public void LoadContent(SpriteBatch sb, ContentManager content)
        {
            Resources = new CommonResources();
            Resources.LoadContent(sb, content);

            Player1.LoadContent(sb, content);
            Ship.LoadContent(sb, content);
            Hud.LoadContent(sb, content);

            //Initialize bg array
            for (int i = 0; i < bgList.GetLength(0); i++)
            {
                for (int j = 0; j < bgList.GetLength(1); j++)
                {
                    bgList[i, j] = Resources.ReturnRandomBackground();
                }
            }

            //Instantiate obj stack
            Objectives = new Stack <Collectible>();
            //Push to objective stack
            Objectives.Push(new Collectible("engine", new Vector2(-3000, -2000), Resources.Engine));
            Objectives.Push(new Collectible("welder", new Vector2(3000, 4000), Resources.Welder));
            Objectives.Push(new Collectible("ai", new Vector2(-200, 200), Resources.Ai));
        }
Ejemplo n.º 3
0
        internal static Texture2D Resize(this Texture2D[,] textures, int size)
        {
            Texture2D result = new Texture2D(Main.graphics.GraphicsDevice, size, size);

            Color[] data1 = new Color[size * size];

            int maxX = textures.GetLength(0);
            int maxY = textures.GetLength(1);

            int maxWidth  = 0;
            int maxHeight = 0;

            for (int x = 0; x < maxX; x++)
            {
                maxWidth += textures[x, 0].Width;
            }
            for (int y = 0; y < maxY; y++)
            {
                maxHeight += textures[0, y].Height;
            }

            float max   = Math.Max(maxWidth, maxHeight);
            float scale = size / max;

            int[] widths  = new int[maxX + 1];
            int[] heights = new int[maxY + 1];

            for (int x = 0; x < maxX; x++)
            {
                for (int y = 0; y < maxY; y++)
                {
                    Texture2D texture = textures[x, y];
                    int       width   = (int)(texture.Width * scale);
                    int       height  = (int)(texture.Height * scale);

                    widths[x + 1]  = widths[x] + width;
                    heights[y + 1] = heights[y] + height;

                    Texture2D texture2;
                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                    {
                        texture.SaveAsPng(ms, width, height);
                        texture2 = Texture2D.FromStream(texture.GraphicsDevice, ms);
                    }
                    Color[] data2 = new Color[width * height];
                    texture2.GetData <Color>(data2);
                    for (int i = 0; i < height; i++)
                    {
                        for (int j = 0; j < width; j++)
                        {
                            data1[heights[y] * size + widths[x] + i * size + j] = data2[i * width + j];
                        }
                    }
                }
            }

            result.SetData(data1);

            return(result);
        }
        public SpriteSheet(Texture2D[,] sprites)
        {
            //Same amount of columns as sprites, 1 row
            cols = sprites.GetLength(0);
            rows = sprites.GetLength(1);

            //Save the sprites
            this.sprites = sprites;
        }
Ejemplo n.º 5
0
    //public Texture2D showTexture;

    public MapTextureShower(Map map, Vector2Int unit, Func <int, Color[]> showerFun = null, Material quadsMaterial = null)
    {
        this.unit          = unit;
        this.map           = map;
        this.showerFun     = showerFun;
        this.quadsMaterial = quadsMaterial;

        map.onAddMapNode    += OnMapAddNode;
        map.onRemoveMapNode += OnMapRemoveNode;
        int x  = map.Size.x / (1024 / unit.x);
        int y  = map.Size.y / (1024 / unit.y);
        int mx = map.Size.x % (1024 / unit.x);
        int my = map.Size.y % (1024 / unit.y);

        if (mx != 0)
        {
            x += 1;
        }
        if (my != 0)
        {
            y += 1;
        }
        textures = new Texture2D[x, y];
        quads    = new GameObject[x, y];
        isModify = new bool[x, y];
        for (int i = 0; i < textures.GetLength(0); i++)
        {
            for (int j = 0; j < textures.GetLength(1); j++)
            {
                int xsize = map.Size.x * unit.x > 1024 ? 1024 : map.Size.x * unit.x;
                int ysize = map.Size.y * unit.y > 1024 ? 1024 : map.Size.y * unit.y;

                if (i == textures.GetLength(0) - 1)
                {
                    xsize = mx == 0 ? xsize : mx * unit.x;
                }
                if (j == textures.GetLength(1) - 1)
                {
                    ysize = my == 0 ? ysize : my * unit.y;
                }
                textures[i, j]          = new Texture2D(xsize, ysize);
                textures[i, j].wrapMode = TextureWrapMode.Clamp;
                quads[i, j]             = GameObject.CreatePrimitive(PrimitiveType.Quad);
                if (quadsMaterial != null)
                {
                    quads[i, j].GetComponent <MeshRenderer>().material = quadsMaterial;
                }
                quads[i, j].GetComponent <MeshRenderer>().material.mainTexture = textures[i, j];
                quads[i, j].transform.position   = new Vector3(i * unit.x, 0, j * unit.y) + new Vector3(xsize / (unit.x * 2), 0, ysize / (unit.y * 2));
                quads[i, j].transform.localScale = new Vector3(xsize / unit.x, ysize / unit.y, 1);
                quads[i, j].transform.rotation   = Quaternion.Euler(90, 0, 0);
            }
        }
    }
 public static void FinishOperation()
 {
     for (var x = 0; x < editorTextures.GetLength(0); x++)
     {
         for (var y = 0; y < editorTextures.GetLength(1); y++)
         {
             if (editorDirty[x, y])
             {
                 editorTextures[x, y].Apply();
                 editorDirty[x, y] = false;
             }
         }
     }
 }
Ejemplo n.º 7
0
 public void Draw(SpriteBatch sb)
 {
     sb.Begin();
     for (int i = 0; i < casinoMap.GetLength(0); i++)
     {
         for (int j = 0; j < casinoMap.GetLength(1); j++)
         {
             Texture2D currText = casinoMap[i, j];
             Rectangle currRect = casinoMapRect[i, j];
             sb.Draw(currText, currRect, Color.White);
         }
     }
     sb.End();
 }
Ejemplo n.º 8
0
 //default map constructor, makes a concrete bitmap with nothing on it
 public Map(ContentManager content, int screenWidth, int screenHeight) {
     tileSize = screenWidth / 20;
     tileMap = new Texture2D[20, 100];
     objectMap = new MapObject[tileMap.GetLength(0), tileMap.GetLength(1)];
     tileRot = new int[tileMap.GetLength(0), tileMap.GetLength(1)];
     objRot = new int[tileMap.GetLength(0), tileMap.GetLength(1)];
     //loops through entire tileMap array and sets each value to concrete
     for (int i = 0; i < tileMap.GetLength(0); i++) {
         for (int j = 0; j < tileMap.GetLength(1); j++) {
             tileMap[i, j] = content.Load<Texture2D>("ConcreteCorner");
         }
     }
     //loops through objectMap array and sets edges to noTexture
     for (int i = 0; i < objectMap.GetLength(0); i++) {
         for (int j = 0; j < objectMap.GetLength(1); j++) {
             objectMap[i, j] = new MapObject(content, true, "NoTexture", i, j);
         }
     }
     for (int i = 1; i < objectMap.GetLength(0) - 1; i++) {
         for (int j = 1; j < objectMap.GetLength(1) - 1; j++) {
             objectMap[i, j] = null;
         }
     }
     for (int i = 1; i < objectMap.GetLength(0); i += 6) {
         for (int j = 0; j < objectMap.GetLength(1) - 3; j++) {
             objectMap[i, j] = new MapObject(content, true, "NoTexture", i, j);
         }
     }
 }
Ejemplo n.º 9
0
        protected void Animate(GameTime gameTime)
        {
            double mod = (speed / (vel.X / gameTime.ElapsedGameTime.TotalSeconds));

            if (mod < 0)
            {
                mod = mod * -1;
            }
            if (is_moving == true && time >= delay * mod && is_falling == false)
            {
                if (currentSprite < img.GetLength(0) - 1)
                {
                    currentSprite++;
                }
                else
                {
                    currentSprite = 0;
                }

                time = 0;
            }
            else if (is_moving == false)
            {
                currentSprite = 0;
            }
            else if (is_falling)
            {
                currentSprite = 2;
            }
        }
Ejemplo n.º 10
0
    public void JoinGrid()
    {
        Texture2D[,] array = currentShape.array;
        int length = array.GetLength(1);

        for (int y = 0; y < length; y++)
        {
            for (int x = 0; x < length; x++)
            {
                int blockX = currentShape.gridpos.X + x;//geeft de positie van de 4 blokjes waaruit een tetrisblokje is opgebouwd op het tetrisgrid
                int blockY = currentShape.gridpos.Y + y;
                if (currentShape.array[x, y].Name != "block")
                {
                    grid.array[blockX, blockY] = currentShape.array[x, y]; //vervangt het grid met blokje
                }
            }
        }
        currentShape         = nextShape;       // zorgt ervoor dat het volgende blokje het huidige blokje wordt
        currentShape.gridpos = new Point(4, 0); //zet de positie rond het midden van de grid
        NewShape();                             //maakt een nieuw volgend blokje
        if (Collision())
        {
            gameState = GameState.GameOver; //als er net een nieuw blokje spawnt en hij collide al meteen met het grid is het game over, helaas pindakaas,
        }
        grid.CheckfullLine();
    }
Ejemplo n.º 11
0
    public bool Collision()     // kijkt of het blokje op een plek zit waar hij mag zijn, dus niet buiten het speelveld of in een blokje in het grid
    {
        bool collision = false; //standaard is er geen collision

        Texture2D[,] array = currentShape.array;
        Point gridpos = currentShape.gridpos;
        int   length  = array.GetLength(1);

        for (int y = 0; y < length; y++)
        {
            for (int x = 0; x < length; x++)
            {
                int blockX = gridpos.X + x;
                int blockY = gridpos.Y + y;
                if (array[x, y].Name != "block")                                                                             //"block" is een lege plek in de array, dus moet er alleen gekeken worden naar entries die niet leeg zijn.
                {
                    if (blockX < 0 || blockX > 9 || blockY < 0 || blockY > 19 || grid.array[blockX, blockY].Name != "block") //kijk of shape niet buiten grid raakt en dat shape niet op een gevuld gridblok staat
                    {
                        collision = true;
                    }
                }
            }
        }
        return(collision);
    }
Ejemplo n.º 12
0
        /// <summary>
        /// Cette fonction s'assure que les textures contenues dans le tableau de
        /// textures fourni en argument (paramètre tex) aient toutes les mêmes
        /// dimensions. Si ce n'est pas le cas, une exception est lancée.
        /// </summary>
        /// <param name="tex">Tableau des textures à valider.</param>
        private static void ValiderDimensionsDeTextures(Texture2D[,] tex)
        {
            // On s'assure que toutes les images ont les mêmes dimensions.
            int largeur = tex[0, 0].Width;
            int hauteur = tex[0, 0].Height;

            for (int row = 0; row < tex.GetLength(0); row++)
            {
                for (int col = 0; col < tex.GetLength(1); col++)
                {
                    if (tex[row, col].Width != largeur || tex[row, col].Height != hauteur)
                    {
                        throw new System.Exception("les images doivent être de dimensions uniformes");
                    }
                }
            }
        }
 void unloadPictureIcons()
 {
     Texture2D[,] texs = PropertiesSingleton.instance.albumsIcons;
     for (int i = 0; i < texs.GetLength(0); i++)
     {
         if (texs[i, 0] != null)
         {
             int j = 0;
             while (texs[i, j] != null && j < texs.GetLength(1))
             {
                 Resources.UnloadAsset(texs[i, j]);
                 texs[i, j] = null;
                 j++;
             }
         }
     }
 }
Ejemplo n.º 14
0
        private void SelectTexture()
        {
            Random rng = new Random();
            int    i;

            foreach (Tile tile2 in Tile2)
            {
                i             = rng.Next(0, mapTextures.GetLength(1) + 2);
                tile2.Texture = mapTextures[i, 3];
            }
        }
Ejemplo n.º 15
0
        void ViewMode.Draw()
        {
            offset = new Vector2(-center.X + Game1.graphics.GraphicsDevice.Viewport.Width / 2, -center.Y + Game1.graphics.GraphicsDevice.Viewport.Height / 2);
            spriteBatch.Begin();

            for (int i = 0; i < stage.GetLength(0); i++)
            {
                for (int j = 0; j < stage.GetLength(1); j++)
                {
                    spriteBatch.Draw(stage[i, j], new Vector2(32 * i, 32 * j) + offset, null);
                }
            }

            for (int i = 0; i < stage.GetLength(0); i++)
            {
                spriteBatch.DrawString(Game1.font, $"{i}", new Vector2(32 * i, -24) + offset, Color.Black, 0, new Vector2(0, 0), 0.6f, SpriteEffects.None, 0);
                spriteBatch.DrawString(Game1.font, $"{i}", new Vector2(32 * i, stage.GetLength(1) * 32) + offset, Color.Black, 0, new Vector2(0, 0), 0.6f, SpriteEffects.None, 0);
            }
            for (int i = 0; i < stage.GetLength(1); i++)
            {
                spriteBatch.DrawString(Game1.font, $"{i,2}", new Vector2(-24, 32 * i) + offset, Color.Black, 0, new Vector2(0, 0), 0.6f, SpriteEffects.None, 0);
                spriteBatch.DrawString(Game1.font, $"{i,2}", new Vector2(stage.GetLength(0) * 32, 32 * i) + offset, Color.Black, 0, new Vector2(0, 0), 0.6f, SpriteEffects.None, 0);
                spriteBatch.DrawString(Game1.font, $"{i,2}", new Vector2(20 * 32, 32 * i) + offset, Color.Red, 0, new Vector2(0, 0), 0.6f, SpriteEffects.None, 0);
                spriteBatch.DrawString(Game1.font, $"{i,2}", new Vector2(40 * 32, 32 * i) + offset, Color.Red, 0, new Vector2(0, 0), 0.6f, SpriteEffects.None, 0);
            }
            spriteBatch.End();
        }
Ejemplo n.º 16
0
    public void Draw(GameTime gameTime, SpriteBatch spriteBatch) //tekent de vormpjes in het speelveld apart van het grid
    {
        int     Height = array.GetLength(1);
        int     Width  = Height;
        Vector2 position;

        position.X = gridpos.X * block.Width;
        position.Y = gridpos.Y * block.Height;
        for (int y = 0; y != Height; y++)
        {
            for (int x = 0; x != Width; x++)
            {
                if (array[x, y] != block)
                {
                    spriteBatch.Draw(array[x, y], position, Color.White);  //als kleur, geef kleur
                }
                position.X += block.Width;
            }
            position.X  = gridpos.X * block.Width;
            position.Y += block.Height;
        }
    }
Ejemplo n.º 17
0
        public void updateSpritesheetPos(float netXMovement, bool player = false)
        {
            if ((player && netXMovement > 0) || (!player && netXMovement < 0))
            {
                //Left player movement
                currentEffect = SpriteEffects.FlipHorizontally;
            }
            else if ((player && netXMovement < 0) || (!player && netXMovement > 0))
            {
                //Right player movement
                currentEffect = SpriteEffects.None;
            }

            if (parentEntity.rigidBody.onGround)
            {
                if (netXMovement == 0)
                {
                    //Standing
                    spritesheetPos = new[] { 0, 0 };
                }
                else
                {
                    //Walking
                    if (spritesheetPos[0] != 1)
                    {
                        //Initial walking
                        spritesheetPos = new[] { 1, 0 };
                    }

                    currentWalkFrameDist += Math.Abs(netXMovement);
                    if (currentWalkFrameDist >= walkFrameDist)
                    {
                        //Change frame
                        currentWalkFrameDist -= walkFrameDist;
                        spritesheetPos[1]++;

                        if (spritesheetPos[1] > spritesheet.GetLength(1) - 1)
                        {
                            //Reset walkTexturePos
                            spritesheetPos[1] = 0;
                        }
                    }
                }
            }
            else
            {
                //Jumping
                spritesheetPos = new[] { 2, 0 };
            }
        }
Ejemplo n.º 18
0
 public void update_loc(int x, int y, sbyte fgd_block)
 {
     if (y < (map.GetLength(1) * 100) - map[0, map.GetLength(1) - 1].Height)
     {
         Color[]   col = new Color[1];
         Rectangle r   = new Rectangle(x % 100, y % 100, 1, 1);
         if (fgd_block < 0)
         {
             col[0] = Color.FromNonPremultiplied(0, 0, 0, 127);
         }
         else
         {
             col[0] = Exilania.block_types.blocks[fgd_block].map_represent;
         }
         map[x / 100, y / 100].SetData <Color>(0, r, col, 0, 1);
     }
 }
Ejemplo n.º 19
0
    void OnGUI()
    {
        var texture2D = MapData.texture;    // Get the map name to load

        if (texture2D != null)
        {
            #region GUI Display
            // Scale the texture view based on the selected choice from the popup
            //scale = (Scale)EditorGUILayout.EnumPopup("Zoom", scale);
            scale = Scale.x1;
            fun   = (FunLevel)EditorGUILayout.EnumPopup("Having fun?", fun); // This is here so I dont have to recalculate off sets again, remove this is scale is field works properly.

            var newScale       = ((int)scale) + 1;
            var newTextureSize = new Vector2(texture2D.width, texture2D.height) * newScale;
            var offset         = new Vector2(10, 65);
            mapViewOffset = new Vector2(10, newTextureSize.y + 85);

            if (isTextureLoaded == false)
            {
                LoadTextures();
            }

            // Export Button
            if (GUILayout.Button("Save Map"))
            {
                MapData.ExportMap();
                Close();
            }

            // Manages the scroll bar if needed
            EditorGUILayout.LabelField("Tile Picker");
            var viewPort    = new Rect(0, 0, position.width - 5, position.height - 5);
            var contentSize = new Rect(0, 0, newTextureSize.x + offset.x, newTextureSize.y + offset.y);
            scrollPosition = GUI.BeginScrollView(viewPort, scrollPosition, contentSize);
            GUI.DrawTexture(new Rect(offset.x, offset.y, newTextureSize.x, newTextureSize.y), texture2D);

            // Size of a tile
            Vector2 tile = new Vector2(15, 15) * newScale;

            tile.x += newScale;
            tile.y += newScale;

            /////////////////
            // Picker view //
            /////////////////

            // Set the dimensions of the texture grid
            var grid = new Vector2(newTextureSize.x / tile.x, newTextureSize.y / tile.y);

            // Set the position of the selected tile and where the mouse is hovering
            var selectionPos = new Vector2(tile.x * currentSelection.x + offset.x, tile.y * currentSelection.y + offset.y);
            pickerHover = new Vector2(tile.x * pickerHover.x + offset.x, tile.y * pickerHover.y + offset.y);

            // Setup the box texture and it's style
            var boxTex = new Texture2D(1, 1);
            boxTex.SetPixel(0, 0, Colors.Aqua);
            boxTex.Apply();
            var style = new GUIStyle(GUI.skin.customStyles[0]);
            style.normal.background = boxTex;

            // Render the selected box
            GUI.Box(new Rect(selectionPos.x, selectionPos.y, tile.x, tile.y), "", style);

            // Change the box texture properties
            boxTex.SetPixel(0, 0, Colors.Purple * 0.5f);
            boxTex.Apply();
            style.normal.background = boxTex;

            // Render the hover box with the modified properties
            GUI.Box(new Rect(pickerHover.x, pickerHover.y, tile.x, tile.y), "", style);

            //////////////
            // Map view //
            //////////////

            // Label
            EditorGUI.LabelField(new Rect(0, mapViewOffset.y - 20, 50, 25), "Map");

            // Set the dimensions of the texture grid
            var map = new Vector2(MapData.mapDimensions.x, MapData.mapDimensions.y);

            // For map view hover
            mapHover = new Vector2(tile.x * mapHover.x + mapViewOffset.x, tile.y * mapHover.y + mapViewOffset.y);

            Debug.Log(tiles.GetLength(0) + " " + tiles.GetLength(1));
            Debug.Log("Map: " + map);
            // Draw map grid
            for (int y = 0; y < map.y; y++)
            {
                for (int x = 0; x < map.x; x++)
                {
                    Debug.Log(MapData.tempMapCoords[x, y] + " x " + x + " y " + y);
                    Debug.Log(tiles[(int)MapData.tempMapCoords[x, y].x, (int)MapData.tempMapCoords[x, y].y]);
                    GUI.DrawTexture(new Rect(x * tile.x + mapViewOffset.x, y * tile.y + mapViewOffset.y, tile.x, tile.y), tiles[(int)MapData.tempMapCoords[x, y].x, (int)MapData.tempMapCoords[x, y].y]);
                }
            }
            #endregion GUI Display

            #region GUI Input
            // Get the current GUI event and the mouse position
            var     cEvent   = Event.current;
            Vector2 mousePos = new Vector2(cEvent.mousePosition.x - offset.x, cEvent.mousePosition.y - offset.y);

            if (mousePos.y < mapViewOffset.y - 62 * newScale)
            {
                // Snap the position to the grid
                pickerHover.x = Mathf.Floor((mousePos.x + scrollPosition.x) / tile.x);
                pickerHover.y = Mathf.Floor((mousePos.y + scrollPosition.y) / tile.y);

                // Make sure the selection is within bounds
                if (pickerHover.x > grid.x - 1)
                {
                    pickerHover.x = grid.x - 1;
                }
                else if (pickerHover.x < 0)
                {
                    pickerHover.x = 0;
                }

                if (pickerHover.y > grid.y - 1)
                {
                    pickerHover.y = grid.y - 1;
                }
                else if (pickerHover.y < 0)
                {
                    pickerHover.y = 0;
                }

                // Mouse click in select area
                if (cEvent.type == EventType.mouseDown && cEvent.button == 0 && mousePos.y < offset.y + newTextureSize.y)
                {
                    currentSelection = pickerHover;

                    // Set the currently selected sprite accordingly
                    MapData.currentSprite         = (int)(currentSelection.y * grid.x + currentSelection.x);
                    MapData.currentSelectedCoords = currentSelection;
                    //Debug.Log("X: " + MapData.currentSelectedCoords.x * 16 + " Y: " + MapData.currentSelectedCoords.y * 16);
                }
            }
            else
            {
                // Re-calculate mouse position
                mousePos = new Vector2(cEvent.mousePosition.x - mapViewOffset.x, cEvent.mousePosition.y - mapViewOffset.y);

                // Snap the position to the grid
                mapHover.x = Mathf.Floor((mousePos.x + scrollPosition.x) / tile.x);
                mapHover.y = Mathf.Floor((mousePos.y + scrollPosition.y) / tile.y);

                // Make sure the selection is within bounds
                if (mapHover.x > map.x - 1)
                {
                    mapHover.x = map.x - 1;
                }
                else if (mapHover.x < 0)
                {
                    mapHover.x = 0;
                }

                if (mapHover.y > map.y - 1)
                {
                    mapHover.y = map.y - 1;
                }
                else if (mapHover.y < 0)
                {
                    mapHover.y = 0;
                }

                // Draw Box
                GUI.Box(new Rect(mapHover.x * tile.x + mapViewOffset.x, mapHover.y * tile.y + mapViewOffset.y, tile.x, tile.y), "", style);

                // Mouse click in map area
                if (cEvent.type == EventType.mouseDown && cEvent.button == 0)
                {
                    // Set new tile
                    MapData.SetTile((int)mapHover.x, (int)mapHover.y);
                    //MapData.tempMapCoords[(int)mapHover.x, (int)mapHover.y] = MapData.currentSelectedCoords;
                    MapData.AddNewCoords((int)mapHover.x, (int)mapHover.y, MapData.currentSelectedCoords);
                }
            }
            #endregion GUI Input

            // End Scroll View
            GUI.EndScrollView();

            // Rerender
            Repaint();
        }
    }
        private static void PackHeightmap(Texture2D[,] allHeightmap, int textureSize, int lodLevel, string path, string terrainName)
        {
            ComputeShader  shader     = Resources.Load <ComputeShader>("MipmapCompute");
            ComputeBuffer  readBuffer = new ComputeBuffer(textureSize * textureSize, sizeof(float));
            MStringBuilder sb         = new MStringBuilder(path.Length + terrainName.Length + 15);

            sb.Add(path);
            if (path[path.Length - 1] != '/')
            {
                sb.Add("/");
            }
            sb.Add(terrainName);
            path += terrainName;
            if (Directory.Exists(sb.str))
            {
                Directory.Delete(sb.str);
            }
            Directory.CreateDirectory(sb.str);
            int pathLength = sb.str.Length;

            for (int i = 0; i < lodLevel; ++i)
            {
                sb.Resize(pathLength);
                sb.Add("/LOD" + i.ToString());
                Directory.CreateDirectory(sb.str);
            }
            sb.Resize(pathLength);
            sb.Add("/LOD0");
            for (int x = 0; x < allHeightmap.GetLength(0); ++x)
            {
                for (int y = 0; y < allHeightmap.GetLength(1); ++y)
                {
                    Texture2D tex = allHeightmap[x, y];
                    if (tex.width != textureSize ||
                        tex.height != textureSize)
                    {
                        readBuffer.Dispose();
                        Resources.UnloadAsset(shader);
                        throw new System.Exception("Texture " + tex.name + " setting is not right!(Width, Height, isReadable)");
                    }
                }
            }
            shader.SetBuffer(1, "_OutputBuffer", readBuffer);
            float[] result = new float[textureSize * textureSize];
            void SaveTexture(StreamWriter writer, Texture tex)
            {
                shader.SetTexture(1, ShaderIDs._MainTex, tex);
                int kernelSize = Mathf.CeilToInt(textureSize / 8f);

                shader.Dispatch(1, kernelSize, kernelSize, 1);
                readBuffer.GetData(result);
                char[] chrArray = new char[result.Length * sizeof(half)];
                half * arrPtr   = (half *)chrArray.Ptr();

                for (int i = 0; i < result.Length; ++i)
                {
                    arrPtr[i] = (half)result[i];
                }
                writer.Write(chrArray);
            }

            using (StreamWriter writer = new StreamWriter(sb.str))
            {
                for (int x = 0; x < allHeightmap.GetLength(0); ++x)
                {
                    for (int y = 0; y < allHeightmap.GetLength(1); ++y)
                    {
                        Texture2D tex = allHeightmap[x, y];
                        SaveTexture(writer, tex);
                    }
                }
            }
            readBuffer.Dispose();
            Resources.UnloadAsset(shader);
        }
Ejemplo n.º 21
0
        public MiniMap(World w, GraphicsDevice g)
        {
            map_pieces = new List <MapMarker>();
            map        = new Texture2D[w.map.GetLength(0) / 100, w.map.GetLength(1) / 100];
            int width  = 100;
            int height = 100;

            for (int x = 0; x < map.GetLength(0); x++)
            {
                for (int y = 0; y < map.GetLength(1); y++)
                {
                    if (x < map.GetLength(0) - 1)
                    {
                        width = 100;
                    }
                    else
                    {
                        if (w.map.GetLength(0) % 100 != 0)
                        {
                            width = w.map.GetLength(0) % 100;
                        }
                        else
                        {
                            width = 100;
                        }
                    }
                    if (y < map.GetLength(1) - 1)
                    {
                        height = 100;
                    }
                    else
                    {
                        if (w.map.GetLength(1) % 100 != 0)
                        {
                            height = w.map.GetLength(1) % 100;
                        }
                        else
                        {
                            height = 100;
                        }
                    }
                    map[x, y] = new Texture2D(g, width, height);
                    Color[] total_map = new Color[width * height];
                    sbyte   temp_col  = -1;
                    for (int ys = 0; ys < height; ys++)
                    {
                        for (int xs = 0; xs < width; xs++)
                        {
                            temp_col = w.map[(x * 100) + xs, (y * 100) + ys].fgd_block;
                            if (temp_col < 0)
                            {
                                if (w.map[(x * 100) + xs, (y * 100) + ys].liquid_id > 0)
                                {
                                    total_map[(ys * width) + xs] = Exilania.block_types.blocks[World.liquid_blocks[w.map[(x * 100) + xs, (y * 100) + ys].liquid_id]].map_represent;
                                }
                                else
                                {
                                    total_map[(ys * width) + xs] = Color.FromNonPremultiplied(0, 0, 0, 127);
                                }
                            }
                            else
                            {
                                total_map[(ys * width) + xs] = Exilania.block_types.blocks[temp_col].map_represent;
                            }
                        }
                    }
                    map[x, y].SetData <Color>(total_map);
                }
            }
        }
Ejemplo n.º 22
0
        /*
         * internal static Texture2D Resize(this Texture2D texture, int size)
         * {
         *      Texture2D result = texture;
         *
         *      float max = Math.Max(texture.Width, texture.Height);
         *      float scale = size / max;
         *      int width = (int)(texture.Width * scale);
         *      int height = (int)(texture.Height * scale);
         *
         *      using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
         *      {
         *              texture.SaveAsPng(ms, width, height);
         *              // Crashes Mac (maybe Linux?)
         *              result = Texture2D.FromStream(texture.GraphicsDevice, ms);
         *      }
         *      return result;
         * }
         */

        internal static Texture2D Resize(this Texture2D[,] textures, int size)
        {
            Texture2D result = new Texture2D(Main.graphics.GraphicsDevice, size, size);

            Color[] data1 = new Color[size * size];

            int maxX = textures.GetLength(0);
            int maxY = textures.GetLength(1);

            int maxWidth  = 0;
            int maxHeight = 0;

            for (int x = 0; x < maxX; x++)
            {
                maxWidth += textures[x, 0].Width;
            }
            for (int y = 0; y < maxY; y++)
            {
                maxHeight += textures[0, y].Height;
            }

            float max   = Math.Max(maxWidth, maxHeight);
            float scale = size / max;

            int[] widths  = new int[maxX + 1];
            int[] heights = new int[maxY + 1];

            // TODO: Wait, shouldn't I just do this all in 1 draw call?
            for (int x = 0; x < maxX; x++)
            {
                for (int y = 0; y < maxY; y++)
                {
                    Texture2D texture = textures[x, y];
                    int       width   = (int)(texture.Width * scale);
                    int       height  = (int)(texture.Height * scale);

                    widths[x + 1]  = widths[x] + width;
                    heights[y + 1] = heights[y] + height;

                    Texture2D texture2;
                    if (Terraria.ModLoader.ModLoader.windows)
                    {
                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                        {
                            // This doesn't work on Mac/Linux but doesn't cause a screen flash.
                            // TODO: Do this in an Update method so screen flash doesn't matter.
                            texture.SaveAsPng(ms, width, height);
                            texture2 = Texture2D.FromStream(texture.GraphicsDevice, ms);
                        }
                    }
                    else
                    {
                        // Alt method for Mac/Linux, causes screen flash
                        texture2 = ResizeTexture(texture, scale);
                    }

                    Color[] data2 = new Color[width * height];
                    texture2.GetData <Color>(data2);
                    for (int i = 0; i < height; i++)
                    {
                        for (int j = 0; j < width; j++)
                        {
                            data1[heights[y] * size + widths[x] + i * size + j] = data2[i * width + j];
                        }
                    }
                }
            }

            result.SetData(data1);

            return(result);
        }
Ejemplo n.º 23
0
 public Level(Texture2D[,] tiles)
 {
     this.tiles = tiles;
     this.tileCols = tiles.GetLength(0);
     this.tileRows = tiles.GetLength(1);
 }
Ejemplo n.º 24
0
        // constructor that reads fro a file map.cs
        public Map(ContentManager content, string filename, Camera c, Character player, List<Enemy> enemies, int screenWidth) {
            Texture2D empTexture = content.Load<Texture2D>("EmptyTile");
            tileSize = screenWidth / 20;

            BinaryReader input = new BinaryReader(File.OpenRead("Content/" + filename));
            int mapWidth = input.ReadInt32();
            int mapHeight = input.ReadInt32();

            tileMap = new Texture2D[mapWidth, mapHeight];
            objectMap = new MapObject[mapWidth, mapHeight];
            tileRot = new int[tileMap.GetLength(0), tileMap.GetLength(1)];
            objRot = new int[tileMap.GetLength(0), tileMap.GetLength(1)];


            for (int i = 0; i < tileMap.GetLength(0); i++) {
                for (int j = 0; j < tileMap.GetLength(1); j++) {
                    string txtrString = input.ReadString();
                    if (!txtrString.Equals("null")) {
                        Texture2D texture = content.Load<Texture2D>(txtrString);
                        tileMap[i, j] = texture;
                    } else {
                        tileMap[i, j] = empTexture;
                    }
                }
            }

            for (int i = 0; i < tileMap.GetLength(0); i++) {
                for (int j = 0; j < tileMap.GetLength(1); j++) {
                    tileRot[i, j] = input.ReadInt32();
                }
            }

            for (int i = 0; i < objectMap.GetLength(0); i++) {
                for (int j = 0; j < objectMap.GetLength(1); j++) {
                    string txtrString = input.ReadString();
                    if (!txtrString.Equals("null")) {
                        objectMap[i, j] = new MapObject(content, true, txtrString, i, j);
                    } else {
                        objectMap[i, j] = null;
                    }
                }
            }

            for (int i = 0; i < objectMap.GetLength(0); i++) {
                for (int j = 0; j < objectMap.GetLength(1); j++) {
                    objRot[i, j] = input.ReadInt32();
                }
            }

            int entWidth = input.ReadInt32();
            int entHieght = input.ReadInt32();
            int[,] entRot = new int[entWidth, entHieght];

            for (int i = 0; i < entRot.GetLength(0); i++) {
                for (int j = 0; j < entRot.GetLength(1); j++) {
                    entRot[i, j] = input.ReadInt32();
                }
            }
            
            for (int x = 0; x < entWidth; x++) {
                for (int y = 0; y < entHieght; y++) {
                    string txtrString = input.ReadString();
                    if (txtrString.Equals("null")) {
                        continue;
                    } else if (txtrString.Equals("Enemy")) {
                        CreateEnemy.CreateNormalEnemy(ref enemies, content, c, this, x, y, entRot[x,y] * -1.5708f);
                    } else if (txtrString.Equals("RiotEnemy")) {
                        CreateEnemy.CreateRiotEnemy(ref enemies, content, c, this, x, y, entRot[x, y] * -1.5708f);
                    }
                }
            }

            string playerPos = input.ReadString();
            string[] playerParts = playerPos.Split(',');
            double distX = player.Loc.X - double.Parse(playerParts[1]);
            double distY = player.Loc.Y - double.Parse(playerParts[2]);
            
            player.Loc.X -= distX;
            player.Loc.Y -= distY;
            c.camPos.X += distX;
            c.camPos.Y += distY;
            
            input.Close();
        }