Example #1
0
 public Tilemap(Node parent, string name, Texture2D tileTexture, Tile[,] tiles, Point tileSize)
     : base(parent, name)
 {
     Body = new Body(this, "Body");
     Render = new TilemapRender(this, "TilemapRender", tileTexture, tiles, tileSize);
     Render.LinkDependency(TilemapRender.DEPENDENCY_BODY, Body);
 }
Example #2
0
 public Tile Clone()
 {
     Tile t = new Tile(Index);
     t.Flip = Flip;
     t.Solid = Solid;
     t.Color = Color;
     return t;
 }
 public Tile[,] MakeTiles(int sizex, int sizey)
 {
     Tile[,] tiles = new Tile[sizex, sizey];
     for (int x = 0; x < sizex; x++)
     {
         for (int y = 0; y < sizey; y++)
         {
             tiles[x, y] = new Tile((short)_rand.Next(0, 3));
         }
     }
     return tiles;
 }
Example #4
0
 public void SetAllTiles(Tile tile)
 {
     Render.SetAllTiles(tile);
 }
Example #5
0
 public void SetTile(Point p, Tile t)
 {
     SetTile(p.X, p.Y, t);
 }
Example #6
0
 public void SetTile(int x, int y, Tile t)
 {
     Render.SetTile(x,y,t);
 }
        public void CheckAllCells()
        {
            //Copy the tiles so we can change the Cell's tiles without screwing up the neighbor detection
            _tiles = Cells.CloneTiles();
            List<Color> colorsToMix = new List<Color>();

            for (int x = 0; x <= _tiles.GetUpperBound(0); x++)
            {
                for (int y = 0; y <= _tiles.GetUpperBound(0); y++)
                {
                    colorsToMix.Clear();

                    Tile tile = _tiles[x, y];
                    short index = tile.Index;
                    int neighborcount = GetNeighborsCount(x, y);

                    //Toggle cell based on Life conditions
                    if (index == ALIVE)
                    {
                        if (neighborcount < 2) Cells.SetTile(x, y, --index);
                        else if (neighborcount > 3) Cells.SetTile(x, y, --index);
                    }
                    //Check to see if the cell is not alive or dead,
                    //subtract its index if not to create the
                    //death map
                    else
                    {
                        if (index < ALIVE || index > DEAD)
                        {
                            index--;
                            if (index < DEAD) index = DEAD;
                            Cells.SetTile(x, y, index);
                        }

                        //Turn it on if it's alive
                        if (neighborcount == 3)
                        {
                            Cells.SetTile(x, y, new Tile(ALIVE) { Color = new RGBColor(0, 0, 0, 1) });
                        }
                    }

                    if (Cells.GetTile(x, y).Index == ALIVE)
                    {
                        //Now we get neighbor colors, mix them by average hue, output a new color.
                        colorsToMix = colorsToMix.Concat(GetNeighborColors(x, y)).ToList();

                        float newhue = 0f;

                        //find lowest and highest bands
                        float minhue = float.MaxValue;
                        float maxhue = 0f;
                        foreach (var color in colorsToMix)
                        {
                            float colorhue = color.ToHSVColor().H;
                            minhue = Math.Min(minhue, colorhue);
                            maxhue = Math.Max(maxhue, colorhue);
                        }

                        //Check if the tile was dead, and now is alive
                        if (Cells.GetTile(x, y).Index == ALIVE && _tiles[x, y].Index != ALIVE)
                        {
                            foreach (var color in colorsToMix)
                            {
                                float colorhue = color.ToHSVColor().H;

                                newhue = colorhue - minhue;
                                //now that we have that, we will subtract each color from our min, average it, and get our new color.

                                newhue /= colorsToMix.Count();
                                newhue += minhue;
                            }
                            Tile newtile = new Tile(ALIVE);
                            newtile.Color = ColorMath.HSVtoRGB(new HSVColor(newhue, 1, 1, 1, ColorOutOfBoundsAction.WrapAround));
                            Cells.SetTile(x, y, newtile);
                        }
                        else if (Cells.GetTile(x, y).Index == ALIVE)
                        {
                            //Get our tile's color
                            HSVColor tilecolor = ColorMath.RGBtoHSV(_tiles[x, y].Color);
                            foreach (var color in colorsToMix)
                            {
                                float colorhue = color.ToHSVColor().H;

                                //find out which direction is the closest route to the color.
                                float route = (Math.Abs(colorhue - tilecolor.H) < Math.Abs(1 - colorhue - tilecolor.H))
                                                  ? colorhue - tilecolor.H
                                                  : 1 - colorhue - tilecolor.H;
                                newhue += route;
                            }

                            //TODO: Update color blending with Cie-LCH, for which you need to implment XYZ and Cie-Lab
                            //now that we have that, we will subtract each color from our min, average it, and get our new color.

                            newhue /= colorsToMix.Count();
                            newhue += tilecolor.H;

                            Tile newtile = new Tile(ALIVE);
                            newtile.Color = ColorMath.HSVtoRGB(new HSVColor(newhue, 1, 1, 1));
                            newtile.Color.Action = ColorOutOfBoundsAction.WrapAround;
                            Cells.SetTile(x, y, newtile);
                        }
                    }
                }
            }
        }
 private void OnTileSelected(Tile tile)
 {
     if (!_manager.RunningSimulation)
     {
         tile.Index = tile.Index != DEAD ? DEAD : ALIVE;
         tile.Color = _currentColor.ToRGBColor();
     }
 }
            public XYZTilemap(Node parent, string name, Point size)
                : base(parent, name, Assets.Pixel, size, new Point(1, 1))
            {
                float huefraction = 1f / (size.X * size.Y);

                for (int x = 0; x < size.X; x++)
                {
                    for (int y = 0; y < size.Y; y++)
                    {
                        Tile t = new Tile(0);
                        t.Color = new HSVColor(huefraction * ((y * size.X) + x), 1, 1, 1).ToRGBColor();
                        t.Color.Action = ColorOutOfBoundsAction.WrapAround;

                        SetTile(x, y, t);
                    }
                }
            }
 private void OnTileSelected(Tile tile)
 {
     if (!_manager.RunningSimulation)
         tile.Index = tile.Index != DEAD ? DEAD : ALIVE;
 }
 public void OnTileSelect(Tile t)
 {
     t.Index++;
     if (t.Index > 2) t.Index = 0;
 }