public SplashScreenState(StateSystem system, TextureManager textureManager, Engine.Font titleFont, SoundManager soundManager)
        {
            _system = system;

            //sound
            _soundManager = soundManager;
            _soundManager.MasterVolume(0.01f);

            //title font
            _title = new Text("Immune Cells vs. Invaders", titleFont);
            _title.SetColor(new Color(0, 0, 0, 1));
            _title.SetPosition(-_title.Width / 2, 300);

            // good guys
            _character1.Texture = textureManager.Get("phagocyte");
            _character1.SetScale(2, 2);
            _character1.SetPosition(-150, 100);

            //bad guys
            _invader1.Texture = textureManager.Get("tatoo_dye");
            _invader1.SetScale(2, 2);
            _invader1.SetPosition(200, 100);

            _invader2.Texture = textureManager.Get("parasite");
            _invader2.SetScale(2, 2);
            _invader2.SetPosition(200, 0);

               // _soundManager.PlaySound("intro_music");
        }
Ejemplo n.º 2
0
        public Level(Input input, TextureManager textureManager, PersistantGameData gameData)
        {
            _input = input;
            _gameData = gameData;
            _textureManager = textureManager;
            _effectsManager = new EffectsManager(_textureManager);
            _playerCharacter = new PlayerCharacter(_textureManager, _bulletManager);

            // -1300 is bad for two reasons
            // 1. It's a magic number in the middle of the code
            // 2. It's based on the size of the form but doesn't directly reference the size of the form
            // this means duplication and two places to edit the code if the form size changes.
            // The form size and the enemy manager play area size should both get their value
            // from one central place.
            _enemyManager = new EnemyManager(_textureManager, _effectsManager, _bulletManager, _playerCharacter, -1300);


            _background = new ScrollingBackground(textureManager.Get("background"));
            _background.SetScale(2, 2);
            _background.Speed = 0.15f;

            _backgroundLayer = new ScrollingBackground(textureManager.Get("background_layer_1"));
            _backgroundLayer.Speed = 0.1f;
            _backgroundLayer.SetScale(2.0, 2.0);

           
        }
        public MultipleTexturesState(TextureManager textureManager)
        {
            _spaceship1.Texture = textureManager.Get("spaceship");
            _spaceship2.Texture = textureManager.Get("spaceship2");

            // Move the first spaceship, so they're not overlapping.
            _spaceship1.SetPosition(-300, 0);
        }
Ejemplo n.º 4
0
        double _speed = 512; // pixels per second

        #endregion Fields

        #region Constructors

        public PlayerCharacter(TextureManager textureManager, BulletManager bulletManager)
        {
            _bulletManager = bulletManager;
            _bulletTexture = textureManager.Get("bullet");
            _sprite.Texture = textureManager.Get("player_spaceship");
            _sprite.SetScale(_scale, _scale);
            //_sprite.SetRotation(Math.PI / 2);
        }
Ejemplo n.º 5
0
        public PlayerCharacter(TextureManager textureManager, BulletManager bulletManager)
        {
            _bulletManager = bulletManager;
            _bulletTexture = textureManager.Get("bullet");

            _sprite.Texture = textureManager.Get("player_ship");
            _sprite.SetScale(0.5, 0.5); // spaceship is quite big, scale it down.
        }
Ejemplo n.º 6
0
 public Enemy(TextureManager textureManager, EffectsManager effectsManager, BulletManager bulletManager)
 {
     Health = 50;
     _sprite.Texture = textureManager.Get("enemy_ship");
     _sprite.SetScale(_scale, _scale);
     _sprite.SetRotation(Math.PI);
     _sprite.SetPosition(200, 0);
     _effectsManager = effectsManager;
     _bulletManager = bulletManager;
     _bulletTexture = textureManager.Get("bullet");
     MaxTimeToShoot = 12;
     MinTimeToShoot = 1;
     RestartShootCountDown();
 }
Ejemplo n.º 7
0
        public Enemy(TextureManager textureManager, EffectsManager effectsManager, BulletManager bulletManager)
        {
            _bulletManager = bulletManager;
            _bulletTexture = textureManager.Get("bullet");
            MaxTimeToShoot = 12;
            MinTimeToShoot = 1;
            RestartShootCountDown();

            _effectsManager = effectsManager;
            Health = 50; // default health value.
            _sprite.Texture = textureManager.Get("enemy_ship");
            _sprite.SetScale(0.3, 0.3);
            _sprite.SetRotation(Math.PI); // make it face the player
            _sprite.SetPosition(200, 0); // put it somewhere easy to see
        }
Ejemplo n.º 8
0
     public Enemy(TextureManager textureManager)
 {
     _sprite.Texture = textureManager.Get("enemy_ship");
     _sprite.SetScale(_scale, _scale);
     _sprite.SetRotation(Math.PI); // make it face the player
     _sprite.SetPosition(200, 0); // put it somewhere easy to see
 }
Ejemplo n.º 9
0
 public CharacterBoard(TextureManager textureManager)
 {
     _phagocyte.Texture = textureManager.Get("phagocyte");
     //_phagocyte.SetScale(2, 2);
     _phagocyte.SetPosition(0, 325);
        //_phagocyte.SetColor(new Color(1, 1, 1, 0));
 }
Ejemplo n.º 10
0
 public PlayerCharacter(TextureManager textureManager, Input input, bool current)
 {
     _input = input;
     _current = current;
     _sprite.Texture = textureManager.Get("phagocyte");
     _sprite.SetScale(_scale, _scale);
 }
Ejemplo n.º 11
0
        public Level(Input input, TextureManager textureManager, PersistantGameData gameData)
        {
            _input = input;
            _gameData = gameData;
            _textureManager = textureManager;

            _background = new ScrollingBackground(textureManager.Get("background"));
            _background.SetScale(2, 2);
            _background.Speed = 0.15f;

            _backgroundLayer = new ScrollingBackground(textureManager.Get("background_layer_1"));
            _backgroundLayer.Speed = 0.1f;
            _backgroundLayer.SetScale(2.0, 2.0);


            _playerCharacter = new PlayerCharacter(_textureManager);
        }
Ejemplo n.º 12
0
 public Block(TextureManager manager, string blockType)
 {
     _sprite.Texture = manager.Get(blockType);
     DropSpeed = 30.0;
     Direction = new Vector(0, -1, 0);
     KeepAlive = true;
     _moveDistance = _sprite.GetWidth();
 }
Ejemplo n.º 13
0
        public Level(Input input, TextureManager textureManager, PersistentGameData gameData)
        {
            _input = input;
            _gameData = gameData;
            _textureManager = textureManager;
            _effectsManager = new EffectsManager(_textureManager);
            _playerCharacter = new PlayerCharacter(_textureManager, _bulletManager);
            _enemyManager = new EnemyManager(_textureManager, _effectsManager, _bulletManager, -1300);
            //_enemyList.Add(new Enemy(_textureManager, _effectsManager));

            _background = new ScrollingBackground(textureManager.Get("background"));
            _background.SetScale(2, 2);
            _background.Speed = 0.15f;

            _backgroundLayer = new ScrollingBackground(textureManager.Get("background_layer_1"));
            _backgroundLayer.Speed = 0.1f;
            _backgroundLayer.SetScale(2.0, 2.0);
        }
Ejemplo n.º 14
0
 public Scoreboard(GameData gameData, TextureManager textureManager)
 {
     this.gameData = gameData;
     font = new Font(textureManager.Get("effects_font"), FontParser.Parse("effectsFont.fnt"));
     level = new Text("Level: " + gameData.Level.ToString(), font);
     score = new Text("Score : " + gameData.Score.ToString(), font);
     position = new Point((float)Block.WIDTH * 7, -30);
     UpdateWidth();
 }
Ejemplo n.º 15
0
 public Block(TextureManager textureManager, Engine.Color color, int gridPosX, int gridPosY)
 {
     sprite = new Sprite();
     sprite.Texture = textureManager.Get("block");
     sprite.SetScale(0.625, 0.625);
     sprite.SetColor(color);
     this.gridPosX = gridPosX;
     this.gridPosY = gridPosY;
 }
Ejemplo n.º 16
0
        public Enemy(TextureManager textureManager, EffectsManager effectsManager)
        {
            _effectsManager = effectsManager;
            Health = 50; // default health value.

            _sprite.Texture = textureManager.Get("enemy_ship");
            _sprite.SetScale(_scale, _scale);
            _sprite.SetRotation(Math.PI); // make it face the player
            _sprite.SetPosition(200, 0); // put it somewhere easy to see
        }
Ejemplo n.º 17
0
        public GameOverState(Input input, StateSystem stateSystem, 
            GameData gameData, TextureManager textureManager)
        {
            this.input = input;
            this.stateSystem = stateSystem;
            this.gameData = gameData;
            this.textureManager = textureManager;

            scoreboard = new Scoreboard(gameData, textureManager);
            scoreboard.SetPosition(new Point(-scoreboard.Width / 2, 0));

            gameOverFont = new Font(textureManager.Get("title_font"), FontParser.Parse("titleFont.fnt"));
            gameOverText = new Text("Game Over", gameOverFont);
            gameOverText.SetPosition(-gameOverText.Width / 2, 100);

            returnFont = new Font(textureManager.Get("effects_font"), FontParser.Parse("effectsFont.fnt"));
            returnText = new Text("Press Enter to return to the start menu", returnFont);
            returnText.SetPosition(-returnText.Width / 2, -200);
        }
Ejemplo n.º 18
0
 public Block(TextureManager manager, string blockType, Vector scaler, Vector position)
 {
     _sprite.Texture = manager.Get(blockType);
     DropSpeed = 30.0;
     Direction = new Vector(0, -1, 0);
     KeepAlive = true;
     _sprite.SetScale(scaler.X, scaler.Y);
     _sprite.SetPosition(position.X, position.Y);
     _moveDistance = _sprite.GetWidth();
 }
Ejemplo n.º 19
0
        public Level(Input input, TextureManager textureManager, PersistantGameData gameData)
        {
            _testSprite.Texture = textureManager.Get("explosion");
            _testSprite.SetAnimation(4, 4);

            _input = input;
            _gameData = gameData;
            _textureManager = textureManager;

            _background = new ScrollingBackground(textureManager.Get("background"));
            _background.SetScale(2, 2);
            _background.Speed = 0.15f;

            _backgroundLayer = new ScrollingBackground(textureManager.Get("background_layer_1"));
            _backgroundLayer.Speed = 0.1f;
            _backgroundLayer.SetScale(2.0, 2.0);

            _playerCharacter = new PlayerCharacter(_textureManager, _bulletManager);

            _enemyList.Add(new Enemy(_textureManager));
        }
Ejemplo n.º 20
0
        public StartMenuState(StateSystem stateSystem, TextureManager textureManager, 
            Input input, GameData gameData)
        {
            this.input = input;
            this.textureManager = textureManager;
            this.stateSystem = stateSystem;
            this.gameData = gameData;

            // Create title
            titleFont = new Font(textureManager.Get("title_font"), FontParser.Parse("titleFont.fnt"));
            titleText = new Text("bTris", titleFont);
            titleText.SetPosition(-titleText.Width / 2, 150);
            titleText.SetColor(new Color(1, 1, 1, 1));

            InitializeMenu();
        }
Ejemplo n.º 21
0
 public PlayerCharacter(TextureManager textureManager, MissileManager missileManager)
 {
     _missileManager = missileManager;
     _missileTexture = textureManager.Get("heart_missile");
     Sprite.Texture = textureManager.Get("pixela_down");
     _upTexture = textureManager.Get("pixela_up");
     _downTexture = textureManager.Get("pixela_down");
     _leftTexture = textureManager.Get("pixela_left");
     _rightTexture = textureManager.Get("pixela_right");
     Sprite.SetScale(Scale, Scale);
     Health = 20;
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Create a font object from a .fnt file (and associated textures)
        /// </summary>
        /// <param name="path">Path to the .fnt file.</param>
        /// <param name="textureManager">Texture manager to load font textures</param>
        /// <returns>Font as described by the .fnt file.</returns>
        public static Font CreateFont(string path, TextureManager textureManager)
        {
            List<Texture> _texturePages = new List<Texture>();
            Dictionary<KernKey, int> kernDictionary = new Dictionary<KernKey, int>();
            Dictionary<char, CharacterData> charDictionary = new Dictionary<char, CharacterData>();

            string[] lines = File.ReadAllLines(path);

            int texturePageInfo = HeaderSize;
            while (lines[texturePageInfo].StartsWith("page"))
            {
                string line = lines[texturePageInfo];
                string[] typesAndValues = line.Split(" ".ToCharArray(),
                  StringSplitOptions.RemoveEmptyEntries);
                string textureString = GetTextValue(typesAndValues[2]).Trim('"');
                string textureId = Path.GetFileNameWithoutExtension(textureString);

                if (textureManager.Exists(textureId))
                {
                    // Really textures should never be loaded twice so it's worth warning the user
                    Console.Error.WriteLine("WARNING: Tried to load a texture that had been already been loaded. "
                        + "[" + textureString + "] when loading font [" + path + "]");
                }
                else
                {
                    // Assume texture files are in the same path as the .fnt file.
                    string directory = Path.GetDirectoryName(path);
                    if (string.IsNullOrEmpty(directory) == false)
                    {
                        directory += "\\";
                    }
                    textureManager.LoadTexture(textureId, directory  + textureString);   
                }

                _texturePages.Add(textureManager.Get(textureId));

                texturePageInfo++;
            }

            texturePageInfo++; // jump over number of characters data.

            for (int i = texturePageInfo; i < lines.Length; i += 1)
            {
                string line = lines[i];
                string[] typesAndValues = line.Split(" ".ToCharArray(),
                    StringSplitOptions.RemoveEmptyEntries);

                // Some fonts have kerning data at the end
                if (line.StartsWith("kernings"))
                {
                    ParseKernData(i + 1, lines, kernDictionary);
                    break;
                }

                // All the data comes in a certain order,
                // used to make the parser shorter
                CharacterData charData = new CharacterData
                {
                    Id = GetValue(typesAndValues[1]),
                    X = GetValue(typesAndValues[2]),
                    Y = GetValue(typesAndValues[3]),
                    Width = GetValue(typesAndValues[4]),
                    Height = GetValue(typesAndValues[5]),
                    XOffset = GetValue(typesAndValues[6]),
                    YOffset = GetValue(typesAndValues[7]),
                    XAdvance = GetValue(typesAndValues[8])
                };
                charDictionary.Add((char)charData.Id, charData);
            }

            return new Font(_texturePages.FirstOrDefault(), charDictionary, kernDictionary);
        }
Ejemplo n.º 23
0
 private static void LoadLayers(XmlTextReader xmlReader, Scene scene, TextureManager textureManager)
 {
     xmlReader.MoveToContent();
     while (xmlReader.Read())
     {
         if ("layer" == xmlReader.Name)
         {
             string name = xmlReader.GetAttribute("name");
             string textureId = xmlReader.GetAttribute("textureid");
             Layer layer = new Layer(name);
             layer.SetImage(textureManager.Get(textureId));
             scene.AddLayer(layer);
         }
         else if ("layers" == xmlReader.Name)
         {
             return;
         }
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Create a font object from a .fnt file (and associated textures)
        /// </summary>
        /// <param name="path">Path to the .fnt file.</param>
        /// <param name="textureManager">Texture manager to load font textures</param>
        /// <returns>Font as described by the .fnt file.</returns>
        public static Font CreateFont(string path, TextureManager textureManager)
        {
            List <Texture>                   _texturePages  = new List <Texture>();
            Dictionary <KernKey, int>        kernDictionary = new Dictionary <KernKey, int>();
            Dictionary <char, CharacterData> charDictionary = new Dictionary <char, CharacterData>();

            string[] lines = File.ReadAllLines(path);

            int texturePageInfo = HeaderSize;

            while (lines[texturePageInfo].StartsWith("page"))
            {
                string   line           = lines[texturePageInfo];
                string[] typesAndValues = line.Split(" ".ToCharArray(),
                                                     StringSplitOptions.RemoveEmptyEntries);
                string textureString = GetTextValue(typesAndValues[2]).Trim('"');
                string textureId     = Path.GetFileNameWithoutExtension(textureString);

                if (textureManager.Exists(textureId))
                {
                    // Really textures should never be loaded twice so it's worth warning the user
                    Console.Error.WriteLine("WARNING: Tried to load a texture that had been already been loaded. "
                                            + "[" + textureString + "] when loading font [" + path + "]");
                }
                else
                {
                    // Assume texture files are in the same path as the .fnt file.
                    string directory = Path.GetDirectoryName(path);
                    if (string.IsNullOrEmpty(directory) == false)
                    {
                        directory += "\\";
                    }
                    textureManager.LoadTexture(textureId, directory + textureString);
                }

                _texturePages.Add(textureManager.Get(textureId));

                texturePageInfo++;
            }

            texturePageInfo++; // jump over number of characters data.

            for (int i = texturePageInfo; i < lines.Length; i += 1)
            {
                string   line           = lines[i];
                string[] typesAndValues = line.Split(" ".ToCharArray(),
                                                     StringSplitOptions.RemoveEmptyEntries);

                // Some fonts have kerning data at the end
                if (line.StartsWith("kernings"))
                {
                    ParseKernData(i + 1, lines, kernDictionary);
                    break;
                }

                // All the data comes in a certain order,
                // used to make the parser shorter
                CharacterData charData = new CharacterData
                {
                    Id       = GetValue(typesAndValues[1]),
                    X        = GetValue(typesAndValues[2]),
                    Y        = GetValue(typesAndValues[3]),
                    Width    = GetValue(typesAndValues[4]),
                    Height   = GetValue(typesAndValues[5]),
                    XOffset  = GetValue(typesAndValues[6]),
                    YOffset  = GetValue(typesAndValues[7]),
                    XAdvance = GetValue(typesAndValues[8])
                };
                charDictionary.Add((char)charData.Id, charData);
            }

            return(new Font(_texturePages.FirstOrDefault(), charDictionary, kernDictionary));
        }
Ejemplo n.º 25
0
        double _speed = 512; // pixels per second

        public PlayerCharacter(TextureManager textureManager)
        {
            _spaceship.Texture = textureManager.Get("player_ship");
            _spaceship.SetScale(0.5, 0.5); // spaceship is quite big, scale it down.
        }
Ejemplo n.º 26
0
 public void ChangeTexture(TextureManager manager, string textureID, Vector scaleFactor)
 {
     _sprite.Texture = manager.Get(textureID);
     _sprite.SetScale(scaleFactor.X, scaleFactor.Y);
 }