コード例 #1
0
ファイル: Game1.cs プロジェクト: snuderl/tdsnud
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            if (level != null)
            {
                float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
                KeyboardState ks = Keyboard.GetState();
                MouseState ms = Mouse.GetState();

                if (level.finished == true)
                {
                    level.Pause();
                    if (ks.IsKeyDown(Keys.Enter))
                    {
                        if (level.Won)
                        {
                            //Next Level
                            level.Finished();
                            if (level.Id < loader.levelDict.Count)
                            {
                                level = loader.levelDict[level.Id];
                                Components.Add(level);
                                level.Start();
                            }
                            else
                            {
                                //If there is no next level
                                level = null;
                            }
                        }
                        else if (level.Lost)
                        {
                            this.Exit();
                        }
                    }
                }

            }
            // TODO: Add your update logic here

            base.Update(gameTime);
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: snuderl/tdsnud
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            boxT = Content.Load<Texture2D>(@"Textures/box");
            ammoT = Content.Load<Texture2D>(@"Textures/ammo");
            sf = Content.Load<SpriteFont>(@"Textures/font");
            circleT = Content.Load<Texture2D>(@"Textures/circle");
            tiles = Content.Load<Texture2D>(@"Textures/Tiles");
            build = Content.Load<Texture2D>(@"Textures/build");
            grass = Content.Load<Texture2D>(@"Textures/Grass_3");
            trap = Content.Load<Texture2D>(@"Textures/TradPlat");
            se = Content.Load<SoundEffect>(@"Audio/fire_laser1");
            music = Content.Load<SoundEffect>(@"Audio/Theme");
            mountain = Content.Load<Texture2D>(@"Textures/004-Mountain01");
            health = Content.Load<Texture2D>(@"Textures/HealthBar2");
            // TODO: use this.Content to load your game content here
            XmlDocument doc = new XmlDocument();
            doc.Load("test.xml");
            loader = new Loader(doc, Content, this);

            sourceRectDict.Add("1", new Rectangle(0, 160, 32, 32));
            sourceRectDict.Add("2", new Rectangle(32, 160, 32, 32));
            sourceRectDict.Add("3", new Rectangle(64, 160, 32, 32));
            sourceRectDict.Add("4", new Rectangle(0, 192, 32, 32));
            sourceRectDict.Add("5", new Rectangle(0, 0, 32, 32));
            sourceRectDict.Add("6", new Rectangle(64, 192, 32, 32));
            sourceRectDict.Add("7", new Rectangle(0, 224, 32, 32));
            sourceRectDict.Add("8", new Rectangle(32, 224, 32, 32));
            sourceRectDict.Add("9", new Rectangle(64, 224, 32, 32));

            level = loader.levelDict[0];
            Components.Add(level);
            level.Start();
        }
コード例 #3
0
        /// <summary>
        /// Set the level in use by the tile engine
        /// </summary>
        /// <param name="aNewLevel">The new level to use for the tile engine</param>
        public static void SetLevel(Level aNewLevel)
        {
            if (aNewLevel == null)
            {
                throw new ArgumentNullException("NewLevel");
            }

            mLevel = aNewLevel;

            //Reset the map origin, which will be recalculated on the first update
            mLevelOriginalPos = Vector2.Zero;
        }
コード例 #4
0
ファイル: Loader.cs プロジェクト: snuderl/tdsnud
        private void LoadAssetsFromXml()
        {
            XmlNode towerDefenceNode = doc["TowerDefence"];
            XmlNode spritesNode = towerDefenceNode["Sprites"];

            Texture2D tmp;
            foreach (XmlNode node in spritesNode.SelectNodes("Sprite"))
            {
                int id = int.Parse(node.Attributes["id"].InnerText);
                bool animated = node.Attributes["animated"] == null ? false : bool.Parse(node.Attributes["animated"].InnerText);
                string filename = node["resourceName"].InnerText;
                tmp = content.Load<Texture2D>(@"Textures/" + filename);
                int width = node["width"] == null ? tmp.Width : int.Parse(node["width"].InnerText);
                int height = node["height"] == null ? tmp.Height : int.Parse(node["height"].InnerText);
                Sprite s;
                if (animated)
                {
                    float spritesPerSecond = float.Parse(node["spritesPerSecond"].InnerText);
                    s = new AnimatedSprite(tmp, width, height, spritesPerSecond);

                }
                else
                {
                    int positionX = node["positionX"] == null ? 0 : int.Parse(node["positionX"].InnerText);
                    int positionY = node["positionY"] == null ? 0 : int.Parse(node["positionY"].InnerText);
                    Vector2 position = new Vector2(positionX, positionY);
                    s = new Sprite(tmp, width, height, position);
                }
                spriteDict.Add(id, s);
            }
            foreach (XmlNode node in towerDefenceNode["Projectiles"].SelectNodes("Projectile"))
            {
                int id = int.Parse(node.Attributes["id"].InnerText);
                int speed = int.Parse(node["speed"].InnerText);
                int spriteid = int.Parse(node["Sprite"].InnerText);
                Sprite s = spriteDict[spriteid];
                Projectile proj = new Projectile(speed, s);
                projectileDict.Add(id, proj);
            }

            foreach (XmlNode node in towerDefenceNode["Towers"].SelectNodes("Tower"))
            {
                int id = int.Parse(node.Attributes["id"].InnerText);
                String name = node["name"].InnerText;
                int spriteid = int.Parse(node["Sprite"].InnerText);
                int projid = int.Parse(node["Projectile"].InnerText);
                int range = int.Parse(node["range"].InnerText);
                int damage = int.Parse(node["damage"].InnerText);
                float shootspeed = float.Parse(node["shootSpeed"].InnerText);
                bool walkable = bool.Parse(node["walkable"].InnerText);
                int cost = int.Parse(node["cost"].InnerText);
                Sprite s = spriteDict[spriteid];
                Projectile proj = projectileDict[projid];
                Tower tow = new Tower(Vector2.Zero, range, shootspeed, walkable, name, 48, s, cost, proj, damage);
                towerDict.Add(id, tow);
            }
            foreach (XmlNode node in towerDefenceNode["Enemies"].SelectNodes("Enemy"))
            {
                int id = int.Parse(node.Attributes["id"].InnerText);
                String name = node["name"].InnerText;
                int spriteid = int.Parse(node["Sprite"].InnerText);
                int health = int.Parse(node["health"].InnerText);
                int speed = int.Parse(node["speed"].InnerText);
                float rotation = float.Parse(node["rotation"].InnerText);
                int drawSize = int.Parse(node["drawSize"].InnerText);
                Sprite s = spriteDict[spriteid];
                Enemy e = new Enemy(health, name, s, drawSize, rotation, speed);
                enemyDict.Add(id, e);
            }

            foreach (XmlNode node in towerDefenceNode.SelectNodes("SpawnPoint"))
            {
                int spawnId = int.Parse(node.Attributes["id"].InnerText);
                float interval = float.Parse(node["interval"].InnerText);
                float delay = float.Parse(node["delay"].InnerText);
                int numToSpawn = int.Parse(node["numToSpawn"].InnerText);
                int enemyId = int.Parse(node["Enemy"].InnerText);
                int posx = int.Parse(node["positionX"].InnerText);
                int posy = int.Parse(node["positionY"].InnerText);
                Vector2 position = new Vector2(posx, posy);
                Enemy s = enemyDict[enemyId];
                SpawnPoint sp = new SpawnPoint(position, interval, delay, numToSpawn, s);
                spawnPointDict.Add(spawnId, sp);
            }

            foreach (XmlNode levelNode in towerDefenceNode.SelectNodes("Level"))
            {
                int id = int.Parse(levelNode.Attributes["id"].InnerText);
                int columns = int.Parse(levelNode["map"]["columns"].InnerText);
                int rows = int.Parse(levelNode["map"]["rows"].InnerText);
                Point end = readPointFromXml(levelNode["end"]);

                List<Wave> waves = new List<Wave>();
                foreach (XmlNode waveNove in levelNode.SelectNodes("Wave"))
                {
                    List<SpawnPoint> spawns = new List<SpawnPoint>();
                    foreach (XmlNode spawnNode in waveNove.SelectNodes("SpawnPoint"))
                    {
                        int spawnId = int.Parse(spawnNode.InnerText);
                        spawns.Add(spawnPointDict[spawnId]);
                    }
                    waves.Add(new Wave(spawns));
                }
                Level lev = new Level(game, 48, rows, columns, end, waves, id);

                foreach (XmlNode towerNode in levelNode.SelectNodes("Tower"))
                {
                    int towid = int.Parse(towerNode.InnerText);
                    lev.towerManager.towerList.Add(towerDict[towid]);
                }

                levelDict.Add(lev);
            }
        }
コード例 #5
0
 public Manager(ContentManager content, GraphicsDevice graphics)
 {
     TextureManager.LoadContent(content);
     Level = new Level(graphics);
 }