public CollideDemo(CollideType primOne, CollideType primTwo)
            : base()
        {
            // Turn this on to keep a reference to all contacts with both bodies
            CaptureBodyContacts = false;

            Restitution = 0.2f;
            Friction = 0.0f;// 1f;
            int positionIterations = 5;
            int velocityIterations = 5;

            float penetrationEpsilon = 0.0001f;// 26f;
            float velocityEpisilon = 0.0001f;// 01f;
            ContactResolver = new ContactResolver(
                positionIterations, velocityIterations,
                penetrationEpsilon, velocityEpisilon);

            primOneCollideType = primOne;
            primTwoCollideType = primTwo;

            DefaultSphereMass = 1f;
            DefaultSphereRadius = 1f;

            DefaultSpawnPosOne = new Vector3(-DefaultSphereRadius * 3.51f, 10.001f, 0.001f);
            DefaultSpawnPosTwo = new Vector3(DefaultSphereRadius * 3.51f, 10.001f, 0.001f);

            DefaultSpawnPosOne = new Vector3(0f, 10f, 0f);
            DefaultSpawnPosTwo = new Vector3(-0.5f, 15f, 0f);

            LastContact = new Contact();
        }
示例#2
0
        static int FindYAbove(Level lvl, ushort x, ushort y, ushort z)
        {
            for (; y <= lvl.Height; y++)
            {
                BlockID above = lvl.GetBlock(x, (ushort)(y + 1), z);
                if (above == Block.Invalid)
                {
                    continue;
                }
                if (!CollideType.IsSolid(lvl.CollideType(above)))
                {
                    continue;
                }

                int             posY = (y + 1) * 32 - 6;
                BlockDefinition def  = lvl.GetBlockDef(above);
                if (def != null)
                {
                    posY += def.MinZ * 2;
                }

                return(posY);
            }
            return(-1);
        }
示例#3
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        CollideType type = collision.gameObject.GetComponent("CollideType") as CollideType;

        switch (type.type)
        {
        case "asteroid_large":
            armor -= type.damage;
            break;

        case "asteroid_med":
            armor -= type.damage;
            break;

        case "asteroid_small":
            armor -= type.damage;
            break;

        case "shield":
            armor -= type.damage;
            break;

        case "ship":
            armor -= type.damage;
            break;
        }
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        if (player == null)
        {
            GameObject oPlayer = GameObject.FindGameObjectWithTag("Player");

            if (oPlayer == null)
            {
                if (!isGameOver)
                {
                    GameObject gameOver = Resources.Load("UI/Game Over") as GameObject;
                    Instantiate(gameOver, new Vector2(0, 2.5f), Quaternion.identity);
                    isGameOver = true;
                }
                return;
            }

            player = oPlayer.transform;
        }

        RaycastHit2D hit = Physics2D.Raycast(turret.transform.position, turret.transform.up, Mathf.Infinity, 1 << LayerMask.NameToLayer("Foreground"));

        if (hit)
        {
            CollideType type = ((CollideType)hit.collider.gameObject.GetComponent("CollideType"));
            if (type.type == "ship" && Time.time > lastFire + weapon.fireRate)
            {
                Fire(weapon.fireCount);
                lastFire = Time.time;
            }
        }

        checkForDead();
    }
示例#5
0
        void GetSound()
        {
            Vector3 pos    = p.interp.next.Pos;
            AABB    bounds = p.Bounds;

            sndType   = SoundType.None;
            anyNonAir = false;

            // first check surrounding liquids/gas for sounds
            p.TouchesAny(bounds, checkSoundNonSolid);
            if (sndType != SoundType.None)
            {
                return;
            }

            // then check block standing on
            pos.Y -= 0.01f;
            Vector3I feetPos    = Vector3I.Floor(pos);
            BlockID  blockUnder = game.World.SafeGetBlock(feetPos);
            float    maxY       = feetPos.Y + game.BlockInfo.MaxBB[blockUnder].Y;

            SoundType   typeUnder   = game.BlockInfo.StepSounds[blockUnder];
            CollideType collideType = game.BlockInfo.Collide[blockUnder];

            if (maxY >= pos.Y && collideType == CollideType.Solid && typeUnder != SoundType.None)
            {
                anyNonAir = true; sndType = typeUnder; return;
            }

            // then check all solid blocks at feet
            bounds.Max.Y = bounds.Min.Y = pos.Y;
            p.TouchesAny(bounds, checkSoundSolid);
        }
示例#6
0
        static bool SolidAt(Level lvl, ushort x, int y, ushort z)
        {
            if (y >= lvl.Height)
            {
                return(false);
            }
            BlockID block = lvl.GetBlock(x, (ushort)y, z);

            return(CollideType.IsSolid(lvl.CollideType(block)));
        }
示例#7
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        CollideType type = collision.gameObject.GetComponent("CollideType") as CollideType;

        switch (type.type)
        {
        case "projectile":
            armor -= type.damage;
            break;
        }
    }
示例#8
0
        public override bool Collides(Circle circle, CollideType detectMethod = CollideType.All)
        {
            double Distance;

            Distance = Math.Sqrt((Math.Pow((double)(circle.position.X - this.position.X), 2)) + (Math.Pow((double)(circle.position.Y - this.position.Y), 2)));

            if (Distance <= (this.radius + circle.radius))
                return true;
            else
                return false;
        }
示例#9
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        CollideType type = collision.GetComponent <CollideType>();

        Debug.Log("Hit by: " + type.type + " in shield trigger");
        switch (type.type)
        {
        case "projectile":
            break;
        }
    }
示例#10
0
 public bool HasCollisionType(CollideType collideType)
 {
     foreach (Transform child in transform)
     {
         if (child.name.Contains($"Collide Set {collideType}"))
         {
             return(true);
         }
     }
     return(false);
 }
示例#11
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        CollideType type = collision.GetComponent <CollideType>();

        if (type.type != "shield")
        {
            Instantiate(explosion, collision.transform.position, Quaternion.identity);
        }

        Destroy(gameObject);
    }
示例#12
0
        public PrivilegedActivationStatus GetPrivilegedActionZoneStatus(CollideType type, int index)
        {
            int activations = 0;

            if (privilegedActivations.ContainsKey(type))
            {
                activations = privilegedActivations[type];
            }
            int offset = index * 2;
            int value  = ((1 << 2) - 1) & (activations >> (offset)); // extract 2 bits from offset

            return((PrivilegedActivationStatus)value);
        }
示例#13
0
        public override bool Collides(Rect rect, CollideType detectMethod = CollideType.All)
        {
            Vector2 circleDistance = new Vector2((float)Math.Abs(this.position.X - rect.position.X), (float)Math.Abs(this.position.Y - rect.position.Y));

            if (circleDistance.X > (rect.size.X / 2 + this.radius)) return false;
            if (circleDistance.Y > (rect.size.Y / 2 + this.radius)) return false;

            if (circleDistance.X <= (rect.size.X / 2)) return true;
            if (circleDistance.Y <= (rect.size.Y / 2)) return true;

            float cornerDistance_sq = (float)(Math.Pow((double)(circleDistance.X - rect.size.X / 2), 2) + Math.Pow((double)(circleDistance.Y - rect.size.Y / 2), 2));
            return (cornerDistance_sq <= (float)Math.Pow(this.radius, 2));
        }
示例#14
0
    // breakup asteroid on collision with projectile
    void OnTriggerEnter2D(Collider2D collision)
    {
        // Get the collision type of the object that hit the asteroid
        CollideType type = collision.gameObject.GetComponent("CollideType") as CollideType;

        switch (type.type)
        {
        // if its a projectile trigger a breakup
        case "projectile":
            breakup(collision);
            break;
        }
    }
        public ModelEntity Create(CollideType primType, Vector3 position, float mass, float dimension = 1f)
        {
            switch (primType)
            {
                case CollideType.Sphere:
                    return CreateSphere(position, mass, dimension);

                case CollideType.Box:
                    return CreateCube(position, mass, dimension);

            }

            throw new ArgumentException("Invalid CollideType");
        }
示例#16
0
        public static int FindIntersectingSolids(AABB bb, Level lvl, ref AABB[] aabbs)
        {
            Vec3S32 min = bb.BlockMin, max = bb.BlockMax;
            int     volume = (max.X - min.X + 1) * (max.Y - min.Y + 1) * (max.Z - min.Z + 1);

            if (volume > aabbs.Length)
            {
                aabbs = new AABB[volume];
            }
            int count = 0;

            for (int y = min.Y; y <= max.Y; y++)
            {
                for (int z = min.Z; z <= max.Z; z++)
                {
                    for (int x = min.X; x <= max.X; x++)
                    {
                        BlockID block   = lvl.GetBlock((ushort)x, (ushort)y, (ushort)z);
                        AABB    blockBB = lvl.blockAABBs[block];

                        blockBB.Min.X += x * 32; blockBB.Min.Y += y * 32; blockBB.Min.Z += z * 32;
                        blockBB.Max.X += x * 32; blockBB.Max.Y += y * 32; blockBB.Max.Z += z * 32;
                        if (!AABB.Intersects(ref bb, ref blockBB))
                        {
                            continue;
                        }

                        BlockDefinition def   = lvl.GetBlockDef(block);
                        bool            solid = false;

                        if (def != null)
                        {
                            solid = CollideType.IsSolid(def.CollideType);
                        }
                        else
                        {
                            solid = block == Block.Invalid || !Block.Walkthrough(Block.Convert(block));
                        }
                        if (!solid)
                        {
                            continue;
                        }

                        aabbs[count] = blockBB;
                        count++;
                    }
                }
            }
            return(count);
        }
示例#17
0
        bool CheckSoundNonSolid(byte b)
        {
            SoundType   newType = game.BlockInfo.StepSounds[b];
            CollideType collide = game.BlockInfo.Collide[b];

            if (newType != SoundType.None && collide != CollideType.Solid)
            {
                sndType = newType;
            }
            if (!game.BlockInfo.IsAir[b])
            {
                anyNonAir = true;
            }
            return(false);
        }
示例#18
0
        internal static void Fall(Player p, AABB bb, bool movingDown)
        {
            // Client position is slightly more precise than server's
            // If don't adjust, it's possible for player to land on edge of a block and not die
            // Only do when not moving down, so hitting a pillar while falling doesn't trigger
            if (!movingDown)
            {
                bb.Min.X -= 1; bb.Max.X += 1;
                bb.Min.Z -= 1; bb.Max.Z += 1;
            }

            bb.Min.Y -= 2; // test block below player feet
            Vec3S32 min = bb.BlockMin, max = bb.BlockMax;
            bool    allGas = true;

            for (int z = min.Z; z <= max.Z; z++)
            {
                for (int x = min.X; x <= max.X; x++)
                {
                    BlockID block   = GetSurvivalBlock(p, x, min.Y, z);
                    byte    collide = p.level.CollideType(block);
                    allGas = allGas && collide == CollideType.WalkThrough;
                    if (!CollideType.IsSolid(collide))
                    {
                        continue;
                    }

                    int fallHeight = p.startFallY - bb.Min.Y;
                    if (fallHeight > p.level.Config.FallHeight * 32)
                    {
                        p.HandleDeath(Block.Air, null, false, true);
                    }

                    p.startFallY = -1;
                    return;
                }
            }

            if (!allGas)
            {
                return;
            }
            if (bb.Min.Y > p.lastFallY)
            {
                p.startFallY = -1;                         // flying up resets fall height
            }
            p.startFallY = Math.Max(bb.Min.Y, p.startFallY);
        }
示例#19
0
    //! 构造
    public Sprite2D()
    {
        m_LocalPosition   = Vector2.zero;
        m_LocalRotation   = 0;
        m_Velocity        = Vector2.zero;
        m_AngularVelocity = 0;
        m_Parent          = null;
        m_MountPosition   = false;
        m_MountRotation   = false;

        m_LocalCollideType      = CollideType.Null;
        m_LocalCollidePointers  = null;
        m_GlobalCollideType     = CollideType.Null;
        m_GlobalCollidePointers = null;
        m_UpdateCollideInfo     = true;
    }
示例#20
0
        bool CheckSoundNonSolid(BlockID b)
        {
            SoundType   newType = game.BlockInfo.StepSounds[b];
            CollideType collide = game.BlockInfo.Collide[b];

            if (newType != SoundType.None && collide != CollideType.Solid)
            {
                sndType = newType;
            }

            if (game.BlockInfo.Draw[b] != DrawType.Gas)
            {
                anyNonAir = true;
            }
            return(false);
        }
示例#21
0
        /// <summary> Updates the block at the given position, mainly intended for manual changes by the player. </summary>
        /// <remarks> Adds to the BlockDB. Also turns block below to grass/dirt depending on light. </remarks>
        /// <returns> Return code from DoBlockchange </returns>
        public ChangeResult ChangeBlock(ushort x, ushort y, ushort z, BlockID block)
        {
            BlockID      old    = level.GetBlock(x, y, z);
            ChangeResult result = level.DoBlockchange(this, x, y, z, block);

            if (result == ChangeResult.Unchanged)
            {
                return(result);
            }
            if (result == ChangeResult.Modified)
            {
                level.BroadcastChange(x, y, z, block);
            }

            ushort flags = BlockDBFlags.ManualPlace;

            if (painting && CollideType.IsSolid(level.CollideType(old)))
            {
                flags = BlockDBFlags.Painted;
            }

            level.BlockDB.Cache.Add(this, x, y, z, flags, old, block);
            y--; // check for growth at block below

            bool grow = level.Config.GrassGrow && (level.physics == 0 || level.physics == 5);

            if (!grow || level.CanAffect(this, x, y, z) != null)
            {
                return(result);
            }
            BlockID below = level.GetBlock(x, y, z);

            BlockID grass = level.Props[below].GrassBlock;

            if (grass != Block.Invalid && block == Block.Air)
            {
                level.Blockchange(this, x, y, z, grass);
            }

            BlockID dirt = level.Props[below].DirtBlock;

            if (dirt != Block.Invalid && !level.LightPasses(block))
            {
                level.Blockchange(this, x, y, z, dirt);
            }
            return(result);
        }
示例#22
0
        /// <summary> Updates the block at the given position, mainly intended for manual changes by the player. </summary>
        /// <remarks> Adds to the BlockDB. Also turns block below to grass/dirt depending on light. </remarks>
        /// <returns> Return code from DoBlockchange </returns>
        public int ChangeBlock(ushort x, ushort y, ushort z, BlockID block)
        {
            BlockID old  = level.GetBlock(x, y, z);
            int     type = level.DoBlockchange(this, x, y, z, block);

            if (type == 0)
            {
                return(type);                                               // no change performed
            }
            if (type == 2)
            {
                Player.GlobalBlockchange(level, x, y, z, block);            // different visually
            }
            ushort flags = BlockDBFlags.ManualPlace;

            if (painting && CollideType.IsSolid(level.CollideType(old)))
            {
                flags = BlockDBFlags.Painted;
            }

            level.BlockDB.Cache.Add(this, x, y, z, flags, old, block);
            y--; // check for growth at block below

            bool grow = level.Config.GrassGrow && (level.physics == 0 || level.physics == 5);

            if (!grow || level.CanAffect(this, x, y, z) != null)
            {
                return(type);
            }
            BlockID below = level.GetBlock(x, y, z);

            BlockID grass = level.Props[below].GrassBlock;

            if (grass != Block.Invalid && block == Block.Air)
            {
                level.Blockchange(this, x, y, z, grass);
            }

            BlockID dirt = level.Props[below].DirtBlock;

            if (dirt != Block.Invalid && !level.LightPasses(block))
            {
                level.Blockchange(this, x, y, z, dirt);
            }
            return(type);
        }
示例#23
0
        static int FindYAbove(Level lvl, ushort x, ushort y, ushort z)
        {
            bool foundAnySolid = false;
            for (ushort yCheck = y; yCheck < lvl.Height; yCheck++) {
                BlockID block = lvl.GetBlock(x, yCheck, z);
                if (block != Block.Invalid &&
                    CollideType.IsSolid(lvl.CollideType(block))) { foundAnySolid = true; continue; }

                BlockID above = lvl.GetBlock(x, (ushort)(yCheck + 1), z);
                if (above != Block.Invalid &&
                    CollideType.IsSolid(lvl.CollideType(above))) { foundAnySolid = true; continue; }

                BlockID below = lvl.GetBlock(x, (ushort)(yCheck - 1), z);
                if (below != Block.Invalid &&
                    CollideType.IsSolid(lvl.CollideType(below)) && yCheck > y) return yCheck;
            }
            return foundAnySolid ? lvl.Height : -1;
        }
示例#24
0
        /// <summary> Updates the block at the given position, mainly intended for manual changes by the player. </summary>
        /// <remarks> Adds to the BlockDB. Also turns block below to grass/dirt depending on light. </remarks>
        /// <returns> Return code from DoBlockchange </returns>
        public int ChangeBlock(ushort x, ushort y, ushort z, ExtBlock block)
        {
            ExtBlock old  = level.GetBlock(x, y, z);
            int      type = level.DoBlockchange(this, x, y, z, block);

            if (type == 0)
            {
                return(type);                                               // no change performed
            }
            if (type == 2)
            {
                Player.GlobalBlockchange(level, x, y, z, block);            // different visually
            }
            ushort flags = BlockDBFlags.ManualPlace;

            if (painting && CollideType.IsSolid(level.CollideType(old)))
            {
                flags = BlockDBFlags.Painted;
            }
            level.BlockDB.Cache.Add(this, x, y, z, flags, old, block);

            bool autoGrass = level.Config.GrassGrow && (level.physics == 0 || level.physics == 5);

            if (!autoGrass)
            {
                return(type);
            }
            ExtBlock below = level.GetBlock(x, (ushort)(y - 1), z);

            ushort grassIdx = level.Props[below.Index].GrassIndex;

            if (grassIdx != Block.Invalid && block.BlockID == Block.Air)
            {
                level.Blockchange(this, x, (ushort)(y - 1), z, ExtBlock.FromIndex(grassIdx));
            }

            ushort dirtIdx = level.Props[below.Index].DirtIndex;

            if (dirtIdx != Block.Invalid && !level.LightPasses(block))
            {
                level.Blockchange(this, x, (ushort)(y - 1), z, ExtBlock.FromIndex(dirtIdx));
            }
            return(type);
        }
示例#25
0
        public static bool IntersectsSolidBlocks(AABB bb, Level lvl)
        {
            Vec3S32 min = bb.BlockMin, max = bb.BlockMax;

            for (int y = min.Y; y <= max.Y; y++)
            {
                for (int z = min.Z; z <= max.Z; z++)
                {
                    for (int x = min.X; x <= max.X; x++)
                    {
                        ushort   xP = (ushort)x, yP = (ushort)y, zP = (ushort)z;
                        ExtBlock block = lvl.GetBlock(xP, yP, zP);

                        AABB blockBB = lvl.blockAABBs[block.Index].Offset(x * 32, y * 32, z * 32);
                        if (!AABB.Intersects(ref bb, ref blockBB))
                        {
                            continue;
                        }

                        BlockDefinition def = lvl.GetBlockDef(block);
                        if (def != null)
                        {
                            if (CollideType.IsSolid(def.CollideType))
                            {
                                return(true);
                            }
                        }
                        else if (block.BlockID == Block.Invalid)
                        {
                            if (y < lvl.Height)
                            {
                                return(true);
                            }
                        }
                        else if (!Block.Walkthrough(Block.Convert(block.BlockID)))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
示例#26
0
        float LowestModifier(AABB bounds, bool checkSolid)
        {
            Vector3I bbMin    = Vector3I.Floor(bounds.Min);
            Vector3I bbMax    = Vector3I.Floor(bounds.Max);
            float    modifier = inf;

            for (int y = bbMin.Y; y <= bbMax.Y; y++)
            {
                for (int z = bbMin.Z; z <= bbMax.Z; z++)
                {
                    for (int x = bbMin.X; x <= bbMax.X; x++)
                    {
                        byte block = game.World.SafeGetBlock(x, y, z);
                        if (block == 0)
                        {
                            continue;
                        }
                        CollideType type = info.Collide[block];
                        if (type == CollideType.Solid && !checkSolid)
                        {
                            continue;
                        }

                        Vector3 min     = new Vector3(x, y, z) + info.MinBB[block];
                        Vector3 max     = new Vector3(x, y, z) + info.MaxBB[block];
                        AABB    blockBB = new AABB(min, max);
                        if (!blockBB.Intersects(bounds))
                        {
                            continue;
                        }

                        modifier = Math.Min(modifier, info.SpeedMultiplier[block]);
                        if (block >= Block.CpeCount && type == CollideType.SwimThrough)
                        {
                            useLiquidGravity = true;
                        }
                    }
                }
            }
            return(modifier);
        }
示例#27
0
        internal static void Fall(Player p, AABB bb)
        {
            bb.Min.Y -= 2; // test block below player feet
            Vec3S32 min = bb.BlockMin, max = bb.BlockMax;
            bool    allGas = true;

            for (int z = min.Z; z <= max.Z; z++)
            {
                for (int x = min.X; x <= max.X; x++)
                {
                    ExtBlock block   = GetSurvivalBlock(p, x, min.Y, z);
                    byte     collide = p.level.CollideType(block);
                    allGas = allGas && collide == CollideType.WalkThrough;
                    if (!CollideType.IsSolid(collide))
                    {
                        continue;
                    }

                    int fallHeight = p.startFallY - bb.Min.Y;
                    if (fallHeight > p.level.Config.FallHeight * 32)
                    {
                        p.HandleDeath(ExtBlock.Air, null, false, true);
                    }

                    p.startFallY = -1;
                    return;
                }
            }

            if (!allGas)
            {
                return;
            }
            if (bb.Min.Y > p.lastFallY)
            {
                p.startFallY = -1;                         // flying up resets fall height
            }
            p.startFallY = Math.Max(bb.Min.Y, p.startFallY);
        }
示例#28
0
 public BoundingSphere GetCollisionSphere(CollideType collideType)
 {
     if (col_s.ContainsKey(collideType))
     {
         return(new BoundingSphere(
                    transform.localToWorldMatrix.MultiplyPoint(col_s[collideType].position), col_s[collideType].radius));
     }
     foreach (Transform child in transform)
     {
         if (child.name.Contains($"Collide Set {collideType}"))
         {
             var ch = child.GetChild(0).GetChild(0);
             if (ch.name.Contains("Spheres"))
             {
                 col_s.Add(collideType, new BoundingSphere(ch.transform.localPosition, ch.localScale.x / 2));
                 return(col_s[collideType]);
             }
         }
     }
     col_s.Add(collideType, new BoundingSphere());
     return(col_s[collideType]);
 }
示例#29
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        CollideType type = collision.collider.GetComponent <CollideType>();

        switch (type.type)
        {
        case "asteroid_large":
            break;

        case "asteroid_med":
            break;

        case "asteroid_small":
            break;

        case "ship":
            break;

        case "shield":
            break;
        }
    }
示例#30
0
 public Bounds GetCollisionBox(CollideType collideType)
 {
     if (col_b.ContainsKey(collideType))
     {
         return(new Bounds(
                    transform.localToWorldMatrix.MultiplyPoint(col_b[collideType].center), col_b[collideType].size));
     }
     foreach (Transform child in transform)
     {
         if (child.name.Contains($"Collide Set {collideType}"))
         {
             var ch = child.GetChild(0).GetChild(0);
             if (ch.name.Contains("Aligned Boxes"))
             {
                 col_b.Add(collideType, new Bounds(ch.transform.localPosition, ch.transform.localScale));
                 return(col_b[collideType]);
             }
         }
     }
     col_b.Add(collideType, new Bounds());
     return(col_b[collideType]);
 }
示例#31
0
        public bool HitTestMap()
        {
            Level map = LevelInfo.FindExact(_curMap);

            int minX = _pos.X / 32 - 2;
            int maxX = _pos.X / 32 + 2;

            int minY = _pos.Y / 32 - 2;
            int maxY = _pos.Y / 32 + 2;

            int minZ = _pos.Z / 32 - 2;
            int maxZ = _pos.Z / 32 + 2;

            for (int i = minY; i <= maxY; i++)
            {
                for (int j = minX; j <= maxX; j++)
                {
                    for (int k = minZ; k <= maxZ; k++)
                    {
                        if (!CollideType.IsSolid(map.CollideType((map.GetBlock((ushort)(j), (ushort)(i), (ushort)(k))))))
                        {
                            continue;
                        }
                        bool touchX = _pos.X + _width > (j * 32) && _pos.X < ((j + 1) * 32);
                        bool touchY = (_pos.Y - 32) + _height > (i * 32) && (_pos.Y - 32) < ((i + 1) * 32);
                        bool touchZ = _pos.Z + _width > (k * 32) && _pos.Z < ((k + 1) * 32);
                        if (touchX && touchY && touchZ)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
示例#32
0
        static int FindYAbove(Level lvl, ushort x, ushort y, ushort z)
        {
            for (; y < lvl.Height; y++)
            {
                BlockID block = lvl.GetBlock(x, y, z);
                if (block != Block.Invalid && CollideType.IsSolid(lvl.CollideType(block)))
                {
                    continue;
                }

                BlockID above = lvl.GetBlock(x, (ushort)(y + 1), z);
                if (above != Block.Invalid && CollideType.IsSolid(lvl.CollideType(above)))
                {
                    continue;
                }

                BlockID below = lvl.GetBlock(x, (ushort)(y - 1), z);
                if (below != Block.Invalid && CollideType.IsSolid(lvl.CollideType(below)))
                {
                    return(y);
                }
            }
            return(-1);
        }
示例#33
0
        static int FindYBelow(Level lvl, ushort x, ushort y, ushort z)
        {
            for (; y > 0; y--)
            {
                ExtBlock block = lvl.GetBlock(x, y, z);
                if (!block.IsInvalid && CollideType.IsSolid(lvl.CollideType(block)))
                {
                    continue;
                }

                ExtBlock above = lvl.GetBlock(x, (ushort)(y + 1), z);
                if (!above.IsInvalid && CollideType.IsSolid(lvl.CollideType(above)))
                {
                    continue;
                }

                ExtBlock below = lvl.GetBlock(x, (ushort)(y - 1), z);
                if (!below.IsInvalid && CollideType.IsSolid(lvl.CollideType(below)))
                {
                    return(y);
                }
            }
            return(-1);
        }
示例#34
0
 public abstract bool Collides(Point point, CollideType detectMethod = CollideType.All);
示例#35
0
 public override bool Collides(Point point, CollideType detectMethod = CollideType.All)
 {
     if (point.x == this.x && point.y == this.y)
         return true;
     else
         return false;
 }
示例#36
0
 public override bool Collides(Circle circle, CollideType detectMethod = CollideType.All)
 {
     return false;
 }
示例#37
0
 public override bool Collides(Rect rect, CollideType detectMethod = CollideType.All)
 {
     return rect.left <= this.right && rect.right >= this.left && rect.top <= this.bottom && rect.bottom >= this.top;
 }
示例#38
0
 public override bool Collides(Point point, CollideType detectMethod = CollideType.All)
 {
     //TODO: Fix
     if (this.top <= point.y && this.left <= point.x && this.right >= point.x && this.bottom >= point.y)
         return true;
     else
         return false;
 }
示例#39
0
 public abstract bool Collides(Rect rect, CollideType detectMethod = CollideType.All);
示例#40
0
 public abstract bool Collides(Circle circle, CollideType detectMethod = CollideType.All);
        public static GeometricObjectCollide Read(Reader reader, Pointer offset, CollideType type = CollideType.None)
        {
            MapLoader l = MapLoader.Loader;
            //l.print("CollideMesh " + offset);
            GeometricObjectCollide m = new GeometricObjectCollide(offset, type);

            //l.print("Mesh obj: " + offset);
            if (Settings.s.engineVersion == Settings.EngineVersion.R3 || Settings.s.game == Settings.Game.R2Revolution)
            {
                m.num_vertices = reader.ReadUInt16();
                m.num_elements = reader.ReadUInt16();
                if (Settings.s.engineVersion == Settings.EngineVersion.R3 && Settings.s.game != Settings.Game.LargoWinch)
                {
                    reader.ReadUInt32();
                }
            }
            if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
            {
                m.num_vertices = (ushort)reader.ReadUInt32();
            }
            m.off_vertices = Pointer.Read(reader);
            if (Settings.s.engineVersion < Settings.EngineVersion.R3 && Settings.s.game != Settings.Game.R2Revolution)
            {
                m.off_normals = Pointer.Read(reader);
                Pointer.Read(reader);
                reader.ReadInt32();
            }
            if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
            {
                m.num_elements = (ushort)reader.ReadUInt32();
            }
            m.off_element_types = Pointer.Read(reader);
            m.off_elements      = Pointer.Read(reader);
            if (Settings.s.game != Settings.Game.R2Revolution && Settings.s.game != Settings.Game.LargoWinch)
            {
                Pointer.Read(reader);
                if (Settings.s.engineVersion == Settings.EngineVersion.R2)
                {
                    reader.ReadInt32();
                    reader.ReadInt32();
                    reader.ReadInt32();
                    reader.ReadInt32();
                    m.num_vertices = reader.ReadUInt16();
                    m.num_elements = reader.ReadUInt16();
                }
                if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
                {
                    reader.ReadInt32();
                    reader.ReadInt32();
                }
            }
            reader.ReadInt32();
            reader.ReadSingle();
            reader.ReadSingle();
            reader.ReadSingle();
            reader.ReadSingle();
            if (Settings.s.engineVersion < Settings.EngineVersion.R3)
            {
                reader.ReadUInt32();
            }

            // Vertices
            Pointer off_current = Pointer.Goto(ref reader, m.off_vertices);

            m.vertices = new Vector3[m.num_vertices];
            for (int i = 0; i < m.num_vertices; i++)
            {
                float x = reader.ReadSingle();
                float z = reader.ReadSingle();
                float y = reader.ReadSingle();
                m.vertices[i] = new Vector3(x, y, z);
            }

            // Normals
            if (m.off_normals != null)
            {
                off_current = Pointer.Goto(ref reader, m.off_normals);
                m.normals   = new Vector3[m.num_vertices];
                for (int i = 0; i < m.num_vertices; i++)
                {
                    float x = reader.ReadSingle();
                    float z = reader.ReadSingle();
                    float y = reader.ReadSingle();
                    m.normals[i] = new Vector3(x, y, z);
                }
            }
            // Read subblock types & initialize arrays
            Pointer.Goto(ref reader, m.off_element_types);
            m.element_types = new ushort[m.num_elements];
            m.elements      = new IGeometricObjectElementCollide[m.num_elements];
            for (uint i = 0; i < m.num_elements; i++)
            {
                m.element_types[i] = reader.ReadUInt16();
            }
            m.gao       = new GameObject("Collide Set " + (type != CollideType.None ? type + " " : "") + "@ " + offset);
            m.gao.tag   = "Collide";
            m.gao.layer = LayerMask.NameToLayer("Collide");
            for (uint i = 0; i < m.num_elements; i++)
            {
                Pointer.Goto(ref reader, m.off_elements + (i * 4));
                Pointer block_offset = Pointer.Read(reader);
                Pointer.Goto(ref reader, block_offset);
                switch (m.element_types[i])
                {
                /*1 = indexedtriangles
                 * 2 = facemap
                 * 3 = sprite
                 * 4 = TMesh
                 * 5 = points
                 * 6 = lines
                 * 7 = spheres
                 * 8 = alignedboxes
                 * 9 = cones
                 * 13 = deformationsetinfo*/
                case 1:     // Collide submesh
                    m.elements[i] = GeometricObjectElementCollideTriangles.Read(reader, block_offset, m);
                    //material_i++;
                    break;

                case 7:
                    m.elements[i] = GeometricObjectElementCollideSpheres.Read(reader, block_offset, m);
                    break;

                case 8:
                    m.elements[i] = GeometricObjectElementCollideAlignedBoxes.Read(reader, block_offset, m);
                    break;

                default:
                    m.elements[i] = null;
                    l.print("Unknown collide geometric element type " + m.element_types[i] + " at offset " + block_offset + " (Object: " + offset + ")");
                    break;
                }
            }

            for (uint i = 0; i < m.num_elements; i++)
            {
                if (m.elements[i] != null)
                {
                    GameObject child = m.elements[i].Gao;
                    child.transform.SetParent(m.gao.transform);
                    child.transform.localPosition = Vector3.zero;

                    /*if (m.subblocks[i] is CollideMeshElement) {
                     *  GameObject child = ((CollideMeshElement)m.subblocks[i]).Gao;
                     *  child.transform.SetParent(m.gao.transform);
                     *  child.transform.localPosition = Vector3.zero;
                     * } else if (m.subblocks[i] is CollideSpheresElement) {
                     *  GameObject child = ((CollideSpheresElement)m.subblocks[i]).Gao;
                     *  child.transform.SetParent(m.gao.transform);
                     *  child.transform.localPosition = Vector3.zero;
                     * } else if (m.subblocks[i] is CollideAlignedBoxesElement) {
                     *  GameObject child = ((CollideAlignedBoxesElement)m.subblocks[i]).Gao;
                     *  child.transform.SetParent(m.gao.transform);
                     *  child.transform.localPosition = Vector3.zero;
                     * }*/
                }
            }
            m.SetVisualsActive(false); // Invisible by default
            //m.gao.SetActive(false); // Invisible by default
            return(m);
        }
示例#42
0
 public override bool Collides(Point point, CollideType detectMethod = CollideType.All)
 {
     return false;
 }
示例#43
0
 public override bool Collides(Rect rect, CollideType detectMethod = CollideType.All)
 {
     if (rect.top >= this.y && rect.left <= this.x && rect.right >= this.x && rect.bottom <= this.y)
         return true;
     else
         return false;
 }