Пример #1
0
        public void Update(GameTime gameTime, Camera gameCamera, Room currentRoom, List<Door> doors, ref Room[,] rooms, bool allRoomsComplete, int exitRoomX, int exitRoomY, Door exitDoor)
        {
            if (Dead) return;

            Health = MathHelper.Clamp(Health, 0f, MaxHealth);

            //Health = MaxHealth;

            Vector2 v2pos = new Vector2(Position.X, Position.Y);
            Vector2 v2speed = new Vector2(Speed.X, Speed.Y);
            if (Speed.Length() > 0f)
            {
                //if (!defending)
                Rotation = Helper.TurnToFace(v2pos, v2pos + (v2speed * 50f), Rotation, 1f, 0.5f);
            }
            if(introTargetReached) CheckCollisions(currentRoom.World, doors, currentRoom);
            Position += Speed;

            v2speed = new Vector2(Speed.X, Speed.Y);
            if (Speed.Length() > 0f)
            {
                frameTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (frameTime >= frameTargetTime)
                {
                    frameTime = 0;
                    currentFrame++;
                    if (currentFrame == 4) currentFrame = 0;
                }
            }

            if (RoomX == exitRoomX && RoomY == exitRoomY && introTargetReached)
            {
                if (Position.X < doors[3].Position.X - 5f && doors[3] == exitDoor) { exitReached = true; }
                if (Position.X > doors[1].Position.X + 5f && doors[1] == exitDoor) { exitReached = true; }
                if (Position.Y < doors[0].Position.Y - 5f && doors[0] == exitDoor) { exitReached = true; }
                if (Position.Y > doors[2].Position.Y + 5f && doors[2] == exitDoor) { exitReached = true; }
            }

            if (introTargetReached)
            {
                if (Position.X < doors[3].Position.X && !(doors[3] == exitDoor && RoomX == exitRoomX && RoomY == exitRoomY)) { RoomX--; Position = doors[1].Position + new Vector3(0f, 0f, 4f); ResetDoors(doors, ref rooms, allRoomsComplete, exitRoomX, exitRoomY, exitDoor); }
                if (Position.X > doors[1].Position.X && !(doors[1] == exitDoor && RoomX == exitRoomX && RoomY == exitRoomY)) { RoomX++; Position = doors[3].Position + new Vector3(0f, 0f, 4f); ResetDoors(doors, ref rooms, allRoomsComplete, exitRoomX, exitRoomY, exitDoor); }
                if (Position.Y < doors[0].Position.Y && !(doors[0] == exitDoor && RoomX == exitRoomX && RoomY == exitRoomY)) { RoomY--; Position = doors[2].Position + new Vector3(0f, 0f, 4f); ResetDoors(doors, ref rooms, allRoomsComplete, exitRoomX, exitRoomY, exitDoor); }
                if (Position.Y > doors[2].Position.Y && !(doors[2] == exitDoor && RoomX == exitRoomX && RoomY == exitRoomY)) { RoomY++; Position = doors[0].Position + new Vector3(0f, 0f, 4f); ResetDoors(doors, ref rooms, allRoomsComplete, exitRoomX, exitRoomY, exitDoor); }

            }

            Vector2 p = Helper.RandomPointInCircle(Helper.PointOnCircle(ref v2pos, 1f, (Rotation - MathHelper.Pi) + 0.1f), 0f, 2f);
            ParticleController.Instance.Spawn(new Vector3(p, Position.Z-1f), new Vector3(0f, 0f, -0.01f - ((float)Helper.Random.NextDouble() * 0.01f)), 0.5f, Color.Black*0.2f, 2000, false);

            drawEffect.Projection = gameCamera.projectionMatrix;
            drawEffect.View = gameCamera.viewMatrix;
            drawEffect.World = gameCamera.worldMatrix *
                               Matrix.CreateRotationX(MathHelper.PiOver2) *
                               Matrix.CreateRotationZ(Rotation - MathHelper.PiOver2) *
                               Matrix.CreateTranslation(new Vector3(0, 0, (-(spriteSheet.Z_SIZE * SpriteVoxel.HALF_SIZE)) + SpriteVoxel.HALF_SIZE)) *
                               Matrix.CreateScale(0.9f) *
                               Matrix.CreateTranslation(Position);

            boundingSphere = new BoundingSphere(Position + new Vector3(0f,0f,-4f), 3f);

            timeSinceLastHit -= gameTime.ElapsedGameTime.TotalMilliseconds;

            if (attacking)
            {
                attackTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (attackTime >= attackTargetTime)
                {
                    attackTime = 0;
                    attackFrame+=attackDir;

                    if (attackFrame == 1 && attackDir == 1)
                    {
                        bool hit = false;
                        float radiusSweep = 1f;
                        foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom))
                        {
                            for (float az = 0f; az > -8f; az -= 1f)
                            {
                                for (float a = Rotation - radiusSweep; a < Rotation + radiusSweep; a += 0.02f)
                                {
                                    for (float dist = 0f; dist < 5f; dist += 0.2f)
                                    {
                                        Vector3 attackPos = new Vector3(Helper.PointOnCircle(ref v2pos, dist, Rotation), Position.Z + az);

                                        if (e.boundingSphere.Contains(attackPos) == ContainmentType.Contains && !hit)
                                        {
                                            e.DoHit(attackPos, new Vector3(Helper.AngleToVector(Rotation, 0.01f), 0f), 10f);
                                            hit = true;
                                        }
                                    }
                                }
                            }
                        }

                    }

                    if (attackFrame == 3) { attackDir = -1; attackFrame = 1; }
                    if (attackFrame == -1) { attackFrame = 0; attacking = false; }

                }
            }

            if (hitAlpha > 0f) hitAlpha -= 0.1f;

            if (Health <= 0f) Die();

            bombRespawnTime -= gameTime.ElapsedGameTime.TotalMilliseconds;
            if (bombRespawnTime <= 0 && numBombs < 3)
            {
                numBombs++;
                bombRespawnTime = 5000;
                if (numBombs == 3) bombRespawnTime = 0;
            }

            if (!introTargetReached)
            {
                if (IntroTarget.X < Position.X) Move(new Vector2(-0.3f, 0f));
                if (IntroTarget.X > Position.X) Move(new Vector2(0.3f, 0f));
                if (IntroTarget.Y < Position.Y) Move(new Vector2(0f,-0.3f));
                if (IntroTarget.Y > Position.Y) Move(new Vector2(0f,0.3f));

                if(Vector3.Distance(IntroTarget, Position)<1f) introTargetReached = true;
            }
        }
Пример #2
0
        private void ResetDoors(List<Door> doors, ref Room[,] rooms, bool allRoomsComplete, int exitRoomX, int exitRoomY, Door exitDoor)
        {
            if (RoomX <= -1) { RoomX = 0; exitReached = true; exitDoor.Close(false); }
            if (RoomY <= -1) { RoomY = 0; exitReached = true; exitDoor.Close(false); }
            if (RoomX >= 4) { RoomX = 3; exitReached = true; exitDoor.Close(false); }
            if (RoomY >= 4) { RoomX = 3; exitReached = true; exitDoor.Close(false); }

            if (!exitReached)
            {
                if (RoomX > 0 && !rooms[RoomX - 1, RoomY].IsGap) doors[3].Open(true); else doors[3].Close(true);
                if (RoomX < 3 && !rooms[RoomX + 1, RoomY].IsGap) doors[1].Open(true); else doors[1].Close(true);
                if (RoomY > 0 && !rooms[RoomX, RoomY - 1].IsGap) doors[0].Open(true); else doors[0].Close(true);
                if (RoomY < 3 && !rooms[RoomX, RoomY + 1].IsGap) doors[2].Open(true); else doors[2].Close(true);

                if (allRoomsComplete && RoomX == exitRoomX && RoomY == exitRoomY) exitDoor.Open(true);

                ParticleController.Instance.Reset();
                ProjectileController.Instance.Reset();
            }
        }
Пример #3
0
        void CreateRoomsAsync()
        {
            int gapRoomX = Helper.Random.Next(4);
            int gapRoomY = Helper.Random.Next(4);

            float roomPercent = 100f / 16f;

            for (int x = 0; x < 4; x++)
                for (int y = 0; y < 4; y++)
                {
                    if (!(x == gapRoomX && y == gapRoomY))
                    {
                        Rooms[x, y] = new Room(tileSheet, objectSheet, false);
                    }
                    else Rooms[x, y] = new Room(tileSheet, objectSheet, true);
                    generatedPercent += (int)roomPercent;
                }

            // make exit
            bool made = false;
            while (!made)
            {
                int side = Helper.Random.Next(4);

                switch (side)
                {
                    case 0:
                        exitRoomX = Helper.Random.Next(4);
                        exitRoomY = -1;
                        if (!Rooms[exitRoomX, exitRoomY + 1].IsGap) made = true;
                        break;
                    case 1:
                        exitRoomY = Helper.Random.Next(4);
                        exitRoomX = 4;
                        if (!Rooms[exitRoomX - 1, exitRoomY].IsGap) made = true;
                        break;
                    case 2:
                        exitRoomX = Helper.Random.Next(4);
                        exitRoomY = 4;
                        if (!Rooms[exitRoomX, exitRoomY - 1].IsGap) made = true;
                        break;
                    case 3:
                        exitRoomY = Helper.Random.Next(4);
                        exitRoomX = -1;
                        if (!Rooms[exitRoomX + 1, exitRoomY].IsGap) made = true;
                        break;
                }
            }

            gameHero.RoomX = exitRoomX;// = new Hero(exitRoomX, exitRoomY, new Vector3(0, 0, 0));
            gameHero.RoomY = exitRoomY;

            //VoxelWorld.ToScreenSpace((7 * 16) + 7, 7, 21) + new Vector3(Voxel.HALF_SIZE,Voxel.HALF_SIZE,Voxel.HALF_SIZE), 0, doorSheet));
            ///VoxelWorld.ToScreenSpace((14 * 16) + 7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 1, doorSheet));
            //VoxelWorld.ToScreenSpace((7 * 16) + 7, (8 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 2, doorSheet));
            //VoxelWorld.ToScreenSpace(7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 3, doorSheet));

            if (gameHero.RoomX == -1)
            {
                gameHero.RoomX = 0;
                exitRoomX = 0;
                gameHero.IntroTarget = Doors[3].Position + new Vector3(7f, 0f, 4f);
                gameHero.Position = Doors[3].Position + new Vector3(-7f, 0f, 4f);
                gameHero.Rotation = 0f;
                Doors[3].Open(true);
                exitDoor = Doors[3];
            }
            if (gameHero.RoomX == 4)
            {
                gameHero.RoomX = 3;
                exitRoomX = 3;
                gameHero.IntroTarget = Doors[1].Position + new Vector3(-7f, 0f, 4f);
                gameHero.Position = Doors[1].Position + new Vector3(7f, 0f, 4f);
                gameHero.Rotation = -MathHelper.Pi;
                Doors[1].Open(true);
                exitDoor = Doors[1];

            }
            if (gameHero.RoomY == -1)
            {
                gameHero.RoomY = 0;
                exitRoomY = 0;
                gameHero.IntroTarget = Doors[0].Position + new Vector3(0f, 7f, 4f);
                gameHero.Position = Doors[0].Position + new Vector3(0f, -7f, 4f);
                gameHero.Rotation = MathHelper.PiOver2;
                Doors[0].Open(true);
                exitDoor = Doors[0];

            }
            if (gameHero.RoomY == 4)
            {
                gameHero.RoomY = 3;
                exitRoomY = 3;
                gameHero.IntroTarget = Doors[2].Position + new Vector3(0f, -7f, 4f);
                gameHero.Position = Doors[2].Position + new Vector3(0f, 7f, 4f);
                gameHero.Rotation = -MathHelper.PiOver2;
                Doors[2].Open(true);
                exitDoor = Doors[2];

            }

            currentRoom = Rooms[gameHero.RoomX, gameHero.RoomY];

            enemyController.Enemies.RemoveAll(en => en.Room == currentRoom);

            gameCamera.Position = new Vector3((currentRoom.World.X_SIZE * Voxel.SIZE) / 2, (currentRoom.World.Y_SIZE * Voxel.SIZE) / 2, 0f);
            gameCamera.Target = new Vector3((currentRoom.World.X_SIZE * Voxel.SIZE) / 2, (currentRoom.World.Y_SIZE * Voxel.SIZE) / 2, 0f);

            generatedPercent = 100;

            OpenDoors();

            AudioController.PlayMusic("0");
        }