Exemplo n.º 1
0
        public void UpdateEnemy(Hero hero, WallSet wall)
        {
            if (CurrentState != EnemyState.Bunny)
            {
                DetectHero(hero);
                Vector2 toTarget     = TargetPosition - Center;
                float   distToTarget = toTarget.Length();
                toTarget.Normalize();

                if (CurrentState == EnemyState.Chaser)
                {
                    ChaserCount--;
                    UpdateEnemyChaseState(hero, distToTarget);
                }

                else if (CurrentState == EnemyState.Patrol)
                {
                    UpdateEnemyPatrolState(wall);
                }

                if (ChaserCount == 0 && distToTarget > kDistToBeginChase)
                {
                    CurrentState = EnemyState.Patrol;
                    ChaserCount  = 500;
                }
            }
        }
Exemplo n.º 2
0
        public Vector2 Update(Enemy[] enemy, WallSet walls)
        {
            Vector2 s = new Vector2(-1f, -1f);

            for (int i = 0; i < list.Count; i++)
            {
                shot temp = list[i];
                if (list[i].shotLife == 0)
                {
                    list[i].bullet.RemoveFromAutoDrawSet();
                    list[i].emitter.RemoveFromAutoDrawSet();
                    list.Remove(list[i]);
                }
                else
                {
                    temp.shotLife--;
                    for (int j = 0; j < enemy.Length; j++)
                    {
                        list[i] = temp;
                        if (list[i].bullet.Collided(enemy[j]) && !list[i].hit)
                        {
                            enemy[j].Caught();
                            if (enemy[j].NumLivesLeft <= 0)
                            {
                                s = enemy[j].TurnEnemyToBunny();
                            }

                            temp.bullet.RemoveFromAutoDrawSet();
                            temp.emitter.RemoveFromAutoDrawSet();
                            list.Remove(list[i]);
                            temp.hit = true;
                            break;
                        }
                    }
                    if (!temp.hit)
                    {
                        list[i] = temp;

                        list[i].emitter.Center = list[i].bullet.Center;

                        for (int k = 0; k < walls.RoomWalls.Length; k++)
                        {
                            if (temp.bullet.Collided(walls.RoomWalls[k]))
                            {
                                temp.bullet.RemoveFromAutoDrawSet();
                                temp.emitter.RemoveFromAutoDrawSet();
                                list.Remove(list[i]);
                            }
                        }
                    }
                }
            }

            return(s);
        }
Exemplo n.º 3
0
 public void deleteRoom()
 {
     roomObjects.RemoveAllFromSet();
     myDoors   = null;
     myEnemies = null;
     walls     = null;
     stairs    = null;
     key       = null;
     backGround.RemoveFromAutoDrawSet();
     backGround = null;
 }
Exemplo n.º 4
0
        public void UpdateEnemyPatrolState(WallSet wall)
        {
            float ran = XNACS1Base.RandomFloat(-20f, 20.0f);

            if (ran < 5)
            {
                UpdateEnemyLeftRightDir(wall);
            }
            else
            {
                UpdateEnemyUpDownDir(wall);
            }
        }
Exemplo n.º 5
0
        public Room(ref StreamReader m, int xCoord, int yCoord)
        {
            x = xCoord;
            y = yCoord;

            roomOrigin = new Vector2((float)xCoord * 100f, (float)yCoord * ((9f / 16f) * 100f));
            backGround = new XNACS1Rectangle(new Vector2(roomOrigin.X + 50f, roomOrigin.Y + 50 * (9f / 16f)), 100f, 100f * (9f / 16f), "bg1");
            walls      = new WallSet(roomOrigin);

            hasStairs  = Convert.ToInt32(m.ReadLine());
            numDoors   = Convert.ToInt32(m.ReadLine());
            myDoors    = new Doors[numDoors];
            numEnemies = Convert.ToInt32(m.ReadLine());

            if (hasStairs == 1)
            {
                float stairX = (float)Convert.ToDouble(m.ReadLine());
                float stairY = (float)Convert.ToDouble(m.ReadLine());
                stairs = new Stair(new Vector2(stairX + roomOrigin.X, stairY + roomOrigin.Y));
            }

            activeEnemies = numEnemies;
            myEnemies     = new Enemy[numEnemies];
            roomObjects   = new XNACS1PrimitiveSet();

            coord = new Vector2((float)x, (float)y);

            for (int i = 0; i < numEnemies; i++)
            {
                float  posX = (float)Convert.ToDouble(m.ReadLine()) + roomOrigin.X;
                string line = m.ReadLine();
                float  posY = (float)Convert.ToDouble(line) + roomOrigin.Y;
                myEnemies[i] = new Enemy(new Vector2(posX, posY), "guard");
                roomObjects.AddToSet(myEnemies[i]);
            }

            for (int i = 0; i < numDoors; i++)
            {
                //takes in the origin of the room and the door type
                myDoors[i] = new Doors(roomOrigin, coord, m.ReadLine());
                roomObjects.AddToSet(myDoors[i]);
            }

            roomObjects.RemoveAllFromAutoDrawSet();

            wand = new Wand();
        }
        int y; //location of the room in y

        #endregion Fields

        #region Constructors

        public Room(ref StreamReader m, int xCoord, int yCoord)
        {
            x = xCoord;
            y = yCoord;

            roomOrigin = new Vector2((float)xCoord * 100f, (float)yCoord * ((9f / 16f) * 100f));
            backGround = new XNACS1Rectangle(new Vector2(roomOrigin.X + 50f, roomOrigin.Y + 50 * (9f / 16f)), 100f, 100f * (9f / 16f), "bg1");
            walls = new WallSet(roomOrigin);

            hasStairs = Convert.ToInt32(m.ReadLine());
            numDoors = Convert.ToInt32(m.ReadLine());
            myDoors = new Doors[numDoors];
            numEnemies = Convert.ToInt32(m.ReadLine());

            if (hasStairs == 1) {
                float stairX = (float)Convert.ToDouble(m.ReadLine());
                float stairY = (float)Convert.ToDouble(m.ReadLine());
                stairs = new Stair(new Vector2(stairX + roomOrigin.X, stairY + roomOrigin.Y));
            }

            activeEnemies = numEnemies;
            myEnemies = new Enemy[numEnemies];
            roomObjects = new XNACS1PrimitiveSet();

            coord = new Vector2((float)x, (float)y);

            for (int i = 0; i < numEnemies; i++) {
                float posX = (float)Convert.ToDouble(m.ReadLine()) + roomOrigin.X;
                string line = m.ReadLine();
                float posY = (float)Convert.ToDouble(line) + roomOrigin.Y;
                myEnemies[i] = new Enemy(new Vector2(posX, posY), "guard");
                roomObjects.AddToSet(myEnemies[i]);
            }

            for (int i = 0; i < numDoors; i++) {
                //takes in the origin of the room and the door type
                myDoors[i] = new Doors(roomOrigin, coord, m.ReadLine());
                roomObjects.AddToSet(myDoors[i]);
            }

            roomObjects.RemoveAllFromAutoDrawSet();

            wand = new Wand();
        }
        public Room(ref StreamReader m, int xCoord, int yCoord)
        {
            x = xCoord;
            y = yCoord;

            roomOrigin = new Vector2((float)xCoord * 100f, (float)yCoord * ((9f / 16f) * 100f));
            walls      = new WallSet(roomOrigin);


            numDoors = Convert.ToInt32(m.ReadLine());
            myDoors  = new Doors[numDoors];

            numEnemies    = Convert.ToInt32(m.ReadLine());
            activeEnemies = numEnemies;
            myEnemies     = new Enemy[numEnemies];
            //line = m.ReadLine();
            //isVisited = Convert.ToBoolean(line);

            //line = m.ReadLine();
            //hasStairs = Convert.ToBoolean(line);
            roomObjects = new XNACS1PrimitiveSet();

            coord = new Vector2((float)x, (float)y);

            for (int i = 0; i < numEnemies; i++)
            {
                float posX = Convert.ToInt64(m.ReadLine()) + roomOrigin.X;
                float posY = Convert.ToInt64(m.ReadLine()) + roomOrigin.Y;
                myEnemies[i] = new Enemy(new Vector2(posX, posY), "guard");
                roomObjects.AddToSet(myEnemies[i]);
            }

            for (int i = 0; i < numDoors; i++)
            {
                //takes in the origin of the room and the door type
                myDoors[i] = new Doors(roomOrigin, coord, m.ReadLine());
                roomObjects.AddToSet(myDoors[i]);
            }

            roomObjects.RemoveAllFromAutoDrawSet();

            wand = new Wand();
        }
        int y; //location of the room in y

        #endregion Fields

        #region Constructors

        public Room(ref StreamReader m, int xCoord, int yCoord)
        {
            x = xCoord;
            y = yCoord;

            roomOrigin = new Vector2((float)xCoord * 100f, (float)yCoord * ((9f / 16f) * 100f));
            walls = new WallSet(roomOrigin);

            numDoors = Convert.ToInt32(m.ReadLine());
            myDoors = new Doors[numDoors];

            numEnemies = Convert.ToInt32(m.ReadLine());
            activeEnemies = numEnemies;
            myEnemies = new Enemy[numEnemies];
            //line = m.ReadLine();
            //isVisited = Convert.ToBoolean(line);

            //line = m.ReadLine();
            //hasStairs = Convert.ToBoolean(line);
            roomObjects = new XNACS1PrimitiveSet();

            coord = new Vector2((float)x, (float)y);

            for (int i = 0; i < numEnemies; i++) {
                float posX = Convert.ToInt64(m.ReadLine()) + roomOrigin.X;
                float posY = Convert.ToInt64(m.ReadLine()) + roomOrigin.Y;
                myEnemies[i] = new Enemy(new Vector2(posX, posY), "guard");
                roomObjects.AddToSet(myEnemies[i]);
            }

            for (int i = 0; i < numDoors; i++) {
                //takes in the origin of the room and the door type
                myDoors[i] = new Doors(roomOrigin, coord, m.ReadLine());
                roomObjects.AddToSet(myDoors[i]);
            }

            roomObjects.RemoveAllFromAutoDrawSet();

            wand = new Wand();
        }
Exemplo n.º 9
0
        public bool UpdateEnemy(Hero hero, WallSet wall)
        {
            if (CurrentState != EnemyState.Bunny)
            {
                DetectHero(hero);
                Vector2 toTarget     = TargetPosition - Center;
                float   distToTarget = toTarget.Length();
                toTarget.Normalize();

                if (CurrentState == EnemyState.Chaser)
                {
                    ChaserCount--;
                    if (UpdateEnemyChaseState(hero, distToTarget))
                    {
                        return(true);
                    }
                }

                else if (CurrentState == EnemyState.Patrol)
                {
                    UpdateEnemyPatrolState(wall);
                }

                if (ChaserCount == 0 && distToTarget > kDistToBeginChase)
                {
                    CurrentState = EnemyState.Patrol;
                    ChaserCount  = 500;
                }
            }

            if (lives > initialLives)
            {
                initialLives = lives;
            }
            health.Update(this.Center, lives, initialLives);

            return(false);
        }
Exemplo n.º 10
0
        public void UpdateEnemyUpDownDir(WallSet wall)
        {
            bool CollidWithUpWall     = Collided(wall.RoomWall[1]);        // collided with up wall
            bool CollidWithBottomWall = Collided(wall.RoomWall[3]);        // collided with bottom wall

            if (CollidWithUpWall)
            {
                flagY = false;
            }
            if (CollidWithBottomWall)
            {
                flagY = true;
            }

            if (flagY)            // going up
            {
                CenterY = (CenterY + Ychange);
            }
            else
            {
                CenterY = (CenterY - Ychange);                // going down
            }
        }
Exemplo n.º 11
0
        public void UpdateEnemyLeftRightDir(WallSet wall)
        {
            bool CollidWithLeftWall  = Collided(wall.RoomWall[0]);           // collided with left wall
            bool CollidWithRightWall = Collided(wall.RoomWall[2]);           // collided with right wall

            if (CollidWithRightWall)
            {
                flagX = false;
            }
            if (CollidWithLeftWall)
            {
                flagX = true;
            }

            if (flagX)            // going right
            {
                CenterX = (CenterX + Xchange);
            }
            else
            {
                CenterX = (CenterX - Xchange);
            }
        }
Exemplo n.º 12
0
        public Room(ref StreamReader m, int xCoord, int yCoord)
        {
            x = xCoord;
            y = yCoord;

            triggerPressed = false;
            roomOrigin     = new Vector2((float)xCoord * 100f, (float)yCoord * ((9f / 16f) * 100f));
            backGround     = new XNACS1Rectangle(new Vector2(roomOrigin.X + 50f, roomOrigin.Y + 50 * (9f / 16f)), 100f, 100f * (9f / 16f), "dungeonFloor");
            walls          = new WallSet(roomOrigin);

            hasStairs   = Convert.ToInt32(m.ReadLine());
            numDoors    = Convert.ToInt32(m.ReadLine());
            myDoors     = new Doors[numDoors];
            numEnemies  = Convert.ToInt32(m.ReadLine());
            numKnights  = Convert.ToInt32(m.ReadLine());
            roomObjects = new XNACS1PrimitiveSet();
            isAlive     = false;
            heroCaught  = false;

            if (hasStairs == 1)
            {
                float stairX = (float)Convert.ToDouble(m.ReadLine());
                float stairY = (float)Convert.ToDouble(m.ReadLine());
                stairs = new Stair(new Vector2(stairX + roomOrigin.X, stairY + roomOrigin.Y));
                roomObjects.AddToSet(stairs);

                float badGuyX = (float)Convert.ToDouble(m.ReadLine());
                float badGuyY = (float)Convert.ToDouble(m.ReadLine());
                badGuy = new Wizard(new Vector2(badGuyX + roomOrigin.X, badGuyY + roomOrigin.Y));

                roomObjects.AddToSet(badGuy);
                hasWon = false;
            }

            activeEnemies = numEnemies;
            myEnemies     = new Enemy[numEnemies];
            numGuards     = numEnemies - numKnights;
            coord         = new Vector2((float)x, (float)y);


            for (int i = 0; i < numGuards; i++)
            {
                float  posX = (float)Convert.ToDouble(m.ReadLine()) + roomOrigin.X;
                string line = m.ReadLine();
                float  posY = (float)Convert.ToDouble(line) + roomOrigin.Y;
                myEnemies[i] = new Guard(new Vector2(posX, posY));
                roomObjects.AddToSet(myEnemies[i]);
            }

            for (int i = numGuards; i < numEnemies; i++)
            {
                float  posX = (float)Convert.ToDouble(m.ReadLine()) + roomOrigin.X;
                string line = m.ReadLine();
                float  posY = (float)Convert.ToDouble(line) + roomOrigin.Y;
                myEnemies[i] = new Knight(new Vector2(posX, posY));
                roomObjects.AddToSet(myEnemies[i]);
            }

            for (int i = 0; i < numDoors; i++)
            {
                //takes in the origin of the room and the door type
                myDoors[i] = new Doors(roomOrigin, coord, m.ReadLine());
                roomObjects.AddToSet(myDoors[i]);
            }

            roomObjects.RemoveAllFromAutoDrawSet();

            wand = new Wand();
        }
Exemplo n.º 13
0
        public bool UpdateEnemy(Hero hero, WallSet wall)
        {
            if (CurrentState != EnemyState.Bunny) {
                DetectHero(hero);
                Vector2 toTarget = TargetPosition - Center;
                float distToTarget = toTarget.Length();
                toTarget.Normalize();

                if (CurrentState == EnemyState.Chaser) {
                    ChaserCount--;
                    if (UpdateEnemyChaseState(hero, distToTarget)) {
                        return true;
                    }
                }

                else if (CurrentState == EnemyState.Patrol)
                    UpdateEnemyPatrolState(wall);

                if (ChaserCount == 0 && distToTarget > kDistToBeginChase) {
                    CurrentState = EnemyState.Patrol;
                    ChaserCount = 500;
                }
            }

            if (lives > initialLives)
                initialLives = lives;
            health.Update(this.Center, lives, initialLives);

            return false;
        }
        public void UpdateEnemy(Hero hero, WallSet wall)
        {
            if (CurrentState != EnemyState.Bunny) {
                DetectHero(hero);
                Vector2 toTarget = TargetPosition - Center;
                float distToTarget = toTarget.Length();
                toTarget.Normalize();

                if (CurrentState == EnemyState.Chaser) {
                    ChaserCount--;
                    UpdateEnemyChaseState(hero, distToTarget);
                }

                else if (CurrentState == EnemyState.Patrol)
                    UpdateEnemyPatrolState(wall);

                if (ChaserCount == 0 && distToTarget > kDistToBeginChase) {
                    CurrentState = EnemyState.Patrol;
                    ChaserCount = 500;
                }
            }
        }
        public void UpdateEnemyLeftRightDir(WallSet wall)
        {
            bool CollidWithLeftWall = Collided(wall.RoomWall[0]);// collided with left wall
            bool CollidWithRightWall = Collided(wall.RoomWall[2]);// collided with right wall

            if (CollidWithRightWall)
                flagX = false;
            if (CollidWithLeftWall)
                flagX = true;

            if (flagX)// going right
                CenterX = (CenterX + Xchange);
            else
                CenterX = (CenterX - Xchange);
        }
Exemplo n.º 16
0
        public Room(ref StreamReader m, int xCoord, int yCoord)
        {
            x = xCoord;
            y = yCoord;

            triggerPressed = false;
            roomOrigin = new Vector2((float)xCoord * 100f, (float)yCoord * ((9f / 16f) * 100f));
            backGround = new XNACS1Rectangle(new Vector2(roomOrigin.X + 50f, roomOrigin.Y + 50 * (9f / 16f)), 100f, 100f * (9f / 16f), "dungeonFloor");
            walls = new WallSet(roomOrigin);

            hasStairs = Convert.ToInt32(m.ReadLine());
            numDoors = Convert.ToInt32(m.ReadLine());
            myDoors = new Doors[numDoors];
            numEnemies = Convert.ToInt32(m.ReadLine());
            numKnights = Convert.ToInt32(m.ReadLine());
            roomObjects = new XNACS1PrimitiveSet();
            isAlive = false;
            heroCaught = false;

            if (hasStairs == 1) {
                float stairX = (float)Convert.ToDouble(m.ReadLine());
                float stairY = (float)Convert.ToDouble(m.ReadLine());
                stairs = new Stair(new Vector2(stairX + roomOrigin.X, stairY + roomOrigin.Y));
                roomObjects.AddToSet(stairs);

                float badGuyX = (float)Convert.ToDouble(m.ReadLine());
                float badGuyY = (float)Convert.ToDouble(m.ReadLine());
                badGuy = new Wizard(new Vector2(badGuyX + roomOrigin.X, badGuyY + roomOrigin.Y));

                roomObjects.AddToSet(badGuy);
                hasWon = false;
            }

            activeEnemies = numEnemies;
            myEnemies = new Enemy[numEnemies];
            numGuards = numEnemies - numKnights;
            coord = new Vector2((float)x, (float)y);

            for (int i = 0; i < numGuards; i++) {
                float posX = (float)Convert.ToDouble(m.ReadLine()) + roomOrigin.X;
                string line = m.ReadLine();
                float posY = (float)Convert.ToDouble(line) + roomOrigin.Y;
                myEnemies[i] = new Guard(new Vector2(posX, posY));
                roomObjects.AddToSet(myEnemies[i]);
            }

            for (int i = numGuards; i < numEnemies; i++) {
                float posX = (float)Convert.ToDouble(m.ReadLine()) + roomOrigin.X;
                string line = m.ReadLine();
                float posY = (float)Convert.ToDouble(line) + roomOrigin.Y;
                myEnemies[i] = new Knight(new Vector2(posX, posY));
                roomObjects.AddToSet(myEnemies[i]);
            }

            for (int i = 0; i < numDoors; i++) {
                //takes in the origin of the room and the door type
                myDoors[i] = new Doors(roomOrigin, coord, m.ReadLine());
                roomObjects.AddToSet(myDoors[i]);
            }

            roomObjects.RemoveAllFromAutoDrawSet();

            wand = new Wand();
        }
Exemplo n.º 17
0
        public void deleteRoom()
        {
            roomObjects.RemoveAllFromSet();
            myDoors = null;
            myEnemies = null;
            walls = null;
            stairs = null;
            key = null;
            if (backGround != null)
                backGround.RemoveFromAutoDrawSet();
            backGround = null;

            badGuy = null;
        }
 public void UpdateEnemyPatrolState(WallSet wall)
 {
     float ran = XNACS1Base.RandomFloat(-20f, 20.0f);
     if (ran < 5) {
         UpdateEnemyLeftRightDir(wall);
     }
     else {
         UpdateEnemyUpDownDir(wall);
     }
 }
Exemplo n.º 19
0
        public Vector2 Update(Enemy[] enemy, WallSet walls)
        {
            Vector2 s = new Vector2(-1f, -1f);
            for (int i = 0; i < list.Count; i++) {
                shot temp = list[i];
                if (list[i].shotLife == 0) {
                    list[i].bullet.RemoveFromAutoDrawSet();
                    list[i].emitter.RemoveFromAutoDrawSet();
                    list.Remove(list[i]);
                }
                else {
                    temp.shotLife--;
                    for (int j = 0; j < enemy.Length; j++) {
                        list[i] = temp;
                        if (list[i].bullet.Collided(enemy[j]) && !list[i].hit) {
                            enemy[j].Caught();
                            if (enemy[j].NumLivesLeft <= 0) {
                                s = enemy[j].TurnEnemyToBunny();
                            }

                            temp.bullet.RemoveFromAutoDrawSet();
                            temp.emitter.RemoveFromAutoDrawSet();
                            list.Remove(list[i]);
                            temp.hit = true;
                            break;
                        }

                    }
                    if (!temp.hit) {
                        list[i] = temp;

                        list[i].emitter.Center = list[i].bullet.Center;

                        for (int k = 0; k < walls.RoomWalls.Length; k++) {
                            if (temp.bullet.Collided(walls.RoomWalls[k])) {
                                temp.bullet.RemoveFromAutoDrawSet();
                                temp.emitter.RemoveFromAutoDrawSet();
                                list.Remove(list[i]);
                            }
                        }
                    }
                }
            }

            return s;
        }
        public void UpdateEnemyUpDownDir(WallSet wall)
        {
            bool CollidWithUpWall = Collided(wall.RoomWall[1]);// collided with up wall
            bool CollidWithBottomWall = Collided(wall.RoomWall[3]);// collided with bottom wall

            if (CollidWithUpWall)
                flagY = false;
            if (CollidWithBottomWall)
                flagY = true;

            if (flagY)// going up
                CenterY = (CenterY + Ychange);
            else
                CenterY = (CenterY - Ychange);// going down
        }