コード例 #1
0
        public void AddEnemy(string enemyType, Vector2 spawnPosition)
        {
            Enemy e;

            //Enemies.Add(new Enemy(worldPosition,
            switch (enemyType)
            {
            case "EnemyFootSoldier":
                e = new Actors.FootSoldier(_worldContent, spawnPosition, this, "EnemyFootSoldier");
                e.WorldPosition = new Vector2(spawnPosition.X, spawnPosition.Y - e.BoundingBox().Height);
                ActiveEnemies.Add(e);
                break;

            case "Zombie":
                e = new Actors.Zombie(_worldContent, spawnPosition, this, "Zombie");
                e.WorldPosition = new Vector2(spawnPosition.X, spawnPosition.Y - e.BoundingBox().Height);
                ActiveEnemies.Add(e);
                break;
            }
        }
コード例 #2
0
        private void InitializeWaitingEnemies(ContentManager content, TiledSharp.TmxMap tmx)
        {
            foreach (TiledSharp.TmxObjectGroup.TmxObject tmxObject in tmx.ObjectGroups[WaitingEnemiesObjectGroupName].Objects)
            {
                // object's Y-coordinate is oriented to the bottom of the placement of the object, and we need top.
                // so, we get the tile and look at its height and subtract that from the object's Y-coordinate to detemrine placement of object.
                float fObjectHeight = 0;

                int gid = tmxObject.Tile.Gid;
                for (int i = 0; i < tmx.Tilesets.Count; i++)
                {
                    fObjectHeight = (float)tmx.Tilesets[i].TileHeight;
                    if (gid > tmx.Tilesets[i].FirstGid)
                    {
                        continue;
                    }
                    if (gid <= tmx.Tilesets[i].FirstGid)
                    {
                        break;
                    }
                }

                Enemy e             = null;
                var   enemyLocation = new Vector2((float)tmxObject.X, (float)tmxObject.Y - fObjectHeight);
                switch (tmxObject.Type)
                {
                case "FootSoldier":
                    e = new Actors.FootSoldier(content, enemyLocation, this, tmxObject.Type);
                    break;

                case "Panel":
                    e = new Actors.Panel(content, enemyLocation, this, tmxObject.Properties["ItemType"]);
                    break;

                case "Sniper":
                    e = new Actors.Sniper(content, enemyLocation, this, tmxObject.Type);
                    break;

                case "Turret":
                    e = new Actors.Turret(content, enemyLocation, this, tmxObject.Type);
                    break;

                case "Level1BossPanel":
                    e = new Actors.Level1BossPanel(content, enemyLocation, this, tmxObject.Type);
                    break;

                case "Capsule":
                    e = new Actors.Capsule(content, enemyLocation, this, tmxObject.Properties["ItemType"]);
                    break;

                case "Cannon":
                    e = new Actors.Cannon(content, enemyLocation, this, tmxObject.Type);
                    break;

                case "Level1BossBomberLeft":
                case "Level1BossBomberRight":
                    e = new Actors.Level1BossBomber(content, enemyLocation, this, tmxObject.Type);
                    break;

                default:
                    throw new Exception("Unexpected enemy type encountered: " + tmxObject.Type);
                }

                waitingEnemies.Add(e);
            }
        }