Пример #1
0
    private IEnumerator _MoveSlug(Slug slug, Vec2i endPos, System.Action callback)
    {
        var trail = trailSys.CreateTrail(slug.pos, endPos, slug.color, turn);

        Vector2 startWPos = GameHelper.TileToWorldPos(slug.pos) + (Vector2)currLvl.transform.position;
        Vector2 endWPos   = GameHelper.TileToWorldPos(endPos) + (Vector2)currLvl.transform.position;

        slug.transform.rotation = GameHelper.GetRotationFromVector(endWPos - startWPos);
        float duration         = GameRules.AnimDurationPrTile * (Vector2.Distance(startWPos, endWPos) / Mathf.Sqrt(3f));
        float endTime          = Time.time + duration;
        bool  checkedColChange = false;

        while (Time.time < endTime)
        {
            float t = 1 - (endTime - Time.time) / duration;
            slug.transform.position = startWPos + (endWPos - startWPos) * t;
            if (trail)
            {
                trail.SetVisible(1 - t);
            }

            if (trail != null && !checkedColChange && t > 0.5)
            {
                //Log("currLvl.Map.GetTOAtPos(endPos): " + currLvl.Map.GetTOAtPos(endPos));
                PaintBucket bucket = null;
                foreach (var item in currLvl.Map.GetTOAtPos(endPos))
                {
                    //Log("item: " + item);
                    if (item.GetType() == typeof(PaintBucket))
                    {
                        bucket = (PaintBucket)item;
                        break;
                    }
                }
                //var bucket = currLvl.Map.GetTOAtPos(endPos).First(x => x is PaintBucket);
                if (bucket != null)
                {
                    trail.SetSecondaryColor(((PaintBucketDefinition)bucket.ToDef).color);
                }
                checkedColChange = true;
            }
            yield return(null);
        }
        slug.SetPosition(endPos);
        if (trail)
        {
            trail.SetVisible(0);
        }

        callback();
    }
Пример #2
0
    private bool SlugTOInteraction(Slug slug, Vec2i pos, bool sliding = true, bool useTeleports = true)
    {
        foreach (var to in currLvl.Map.GetTOAtPos(pos))
        {
            var result = to.PlayerEntered();
            Log("PlayerTOInteraction - sliding: " + sliding + ", result.type: " + result.type);

            switch (result.type)
            {
            case TileObjectInteractionResultType.Kill:
                LoseLevel();
                return(true);

            case TileObjectInteractionResultType.Teleport:
                //Debug.LogError("CURRENTLY NOT WORKING - TODO!");
                //Set Player position, interact with end tile
                //playerPos = result.position;
                //playerObj.transform.position = (Vector3)GameHelper.TileToWorldPos(result.position) + currLvl.transform.position;

                if (useTeleports)
                {
                    slug.SetPosition(result.pos);
                }

                // interact with end tile
                //if (PlayerTileInteraction()) return true;
                break;

            case TileObjectInteractionResultType.PickupColor:
                slug.SetColor(result.color);
                currLvl.Map.DeleteTOAtPos(pos, to);
                break;

            case TileObjectInteractionResultType.Exit:
                if (!sliding)
                {
                    Log("Slug on exit - exit color: " + ((ExitDefinition)to.ToDef).color + ", slug color: " + slug.color);
                    if (((ExitDefinition)to.ToDef).color == TileColor.None || ((ExitDefinition)to.ToDef).color == slug.color)
                    {
                        slug.isOnExit = true;

                        if (GameRules.RemoveSlugsWhenTouchExit)
                        {
                            slugList.Remove(slug);
                            Destroy(slug.gameObject);
                        }

                        bool allSlugsOnExit = true;
                        foreach (var otherSlug in slugList)
                        {
                            if (!otherSlug.isOnExit)
                            {
                                allSlugsOnExit = false;
                            }
                        }
                        if (allSlugsOnExit)
                        {
                            WinLevel();
                            return(true);
                        }
                    }
                }
                break;

            default: break;
            }
            //if (result.kill)
            //if (to.GetType() == typeof(Spikes)) {
            //	SpikesDefintion spikesDef = (SpikesDefintion)to.ToDef;
            //	if (spikesDef.isRaised) {
            //		LoseLevel();
            //		return true;
            //	}
            //}
        }
        return(false);
    }