Beispiel #1
0
 public void setCurrentZoneFromNumber(int zoneNumber)
 {
     currentZoneNumber = zoneNumber;
     switch (zoneNumber)
     {
         case -4:
             currentZone = testZoneFactory.getTestTileZone();
             break;
         default:
             break;
     }
 }
Beispiel #2
0
 public bool checkCollision(Vector2 location, Enemy enemy, Zone currentZone, int level)
 {
     for (int i = (int) location.Y; i < (int) (location.Y + enemy.getWalkingSize().Y); i++)
     {
         for (int j = (int) location.X; j < (int) (location.X + enemy.getWalkingSize().X); j++)
         {
             if (currentZone.getCollisionMap()[level].getCollisionMap()[i, j] == false || currentZone.getTrafficMap()[level].getTrafficMap()[i, j] == true || currentZone.getEnemyMap()[level].getTrafficMap()[i, j] == true)
             {
                 return false;
             }
         }
     }
     return true;
 }
Beispiel #3
0
        public NPC(String name, Zone zone, Vector2 tileLocation, int level, Vector2 size, Vector2 drawSize, int facingDirection)
        {
            this.name = name;
            this.currentZone = zone;
            this.currentLocation = new Vector2(tileLocation.X * 30, tileLocation.Y * 30);
            this.currentLevel = level;
            this.size = size;
            this.drawSize = drawSize;
            this.facingDirection = facingDirection;

            chatPages = new List<ChatPage>();
            stationary = true;
            drawOffset = new Vector2(0, drawSize.Y - size.Y);
        }
Beispiel #4
0
        public NPC(String name, Zone startingZone, Vector2 startingLocation, int startingLevel, Vector2 drawDimensions)
        {
            this.name = name;
            this.startingZone = startingZone;
            this.startingLocation = startingLocation;
            this.startingLevel = startingLevel;
            currentLocation = startingLocation;
            currentZone = startingZone;
            currentLevel = startingLevel;

            yOffset = (int)drawDimensions.Y - 30;
            width = (int)drawDimensions.X;
            height = 30;
        }
Beispiel #5
0
 public void setCurrentZone(Zone newCurrentZone)
 {
     currentZone = newCurrentZone;
 }
 public abstract void activate(ContentHandler content, Zone currentZone, string activationCode);
Beispiel #7
0
 public void setCurrentZone(Zone zone)
 {
     currentZone = zone;
 }
        private int isTransition(Player player, Zone currentZone)
        {
            Vector2 location = player.getGlobalLocation();

            for (int i = 0; i < player.getSize().X; i++)
            {
                for (int j = 0; j < player.getMoveSpeed(); j++)
                {
                    int xPos = ((int)location.X + i) / 30;
                    int yPos = ((int)location.Y + j) / 30;
                    int xOff = ((int)location.X + i) % 30;
                    int yOff = ((int)location.Y + j) % 30;

                    int transNum = currentZone.getZoneTileMap().getTile(yPos, xPos, player.getCurrentZoneLevel()).checkPixel(yOff, xOff);

                    if (transNum > 1)
                    {
                        //Console.WriteLine("xPos: " + xPos + " yPos: " + yPos);
                        return transNum;
                    }

                }
            }

            for (int i = 0; i < (player.getSize().Y - player.getMoveSpeed()); i++)
            {
                for (int j = 0; j < player.getMoveSpeed(); j++)
                {
                    int xPos = ((int)location.X + j) / 30;
                    int yPos = ((int)location.Y + i + player.getMoveSpeed()) / 30;
                    int xOff = ((int)location.X + j) % 30;
                    int yOff = ((int)location.Y + i + player.getMoveSpeed()) % 30;

                    int transNum = currentZone.getZoneTileMap().getTile(yPos, xPos, player.getCurrentZoneLevel()).checkPixel(yOff, xOff);

                    if (transNum > 1)
                    {
                        Console.WriteLine(player.getGlobalLocation());
                        Console.WriteLine("xPos: " + xPos + " yPos: " + yPos);
                        Console.WriteLine("xOff: " + xOff + " yOff: " + yOff);
                        Console.WriteLine(i);
                        return transNum;
                    }
                }
            }

            for (int i = 0; i < player.getSize().Y - player.getMoveSpeed(); i++)
            {
                for (int j = 0; j < player.getMoveSpeed(); j++)
                {
                    int xPos = ((int)location.X + (int)player.getSize().X - player.getMoveSpeed() + j) / 30;
                    int yPos = ((int)location.Y + i + player.getMoveSpeed()) / 30;
                    int xOff = ((int)location.X + (int)player.getSize().X - player.getMoveSpeed() + j) % 30;
                    int yOff = ((int)location.Y + i + player.getMoveSpeed()) % 30;

                    int transNum = currentZone.getZoneTileMap().getTile(yPos, xPos, player.getCurrentZoneLevel()).checkPixel(yOff, xOff);

                    if (transNum > 1)
                    {
                        //Console.WriteLine("xPos: " + xPos + " yPos: " + yPos);
                        return transNum;
                    }
                }
            }

            for (int i = 0; i < player.getSize().X - player.getMoveSpeed() - player.getMoveSpeed(); i++)
            {
                for (int j = 0; j < player.getMoveSpeed(); j++)
                {
                    int xPos = ((int)location.X + player.getMoveSpeed() + i) / 30;
                    int yPos = ((int)location.Y + (int)player.getSize().Y - player.getMoveSpeed() + j) / 30;
                    int xOff = ((int)location.X + player.getMoveSpeed() + i) % 30;
                    int yOff = ((int)location.Y + (int)player.getSize().Y - player.getMoveSpeed() + j) % 30;

                    int transNum = currentZone.getZoneTileMap().getTile(yPos, xPos, player.getCurrentZoneLevel()).checkPixel(yOff, xOff);

                    if (transNum > 1)
                    {
                        //Console.WriteLine("xPos: " + xPos + " yPos: " + yPos);
                        return transNum;
                    }
                }
            }

            return 0;
        }
Beispiel #9
0
 private void createEnemy(string type, Vector2 location, int facingDirection, int currentZoneLevel, Zone currentZone)
 {
     Console.WriteLine("creating enemy");
     spawnEnemiesLeft--;
     Enemy enemy;
     if (type == "Goblin")
     {
         enemy = new Goblin(location, facingDirection, currentZoneLevel);
         currentZone.getEnemies().Add(enemy);
         currentZone.getEnemyMap()[currentZoneLevel].insertEnemy(enemy);
     }
     else if (type == "Rabbit")
     {
         enemy = new Rabbit(location, facingDirection, currentZoneLevel);
         currentZone.getEnemies().Add(enemy);
         currentZone.getEnemyMap()[currentZoneLevel].insertEnemy(enemy);
     }
 }
Beispiel #10
0
 public void spawnEnemy(string type, Zone currentZone, int level)
 {
     Enemy enemy = placeholderEnemies[type];
     setSpawnLocations(enemy.getWalkingSize());
     for (int i = 0; i < spawnLocations.Count; i++)
     {
         if (canSpawn(i))
         {
             if (checkCollision(spawnLocations[i], enemy, currentZone, level))
             {
                 if (spawnEnemiesLeft > 0)
                 {
                     createEnemy(type, spawnLocations[i], 1, level, currentZone);
                 }
             }
         }
     }
 }
        private int checkCollision(int distance, int direction, Player player, Zone currentZone)
        {
            Vector2 startingPoint;

            if (direction == 0)
            {
                startingPoint = player.getGlobalLocation();

                int i = 0;

                while (i <= distance)
                {
                    i += 2;

                    if (!bump)
                    {
                        int leftCol = 0;
                        int centerCol = 0;
                        int rightCol = 0;

                        for (int j = 0; j < (int)player.getSize().Y; j += 2)
                        {
                            int xTile = ((int)startingPoint.X + j) / 30;
                            int yTile = ((int)startingPoint.Y - i) / 30;

                            if ((int)startingPoint.Y - i < 0)
                            {
                                upDistance += (i - 2);
                                return i - 2;
                            }

                            int xOffset = ((int)startingPoint.X + j) % 30;
                            int yOffset = ((int)startingPoint.Y - i) % 30;

                            if (currentZone.getZoneTileMap().getTile(yTile, xTile, player.getCurrentZoneLevel()).checkPixel(yOffset, xOffset) == 1)
                            {
                                if (j < 14)
                                {
                                    leftCol++;
                                }
                                else if (j >= 16)
                                {
                                    rightCol++;
                                }
                                else
                                {
                                    centerCol++;
                                }
                            }
                        }

                        if (leftCol > 0 && centerCol == 0)
                        {
                            bump = true;
                            player.moveRight(checkCollision(2, 2, player, currentZone));
                            upDistance += (i - 2);
                            return i - 2;
                        }
                        else if (rightCol > 0 && centerCol == 0)
                        {
                            bump = true;
                            player.moveLeft(checkCollision(2, 3, player, currentZone));
                            upDistance += (i - 2);
                            return i - 2;
                        }
                        else if (centerCol > 0)
                        {
                            upDistance += (i - 2);
                            return i - 2;
                        }
                    }
                    else
                    {
                        bump = false;

                        for (int j = 0; j < (int)player.getSize().Y; j += 2)
                        {
                            int xTile = ((int)startingPoint.X + j) / 30;
                            int yTile = ((int)startingPoint.Y - i) / 30;

                            if ((int)startingPoint.Y - i < 0)
                            {
                                upDistance += (i - 2);
                                return i - 2;
                            }

                            int xOffset = ((int)startingPoint.X + j) % 30;
                            int yOffset = ((int)startingPoint.Y - i) % 30;

                            if (currentZone.getZoneTileMap().getTile(yTile, xTile, player.getCurrentZoneLevel()).checkPixel(yOffset, xOffset) == 1)
                            {
                                upDistance += (i - 2);
                                return i - 2;
                            }
                        }
                    }

                }
                upDistance += (i - 2);
                return i - 2;
            }
            else if (direction == 1)
            {
                startingPoint = player.getGlobalLocation() + new Vector2(0, 29);

                int i = 0;

                while (i <= distance)
                {
                    i += 2;

                    if (!bump)
                    {
                        int leftCol = 0;
                        int centerCol = 0;
                        int rightCol = 0;

                        for (int j = 0; j < (int)player.getSize().Y; j += 2)
                        {
                            int xTile = ((int)startingPoint.X + j) / 30;
                            int yTile = ((int)startingPoint.Y + i) / 30;

                            if ((int)startingPoint.Y + i >= currentZone.getHeight())
                            {
                                downDistance += (i - 2);
                                return i - 2;
                            }

                            int xOffset = ((int)startingPoint.X + j) % 30;
                            int yOffset = ((int)startingPoint.Y + i) % 30;

                            if (currentZone.getZoneTileMap().getTile(yTile, xTile, player.getCurrentZoneLevel()).checkPixel(yOffset, xOffset) == 1)
                            {
                                if (j < 14)
                                {
                                    leftCol++;
                                }
                                else if (j >= 16)
                                {
                                    rightCol++;
                                }
                                else
                                {
                                    centerCol++;
                                }
                            }
                        }

                        if (leftCol > 0 && centerCol == 0)
                        {
                            bump = true;
                            player.moveRight(checkCollision(2, 2, player, currentZone));
                            downDistance += (i - 2);
                            return i - 2;
                        }
                        else if (rightCol > 0 && centerCol == 0)
                        {
                            bump = true;
                            player.moveLeft(checkCollision(2, 3, player, currentZone));
                            downDistance += (i - 2);
                            return i - 2;
                        }
                        else if (centerCol > 0)
                        {
                            downDistance += (i - 2);
                            return i - 2;
                        }
                    }
                    else
                    {
                        bump = false;

                        for (int j = 0; j < (int)player.getSize().Y; j += 2)
                        {
                            int xTile = ((int)startingPoint.X + j) / 30;
                            int yTile = ((int)startingPoint.Y + i) / 30;

                            if ((int)startingPoint.Y + i >= currentZone.getHeight())
                            {
                                downDistance += (i - 2);
                                return i - 2;
                            }

                            int xOffset = ((int)startingPoint.X + j) % 30;
                            int yOffset = ((int)startingPoint.Y + i) % 30;

                            if (currentZone.getZoneTileMap().getTile(yTile, xTile, player.getCurrentZoneLevel()).checkPixel(yOffset, xOffset) == 1)
                            {
                                downDistance += (i - 2);
                                return i - 2;
                            }
                        }
                    }

                }
                downDistance += (i - 2);
                return i - 2;
            }
            else if (direction == 2)
            {
                startingPoint = player.getGlobalLocation() + new Vector2(29, 0);

                int i = 0;

                while (i <= distance)
                {
                    i += 2;

                    if (!bump)
                    {
                        int upCol = 0;
                        int centerCol = 0;
                        int downCol = 0;

                        for (int j = 0; j < (int)player.getSize().Y; j += 2)
                        {
                            int xTile = ((int)startingPoint.X + i) / 30;
                            int yTile = ((int)startingPoint.Y + j) / 30;

                            if ((int)startingPoint.X + i >= currentZone.getWidth())
                            {
                                rightDistance += (i - 2);
                                return i - 2;
                            }

                            int xOffset = ((int)startingPoint.X + i) % 30;
                            int yOffset = ((int)startingPoint.Y + j) % 30;

                            if (currentZone.getZoneTileMap().getTile(yTile, xTile, player.getCurrentZoneLevel()).checkPixel(yOffset, xOffset) == 1)
                            {
                                if (j < 14)
                                {
                                    upCol++;
                                }
                                else if (j >= 16)
                                {
                                    downCol++;
                                }
                                else
                                {
                                    centerCol++;
                                }
                            }
                        }

                        if (upCol > 0 && centerCol == 0)
                        {
                            bump = true;
                            player.moveDown(checkCollision(2, 1, player, currentZone));
                            rightDistance += (i - 2);
                            return i - 2;
                        }
                        else if (downCol > 0 && centerCol == 0)
                        {
                            bump = true;
                            player.moveUp(checkCollision(2, 0, player, currentZone));
                            rightDistance += (i - 2);
                            return i - 2;
                        }
                        else if (centerCol > 0)
                        {
                            rightDistance += (i - 2);
                            return i - 2;
                        }
                    }
                    else
                    {
                        bump = false;

                        for (int j = 0; j < (int)player.getSize().Y; j += 2)
                        {
                            int xTile = ((int)startingPoint.X + i) / 30;
                            int yTile = ((int)startingPoint.Y + j) / 30;

                            if ((int)startingPoint.X + i >= currentZone.getWidth())
                            {
                                rightDistance += (i - 2);
                                return i - 2;
                            }

                            int xOffset = ((int)startingPoint.X + i) % 30;
                            int yOffset = ((int)startingPoint.Y + j) % 30;

                            if (currentZone.getZoneTileMap().getTile(yTile, xTile, player.getCurrentZoneLevel()).checkPixel(yOffset, xOffset) == 1)
                            {
                                rightDistance += (i - 2);
                                return i - 2;
                            }
                        }
                    }

                }
                rightDistance += (i - 2);
                return i - 2;
            }
            else if (direction == 3)
            {
                startingPoint = player.getGlobalLocation();

                int i = 0;

                while (i <= distance)
                {
                    i += 2;

                    if (!bump)
                    {
                        int upCol = 0;
                        int centerCol = 0;
                        int downCol = 0;

                        for (int j = 0; j < (int)player.getSize().Y; j += 2)
                        {
                            int xTile = ((int)startingPoint.X - i) / 30;
                            int yTile = ((int)startingPoint.Y + j) / 30;

                            if ((int)startingPoint.X - i < 0)
                            {
                                leftDistance += (i - 2);
                                return i - 2;
                            }

                            int xOffset = ((int)startingPoint.X - i) % 30;
                            int yOffset = ((int)startingPoint.Y + j) % 30;

                            if (currentZone.getZoneTileMap().getTile(yTile, xTile, player.getCurrentZoneLevel()).checkPixel(yOffset, xOffset) == 1)
                            {
                                if (j < 14)
                                {
                                    upCol++;
                                }
                                else if (j >= 16)
                                {
                                    downCol++;
                                }
                                else
                                {
                                    centerCol++;
                                }
                            }
                        }

                        if (upCol > 0 && centerCol == 0)
                        {
                            bump = true;
                            player.moveDown(checkCollision(2, 1, player, currentZone));
                            leftDistance += (i - 2);
                            return i - 2;
                        }
                        else if (downCol > 0 && centerCol == 0)
                        {
                            bump = true;
                            player.moveUp(checkCollision(2, 0, player, currentZone));
                            leftDistance += (i - 2);
                            return i - 2;
                        }
                        else if (centerCol > 0)
                        {
                            leftDistance += (i - 2);
                            return i - 2;
                        }
                    }
                    else
                    {
                        bump = false;

                        for (int j = 0; j < (int)player.getSize().Y; j += 2)
                        {
                            int xTile = ((int)startingPoint.X - i) / 30;
                            int yTile = ((int)startingPoint.Y + j) / 30;

                            if ((int)startingPoint.X - i < 0)
                            {
                                leftDistance += (i - 2);
                                return i - 2;
                            }

                            int xOffset = ((int)startingPoint.X - i) % 30;
                            int yOffset = ((int)startingPoint.Y + j) % 30;

                            if (currentZone.getZoneTileMap().getTile(yTile, xTile, player.getCurrentZoneLevel()).checkPixel(yOffset, xOffset) == 1)
                            {
                                leftDistance += (i - 2);
                                return i - 2;
                            }
                        }
                    }

                }
                leftDistance += (i - 2);
                return i - 2;
            }

            return 0;
        }
        public void updateDrawLocations(Player player, Zone currentZone)
        {
            float playerDrawLocationX;
            float playerDrawLocationY;
            float zoneDrawLocationX;
            float zoneDrawLocationY;

            if (player.getGlobalLocation().X + player.getCenterFromGlobal().X >= 450 && player.getGlobalLocation().X + player.getCenterFromGlobal().X < currentZone.getWidth() - 450)
            {
                playerDrawLocationX = 450 - (int) player.getCenterFromGlobal().X;
                zoneDrawLocationX = -(player.getGlobalLocation().X + player.getCenterFromGlobal().X) + 450;
            }
            else
            {
                if (player.getGlobalLocation().X + player.getCenterFromGlobal().X < 450)
                {
                    playerDrawLocationX = player.getGlobalLocation().X;
                    zoneDrawLocationX = 0;
                }
                else
                {
                    playerDrawLocationX = 900 - (currentZone.getWidth() - player.getGlobalLocation().X);
                    zoneDrawLocationX = -currentZone.getWidth() + 900;
                }
            }

            if (player.getGlobalLocation().Y + player.getCenterFromGlobal().Y >= 300 && player.getGlobalLocation().Y + player.getCenterFromGlobal().Y < currentZone.getHeight() - 300)
            {
                playerDrawLocationY = 300 - (player.getDrawingSize().Y - player.getSize().Y + player.getCenterFromGlobal().Y);
                zoneDrawLocationY = -(player.getGlobalLocation().Y + player.getCenterFromGlobal().Y - 300);
            }
            else
            {
                if (player.getGlobalLocation().Y + player.getCenterFromGlobal().Y < 300)
                {
                    playerDrawLocationY = player.getGlobalLocation().Y - (player.getDrawingSize().Y - player.getSize().Y);
                    zoneDrawLocationY = 0;
                }
                else
                {
                    playerDrawLocationY = 600 - (currentZone.getHeight() - player.getGlobalLocation().Y - player.getSize().Y + player.getDrawingSize().Y);
                    zoneDrawLocationY = -currentZone.getHeight() + 600;
                }
            }

            player.setDrawLocation(new Vector2(playerDrawLocationX, playerDrawLocationY));
            currentZone.setDrawLocation(new Vector2(zoneDrawLocationX, zoneDrawLocationY));
        }