コード例 #1
0
ファイル: Map.cs プロジェクト: Mszauer/TileBasedGames
 public void Update(float dTime, PlayerCharacter hero, List<Bullet> projectiles)
 {
     for (int i = projectiles.Count - 1; i >= 0; i--) {
         int xTile = (int)projectiles[i].Position.X / 30;
         int yTile = (int)projectiles[i].Position.Y / 30;
         if (xTile >= this[0].Length || xTile < 0) {
             projectiles.RemoveAt(i);
         }
         else if (yTile >= this.Length || yTile < 0) {
             projectiles.RemoveAt(i);
         }
         else if (!this[yTile][xTile].Walkable) {
             projectiles.RemoveAt(i);
         }
     }
     for (int i = enemies.Count - 1; i >= 0; i--) {
         enemies[i].Update(dTime);
         Rectangle intersection = Intersections.Rect(hero.Rect, enemies[i].Rect);
         if (intersection.Width * intersection.Height > 0) {
             Game.Instance.GameOver = true;
         }
         for (int j = projectiles.Count - 1; j >= 0; j--) {
             intersection = Intersections.Rect(enemies[i].Rect, projectiles[j].Rect);
             if (intersection.Width * intersection.Height > 0) {
                 enemies[i].Destroy();
                 enemies.RemoveAt(i);
                 projectiles.RemoveAt(j);
                 break;
             }
         }
     }
     for (int i = items.Count - 1; i >= 0; i--) {
         Rectangle intersection = Intersections.Rect(items[i].Rect, hero.Rect);
         if (intersection.Height * intersection.Width > 0) {
             Game.Instance.Score += items[i].Value;
             items[i].Destroy();
             items.RemoveAt(i);
         }
     }
 }
コード例 #2
0
ファイル: Game.cs プロジェクト: Mszauer/TileBasedGames
        public void Initialize(OpenTK.GameWindow window)
        {
            Window = window;
            //window.ClientSize = new Size(room1Layout[0].Length * tileSize, room1Layout.Length * tileSize);
            Window.ClientSize = new Size(8 * tileSize, 6 * tileSize);
            projectiles = new List<Bullet>();
            TextureManager.Instance.UseNearestFiltering = true;

            GraphicsManager.Instance.SetDepthRange(0, 21 * 21);

            hero = new PlayerCharacter(heroSheet, new Point(spawnTile.X * tileSize, spawnTile.Y * tileSize), 20);
            room1 = new Map(room1Layout, spriteSheets, spriteSources, 2, 0);
            room2 = new Map(room2Layout, spriteSheets, spriteSources, 0, 2);
            room1[4][13].MakeDoor(room2, new Point(1, 1));
            room2[1][0].MakeDoor(room1, new Point(12, 4));
            currentMap = room1;

            room1.AddEnemy(npcSheet, new Point(6 * tileSize, 1 * tileSize), true);
            room2.AddEnemy(npcSheet, new Point(1 * tileSize, 4 * tileSize), false);
            room1.AddItem(spriteSheets, new Rectangle(350, 255, 16, 16), 10, new Point(4 * tileSize + 7, 2 * tileSize + 7));
            room1.AddItem(spriteSheets, new Rectangle(381, 256, 13, 15), 20, new Point(5 * tileSize + 7, 4 * tileSize + 7));
            room2.AddItem(spriteSheets, new Rectangle(412, 256, 16, 15), 30, new Point(4 * tileSize + 7, 2 * tileSize + 7));
        }
コード例 #3
0
ファイル: Map.cs プロジェクト: Mszauer/TileBasedGames
        public Map ResolveDoors(PlayerCharacter hero)
        {
            Map result = this;
            for (int row = 0; row < tileMap.Length; row++) {
                for (int col = 0; col < tileMap[row].Length; col++) {
                    if (tileMap[row][col].IsDoor) {
                        //get doors bouding rectangle
                        Rectangle doorRect = new Rectangle(col * 30, row * 30, 30, 30);
                        //get a small rectangle in center of the player
                        Rectangle playerCenter = new Rectangle((int)hero.Center.X - 2, (int)hero.Center.Y - 2, 4, 4);

                        //look for an intersection
                        Rectangle intersection = Intersections.Rect(doorRect, playerCenter);
                        if (intersection.Width * intersection.Height > 0) {
                            result = tileMap[row][col].DoorTarget;
                            hero.Position.X = tileMap[row][col].DoorLocation.X * 30;
                            hero.Position.Y = tileMap[row][col].DoorLocation.Y * 30;
                        }
                    }
                }
            }
            return result;
        }