コード例 #1
0
 public void PlayerTileCollide(Player player, Exit exit)
 {
     game.transition = true;
     game.level = new Level(exit.destination, game);
     game.keyboard = new KeyboardController(game.level.player, game);
     game.level.player.position = new Vector2(game.prevPlayerPosition.X, game.prevPlayerPosition.Y + 10);
 }
コード例 #2
0
 public void PlayerEnemyCollide(Player player, Enemy enemy)
 {
     Rectangle playerBox = player.state.GetBoundingBox(player.position);
     Rectangle enemyBox = enemy.state.GetBoundingBox(enemy.position);
     Rectangle intersection = Rectangle.Intersect(playerBox, enemyBox);
     player.interactable = true;
     player.interactEnemy = enemy;
     if (intersection.Height > intersection.Width)
     {
         if (playerBox.Right > enemyBox.Left && playerBox.Right < enemyBox.Right)
         {
             player.position.X -= intersection.Width; // left
         }
         else
         {
             player.position.X += intersection.Width; // right
         }
     }
     else if (intersection.Height < intersection.Width)
     {
         if (playerBox.Bottom > enemyBox.Top && playerBox.Bottom < enemyBox.Bottom)
         {
             player.position.Y -= intersection.Height; // up
         }
         else
         {
             player.position.Y += intersection.Height; // down
         }
     }
 }
コード例 #3
0
        public void PlayerTileCollide(Player player, Tile tile)
        {
            Rectangle playerBox = player.state.GetBoundingBox(player.position);
            Rectangle tileBox = tile.GetBoundingBox();
            Rectangle intersection = Rectangle.Intersect(playerBox, tileBox);

            if (intersection.Height > intersection.Width)
            {
                if (playerBox.Right > tileBox.Left && playerBox.Right < tileBox.Right)
                {
                    player.position.X -= intersection.Width;
                }
                else
                {
                    player.position.X += intersection.Width;
                }
            }
            else if (intersection.Height < intersection.Width)
            {
                if (playerBox.Bottom > tileBox.Top && playerBox.Bottom < tileBox.Bottom)
                {
                    if (intersection.Height > 1)
                    {
                        player.position.Y -= intersection.Height;
                    }
                }
                else
                {
                    player.position.Y += intersection.Height;
                }
            }
        }
コード例 #4
0
ファイル: Level.cs プロジェクト: buttsj/CSharpMon
 public Level(string fileName, Game1 game)
 {
     this.game = game;
     builder = new LevelBuilder(this);
     player = builder.Build(fileName);
     collision = new CollisionDetection(player, game);
 }
コード例 #5
0
 public CollisionDetection(Player player, Game1 game)
 {
     this.game = game;
     grassResponse = new GrassCollisionResponse(game);
     tileResponse = new TileCollisionResponse(game);
     ledgeResponse = new LedgeCollisionResponse(game);
     buildingResponse = new BuildingCollisionResponse(game);
     enemyResponse = new EnemyCollisionResponse(game);
     exitResponse = new ExitCollisionResponse(game);
 }
コード例 #6
0
 public KeyboardController(Player currentPlayer, Game1 game)
 {
     player = currentPlayer;
     commandLibrary = new Dictionary<Keys, ICommands>();
     commandLibrary.Add(Keys.W, currentCommand = new UpCommand(player));
     commandLibrary.Add(Keys.A, currentCommand = new LeftCommand(player));
     commandLibrary.Add(Keys.S, currentCommand = new DownCommand(player));
     commandLibrary.Add(Keys.D, currentCommand = new RightCommand(player));
     commandLibrary.Add(Keys.Space, currentCommand = new InteractCommand(player));
     commandLibrary.Add(Keys.Enter, currentCommand = new PauseCommand(game));
 }
コード例 #7
0
        public void PlayerTileCollide(Player player, Building building)
        {
            Rectangle playerBox = player.state.GetBoundingBox(player.position);
            Rectangle buildingBox = building.GetBoundingBox();
            int middle = buildingBox.Left + buildingBox.Width / 2;
            int right = buildingBox.Right;

            Rectangle intersection = Rectangle.Intersect(playerBox, buildingBox);

            if (intersection.Height > intersection.Width)
            {
                if (playerBox.Right > buildingBox.Left && playerBox.Right < buildingBox.Right)
                {
                    player.position.X -= intersection.Width;
                }
                else
                {
                    player.position.X += intersection.Width;
                }
            }
            else if (intersection.Height < intersection.Width)
            {
                if (playerBox.Bottom > buildingBox.Top && playerBox.Bottom < buildingBox.Bottom)
                {
                    if (intersection.Height > 1)
                    {
                        player.position.Y -= intersection.Height;
                    }
                }
                else if (playerBox.Location.X > middle && playerBox.Location.X < right && building.isDoor)
                {
                    game.prevPlayerPosition = game.level.player.position;
                    game.transition = true;
                    game.level = new Level(building.destination, game);
                    game.keyboard = new KeyboardController(game.level.player, game);
                }
                else
                {
                    player.position.Y += intersection.Height;
                }
            }
        }
コード例 #8
0
ファイル: RightWalkingState.cs プロジェクト: buttsj/CSharpMon
 public RightWalkingState(Player currentPlayer)
 {
     ISpriteFactory factory = new SpriteFactory();
     Sprite = factory.builder(SpriteFactory.sprites.rightWalkingPlayer);
     player = currentPlayer;
 }
コード例 #9
0
 public void Detect(Player player, List<Tile> levelTiles, List<Grass> levelGrass, List<Ledge> levelLedges, List<Building> levelBuildings, List<Enemy> levelEnemies, List<Exit> levelExits)
 {
     Rectangle playerBox = player.state.GetBoundingBox(player.position);
     foreach (Tile tile in levelTiles)
     {
         Rectangle tileBox = tile.GetBoundingBox();
         if (tileBox.Intersects(playerBox) && tile.collision)
         {
             tileResponse.PlayerTileCollide(player, tile);
             if (tile.sign)
             {
                 game.level.DisplayInfo(tile.signTex);
             }
         }
         else if (!tileBox.Intersects(playerBox) && tile.sign)
         {
             game.level.displaySign = false;
         }
     }
     foreach (Grass grass in levelGrass)
     {
         Rectangle grassBox = grass.GetBoundingBox();
         if (grassBox.Intersects(playerBox) && !grass.intersected)
         {
             grass.intersected = true;
             grassResponse.PlayerTileCollide(grass);
         }
         if (!grassBox.Intersects(playerBox))
         {
             grass.intersected = false;
         }
     }
     foreach (Ledge ledge in levelLedges)
     {
         Rectangle ledgeBox = ledge.GetBoundingBox();
         if (ledgeBox.Intersects(playerBox))
         {
             ledgeResponse.PlayerTileCollide(player, ledge);
         }
     }
     foreach (Building building in levelBuildings)
     {
         Rectangle buildingBox = building.GetBoundingBox();
         if (buildingBox.Intersects(playerBox))
         {
             buildingResponse.PlayerTileCollide(player, building);
         }
     }
     foreach (Enemy enemy in levelEnemies)
     {
         Rectangle enemyBox = enemy.state.GetBoundingBox(enemy.position);
         if (enemyBox.Intersects(playerBox))
         {
             enemyResponse.PlayerEnemyCollide(player, enemy);
         }
     }
     foreach (Exit exit in levelExits)
     {
         Rectangle exitBox = exit.sprite.GetBoundingBox(exit.position);
         if (exitBox.Intersects(playerBox))
         {
             exitResponse.PlayerTileCollide(player, exit);
         }
     }
 }
コード例 #10
0
ファイル: RightCommand.cs プロジェクト: buttsj/CSharpMon
 public RightCommand(Player currentPlayer)
 {
     player = currentPlayer;
 }
コード例 #11
0
ファイル: DownCommand.cs プロジェクト: buttsj/CSharpMon
 public DownCommand(Player currentPlayer)
 {
     player = currentPlayer;
 }
コード例 #12
0
ファイル: LevelBuilder.cs プロジェクト: buttsj/CSharpMon
        public Player Build(string fileName)
        {
            float xCoord = 0, yCoord = 0;
            StreamReader sr;
            sr = File.OpenText(Game1.GetInstance().Content.RootDirectory + "\\" + fileName);
            string line;
            int reference = 0;

            // LEVEL DESTINATIONS
            int currDest = 0;
            List<string> destinations = new List<string>();

            // LEVEL TILES
            List<TileFactory.TileType> tileChoices = new List<TileFactory.TileType>();
            tileChoices.Add(TileFactory.TileType.grass);
            tileChoices.Add(TileFactory.TileType.pokePlainFloor);
            int tileNumber = 0;

            // LEVEL DATA
            line = sr.ReadLine();
            string[] initialWords = line.Split(',');
            try
            {
                tileNumber = Int32.Parse(initialWords[0]);
            }
            catch
            {
            }
            for (int i = 0; i < initialWords.Length; i++)
            {
                if (initialWords[i].Contains("Levels"))
                {
                    destinations.Add(initialWords[i]);
                }
            }

            // MAIN LEVEL
            while ((line = sr.ReadLine()) != null)
            {
                xCoord = 0;
                string[] words = line.Split(',');

                for (int i = 0; i < words.Length; i++)
                {
                    if (words[i].Length > 1)
                    {
                        try
                        {
                            string tmp = words[i].Remove(1);
                            reference = Int32.Parse(words[i][1].ToString());
                            words[i] = tmp;
                        }
                        catch
                        {
                            // exception here
                        }
                    }
                    if (xCoord % 32 == 0 && yCoord % 32 == 0)
                    {
                        Tile tile = tileFactory.builder(tileChoices[tileNumber], new Vector2(xCoord, yCoord));
                        level.levelBackground.Add(tile);
                    }
                    if (words[i] == "P")
                    {
                        player = new Player(new Vector2(xCoord, yCoord));
                    }
                    if (tileDictionary.ContainsKey(words[i]))
                    {
                        Tile tile = tileFactory.builder(tileDictionary[words[i]], new Vector2(xCoord, yCoord));
                        if (words[i] == "0" || words[i] == "q")
                        {
                            tile.collision = false;
                        }
                        if (words[i] == "q")
                        {
                            tile.position.X += 8f;
                            tile.position.Y += 4f;
                        }
                        if (words[i] == "p")
                        {
                            tile.sign = true;
                            tile.signTex = factory.builder(SpriteFactory.sprites.instructions);
                        }
                        level.levelTiles.Add(tile);
                    }
                    if (grassDictionary.ContainsKey(words[i]))
                    {
                        Grass grass = grassFactory.builder(grassDictionary[words[i]], new Vector2(xCoord, yCoord));
                        level.levelGrass.Add(grass);
                    }
                    if (ledgeDictionary.ContainsKey(words[i]))
                    {
                        Ledge ledge = ledgeFactory.builder(ledgeDictionary[words[i]], new Vector2(xCoord, yCoord));
                        level.levelLedges.Add(ledge);
                    }
                    if (buildingDictionary.ContainsKey(words[i]))
                    {
                        Building building = buildingFactory.builder(buildingDictionary[words[i]], new Vector2(xCoord, yCoord));
                        if (words[i] == "I")
                        {
                            building.isDoor = true;
                            building.destination = destinations[currDest];
                            building.source = fileName;
                            currDest++;
                        }
                        level.levelBuildings.Add(building);
                    }
                    if (exitDictionary.ContainsKey(words[i]))
                    {
                        Exit exit = new Exit(factory.builder(exitDictionary[words[i]]), new Vector2(xCoord, yCoord));
                        exit.destination = destinations[currDest];
                        currDest++;
                        level.levelExits.Add(exit);
                    }
                    if (enemyDictionary.ContainsKey(words[i]))
                    {
                        Enemy enemy = enemyFactory.builder(enemyDictionary[words[i]], new Vector2(xCoord, yCoord), reference);
                        level.levelEnemies.Add(enemy);
                    }
                    xCoord += spacingIncrement;
                }
                yCoord += spacingIncrement;
            }
            return player;
        }
コード例 #13
0
ファイル: UpCommand.cs プロジェクト: buttsj/CSharpMon
 public UpCommand(Player currentPlayer)
 {
     player = currentPlayer;
 }
コード例 #14
0
ファイル: LeftCommand.cs プロジェクト: buttsj/CSharpMon
 public LeftCommand(Player currentPlayer)
 {
     player = currentPlayer;
 }
コード例 #15
0
ファイル: InteractCommand.cs プロジェクト: buttsj/CSharpMon
 public InteractCommand(Player currentPlayer)
 {
     player = currentPlayer;
 }
コード例 #16
0
ファイル: UpIdleState.cs プロジェクト: buttsj/CSharpMon
 public UpIdleState(Player currentPlayer)
 {
     ISpriteFactory factory = new SpriteFactory();
     Sprite = factory.builder(SpriteFactory.sprites.upIdlePlayer);
     player = currentPlayer;
 }