コード例 #1
0
        public void Update(GameTime gameTime, VoxelWorld gameWorld)
        {
            Time += gameTime.ElapsedGameTime.TotalMilliseconds;

            if (affectedByGravity)
            {
                Speed.Z += GRAVITY;

                if (Speed.Z > 0f)
                {
                    Voxel v = gameWorld.GetVoxel(Position + new Vector3(0f, 0f, Scale));
                    if (v.Active && gameWorld.CanCollideWith(v.Type))
                    {
                        Speed = new Vector3(Speed.X / 2, Speed.Y / 2, -(Speed.Z / 2f));
                    }
                }
                Speed.Z = (float)Math.Round(Speed.Z, 3);
            }

            Position += Speed;

            if (Position.Z > 20f)
            {
                Active = false;
            }

            if (Time >= Life)
            {
                Scale -= 0.01f;
                if (Scale <= 0f)
                {
                    Active = false;
                }
            }
        }
コード例 #2
0
ファイル: Particle.cs プロジェクト: JamesHetfield/LD27
        public void Update(GameTime gameTime, VoxelWorld gameWorld)
        {
            Time += gameTime.ElapsedGameTime.TotalMilliseconds;

            if (affectedByGravity)
            {
                Speed.Z += GRAVITY;

                if (Speed.Z > 0f)
                {
                    Voxel v = gameWorld.GetVoxel(Position +  new Vector3(0f,0f,Scale));
                    if (v.Active && gameWorld.CanCollideWith(v.Type)) Speed = new Vector3(Speed.X/2,Speed.Y/2,-(Speed.Z / 2f));
                }
                Speed.Z = (float)Math.Round(Speed.Z, 3);
            }

            Position += Speed;

            if (Position.Z > 20f) Active = false;

            if (Time >= Life)
            {
                Scale -= 0.01f;
                if(Scale<=0f) Active = false;
            }
        }
コード例 #3
0
ファイル: Room.cs プロジェクト: JamesHetfield/LD27
        void CreateMap(VoxelSprite tileSheet)
        {
            for (int x = 0; x < 15; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    wallRots[x, y] = MathHelper.PiOver2 * (float)Helper.Random.Next(4);
                    if (x == 0 || x == 14 || y == 0 || y == 8)
                    {
                        if (x != 7 && y != 4)
                        {
                            World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[0], Helper.Random.Next(4), 0);
                        }
                        else
                        {
                            World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[(x == 7 ? 2 : 1)], 0, 0);
                        }
                    }
                }
            }



            for (int i = 0; i < 3; i++)
            {
                int rx = 1 + Helper.Random.Next(6);
                int ry = 1 + Helper.Random.Next(3);

                int t = 6 + Helper.Random.Next(1);

                World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite(rx * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);

                if (Helper.Random.Next(5) == 1)
                {
                    PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace((rx * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (ry * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21));
                }
                if (Helper.Random.Next(5) == 1)
                {
                    PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace(((14 - rx) * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (ry * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21));
                }
                if (Helper.Random.Next(5) == 1)
                {
                    PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace((rx * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), ((8 - ry) * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21));
                }
                if (Helper.Random.Next(5) == 1)
                {
                    PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace(((14 - rx) * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), ((8 - ry) * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21));
                }
            }

            for (int i = 0; i < 1; i++)
            {
                int rx = 2 + Helper.Random.Next(5);
                int t  = 4 + Helper.Random.Next(3);

                World.CopySprite(rx * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
            }
            for (int i = 0; i < 1; i++)
            {
                int ry = 2 + Helper.Random.Next(2);
                int t  = 4 + Helper.Random.Next(3);

                World.CopySprite(7 * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite(7 * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
            }

            //if (!((rx == 1 || rx == 14) && ry == 4) && !((ry == 1 || ry == 8) && rx == 7))
            //{

            //    World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[3], 0);

            //}

            int  enemiesSpawned = 0;
            bool headSpawned    = false;
            bool oozeSpawned    = false;
            int  numEnemies     = 0 + Helper.Random.Next(6);

            while (enemiesSpawned < numEnemies)
            {
                for (int x = 1; x < 14; x++)
                {
                    for (int y = 1; y < 8; y++)
                    {
                        if (!World.GetVoxel((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 23).Active)
                        {
                            // Create an enemy?
                            if (!(x == 7 && y == 4))
                            {
                                if (enemiesSpawned < numEnemies && Helper.Random.Next(50) == 1)
                                {
                                    EnemyType type = (EnemyType)Helper.Random.Next(Enum.GetValues(typeof(EnemyType)).Length);
                                    if (type != EnemyType.Head)
                                    {
                                        if (type == EnemyType.Ooze && oozeSpawned)
                                        {
                                            continue;
                                        }
                                        if (type == EnemyType.Ooze)
                                        {
                                            oozeSpawned = true;
                                        }

                                        EnemyController.Instance.Spawn(type, VoxelWorld.ToScreenSpace((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21), this);
                                        enemiesSpawned++;
                                    }
                                }
                            }
                            if (x == 7 && y == 4)
                            {
                                if (enemiesSpawned < numEnemies && !headSpawned && Helper.Random.Next(5) == 1)
                                {
                                    enemiesSpawned++;
                                    EnemyController.Instance.Spawn(EnemyType.Head, VoxelWorld.ToScreenSpace((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21), this);
                                    headSpawned = true;
                                }
                            }
                        }
                    }
                }
            }

            World.UpdateWorldMeshes();
        }
コード例 #4
0
ファイル: Room.cs プロジェクト: MattDrivenDev/LD27
        void CreateMap(VoxelSprite tileSheet)
        {
            for (int x = 0; x < 15; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    wallRots[x, y] = MathHelper.PiOver2 * (float)Helper.Random.Next(4);
                    if (x == 0 || x == 14 || y == 0 || y == 8)
                    {
                        if (x != 7 && y != 4)
                        {
                            World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[0], Helper.Random.Next(4), 0);
                        }
                        else
                        {
                            World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[(x == 7 ? 2 : 1)], 0, 0);
                        }
                    }
                }
            }



            for (int i = 0; i < 3; i++)
            {
                int rx = 1 + Helper.Random.Next(6);
                int ry = 1 + Helper.Random.Next(3);

                int t = 6 + Helper.Random.Next(1);

                World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite(rx * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
            }

            for (int i = 0; i < 1; i++)
            {
                int rx = 2 + Helper.Random.Next(5);
                int t  = 4 + Helper.Random.Next(3);

                World.CopySprite(rx * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
            }
            for (int i = 0; i < 1; i++)
            {
                int ry = 2 + Helper.Random.Next(2);
                int t  = 4 + Helper.Random.Next(3);

                World.CopySprite(7 * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite(7 * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
            }

            //if (!((rx == 1 || rx == 14) && ry == 4) && !((ry == 1 || ry == 8) && rx == 7))
            //{

            //    World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[3], 0);

            //}

            int enemiesSpawned = 0;

            for (int x = 1; x < 14; x++)
            {
                for (int y = 1; y < 8; y++)
                {
                    if (!World.GetVoxel((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21).Active)
                    {
                        // Create an enemy?
                        if (enemiesSpawned < 4 && Helper.Random.Next(50) == 1)
                        {
                            enemiesSpawned++;

                            EnemyType type = (EnemyType)Helper.Random.Next(Enum.GetValues(typeof(EnemyType)).Length);
                            EnemyController.Instance.Spawn(type, VoxelWorld.ToScreenSpace((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21), this);
                        }
                    }
                }
            }

            World.UpdateWorldMeshes();
        }
コード例 #5
0
ファイル: Enemy.cs プロジェクト: GarethIW/LD27
        public virtual void CheckCollisions(VoxelWorld world, List<Door> doors, Room currentRoom, Hero gameHero)
        {
            float checkRadius = 3.5f;
            float radiusSweep = 0.75f;
            Vector2 v2Pos = new Vector2(Position.X, Position.Y);
            float checkHeight = Position.Z - 1f;
            Voxel checkVoxel;
            Vector3 checkPos;

            Vector3 mapBoundsMin = new Vector3(Chunk.X_SIZE * Voxel.SIZE, Chunk.Y_SIZE * Voxel.SIZE, 0f);
            Vector3 mapBoundsMax = new Vector3(world.X_SIZE * Voxel.SIZE, world.Y_SIZE * Voxel.SIZE, world.Z_SIZE) - new Vector3(Chunk.X_SIZE * Voxel.SIZE, Chunk.Y_SIZE * Voxel.SIZE, 0f);

            if (Speed.Y < 0f)
            {
                for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(false, true, false, checkPos, currentRoom, gameHero, false);
                    }
                    foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; }
                    if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en!=this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; }
                    if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break; }
                    if (checkPos.Y < mapBoundsMin.Y || checkPos.Y > mapBoundsMax.Y) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; }
                }
            }
            if (Speed.Y > 0f)
            {
                for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(false, true, false, checkPos, currentRoom, gameHero, false);
                    }
                    foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; }
                    if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; }
                    if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break; }
                    if (checkPos.Y < mapBoundsMin.Y || checkPos.Y > mapBoundsMax.Y) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; }

                }
            }
            if (Speed.X < 0f)
            {
                for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(true, false, false, checkPos, currentRoom, gameHero, false);
                    }
                    foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; }
                    if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; }
                    if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break; }
                    if (checkPos.X < mapBoundsMin.X || checkPos.X > mapBoundsMax.X) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; }

                }
            }
            if (Speed.X > 0f)
            {
                for (float a = -radiusSweep; a < radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(true, false, false, checkPos, currentRoom, gameHero, false);
                    }
                    foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; }
                    if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; }
                    if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break;}
                    if (checkPos.X < mapBoundsMin.X || checkPos.X > mapBoundsMax.X) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; }

                }
            }
        }
コード例 #6
0
ファイル: Hero.cs プロジェクト: GarethIW/LD27
        void CheckCollisions(VoxelWorld world, List<Door> doors, Room currentRoom)
        {
            float checkRadius = 3.5f;
            float radiusSweep = 0.75f;
            Vector2 v2Pos = new Vector2(Position.X, Position.Y);
            float checkHeight = Position.Z - 1f;
            Voxel checkVoxel;
            Vector3 checkPos;

            if (Speed.Y < 0f)
            {
                for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        Speed.Y = 0f;
                    }
                    foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos)==ContainmentType.Contains) Speed.Y = 0f; }
                    foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f,0f,-5f)) == ContainmentType.Contains) Speed.Y = 0f; }

                }
            }
            if (Speed.Y > 0f)
            {
                for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        Speed.Y = 0f;
                    }
                    foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) Speed.Y = 0f; }
                    foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) Speed.Y = 0f; }

                }
            }
            if (Speed.X < 0f)
            {
                for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        Speed.X = 0f;
                    }
                    foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) Speed.X = 0f; }
                    foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) Speed.X = 0f; }

                }
            }
            if (Speed.X > 0f)
            {
                for (float a = -radiusSweep; a < radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        Speed.X = 0f;
                    }
                    foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) Speed.X = 0f; }
                    foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) Speed.X = 0f; }

                }
            }
        }
コード例 #7
0
ファイル: Enemy.cs プロジェクト: JamesHetfield/LD27
        public virtual void CheckCollisions(VoxelWorld world, List <Door> doors, Room currentRoom, Hero gameHero)
        {
            float   checkRadius = 3.5f;
            float   radiusSweep = 0.75f;
            Vector2 v2Pos       = new Vector2(Position.X, Position.Y);
            float   checkHeight = Position.Z - 1f;
            Voxel   checkVoxel;
            Vector3 checkPos;

            Vector3 mapBoundsMin = new Vector3(Chunk.X_SIZE * Voxel.SIZE, Chunk.Y_SIZE * Voxel.SIZE, 0f);
            Vector3 mapBoundsMax = new Vector3(world.X_SIZE * Voxel.SIZE, world.Y_SIZE * Voxel.SIZE, world.Z_SIZE) - new Vector3(Chunk.X_SIZE * Voxel.SIZE, Chunk.Y_SIZE * Voxel.SIZE, 0f);

            if (Speed.Y < 0f)
            {
                for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos   = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(false, true, false, checkPos, currentRoom, gameHero, false);
                    }
                    foreach (Door d in doors)
                    {
                        if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains)
                        {
                            DoCollide(false, true, false, checkPos, currentRoom, gameHero, false);
                        }
                        break;
                    }
                    if (knockbackTime <= 0)
                    {
                        foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this))
                        {
                            if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains)
                            {
                                DoCollide(false, true, false, checkPos, currentRoom, gameHero, false);
                            }
                            break;
                        }
                    }
                    if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains)
                    {
                        DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break;
                    }
                    if (checkPos.Y < mapBoundsMin.Y || checkPos.Y > mapBoundsMax.Y)
                    {
                        DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break;
                    }
                }
            }
            if (Speed.Y > 0f)
            {
                for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos   = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(false, true, false, checkPos, currentRoom, gameHero, false);
                    }
                    foreach (Door d in doors)
                    {
                        if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains)
                        {
                            DoCollide(false, true, false, checkPos, currentRoom, gameHero, false);
                        }
                        break;
                    }
                    if (knockbackTime <= 0)
                    {
                        foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this))
                        {
                            if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains)
                            {
                                DoCollide(false, true, false, checkPos, currentRoom, gameHero, false);
                            }
                            break;
                        }
                    }
                    if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains)
                    {
                        DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break;
                    }
                    if (checkPos.Y < mapBoundsMin.Y || checkPos.Y > mapBoundsMax.Y)
                    {
                        DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break;
                    }
                }
            }
            if (Speed.X < 0f)
            {
                for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f)
                {
                    checkPos   = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(true, false, false, checkPos, currentRoom, gameHero, false);
                    }
                    foreach (Door d in doors)
                    {
                        if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains)
                        {
                            DoCollide(true, false, false, checkPos, currentRoom, gameHero, false);
                        }
                        break;
                    }
                    if (knockbackTime <= 0)
                    {
                        foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this))
                        {
                            if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains)
                            {
                                DoCollide(true, false, false, checkPos, currentRoom, gameHero, false);
                            }
                            break;
                        }
                    }
                    if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains)
                    {
                        DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break;
                    }
                    if (checkPos.X < mapBoundsMin.X || checkPos.X > mapBoundsMax.X)
                    {
                        DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break;
                    }
                }
            }
            if (Speed.X > 0f)
            {
                for (float a = -radiusSweep; a < radiusSweep; a += 0.02f)
                {
                    checkPos   = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(true, false, false, checkPos, currentRoom, gameHero, false);
                    }
                    foreach (Door d in doors)
                    {
                        if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains)
                        {
                            DoCollide(true, false, false, checkPos, currentRoom, gameHero, false);
                        }
                        break;
                    }
                    if (knockbackTime <= 0)
                    {
                        foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this))
                        {
                            if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains)
                            {
                                DoCollide(true, false, false, checkPos, currentRoom, gameHero, false);
                            }
                            break;
                        }
                    }
                    if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains)
                    {
                        DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break;
                    }
                    if (checkPos.X < mapBoundsMin.X || checkPos.X > mapBoundsMax.X)
                    {
                        DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break;
                    }
                }
            }
        }
コード例 #8
0
        void CheckCollisions(VoxelWorld world, List <Door> doors, Room currentRoom)
        {
            float   checkRadius = 3.5f;
            float   radiusSweep = 0.75f;
            Vector2 v2Pos       = new Vector2(Position.X, Position.Y);
            float   checkHeight = Position.Z - 1f;
            Voxel   checkVoxel;
            Vector3 checkPos;

            if (Speed.Y < 0f)
            {
                for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos   = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        Speed.Y = 0f;
                    }
                    foreach (Door d in doors)
                    {
                        if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains)
                        {
                            Speed.Y = 0f;
                        }
                    }
                    foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom))
                    {
                        if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains)
                        {
                            Speed.Y = 0f;
                        }
                    }
                }
            }
            if (Speed.Y > 0f)
            {
                for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos   = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        Speed.Y = 0f;
                    }
                    foreach (Door d in doors)
                    {
                        if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains)
                        {
                            Speed.Y = 0f;
                        }
                    }
                    foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom))
                    {
                        if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains)
                        {
                            Speed.Y = 0f;
                        }
                    }
                }
            }
            if (Speed.X < 0f)
            {
                for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f)
                {
                    checkPos   = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        Speed.X = 0f;
                    }
                    foreach (Door d in doors)
                    {
                        if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains)
                        {
                            Speed.X = 0f;
                        }
                    }
                    foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom))
                    {
                        if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains)
                        {
                            Speed.X = 0f;
                        }
                    }
                }
            }
            if (Speed.X > 0f)
            {
                for (float a = -radiusSweep; a < radiusSweep; a += 0.02f)
                {
                    checkPos   = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        Speed.X = 0f;
                    }
                    foreach (Door d in doors)
                    {
                        if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains)
                        {
                            Speed.X = 0f;
                        }
                    }
                    foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom))
                    {
                        if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains)
                        {
                            Speed.X = 0f;
                        }
                    }
                }
            }
        }