private void OnTriggerEnter2D(Collider2D other)
    {
        if (farted && initialFartTime - fartTime > 0.05f && CollisionLayers.ContainsLayer(other.gameObject))
        {
            StopFart(!IsGrounded);
        }

        if (other.tag == "Carrot")
        {
            other.GetComponent <Carrot>().Collect();
            PlayerHealth.Instance.Health += (PlayerHealth.Instance.carrotHealthRechargePercent * PlayerHealth.Instance.maxHealth);
            fartAvailableTime             = Mathf.Min(fartAvailableTime + (fartMaxAvailableTime * carrotFartRechargePercent), fartMaxAvailableTime);
            PlayCarrotSound();
        }
        else if (other.tag == "Coin")
        {
            other.GetComponent <Coin>().Collect();
            coins++;
            PlayCoinSound();
        }
        else if (other.tag == "Flagpole")
        {
            var flagpole = other.GetComponent <Flagpole>();

            if (!flagpole.Activated)
            {
                PlayerHealth.Instance.PlayFlagSound();
                flagpole.Activate();
                DisableInput();
                StartCoroutine(GameMenu.Instance.ShowGameOver(1.2f));
            }
        }
    }
Esempio n. 2
0
        public static RaycastHit Raycast(Vector2 from, Vector2 to, float rayLength = Mathf.Infinity, float maxRayLength = Mathf.Infinity, int size = 1, GameObject ignore = null)
        {
            CollisionLayers mask    = CollisionLayers.Walk;
            var             hit     = new RaycastHit();
            var             diff    = to - from;
            var             stepLen = 0.2f;

            if (rayLength == Mathf.Infinity)
            {
                rayLength = Mathf.Min(diff.magnitude, maxRayLength);
            }
            int stepCount = Mathf.RoundToInt(rayLength / stepLen);
            var step      = diff.normalized * stepLen;
            var pos       = from;

            for (int i = 0; i < stepCount; ++i)
            {
                pos += step;
                Cell cell     = GetCell(pos);
                bool passable = Passable(pos, mask, size, ignore);
                if (!passable)
                {
                    hit.hit        = !passable;
                    hit.gameObject = cell.gameObject;
                    hit.pos        = pos;
                    break;
                }
            }
            return(hit);
        }
Esempio n. 3
0
        public static void SetPassable(Vector2i pos, int sizeX, int sizeY, bool passable, GameObject gameObject)
        {
            CollisionLayers layers = CollisionLayers.Walk;
            int             index  = instance.MapToIndex(pos) - sizeX / 2 - sizeY / 2 * instance.height;
            int             step   = instance.width - sizeX;

            for (int y = 0; y < sizeY; ++y)
            {
                int end = index + sizeX;
                while (index < end)
                {
                    Cell cell = instance.map[index];
                    if (passable && cell.gameObject == gameObject)
                    {
                        cell.blocked        = CollisionLayers.None;
                        cell.gameObject     = null;
                        instance.map[index] = cell;
                    }
                    else if (!passable && cell.blocked == CollisionLayers.None)
                    {
                        cell.blocked        = layers;
                        cell.gameObject     = gameObject;
                        instance.map[index] = cell;
                    }
                    ++index;
                }
                index += step;
            }
        }
Esempio n. 4
0
        public static bool Fit(Vector3 pos, out Vector3 result, int size = 1, CollisionLayers mask = CollisionLayers.Walk)
        {
            int index = instance.MapToIndex(pos);

            int maxIterations = 100;
            int sign          = 1;

            for (int i = 1; i < maxIterations; ++i, sign = -sign)
            {
                int end = index + sign * i;
                for (; index != end && index > size && index < instance.map.Length - size - 1; index += sign)
                {
                    if (Passable(index, mask, size))
                    {
                        result = instance.MapToIso(index);
                        return(true);
                    }
                }

                end = index - sign * i * instance.width;
                int step = -sign * instance.width;
                for (; index != end && index > size && index < instance.map.Length - size - 1; index += step)
                {
                    if (Passable(index, mask, size))
                    {
                        result = instance.MapToIso(index);
                        return(true);
                    }
                }
            }

            result = new Vector3();
            return(false);
        }
Esempio n. 5
0
        public static bool Passable(int index, CollisionLayers mask, int size = 1, GameObject ignore = null)
        {
            if (index - size - size * instance.width < 0 || index + size + size * instance.width >= instance.map.Length)
            {
                return(false);
            }

            index = index - size / 2 - size / 2 * instance.height;
            int step = instance.width - size;

            for (int y = 0; y < size; ++y)
            {
                int end = index + size;
                while (index < end)
                {
                    var  cell     = instance.map[index];
                    bool passable = (cell.blocked & mask) == 0;
                    if (!passable && (ignore == null || ignore != cell.gameObject))
                    {
                        return(false);
                    }
                    ++index;
                }
                index += step;
            }

            return(true);
        }
Esempio n. 6
0
        private static void ApplyTileCollisions(DT1.Tile tile, int x, int y)
        {
            var pos = Iso.MapTileToWorld(x, y);
            var collisionMapOffset = Iso.Snap(Iso.MapToIso(pos));
            int flagIndex          = 0;

            DT1.BlockFlags mask = DT1.BlockFlags.Walk | DT1.BlockFlags.PlayerWalk;
            for (int dy = 2; dy > -3; --dy)
            {
                for (int dx = -2; dx < 3; ++dx, ++flagIndex)
                {
                    Vector2i        subCellPos    = collisionMapOffset + new Vector2i(dx, dy);
                    bool            passable      = (tile.flags[flagIndex] & mask) == 0;
                    CollisionLayers blockedLayers = passable ? CollisionLayers.None : CollisionLayers.Walk;
                    if (tile.orientation == 0)
                    {
                        CollisionMap.SetBlocked(subCellPos, blockedLayers);
                    }
                    else if (CollisionMap.Passable(subCellPos, CollisionLayers.Walk) && !passable)
                    {
                        CollisionMap.SetBlocked(subCellPos, blockedLayers);
                    }
                }
            }
        }
Esempio n. 7
0
        private static void Spawn(MonStat monStat, int x, int y, int level, Transform root)
        {
            CollisionLayers collisionMask = CollisionLayers.Walk;

            if (!CollisionMap.Passable(new Vector2i(x, y) * Iso.SubTileCount, collisionMask, monStat.ext.sizeX))
            {
                return;
            }

            int count = Random.Range(monStat.minGrp, monStat.maxGrp + 1);

            for (int i = 0; i < count; ++i)
            {
                var mon = global::Diablerie.Game.World.WorldBuilder.SpawnMonster(monStat, Iso.MapTileToWorld(x, y), root);
                mon.level = level;
            }

            if (monStat.minion1 != null)
            {
                int minionCount = Random.Range(monStat.partyMin, monStat.partyMax);
                for (int i = 0; i < minionCount; ++i)
                {
                    var mon = global::Diablerie.Game.World.WorldBuilder.SpawnMonster(monStat.minion1, Iso.MapTileToWorld(x, y), root);
                    mon.level = level;
                }
            }
        }
Esempio n. 8
0
 public BoxData(Vector position, Vector scale, bool trigger, CollisionLayers layer, string name = "Unamed")
 {
     Position    = position;
     Scale       = scale;
     TriggerOnly = trigger;
     Layer       = layer;
     Name        = name;
 }
Esempio n. 9
0
        private static void StepTo(Node node)
        {
            CollisionLayers collisionMask = CollisionLayers.Walk;
            Node            newNode       = null;

            int dirStart;
            int dirEnd;

            if (node.directionIndex == -1)
            {
                dirStart = 0;
                dirEnd   = 8;
            }
            else if (node.directionIndex % 2 == 0)
            {
                dirStart = ((node.directionIndex - 1) + 8) % 8;
                dirEnd   = dirStart + 3;
            }
            else
            {
                dirStart = ((node.directionIndex - 2) + 8) % 8;
                dirEnd   = dirStart + 5;
            }

            for (int i = dirStart; i < dirEnd; ++i)
            {
                int      dir      = i % 8;
                Vector2i pos      = node.pos + directions[dir];
                bool     passable = CollisionMap.Passable(pos, collisionMask, size: size, ignore: self);

                if (passable)
                {
                    if (newNode == null)
                    {
                        newNode = Node.Get();
                    }
                    newNode.pos = pos;

                    bool closed = closeNodes.Contains(newNode);
                    if (!closed)
                    {
                        newNode.parent         = node;
                        newNode.gScore         = node.gScore + 1;
                        newNode.hScore         = Vector2i.manhattanDistance(target, newNode.pos);
                        newNode.score          = newNode.gScore + newNode.hScore;
                        newNode.directionIndex = dir;
                        openNodes.Add(newNode);
                        closeNodes.Add(newNode);
                        newNode = null;
                    }
                }
            }

            if (newNode != null)
            {
                newNode.Recycle();
            }
        }
Esempio n. 10
0
        protected void OnDrawGizmos()
        {
            var layerNumber = CollisionLayers.GetLayerNumber(NewLayer);

            if (layerNumber >= 0 && layerNumber <= 9)
            {
                Gizmos.DrawIcon(transform.position, "Collision Layers/gizmo_layer_" + layerNumber);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxColliderComponent"/> class.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="layer">The layer.</param>
        public BoxColliderComponent(Entity entity, float width, float height, CollisionLayers layer)
        {
            this.Entity       = entity;
            this.Width        = width;
            this.Height       = height;
            this.Layer        = layer;
            this.BoundaryType = CollisionBoundaryType.Square;

            _debugLines = new Texture2D(GameManager.Instance.GraphicsDevice, 1, 1);
            _debugLines.SetData <Color>(new Color[] { Color.White });
        }
 public TriangleColliderComponent(Entity entity, float width, float height, CollisionLayers layer, Oritation oritation)
 {
     this.Width        = width;
     this.Height       = height;
     this.Entity       = entity;
     this.Layer        = layer;
     this.BoundaryType = CollisionBoundaryType.Triangle;
     this.myOritation  = oritation;
     this.Position     = entity.Position;
     this.size         = entity.Height;
     this.NormalVector = TriangleColliderComponent.Normals[(int)this.myOritation];
     this.NormalVector.Normalize();
 }
Esempio n. 13
0
        protected void OnDrawGizmos()
        {
            var layerNumber = CollisionLayers.GetLayerNumber(NegativeLayer);

            if (layerNumber >= 0 && layerNumber <= 9)
            {
                Gizmos.DrawIcon(transform.position + Vector3.left / 2f, "Collision Layers/gizmo_layer_" + layerNumber);
            }

            layerNumber = CollisionLayers.GetLayerNumber(PositiveLayer);
            if (layerNumber >= 0 && layerNumber <= 9)
            {
                Gizmos.DrawIcon(transform.position + Vector3.right / 2f, "Collision Layers/gizmo_layer_" + layerNumber);
            }
        }
Esempio n. 14
0
 public static void SetBlocked(Vector3 pos, CollisionLayers value)
 {
     SetBlocked(Iso.Snap(pos), value);
 }
Esempio n. 15
0
 public void AddCollisionLayer(int layer)
 {
     CollisionLayers.Add(layer);
     GenerateMask();
 }
Esempio n. 16
0
        public static bool Passable(Vector2i pos, CollisionLayers mask, int size = 1, GameObject ignore = null)
        {
            int index = instance.MapToIndex(pos);

            return(Passable(index, mask, size, ignore));
        }
Esempio n. 17
0
 public static bool Passable(Vector3 pos, CollisionLayers mask, int size = 1, GameObject ignore = null)
 {
     return(Passable(Iso.Snap(pos), mask, size, ignore));
 }
Esempio n. 18
0
 public void RemoveCollisionLayer(int layer)
 {
     CollisionLayers.Remove(layer);
     GenerateMask();
 }
Esempio n. 19
0
        public static void SetBlocked(Vector2i pos, CollisionLayers value)
        {
            int index = instance.MapToIndex(pos);

            instance.map[index].blocked = value;
        }
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            world = new World(new Vector2(0f, 9.8f));
            mapDisaplayDevice = new XnaDisplayDevice(this.content, ScreenManager.GraphicsDevice);

            map = content.Load<Map>("Maps\\lvl1");
            map.LoadTileSheets(mapDisaplayDevice);

               collisionLayers = new CollisionLayers(ScreenManager.Game, world, map);

            gamePlayButtons = new GamePlayButtons(ScreenManager.Game, world);
            gamePlayButtons.LoadContent();

            playerManager = new PlayerManager(ScreenManager.Game, world, map);
            gameObjects.AddRange(playerManager.players);

            GameObjectLayersManager xTileGameObjects = new GameObjectLayersManager(ScreenManager.Game, world, map);
            gameObjects.AddRange(xTileGameObjects.GameObjects);

            //add game cam
            cam = new Camera(ScreenManager.GraphicsDevice.Viewport);
            cam.activePlayer = playerManager.currentPlayer;

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }
Esempio n. 21
0
        static Renderer CreateTile(DT1.Tile tile, int x, int y, int orderInLayer = 0, Transform parent = null)
        {
            var texture = tile.texture;
            var pos     = Iso.MapTileToWorld(x, y);

            GameObject gameObject = new GameObject();

            gameObject.name = tile.mainIndex + "_" + tile.subIndex + "_" + tile.orientation;
            gameObject.transform.position = pos;
            if (parent)
            {
                gameObject.transform.SetParent(parent);
            }
            var   meshRenderer = gameObject.AddComponent <MeshRenderer>();
            var   meshFilter   = gameObject.AddComponent <MeshFilter>();
            Mesh  mesh         = new Mesh();
            float x0           = tile.textureX;
            float y0           = tile.textureY;
            float w            = tile.width / Iso.pixelsPerUnit;
            float h            = (-tile.height) / Iso.pixelsPerUnit;

            if (tile.orientation == 0 || tile.orientation == 15)
            {
                var topLeft = new Vector3(-1f, 0.5f);
                if (tile.orientation == 15)
                {
                    topLeft.y += tile.roofHeight / Iso.pixelsPerUnit;
                }
                mesh.vertices = new Vector3[]
                {
                    topLeft,
                    topLeft + new Vector3(0, -h),
                    topLeft + new Vector3(w, -h),
                    topLeft + new Vector3(w, 0)
                };
                mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 };
                mesh.uv        = new Vector2[]
                {
                    new Vector2(x0 / texture.width, -y0 / texture.height),
                    new Vector2(x0 / texture.width, (-y0 + tile.height) / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, (-y0 + tile.height) / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height)
                };

                meshRenderer.sortingLayerID = tile.orientation == 0 ? SortingLayers.Floor : SortingLayers.Roof;
                meshRenderer.sortingOrder   = orderInLayer;

                gameObject.name += tile.orientation == 0 ? " (floor)" : " (roof)";
            }
            else if (tile.orientation > 15)
            {
                int upperPart = Math.Min(96, -tile.height);
                y0 -= upperPart;
                var topLeft = new Vector3(-1f, upperPart / Iso.pixelsPerUnit - 0.5f);
                mesh.vertices = new Vector3[] {
                    topLeft,
                    topLeft + new Vector3(0, -h),
                    topLeft + new Vector3(w, -h),
                    topLeft + new Vector3(w, 0)
                };
                mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 };
                mesh.uv        = new Vector2[] {
                    new Vector2(x0 / texture.width, -y0 / texture.height),
                    new Vector2(x0 / texture.width, (-y0 + tile.height) / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, (-y0 + tile.height) / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height)
                };
                meshRenderer.sortingLayerID = SortingLayers.LowerWall;
                meshRenderer.sortingOrder   = orderInLayer;

                gameObject.name += " (lower wall)";
            }
            else
            {
                var topLeft = new Vector3(-1f, h - 0.5f);
                mesh.vertices = new Vector3[] {
                    topLeft,
                    topLeft + new Vector3(0, -h),
                    topLeft + new Vector3(w, -h),
                    topLeft + new Vector3(w, 0)
                };
                mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 };
                mesh.uv        = new Vector2[] {
                    new Vector2(x0 / texture.width, (-y0 - tile.height) / texture.height),
                    new Vector2(x0 / texture.width, -y0 / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height),
                    new Vector2((x0 + tile.width) / texture.width, (-y0 - tile.height) / texture.height)
                };
                if (tile.orientation == 13) // shadows
                {
                    meshRenderer.sortingLayerID = SortingLayers.Shadow;
                }
                meshRenderer.sortingOrder = Iso.SortingOrder(pos) - 4;
            }
            meshFilter.mesh = mesh;

            int flagIndex          = 0;
            var collisionMapOffset = Iso.Snap(Iso.MapToIso(pos));

            DT1.BlockFlags mask = DT1.BlockFlags.Walk | DT1.BlockFlags.PlayerWalk;
            for (int dy = 2; dy > -3; --dy)
            {
                for (int dx = -2; dx < 3; ++dx, ++flagIndex)
                {
                    Vector2i        subCellPos    = collisionMapOffset + new Vector2i(dx, dy);
                    bool            passable      = (tile.flags[flagIndex] & mask) == 0;
                    CollisionLayers blockedLayers = passable ? CollisionLayers.None : CollisionLayers.Walk;
                    if (tile.orientation == 0)
                    {
                        CollisionMap.SetBlocked(subCellPos, blockedLayers);
                    }
                    else if (CollisionMap.Passable(subCellPos, CollisionLayers.Walk) && !passable)
                    {
                        CollisionMap.SetBlocked(subCellPos, blockedLayers);
                    }
                }
            }

            meshRenderer.material = tile.material;
            return(meshRenderer);
        }