Example #1
0
 private TileProperties[,] areasToTiles(tileType[,] mapAreas)
 {
     var mapTiles = new TileProperties[totalRows,totalCols];
     var thisTile = StaticTiles.GrassTile;
     for (int ii=0; ii<totalRows; ii++)
     {
         for (int jj=0; jj<totalCols; jj++)
         {
             switch (mapAreas[ii,jj])
             {
                 case tileType.outdoor:
                     thisTile = (rand.NextDouble() < 0.7) ? StaticTiles.GrassTile : StaticTiles.ForestTile; // eventually I need to make these into bunched forests
                     break;
                 case tileType.indoor:
                     thisTile = StaticTiles.FloorTile;
                     break;
                 case tileType.door:
                     thisTile = StaticTiles.FloorTile;
                     break;
                 case tileType.wall:
                     thisTile = StaticTiles.WallTile;
                     break;
                 default:
                     thisTile = StaticTiles.GrassTile;
                     break;
             }
             mapTiles[ii,jj] = thisTile;
         }
     }
     return mapTiles;
 }
Example #2
0
	/* LEVEL 1 FUNCTIONS
	 * 1: ENEMY MOVE
	 * 2: CHECK FOR PLAYER
	 */

	public IEnumerator EnemyMove(TileProperties targetTile)
	{
		UnmarkTileAsOccupied();
		yield return StartCoroutine(LerpToTargetLocation(targetTile.transform.position + 0.5f*Vector3.up));
		enemyStats.movesLeft -= 1;
		enemySpeedText.text = enemyStats.movesLeft + "/" + enemyStats.speed;
		SetCurrentTile();
		MarkTileAsOccupied();
	}
Example #3
0
        protected Tile ()
        {
            _uid = Guid.NewGuid();
            _dependents = new List<DependentTile>();

            _properties = new PropertyCollection(new string[0]);
            _predefinedProperties = new Tile.TileProperties(this);

            _properties.Modified += (s, e) => OnModified(EventArgs.Empty);
        }
Example #4
0
    // Use this for initialization
    void Start()
    {
        FutileParams futileParams = new FutileParams(true, true, true, true);
        manager = new MouseManager(this);
        futileParams.AddResolutionLevel(800, 1, 1, "");

        futileParams.origin = new Vector2(
            0.0f, 0.0f);
        Futile.instance.Init(futileParams);
        Futile.atlasManager.LoadImage("grasstile");
        Futile.atlasManager.LoadImage("foresttile");
        Futile.atlasManager.LoadImage("soldier");
        Futile.atlasManager.LoadImage("bluehighlight");
        var tileSize = 30;
        var width = 50;
        var height = 35;
        var tiles = new TileProperties[width, height];

        var grassTile = new TileProperties()
        {
            SpriteName = "grasstile",
            MovementPenalty = 1
        };

        var forestTile = new TileProperties()
        {
            SpriteName = "foresttile",
            MovementPenalty = 2
        };

        var actorProps = new ActorProperties()
        {
            SpriteName = "soldier",
            Name = "Hunkfort",
            MovementPoints = 5
        };

        var rand = new System.Random();
        for (int ii = 0; ii < width; ii++)
        {
            for (int jj = 0; jj < height; jj++)
            {
                tiles[ii, jj] = (rand.NextDouble() < 0.7) ? grassTile : forestTile;
            }
        }

        this.map = new Map(tiles, tileSize);
        this.map.AddActor(actorProps, new Vector2i(5, 5));
        this.map.Start();

        tileStage = new FStage("test");
        Futile.AddStage(tileStage);
        tileStage.stage.AddChild(this.map);
    }
Example #5
0
 public TileProperties[,] GenerateMap(int mapWidth, int mapHeight, int desiredNumberOfBuildings = 3, int randomSeed = -1)
 {
     totalCols = mapWidth;
     totalRows = mapHeight;
     maxBuildings = desiredNumberOfBuildings;
     mapSeed = randomSeed;
     if (mapSeed == -1) {
         rand = new System.Random();
     } else {
         rand = new System.Random(mapSeed);
     }
     //this.tileSet = tileSet;
     var map = new TileProperties[totalRows, totalCols];
     var mapAreas = assignAreas();
     map = areasToTiles(mapAreas);
     return map;
 }
Example #6
0
	/* LEVEL 2 FUNCTIONS
	 * 1: MOVE PLAYER
	 * 2: LERP TO TARGET LOCATION
	 * 3: SET ADJACENT TILES
	 * 4: UNSET ADJACENT TILES
	 * 5: TURN ON TILE GLOW
	 * 6: TURN OFF TILE GLOW
	 * 7: SET CURRENT TILE
	 * 8: MARK TILE AS OCCUPIED
	 * 9t,: UNMARK TILE AS OCCUPIED
	 */

	public IEnumerator PlayerMove(TileProperties targetTile)
	{
		moving = true;
		TurnOffTileGlow();
		UnsetAdjacentTiles();
		UnmarkTileAsOccupied();
		yield return StartCoroutine(LerpToTargetLocation(targetTile.transform.position + 0.5f*Vector3.up));
		SetCurrentTile();
		SetAdjacentTiles();
		TurnOnTileGlow();
		MarkTileAsOccupied();
		PlayerStats.movesLeft --;
		speedText.text = PlayerStats.movesLeft + "/" + PlayerStats.speed;
		moving = false;
		if(PlayerStats.movesLeft == 0)
			gameManager.EndTurn();
    }
        public TilePropForm(TilesetEditor editor, TileProperties properties)
        {
            InitializeComponent();

            this.Tileset = editor;
            this.Properties = properties;
            name.Text = properties.Name;
            checkBlocking.Checked = properties.Blocking;
            checkLethal.Checked = properties.Lethal;
            checkClimb.Checked = properties.Climbable;
            resistX.Value = (decimal)properties.ResistX;
            resistY.Value = (decimal)properties.ResistY;
            pushX.Value = (decimal)properties.PushX;
            pushY.Value = (decimal)properties.PushY;
            dragX.Value = (decimal)properties.DragX;
            dragY.Value = (decimal)properties.DragY;

            Tileset.Closed += (e) => this.Close();
        }
 public void AddProperties(TileProperties properties)
 {
     tileset.AddProperties(properties);
     Dirty = true;
 }
Example #9
0
    void GetSoundAmbient()
    {
        Ray   rMin  = cam.ViewportPointToRay(Vector3.zero);
        Ray   rMax  = cam.ViewportPointToRay(Vector3.one);
        Plane plane = new Plane(Vector3.forward, Vector3.zero);

        float distMin = 0.0f;
        float distMax = 0.0f;

        if (!plane.Raycast(rMin, out distMin))
        {
            return;
        }
        if (!plane.Raycast(rMax, out distMax))
        {
            return;
        }

        Vector3    minPoint = rMin.GetPoint(distMin);
        Vector3Int cellMin  = grid.Tilemap.WorldToCell(minPoint);

        Vector3    maxPoint = rMax.GetPoint(distMax);
        Vector3Int cellMax  = grid.Tilemap.WorldToCell(maxPoint);

        cellMax.x++;
        cellMax.y++;
        cellMax.z = 1;

        BoundsInt b = new BoundsInt();

        b.min = cellMin;
        b.max = cellMax;

        Dictionary <string, AudioTile> ambientRTPCs = new Dictionary <string, AudioTile>();

        ambientRTPCs.Add("DESERT", new AudioTile()
        {
            num = 0
        });
        ambientRTPCs.Add("PRAIRIE", new AudioTile()
        {
            num = 0
        });
        ambientRTPCs.Add("WATER", new AudioTile()
        {
            num = 0
        });
        ambientRTPCs.Add("WETLANDS", new AudioTile()
        {
            num = 0
        });
        ambientRTPCs.Add("RIVER", new AudioTile()
        {
            num = 0
        });

        int total = 0;

        foreach (Vector3Int p in b.allPositionsWithin)
        {
            TileProperties prop     = grid.GetTile(p);
            CustomTile     tileData = prop.Tile;
            if (!tileData)
            {
                continue;
            }

            Vector2 posCam = new Vector2(
                Mathf.InverseLerp(b.min.x, b.max.x - 1, p.x),
                Mathf.InverseLerp(b.min.y, b.max.y - 1, p.y)
                );

            if (prop.asRiver)
            {
                ambientRTPCs["RIVER"].num++;
                ambientRTPCs["RIVER"].sumPos += posCam;

                total++;
            }
            if (prop.asLake)
            {
                ambientRTPCs["WATER"].num++;
                ambientRTPCs["WATER"].sumPos += posCam;

                total++;
            }

            ambientRTPCs[tileData.ambientRTPC].num++;
            ambientRTPCs[tileData.ambientRTPC].sumPos += posCam;

            total++;
        }

        foreach (var d in ambientRTPCs)
        {
            AkSoundEngine.SetRTPCValue("AMBIANCE_VOLUME_" + d.Key, (float)d.Value.num / (float)total * 100.0f);
            if (d.Value.num != 0)
            {
                AkSoundEngine.SetRTPCValue("AMBIANCE_SPAT_" + d.Key, (d.Value.sumPos / d.Value.num).x);
            }
        }
    }
Example #10
0
    private void Initialize(TileProperties[,] tileProperties, int size)
    {
        this.tileSize = size;
        this.halfTileSize = this.tileSize / 2f;
        this.Width = tileProperties.GetUpperBound(0) + 1;
        this.Height = tileProperties.GetUpperBound(1) + 1;
        this.actorToPoint = new Dictionary<Actor, Vector2i>();
        this.pointToActor = new Dictionary<Vector2i, Actor>();

        this.Tiles = new Tile[this.Width, this.Height];
        for (int ii = 0; ii < this.Width; ii++)
        {
            for (int jj = 0; jj < this.Height; jj++)
            {
                var tile = new Tile(tileProperties[ii,jj]);
                tile.x = ii * this.tileSize + this.tileSize / 2;
                tile.y = jj * this.tileSize + this.tileSize / 2;
                tile.width = tile.height = this.tileSize;
                this.Tiles[ii, jj] = tile;
            }
        }

        this.mouseManager = new MouseManager(this);

        this.tileInterface = new TileInterface(this);
    }
Example #11
0
        private static void LoadObjectDbXml(string file)
        {
            var xmlSettings = XElement.Load(file);

            // Load Colors
            foreach (var xElement in xmlSettings.Elements("GlobalColors").Elements("GlobalColor"))
            {
                string    name  = (string)xElement.Attribute("Name");
                XNA.Color color = XnaColorFromString((string)xElement.Attribute("Color"));
                GlobalColors.Add(name, color);
            }

            foreach (var xElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                var curTile = new TileProperty();

                // Read XML attributes
                curTile.Color      = ColorFromString((string)xElement.Attribute("Color"));
                curTile.Name       = (string)xElement.Attribute("Name");
                curTile.Id         = (int?)xElement.Attribute("Id") ?? 0;
                curTile.IsFramed   = (bool?)xElement.Attribute("Framed") ?? false;
                curTile.IsSolid    = (bool?)xElement.Attribute("Solid") ?? false;
                curTile.SaveSlope  = (bool?)xElement.Attribute("SaveSlope") ?? false;
                curTile.IsSolidTop = (bool?)xElement.Attribute("SolidTop") ?? false;
                curTile.IsLight    = (bool?)xElement.Attribute("Light") ?? false;
                curTile.IsAnimated = (bool?)xElement.Attribute("IsAnimated") ?? false;
                curTile.FrameSize  = StringToVector2ShortArray((string)xElement.Attribute("Size"), 1, 1);
                // curTile.FrameSize = StringToVector2Short((string)xElement.Attribute("Size"), 1, 1);
                curTile.Placement   = InLineEnumTryParse <FramePlacement>((string)xElement.Attribute("Placement"));
                curTile.TextureGrid = StringToVector2Short((string)xElement.Attribute("TextureGrid"), 16, 16);
                curTile.FrameGap    = StringToVector2Short((string)xElement.Attribute("FrameGap"), 2, 2);
                curTile.IsGrass     = "Grass".Equals((string)xElement.Attribute("Special"));    /* Heathtech */
                curTile.IsPlatform  = "Platform".Equals((string)xElement.Attribute("Special")); /* Heathtech */
                curTile.IsCactus    = "Cactus".Equals((string)xElement.Attribute("Special"));   /* Heathtech */
                curTile.IsStone     = (bool?)xElement.Attribute("Stone") ?? false;              /* Heathtech */
                curTile.CanBlend    = (bool?)xElement.Attribute("Blends") ?? false;             /* Heathtech */
                curTile.MergeWith   = (int?)xElement.Attribute("MergeWith") ?? null;            /* Heathtech */
                string frameNamePostfix = (string)xElement.Attribute("FrameNamePostfix") ?? null;

                foreach (var elementFrame in xElement.Elements("Frames").Elements("Frame"))
                {
                    var curFrame = new FrameProperty();
                    // Read XML attributes
                    curFrame.Name    = (string)elementFrame.Attribute("Name");
                    curFrame.Variety = (string)elementFrame.Attribute("Variety");
                    curFrame.UV      = StringToVector2Short((string)elementFrame.Attribute("UV"), 0, 0);
                    curFrame.Anchor  = InLineEnumTryParse <FrameAnchor>((string)elementFrame.Attribute("Anchor"));
                    var frameSize = StringToVector2Short((string)elementFrame.Attribute("FrameSize"), curTile.FrameSize[0].X, curTile.FrameSize[0].Y);

                    // Assign a default name if none existed
                    if (string.IsNullOrWhiteSpace(curFrame.Name))
                    {
                        curFrame.Name = curTile.Name;
                    }

                    curTile.Frames.Add(curFrame);
                    string spriteName = null;
                    if (curFrame.Name == curTile.Name)
                    {
                        if (!string.IsNullOrWhiteSpace(curFrame.Variety))
                        {
                            spriteName += curFrame.Variety;
                        }
                    }
                    else
                    {
                        spriteName += curFrame.Name;
                        if (!string.IsNullOrWhiteSpace(curFrame.Variety))
                        {
                            spriteName += " - " + curFrame.Variety;
                        }
                    }
                    Sprites.Add(new Sprite
                    {
                        Anchor           = curFrame.Anchor,
                        IsPreviewTexture = false,
                        Name             = spriteName,
                        Origin           = curFrame.UV,
                        Size             = frameSize,
                        Tile             = (ushort)curTile.Id, /* SBlogic */
                        TileName         = curTile.Name
                    });
                }
                if (curTile.Frames.Count == 0 && curTile.IsFramed)
                {
                    var curFrame = new FrameProperty();
                    // Read XML attributes
                    curFrame.Name    = curTile.Name;
                    curFrame.Variety = string.Empty;
                    curFrame.UV      = new Vector2Short(0, 0);
                    //curFrame.Anchor = InLineEnumTryParse<FrameAnchor>((string)xElement.Attribute("Anchor"));

                    curTile.Frames.Add(curFrame);
                    Sprites.Add(new Sprite
                    {
                        Anchor           = curFrame.Anchor,
                        IsPreviewTexture = false,
                        Name             = null,
                        Origin           = curFrame.UV,
                        Size             = curTile.FrameSize[0],
                        Tile             = (ushort)curTile.Id,
                        TileName         = curTile.Name
                    });
                }
                TileProperties.Add(curTile);
                if (!curTile.IsFramed)
                {
                    TileBricks.Add(curTile);
                    TileBricksMask.Add(curTile);
                }
            }
            for (int i = TileProperties.Count; i < 255; i++)
            {
                TileProperties.Add(new TileProperty(i, "UNKNOWN", Color.FromArgb(255, 255, 0, 255), true));
            }

            foreach (var xElement in xmlSettings.Elements("Walls").Elements("Wall"))
            {
                var curWall = new WallProperty();
                curWall.Color = ColorFromString((string)xElement.Attribute("Color"));
                curWall.Name  = (string)xElement.Attribute("Name");
                curWall.Id    = (int?)xElement.Attribute("Id") ?? -1;
                WallProperties.Add(curWall);
                WallPropertiesMask.Add(curWall);
            }



            foreach (var xElement in xmlSettings.Elements("Items").Elements("Item"))
            {
                var curItem = new ItemProperty();
                curItem.Id           = (int?)xElement.Attribute("Id") ?? -1;
                curItem.Name         = (string)xElement.Attribute("Name");
                curItem.Scale        = (float?)xElement.Attribute("Scale") ?? 1f;
                curItem.MaxStackSize = (int?)xElement.Attribute("MaxStackSize") ?? 0;

                ItemProperties.Add(curItem);
                _itemLookup.Add(curItem.Id, curItem);
                int tally = (int?)xElement.Attribute("Tally") ?? 0;
                if (tally > 0)
                {
                    _tallynames.Add(tally, curItem.Name);
                }
                int head = (int?)xElement.Attribute("Head") ?? -1;
                if (head >= 0)
                {
                    _armorHeadNames.Add(curItem.Id, curItem.Name);
                }
                int body = (int?)xElement.Attribute("Body") ?? -1;
                if (body >= 0)
                {
                    _armorBodyNames.Add(curItem.Id, curItem.Name);
                }
                int legs = (int?)xElement.Attribute("Legs") ?? -1;
                if (legs >= 0)
                {
                    _armorLegsNames.Add(curItem.Id, curItem.Name);
                }
                bool rack = (bool?)xElement.Attribute("Rack") ?? false;
                if (rack)
                {
                    _rackable.Add(curItem.Id, curItem.Name);
                }

                bool food = (bool?)xElement.Attribute("IsFood") ?? false;
                if (food)
                {
                    _foodNames.Add(curItem.Id, curItem.Name);
                    curItem.IsFood = true;
                }

                bool acc = (bool?)xElement.Attribute("Accessory") ?? false;
                if (acc)
                {
                    _accessoryNames.Add(curItem.Id, curItem.Name);
                }

                if (curItem.Name.Contains("Dye"))
                {
                    _dyeNames.Add(curItem.Id, curItem.Name);
                }
            }

            foreach (var xElement in xmlSettings.Elements("Paints").Elements("Paint"))
            {
                var curPaint = new PaintProperty();
                curPaint.Id    = (int?)xElement.Attribute("Id") ?? -1;
                curPaint.Name  = (string)xElement.Attribute("Name");
                curPaint.Color = ColorFromString((string)xElement.Attribute("Color"));
                PaintProperties.Add(curPaint);
            }

            int chestId = 0;

            foreach (var tileElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                string tileName = (string)tileElement.Attribute("Name");
                int    type     = (int)tileElement.Attribute("Id");
                if (Tile.IsChest(type))
                {
                    foreach (var xElement in tileElement.Elements("Frames").Elements("Frame"))
                    {
                        var curItem = new ChestProperty();
                        curItem.Name = (string)xElement.Attribute("Name");
                        string variety = (string)xElement.Attribute("Variety");
                        if (variety != null)
                        {
                            if (tileName == "Dresser")
                            {
                                curItem.Name = variety + " " + "Dresser";
                            }
                            else
                            {
                                curItem.Name = curItem.Name + " " + variety;
                            }
                        }
                        curItem.ChestId  = chestId++;
                        curItem.UV       = StringToVector2Short((string)xElement.Attribute("UV"), 0, 0);
                        curItem.TileType = (ushort)type;
                        ChestProperties.Add(curItem);
                    }
                }
            }

            int signId = 0;

            foreach (var tileElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                var    tileId   = (int?)tileElement.Attribute("Id") ?? 0;
                string tileName = (string)tileElement.Attribute("Name");
                if (Tile.IsSign(tileId))
                {
                    ushort type = (ushort)((int?)tileElement.Attribute("Id") ?? 55);
                    foreach (var xElement in tileElement.Elements("Frames").Elements("Frame"))
                    {
                        var    curItem = new SignProperty();
                        string variety = (string)xElement.Attribute("Variety");
                        string anchor  = (string)xElement.Attribute("Anchor");
                        curItem.Name     = $"{tileName} {variety} {anchor}";
                        curItem.SignId   = signId++;
                        curItem.UV       = StringToVector2Short((string)xElement.Attribute("UV"), 0, 0);
                        curItem.TileType = type;
                        SignProperties.Add(curItem);
                    }
                }
            }

            foreach (var xElement in xmlSettings.Elements("Npcs").Elements("Npc"))
            {
                int    id   = (int?)xElement.Attribute("Id") ?? -1;
                string name = (string)xElement.Attribute("Name");
                NpcIds[name] = id;
                NpcNames[id] = name;
                var frames = StringToVector2Short((string)xElement.Attribute("Size"), 16, 40);
                NpcFrames[id] = frames;
            }

            foreach (var xElement in xmlSettings.Elements("ItemPrefix").Elements("Prefix"))
            {
                int    id   = (int?)xElement.Attribute("Id") ?? -1;
                string name = (string)xElement.Attribute("Name");
                ItemPrefix.Add((byte)id, name);
            }

            foreach (var xElement in xmlSettings.Elements("ShortCutKeys").Elements("Shortcut"))
            {
                var key      = InLineEnumTryParse <Key>((string)xElement.Attribute("Key"));
                var modifier = InLineEnumTryParse <ModifierKeys>((string)xElement.Attribute("Modifier"));
                var tool     = (string)xElement.Attribute("Action");
                ShortcutKeys.Add(tool, key, modifier);
            }

            XElement appSettings   = xmlSettings.Element("App");
            int      appWidth      = (int?)appSettings.Attribute("Width") ?? 800;
            int      appHeight     = (int?)appSettings.Attribute("Height") ?? 600;
            int      clipboardSize = (int)XNA.MathHelper.Clamp((int?)appSettings.Attribute("ClipboardRenderSize") ?? 512, 64, 4096);

            _appSize = new Vector2(appWidth, appHeight);
            ClipboardBuffer.ClipboardRenderSize = clipboardSize;

            ToolDefaultData.LoadSettings(xmlSettings.Elements("Tools"));

            AltC        = (string)xmlSettings.Element("AltC");
            SteamUserId = (int?)xmlSettings.Element("SteamUserId") ?? null;
        }
Example #12
0
 private static void setCollisionType(GameObject o, TileProperties properties)
 {
     CollisionType collisionType = o.GetComponent<CollisionType> ();
     if(collisionType != null){
         switch (properties.GetColliderType())
         {
             case "None":
                 collisionType.Type = CollisionType.ColliderType.None;
                 break;
             case "Solid":
                 collisionType.Type = CollisionType.ColliderType.Solid;
                 break;
             case "SemiSolid":
                 collisionType.Type = CollisionType.ColliderType.SemiSolid;
                 break;
             case "Moveable":
                 collisionType.Type = CollisionType.ColliderType.Moveable;
                 break;
             default:
                 collisionType.Type = CollisionType.ColliderType.None;
                 o.tag = "None";
                 break;
         }
     }
     o.tag = properties.GetColliderType ();
 }
Example #13
0
 public Tile(TileProperties tileProperties)
     : base(tileProperties == null ? "unknown" : tileProperties.SpriteName)
 {
     this.Properties = tileProperties;
 }
    void Update()
    {
        if (Tile.getSelectedTile() == null)
        {
            soilButtons.SetActive(false);
            commonButtons.transform.Find("populate").gameObject.SetActive(false);

            return;
        }
        activeTileObject     = Tile.getSelectedTile();
        actualTileType       = activeTileObject.GetComponent <TileTypeHandler>();
        actualTileProperties = activeTileObject.GetComponent <TileProperties>();
        actualTileBehaviour  = activeTileObject.GetComponent <TileScriptsBehaviourHandler>();

        handlePopulateButton();

        if (actualTileBehaviour.populated)
        {
            switch (actualTileType.tileType)
            {
            case TileType.Soil:
            {
                soilButtons.SetActive(true);

                if (activeTileObject.GetComponent <TileSoilBehaviour>().growing)
                {
                    soilButtons.transform.Find("stopGrow").gameObject.SetActive(true);
                    soilButtons.transform.Find("startGrow").gameObject.SetActive(false);
                }
                else
                {
                    soilButtons.transform.Find("stopGrow").gameObject.SetActive(false);
                    soilButtons.transform.Find("startGrow").gameObject.SetActive(true);
                }
                break;
            }

            case TileType.Water:
            {
                soilButtons.SetActive(false);
                break;
            }

            case TileType.None:
            {
                soilButtons.SetActive(false);
                break;
            }

            case TileType.MainHouse:
            {
                soilButtons.SetActive(false);
                break;
            }
            }
        }
        else
        {
            disableAllButtons();
        }
    }
Example #15
0
        private static void LoadObjectDbXml(string file)
        {
            var xmlSettings = XElement.Load(file);

            // Load Colors
            foreach (var xElement in xmlSettings.Elements("GlobalColors").Elements("GlobalColor"))
            {
                string    name  = (string)xElement.Attribute("Name");
                XNA.Color color = XnaColorFromString((string)xElement.Attribute("Color"));
                GlobalColors.Add(name, color);
            }

            foreach (var xElement in xmlSettings.Elements("Tiles").Elements("Tile"))
            {
                var curTile = new TileProperty();

                // Read XML attributes
                curTile.Color       = ColorFromString((string)xElement.Attribute("Color"));
                curTile.Name        = (string)xElement.Attribute("Name");
                curTile.Id          = (int?)xElement.Attribute("Id") ?? 0;
                curTile.IsFramed    = (bool?)xElement.Attribute("Framed") ?? false;
                curTile.IsSolid     = (bool?)xElement.Attribute("Solid") ?? false;
                curTile.IsSolidTop  = (bool?)xElement.Attribute("SolidTop") ?? false;
                curTile.IsLight     = (bool?)xElement.Attribute("Light") ?? false;
                curTile.FrameSize   = StringToVector2Short((string)xElement.Attribute("Size"), 1, 1);
                curTile.Placement   = InLineEnumTryParse <FramePlacement>((string)xElement.Attribute("Placement"));
                curTile.TextureGrid = StringToVector2Short((string)xElement.Attribute("TextureGrid"), 16, 16);
                curTile.IsGrass     = "Grass".Equals((string)xElement.Attribute("Special"));    /* Heathtech */
                curTile.IsPlatform  = "Platform".Equals((string)xElement.Attribute("Special")); /* Heathtech */
                curTile.IsCactus    = "Cactus".Equals((string)xElement.Attribute("Special"));   /* Heathtech */
                curTile.IsStone     = (bool?)xElement.Attribute("Stone") ?? false;              /* Heathtech */
                curTile.CanBlend    = (bool?)xElement.Attribute("Blends") ?? false;             /* Heathtech */
                curTile.MergeWith   = (int?)xElement.Attribute("MergeWith") ?? null;            /* Heathtech */
                foreach (var elementFrame in xElement.Elements("Frames").Elements("Frame"))
                {
                    var curFrame = new FrameProperty();
                    // Read XML attributes
                    curFrame.Name    = (string)elementFrame.Attribute("Name");
                    curFrame.Variety = (string)elementFrame.Attribute("Variety");
                    curFrame.UV      = StringToVector2Short((string)elementFrame.Attribute("UV"), 0, 0);
                    curFrame.Anchor  = InLineEnumTryParse <FrameAnchor>((string)elementFrame.Attribute("Anchor"));

                    // Assign a default name if none existed
                    if (string.IsNullOrWhiteSpace(curFrame.Name))
                    {
                        curFrame.Name = curTile.Name;
                    }

                    curTile.Frames.Add(curFrame);
                    Sprites.Add(new Sprite
                    {
                        Anchor           = curFrame.Anchor,
                        IsPreviewTexture = false,
                        Name             = curFrame.Name + ", " + curFrame.Variety,
                        Origin           = curFrame.UV,
                        Size             = curTile.FrameSize,
                        Tile             = (byte)curTile.Id,
                        TileName         = curTile.Name
                    });
                }
                if (curTile.Frames.Count == 0 && curTile.IsFramed)
                {
                    var curFrame = new FrameProperty();
                    // Read XML attributes
                    curFrame.Name    = curTile.Name;
                    curFrame.Variety = string.Empty;
                    curFrame.UV      = new Vector2Short(0, 0);
                    //curFrame.Anchor = InLineEnumTryParse<FrameAnchor>((string)xElement.Attribute("Anchor"));

                    // Assign a default name if none existed
                    if (string.IsNullOrWhiteSpace(curFrame.Name))
                    {
                        curFrame.Name = curTile.Name;
                    }

                    curTile.Frames.Add(curFrame);
                    Sprites.Add(new Sprite
                    {
                        Anchor           = curFrame.Anchor,
                        IsPreviewTexture = false,
                        Name             = curFrame.Name + ", " + curFrame.Variety,
                        Origin           = curFrame.UV,
                        Size             = curTile.FrameSize,
                        Tile             = (byte)curTile.Id,
                        TileName         = curTile.Name
                    });
                }
                TileProperties.Add(curTile);
                if (!curTile.IsFramed)
                {
                    TileBricks.Add(curTile);
                }
            }
            for (int i = TileProperties.Count; i < 255; i++)
            {
                TileProperties.Add(new TileProperty(i, "UNKNOWN", Color.FromArgb(255, 255, 0, 255), true));
            }

            foreach (var xElement in xmlSettings.Elements("Walls").Elements("Wall"))
            {
                var curWall = new WallProperty();
                curWall.Color   = ColorFromString((string)xElement.Attribute("Color"));
                curWall.Name    = (string)xElement.Attribute("Name");
                curWall.Id      = (int?)xElement.Attribute("Id") ?? -1;
                curWall.IsHouse = (bool?)xElement.Attribute("IsHouse") ?? false;
                WallProperties.Add(curWall);
            }

            foreach (var xElement in xmlSettings.Elements("Items").Elements("Item"))
            {
                var curItem = new ItemProperty();
                curItem.Id   = (int?)xElement.Attribute("Id") ?? -1;
                curItem.Name = (string)xElement.Attribute("Name");
                ItemProperties.Add(curItem);
                _itemLookup.Add(curItem.Id, curItem);
            }

            foreach (var xElement in xmlSettings.Elements("Npcs").Elements("Npc"))
            {
                int    id   = (int?)xElement.Attribute("Id") ?? -1;
                string name = (string)xElement.Attribute("Name");
                NpcIds.Add(name, id);
                NpcNames.Add(id, name);
                int frames = (int?)xElement.Attribute("Frames") ?? 16;
                NpcFrames.Add(id, frames);
            }

            foreach (var xElement in xmlSettings.Elements("ItemPrefix").Elements("Prefix"))
            {
                int    id   = (int?)xElement.Attribute("Id") ?? -1;
                string name = (string)xElement.Attribute("Name");
                ItemPrefix.Add((byte)id, name);
            }

            foreach (var xElement in xmlSettings.Elements("ShortCutKeys").Elements("Shortcut"))
            {
                var key  = InLineEnumTryParse <Key>((string)xElement.Attribute("Key"));
                var tool = (string)xElement.Attribute("Tool");
                ShortcutKeys.Add(key, tool);
            }

            XElement appSettings = xmlSettings.Element("App");
            int      appWidth    = (int?)appSettings.Attribute("Width") ?? 800;
            int      appHeight   = (int?)appSettings.Attribute("Height") ?? 600;

            _appSize = new Vector2(appWidth, appHeight);

            ToolDefaultData.LoadSettings(xmlSettings.Elements("Tools"));

            AltC = (string)xmlSettings.Element("AltC");
        }
        public TileProperties LoadProperties(XElement node)
        {
            var properties = new TileProperties();

            properties.Name = "Default";
            foreach (XAttribute attr in node.Attributes())
            {
                bool  b;
                float f;
                switch (attr.Name.LocalName.ToLower())
                {
                case "name":
                    properties.Name = attr.Value;
                    break;

                case "blocking":
                    if (!bool.TryParse(attr.Value, out b))
                    {
                        throw new Exception("Tile property blocking attribute was not a valid bool.");
                    }
                    properties.Blocking = b;
                    break;

                case "climbable":
                    if (!bool.TryParse(attr.Value, out b))
                    {
                        throw new Exception("Tile property climbable attribute was not a valid bool.");
                    }
                    properties.Climbable = b;
                    break;

                case "lethal":
                    if (!bool.TryParse(attr.Value, out b))
                    {
                        throw new Exception("Tile property lethal attribute was not a valid bool.");
                    }
                    properties.Lethal = b;
                    break;

                case "pushx":
                    if (!attr.Value.TryParse(out f))
                    {
                        throw new Exception("Tile property pushX attribute was not a valid number.");
                    }
                    properties.PushX = f;
                    break;

                case "pushy":
                    if (!attr.Value.TryParse(out f))
                    {
                        throw new Exception("Tile property pushY attribute was not a valid number.");
                    }
                    properties.PushY = f;
                    break;

                case "resistx":
                    if (!attr.Value.TryParse(out f))
                    {
                        throw new Exception("Tile property resistX attribute was not a valid number.");
                    }
                    properties.ResistX = f;
                    break;

                case "resisty":
                    if (!attr.Value.TryParse(out f))
                    {
                        throw new Exception("Tile property resistY attribute was not a valid number.");
                    }
                    properties.ResistY = f;
                    break;

                case "dragx":
                    if (!attr.Value.TryParse(out f))
                    {
                        throw new Exception("Tile property dragX attribute was not a valid number.");
                    }
                    properties.DragX = f;
                    break;

                case "dragy":
                    if (!attr.Value.TryParse(out f))
                    {
                        throw new Exception("Tile property dragY attribute was not a valid number.");
                    }
                    properties.DragY = f;
                    break;

                case "sinking":
                    if (!attr.Value.TryParse(out f))
                    {
                        throw new Exception("Tile property sinking attribute was not a valid number.");
                    }
                    properties.Sinking = f;
                    break;

                case "gravitymult":
                    if (!attr.Value.TryParse(out f))
                    {
                        throw new Exception("Tile property gravitymult attribute was not a valid number.");
                    }
                    properties.GravityMult = f;
                    break;

                case "onenter":
                    properties.OnEnter = attr.Value;
                    break;

                case "onleave":
                    properties.OnLeave = attr.Value;
                    break;

                case "onover":
                    properties.OnOver = attr.Value;
                    break;
                }
            }

            return(properties);
        }
Example #17
0
 private void Start()
 {
     singleton = this;
 }
Example #18
0
        private Func <Color32BppArgb, Color32BppArgb, Color32BppArgb> TransformPixel(TileProperties tileProperties)
        {
            switch (tileProperties)
            {
            case TileProperties.Invert:
                return((pixel, bottom) =>
                {
                    pixel.R ^= 0xFF;
                    pixel.G ^= 0xFF;
                    pixel.B ^= 0xFF;
                    return pixel;
                });

            case TileProperties.Red:
                return((pixel, bottom) =>
                {
                    pixel.R = 0xFF;
                    return pixel;
                });

            case TileProperties.Green:
                return((pixel, bottom) =>
                {
                    pixel.G = 0xFF;
                    return pixel;
                });

            case TileProperties.Blue:
                return((pixel, bottom) =>
                {
                    pixel.B = 0xFF;
                    return pixel;
                });

            case TileProperties.Yellow:
                return((pixel, bottom) =>
                {
                    pixel.R = 0xFF;
                    pixel.G = 0xFF;
                    return pixel;
                });

            case TileProperties.Magenta:
                return((pixel, bottom) =>
                {
                    pixel.R = 0xFF;
                    pixel.B = 0xFF;
                    return pixel;
                });

            case TileProperties.Cyan:
                return((pixel, bottom) =>
                {
                    pixel.G = 0xFF;
                    pixel.B = 0xFF;
                    return pixel;
                });

            case TileProperties.Transparent:
                return((pixel, bottom) =>
                {
                    pixel.R = (byte)((pixel.R + (1 * bottom.R)) >> 1);
                    pixel.G = (byte)((pixel.G + (1 * bottom.G)) >> 1);
                    pixel.B = (byte)((pixel.B + (1 * bottom.B)) >> 1);
                    return pixel;
                });

            case TileProperties.None:
            default:
                return((pixel, bottom) => pixel);
            }
        }
    void Start()
    {
        tileProperties = GetComponent<TileProperties>();

        setTileType();
    }
Example #20
0
    private void Initialize(TileProperties[,] tileProperties, int size)
    {
        this.tileSize = size;
        this.halfTileSize = this.tileSize / 2f;
        this.Columns = tileProperties.GetUpperBound(0) + 1;
        this.Rows = tileProperties.GetUpperBound(1) + 1;
        this.actorToPoint = new Dictionary<Actor, Vector2i>();
        this.pointToActor = new Dictionary<Vector2i, Actor>();

        this.Tiles = new Tile[this.Columns, this.Rows];
        for (int ii = 0; ii < this.Columns; ii++)
        {
            for (int jj = 0; jj < this.Rows; jj++)
            {
                var tile = new Tile(tileProperties[ii,jj]);
                tile.x = ii * this.tileSize + this.tileSize / 2;
                tile.y = jj * this.tileSize + this.tileSize / 2;
                tile.width = tile.height = this.tileSize;
                this.Tiles[ii, jj] = tile;
            }
        }
    }
Example #21
0
    /// <summary>
    /// Initialize resources.  Right now, for testing purposes, a simple random map is 
    /// generated here with a few actors in it.
    /// </summary>
    public override void Start()
    {
        var width = 50;
        var height = 35;
        var mapSeed = "blah blah";
        var tiles = new TileProperties[width, height];

        this.mapContainer = new FContainer();
        this.hud = new FContainer();

        // This handles GUI and stuff
        //this.interfaceManager = new InterfaceManager();
        //this.interfaceManager = ScriptableObject.CreateInstance("InterfaceManager");;

        // Generate a very simple random map tiles
        this.mapGenerator = new MapGenerator();
        tiles = mapGenerator.GenerateMap(width, height, 10);

        /*
         * this is the old code for generating a random map
        var rand = new System.Random();
        for (int ii = 0; ii < width; ii++)
        {
            for (int jj = 0; jj < height; jj++)
            {
                tiles[ii, jj] = (rand.NextDouble() < 0.7) ? StaticTiles.GrassTile : StaticTiles.ForestTile;
            }
        }
        */
        this.Map = new Map(tiles);

        int i = 5;
        int j = 5;
        foreach (var team in this.teams)
        {
            var actorList = new List<Actor>();
            foreach (var member in team.Members)
            {
                var actor = new Actor(member, team);
                actorList.Add(actor);
                this.Map.AddActor(actor, new Vector2i(i++, j++));
            }
        }

        this.Map.Start();
        this.mapContainer.AddChild(this.Map);

        // Initialize overlay
        this.visibleOverlayIndices = new HashSet<Vector2i>();
        this.overlay = new FSprite[Map.Columns, Map.Rows];
        for (int ii = 0; ii < Map.Columns; ii++)
        {
            for (int jj = 0; jj < Map.Rows; jj++)
            {
                var overlaySprite = new FSprite("bluehighlight");
                overlaySprite.x = ii * AwayTeam.TileSize + AwayTeam.TileSize / 2;
                overlaySprite.y = jj * AwayTeam.TileSize + AwayTeam.TileSize / 2;
                overlaySprite.isVisible = false;
                overlaySprite.width = overlaySprite.height = AwayTeam.TileSize;
                this.overlay[ii, jj] = overlaySprite;
                this.mapContainer.AddChild(overlaySprite);
            }
        }

        this.AddChild(this.mapContainer);
        this.AddChild(this.hud);
        this.teamIndex = 0;
        this.turnState = TurnState.TurnBegin;
        this.started = true;
    }
Example #22
0
    /// <summary>
    /// Initialize resources.  Right now, for testing purposes, a simple random map is 
    /// generated here with a few actors in it.
    /// </summary>
    public override void Start()
    {
        this.tileSize = 32;
        var width = 50;
        var height = 35;
        var tiles = new TileProperties[width, height];
        this.localAttackablePoints = new HashSet<Vector2i>();

        // Generate a very simple random map with two different kinds of tiles
        var rand = new System.Random();
        for (int ii = 0; ii < width; ii++)
        {
            for (int jj = 0; jj < height; jj++)
            {
                tiles[ii, jj] = (rand.NextDouble() < 0.7) ? StaticTiles.GrassTile : StaticTiles.ForestTiles;
            }
        }

        // Add a few actors to the map
        this.map = new Map(tiles, tileSize);
        this.map.AddActor(StaticActors.GoodSoldier, new Vector2i(5, 5));
        this.map.AddActor(StaticActors.GoodSoldier, new Vector2i(5, 6));
        this.map.AddActor(StaticActors.EvilSoldier, new Vector2i(5, 7), true);
        this.map.Start();
        this.AddChild(this.map);

        // Initilialize buttons
        this.crosshair = new FSprite("crosshair");
        this.crosshair.width = this.crosshair.height = this.tileSize;
        this.moveButton = new FButton("move");
        this.moveButton.sprite.width = this.moveButton.sprite.height = 32;
        this.attackButton = new FButton("attack");
        this.attackButton.sprite.width = this.attackButton.sprite.height = 32;
        this.waitButton = new FButton("wait");
        this.waitButton.sprite.width = this.waitButton.sprite.height = 32;
        this.useItemButton = new FButton("useitem");
        this.useItemButton.sprite.width = this.useItemButton.sprite.height = 32;
        this.moveButton.SignalRelease += new Action<FButton>(moveButton_SignalRelease);
        this.attackButton.SignalRelease += new Action<FButton>(attackButton_SignalRelease);
        this.waitButton.SignalRelease += new Action<FButton>(waitButton_SignalRelease);

        // Initialize highlights
        this.highlightedIndicies = new HashSet<Vector2i>();
        this.highlights = new FSprite[map.Columns, map.Rows];
        this.highlightedPath = new List<Vector2i>();
        for (int ii = 0; ii < map.Columns; ii++)
        {
            for (int jj = 0; jj < map.Rows; jj++)
            {
                var highlightSprite = new FSprite("bluehighlight");
                highlightSprite.x = ii * this.tileSize + this.tileSize / 2;
                highlightSprite.y = jj * this.tileSize + this.tileSize / 2;
                highlightSprite.isVisible = false;
                highlightSprite.width = highlightSprite.height = this.tileSize;
                this.highlights[ii, jj] = highlightSprite;
                this.AddChild(highlightSprite);
            }
        }
    }
Example #23
0
 public Map(TileProperties[,] tiles)
 {
     this.Initialize(tiles);
 }
Example #24
0
        private void comboProperties_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tileset == null) return;
            if (comboProperties.SelectedIndex == comboProperties.Items.Count - 1) // <New...> selected
            {
                MegaMan.TileProperties properties = new TileProperties();
                properties.Name = "NewProperties";
                TilePropForm propForm = new TilePropForm(tileset, properties);
                propForm.OkPressed += propForm_OkPressed;
                propForm.Show();

                comboProperties.SelectedIndex = 0;
            }
            else tileset.SetProperties(selected, comboProperties.SelectedItem.ToString());
        }
Example #25
0
    private static void setMaterials(TileProperties properties, GameObject mapPrimitive, int number, TiledLevel level, TileSet set)
    {
        MapComponent primitve = mapPrimitive.GetComponent<MapComponent> ();
        if (primitve == null)
            return;
        string name = set.Name;
        //Texture2D text = (Texture2D) level.Tilesets[0].Texture;
        string texturepath = "Assets/Textures/" + name + ".asset";

        string frontpath = SaveTileMaterial(name, number, texturepath, set);
        string backpath = SaveTileMaterial(name, properties.Back, texturepath, set);
        string toppath = SaveTileMaterial(name, properties.Top, texturepath, set);
        string bottompath = SaveTileMaterial(name, properties.Bottom, texturepath, set);
        string leftpath = SaveTileMaterial(name, properties.Left, texturepath, set);
        string rightpath = SaveTileMaterial(name, properties.Right, texturepath, set);

        if (!frontpath.Equals ("")) {
            primitve.SetFrontMaterial((Material) AssetDatabase.LoadAssetAtPath(frontpath, typeof(Material)));
        }
        if (!backpath.Equals ("")) {
            primitve.SetBackMaterial((Material) AssetDatabase.LoadAssetAtPath(backpath, typeof(Material)));
        }
        if (!toppath.Equals ("")) {
            primitve.SetTopMaterial((Material) AssetDatabase.LoadAssetAtPath(toppath, typeof(Material)));
        }
        if (!bottompath.Equals ("")) {
            primitve.SetBottomMaterial((Material) AssetDatabase.LoadAssetAtPath(bottompath, typeof(Material)));
        }
        if (!leftpath.Equals ("")) {
            primitve.SetLeftMaterial((Material) AssetDatabase.LoadAssetAtPath(leftpath, typeof(Material)));
        }
        if (!rightpath.Equals ("")) {
            primitve.SetRightMaterial((Material) AssetDatabase.LoadAssetAtPath(rightpath, typeof(Material)));
        }
    }
Example #26
0
    private void Initialize(TileProperties[,] tileProperties)
    {
        this.halfTileSize = AwayTeam.TileSize / 2f;
        this.Columns = tileProperties.GetUpperBound(0) + 1;
        this.Rows = tileProperties.GetUpperBound(1) + 1;

        this.Tiles = new Tile[this.Columns, this.Rows];
        for (int ii = 0; ii < this.Columns; ii++)
        {
            for (int jj = 0; jj < this.Rows; jj++)
            {
                var tile = new Tile(tileProperties[ii,jj]);
                tile.x = ii * AwayTeam.TileSize + this.halfTileSize;
                tile.y = jj * AwayTeam.TileSize + this.halfTileSize;
                tile.width = tile.height = AwayTeam.TileSize;
                this.Tiles[ii, jj] = tile;
            }
        }

        this.actors = new List<Actor>();
    }
Example #27
0
 public Map(TileProperties[,] tiles, int size)
 {
     this.Initialize(tiles, size);
 }
Example #28
0
        public Tile(string color, int type, Texture2D tileMap, TileProperties obstacle, string objectColor)
        {
            this.Sort = color;
            this.Type = type;
            this.TileMap = tileMap;
            this.Property = obstacle;
            this.objectColor = objectColor;

            if (Sort == Properties.TileColorCodes.Grass)
                TileType = 21;
            else if (Sort == Properties.TileColorCodes.Path && type == TL)
                TileType = 3;
            else if (Sort == Properties.TileColorCodes.Path && type == TM)
                TileType = 4;
            else if (Sort == Properties.TileColorCodes.Path && type == TR)
                TileType = 5;
            else if (Sort == Properties.TileColorCodes.Path && type == L)
                TileType = 13;
            else if (Sort == Properties.TileColorCodes.Path && type == M)
                TileType = 14;
            else if (Sort == Properties.TileColorCodes.Path && type == R)
                TileType = 15;
            else if (Sort == Properties.TileColorCodes.Path && type == BL)
                TileType = 23;
            else if (Sort == Properties.TileColorCodes.Path && type == BM)
                TileType = 24;
            else if (Sort == Properties.TileColorCodes.Path && type == BR)
                TileType = 25;
            else if (Sort == Properties.TileColorCodes.Roof && type == BM)
                TileType = 28;
            else if (Sort == Properties.TileColorCodes.Roof && type == BL)
                TileType = 26;
            else if (Sort == Properties.TileColorCodes.Roof && type == BR)
                TileType = 30;
            else if (Sort == Properties.TileColorCodes.Roof && (type == TL || type == TM || type == TR))
                TileType = 8;
            else if (Sort == Properties.TileColorCodes.Roof)
                TileType = 18;
            else if (Sort == Properties.TileColorCodes.Wall && type == BL)
                TileType = 36;
            else if (Sort == Properties.TileColorCodes.Wall && type == BR)
                TileType = 40;
            else if (Sort == Properties.TileColorCodes.Wall && type == BM)
                TileType = 38;
            else if (Sort == Properties.TileColorCodes.Wall && (type == M || type == TM))
                TileType = 27;
            else if (Sort == Properties.TileColorCodes.Wall && (type == L || type == TL))
                TileType = 19;
            else if (Sort == Properties.TileColorCodes.Wall && (type == R || type == TR))
                TileType = 29;
            else if (Sort == Properties.TileColorCodes.Forest && type == M)
                TileType = 52;
            else if (Sort == Properties.TileColorCodes.Forest && type == R)
                TileType = 53;
            else if (Sort == Properties.TileColorCodes.Forest && type == L)
                TileType = 51;
            else if (Sort == Properties.TileColorCodes.Forest && type == TM)
                TileType = 42;
            else if (Sort == Properties.TileColorCodes.Forest && type == TR)
                TileType = 43;
            else if (Sort == Properties.TileColorCodes.Forest && type == TL)
                TileType = 41;
            else if (Sort == Properties.TileColorCodes.Forest && type == BM)
                TileType = 62;
            else if (Sort == Properties.TileColorCodes.Forest && type == BR)
                TileType = 63;
            else if (Sort == Properties.TileColorCodes.Forest && type == BL)
                TileType = 61;
            else if (Sort == Properties.TileColorCodes.TallGrass && (type == L || type == TL || type == BL))
                TileType = 33;
            else if (Sort == Properties.TileColorCodes.TallGrass && (type == R || type == TR || type == BR))
                TileType = 35;
            else if (Sort == Properties.TileColorCodes.TallGrass)
                TileType = 34;

            if (objectColor == Properties.TileColorCodes.Window)
                ObjectType = 1;
            else if (objectColor == Properties.TileColorCodes.Door)
                ObjectType = 2;
        }
Example #29
0
	public void SetCurrentTile()
	{
		Ray tileCheck = new Ray(transform.position + Vector3.up, Vector3.down);
		RaycastHit tileHit;
		if(Physics.Raycast(tileCheck, out tileHit))
			currentTile = tileHit.collider.gameObject.GetComponent<TileProperties>();
	}
Example #30
0
    private void Initialize(TileProperties[,] tileProperties, int size)
    {
        this.tileSize = size;
        this.halfTileSize = this.tileSize / 2f;
        this.Columns = tileProperties.GetUpperBound(0) + 1;
        this.Rows = tileProperties.GetUpperBound(1) + 1;
        this.actorToPoint = new Dictionary<Actor, Vector2i>();
        this.pointToActor = new Dictionary<Vector2i, Actor>();
        this.highlightedIndicies = new List<Vector2i>();

        this.Tiles = new Tile[this.Columns, this.Rows];
        this.highlights = new FSprite[this.Columns, this.Rows];
        for (int ii = 0; ii < this.Columns; ii++)
        {
            for (int jj = 0; jj < this.Rows; jj++)
            {
                var highlightSprite = new FSprite("bluehighlight");
                highlightSprite.x = ii * this.tileSize + this.tileSize / 2;
                highlightSprite.y = jj * this.tileSize + this.tileSize / 2;
                highlightSprite.isVisible = false;
                highlightSprite.width = highlightSprite.height = this.tileSize;
                this.highlights[ii, jj] = highlightSprite;

                var tile = new Tile(tileProperties[ii,jj]);
                tile.x = ii * this.tileSize + this.tileSize / 2;
                tile.y = jj * this.tileSize + this.tileSize / 2;
                tile.width = tile.height = this.tileSize;
                this.Tiles[ii, jj] = tile;
            }
        }

        this.mouseManager = new MouseManager(this);
    }
	private TileProperties[] GetBoardNeighbours(int i, int j)
	{
		TileProperties[] ret = new TileProperties[8];
		int indexCounter = 0;
		for(int x = i-1; x <= i+1; x++)
		{
			for(int y = j-1; y <= j+1; y++)
			{
				if(x==i && y==j) continue;

				if(x >= 0 && x < RawBoard.GetLength(0))
					if(y >= 0 && y < RawBoard.GetLength(1))
						ret[indexCounter] = RawBoard[x,y].GetComponent<TileProperties>();
				indexCounter++;
			}
		}
		return ret;
	}
Example #32
0
    private void OnGUI()
    {
        if (data == null)
        {
            LoadData();
            Assert.IsNotNull(data);
        }

        if (data.Count == -1)
        {
            Debug.LogWarning("TileData asset exists, but contains no data!");
            ResetData();
            return;
        }

        if (collapsed.Length != data.Count)
        {
            collapsed = new bool[data.Count];

            for (int i = 0; i < collapsed.Length; i++)
            {
                collapsed[i] = true;
            }
        }

        if (GUI.Button(new Rect(position.width - 140.0f, 15.0f, 100.0f, 30.0f), "Save"))
        {
            SaveAsset();
        }

        if (GUI.Button(new Rect(position.width - 140.0f, 50.0f, 100.0f, 30.0f), "Refresh"))
        {
            if (!data.Refresh())
            {
                Debug.LogWarning("Something went wrong. Resetting the tile data.");
                ResetData();
                return;
            }
        }

        float y = 15.0f;

        scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Width(position.width), GUILayout.Height(position.height));

        for (int i = 0; i < data.Count; i++)
        {
            TileData td = data[i];

            if (collapsed[i])
            {
                GUI.contentColor = Color.gray;
                EditorGUI.LabelField(new Rect(15.0f, y, 100.0f, 20.0f), td.name, EditorStyles.boldLabel);
                GUI.contentColor = Color.white;

                GUI.color = GUI.color.SetAlpha(0.0f);

                if (GUI.Button(new Rect(15.0f, y, 100.0f, 20.0f), GUIContent.none))
                {
                    collapsed[i] = false;
                }

                GUI.color = GUI.color.SetAlpha(1.0f);
                y        += 20.0f;
                continue;
            }
            else
            {
                GUI.contentColor = Color.green;
                EditorGUI.LabelField(new Rect(15.0f, y, 100.0f, 20.0f), td.name, EditorStyles.boldLabel);
                GUI.contentColor = Color.white;

                GUI.color = GUI.color.SetAlpha(0.0f);

                if (GUI.Button(new Rect(15.0f, y, 100.0f, 20.0f), GUIContent.none))
                {
                    collapsed[i] = true;
                }

                GUI.color = GUI.color.SetAlpha(1.0f);
            }

            y      += 25.0f;
            td.type = (TileType)EditorGUI.EnumPopup(new Rect(15.0f, y, 120.0f, 20.0f), td.type);

            y += 25.0f;
            EditorGUI.BeginChangeCheck();

            EditorGUI.LabelField(new Rect(15.0f, y, 50.0f, 20.0f), "Variants");
            td.variantCount = EditorGUI.IntField(new Rect(80.0f, y, 25.0f, 20.0f), td.variantCount);

            if (EditorGUI.EndChangeCheck())
            {
                td.variantCount = Clamp(td.variantCount, 1, 100);
                Array.Resize(ref td.variants, td.variantCount);
                td.InitializeProperties();
            }

            y += 25.0f;

            float x = 15.0f;
            float lastLeftY = 0.0f, lastRightY = 0.0f;

            for (int v = 0; v < td.variantCount; v++)
            {
                float startY = y;

                if (td.variantCount != 1)
                {
                    GUI.contentColor = Color.magenta;
                    EditorGUI.LabelField(new Rect(x, y, 80.0f, 20.0f), "- " + v.ToString() + " -", EditorStyles.boldLabel);
                    GUI.contentColor = Color.white;
                    y += 25.0f;
                }

                TileProperties props = td.GetProperties(v);

                EditorGUI.LabelField(new Rect(x, y, 60.0f, 20.0f), "Invisible");
                props.invisible = EditorGUI.Toggle(new Rect(x + 55.0f, y, 15.0f, 25.0f), props.invisible);

                EditorGUI.LabelField(new Rect(x + 85.0f, y, 80.0f, 20.0f), "Has Collider");
                props.hasCollider = EditorGUI.Toggle(new Rect(x + 160.0f, y, 15.0f, 25.0f), props.hasCollider);

                if (props.hasCollider)
                {
                    EditorGUI.LabelField(new Rect(x + 190.0f, y, 60.0f, 20.0f), "Trigger");
                    props.trigger = EditorGUI.Toggle(new Rect(x + 240.0f, y, 15.0f, 25.0f), props.trigger);

                    y += 25.0f;
                    props.colliderSize   = EditorGUI.Vector2Field(new Rect(x, y, 120.0f, 20.0f), "Collider Size", props.colliderSize);
                    props.colliderOffset = EditorGUI.Vector2Field(new Rect(x + 135.0f, y, 120.0f, 20.0f), "Collider Offset", props.colliderOffset);
                    y += 15.0f;
                }

                if (!props.invisible)
                {
                    y += 25.0f;
                    props.renderOffset = EditorGUI.Vector3Field(new Rect(x, y, 180.0f, 20.0f), "Render Offset", props.renderOffset);

                    y += 45.0f;

                    EditorGUI.BeginChangeCheck();
                    props.sprite = (Sprite)EditorGUI.ObjectField(new Rect(x, y, 150.0f, 15.0f), props.sprite, typeof(Sprite), false);

                    if (EditorGUI.EndChangeCheck())
                    {
                        if (props.hasCollider)
                        {
                            props.colliderSize.x = props.sprite.rect.width / props.sprite.pixelsPerUnit;
                            props.colliderSize.y = props.sprite.rect.height / props.sprite.pixelsPerUnit;
                        }
                    }

                    props.color = EditorGUI.ColorField(new Rect(x + 165.0f, y, 150.0f, 15.0f), props.color);
                }

                y += 25.0f;
                props.component = (TileComponent)EditorGUI.ObjectField(new Rect(x, y, 160.0f, 15.0f), props.component, typeof(TileComponent), false);

                if (v % 2 == 0)
                {
                    x        += 400.0f;
                    lastLeftY = y;

                    if (v < td.variantCount - 1)
                    {
                        y = startY;
                    }
                    else
                    {
                        y += 25.0f;
                    }
                }
                else
                {
                    lastRightY = y;
                    y          = Max(lastLeftY, lastRightY) + 25.0f;
                    x          = 15.0f;
                }
            }
        }

        GUILayout.Space(y - 15.0f);
        EditorGUILayout.EndScrollView();
    }