Ejemplo n.º 1
0
        private void MakeStep()
        {
            var         firstSegmentPos = segments[0].Position;
            var         direction       = input.GetLastDirection();
            FieldCoords deltaPos;

            switch (direction)
            {
            case MoveDirection.Up:
                deltaPos = FieldCoords.up;
                break;

            case MoveDirection.Right:
                deltaPos = FieldCoords.right;
                break;

            case MoveDirection.Down:
                deltaPos = FieldCoords.down;
                break;

            case MoveDirection.Left:
                deltaPos = FieldCoords.left;
                break;

            default:
                throw new NotImplementedException(string.Format("Unknown move direction", direction));
            }
            FieldCoords nextPos = firstSegmentPos + deltaPos;

            if (segments.Count > 1)
            {
                var secondSegmentPos = segments[1].Position;
                if (nextPos == secondSegmentPos)
                {
                    // incorrect direction input
                    nextPos = firstSegmentPos - deltaPos;
                }
            }

            for (int i = 0; i < segments.Count; i++)
            {
                var segment = segments[i];
                var oldPos  = segment.Position;
                segment.Position        = nextPos;
                segment.View.position   = nextPos.ToVector3();
                segment.View.localScale = bonuses.Has(nextPos) ? fatSegmentScale : Vector3.one;

                nextPos = oldPos;
            }
            if (bonuses.Use(nextPos))
            {
                SpawnBodySegment(nextPos);
            }
        }
Ejemplo n.º 2
0
        public void SpawnBonus(Bonus what, FieldCoords where)
        {
            Transform prefab;

            if (bonusPrefabs.TryGetValue(what, out prefab))
            {
                var pos = where.ToVector3();
                pos.y = bonusSpawnHeight;
                var bonusView = GameObject.Instantiate(prefab, pos, Quaternion.identity, fieldRoot);
                spawnedBonuses.Add(where, bonusView);
            }
        }