Exemple #1
0
 public Grunt(Texture2D sprite, Texture2D shotSprite, int spriteWidth, int spriteHeight, int xPos, int yPos, int health, double maxRotSpeed, Constants constants)
 {
     this.alive = true;
     this.sprite = sprite;
     this.shotSprite = shotSprite;
     this.spriteWidth = spriteWidth;
     this.spriteHeight = spriteHeight;
     this.xPos = xPos;
     this.yPos = yPos;
     this.health = health;
     this.hitBox = new Rectangle(xPos - spriteWidth / 2, yPos - spriteHeight / 2, spriteWidth, spriteHeight);
     this.origin = new Vector2(spriteWidth / 2, spriteHeight / 2);
     this.rotSpeed = 0;
     this.maxRotSpeed = 0.1;
     this.shotSpeed = 3;
     this.constants = constants;
 }
Exemple #2
0
        public Boss(Texture2D sprite, List<Shot> shotTypes, int spriteWidth, int spriteHeight, int xPos, int yPos, int health,
            int tarx, int tary, Constants constants)
        {
            // Sprite variables
            this.sprite = sprite;
            this.spriteWidth = spriteWidth;
            this.spriteHeight = spriteHeight;

            // Shot variables
            this.shotTypes = shotTypes;

            // Other
            this.xPos = xPos;
            this.yPos = yPos;
            this.health = health;

            this.tarx = tarx;
            this.tary = tary;
        }
Exemple #3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            LoadContent();
            Constants constants = new Constants();
            activeList = new Enemy[20];
            shotList = new EnemyShot[100000];

            // Create Level Reader
            LevelReader reader = new LevelReader();

            // Load Background

            ArrayList tmpRemoveLst = new ArrayList();

            foreach (Enemy enemy in reader.enemyList)
            {
                if (enemy is Grunt)
                {
                    enemy.init(enemyText, enemyShot, constants);
                    enemyList.Add(enemy);
                }
                else if (enemy is Boss)
                {
                    boss = (Boss)enemy;
                    boss.init(enemyText, enemyShot, constants);
                }
            }

            foreach (Boss boss in tmpRemoveLst)
            {
                enemyList.Remove(boss);
            }

            // load background song
            if (reader.levelSong != "none")
            {
                Uri uri = new Uri(reader.levelSong,UriKind.Relative);
                try
                {
                    bsong = Song.FromUri(reader.levelSong, uri);
                    //MediaPlayer.Play(bsong);
                }
                catch (System.ArgumentException)
                {
                    Console.Error.WriteLine("Error loading file: " + (string)reader.levelSong + " ... Ignoring");
                }
            }

            // Load background
            if (reader.background != "none")
            {
                try
                {
                    Stream str = File.OpenRead(reader.background);
                    backgroundTexture = Texture2D.FromStream(GraphicsDevice, str);
                }
                catch (System.IO.DirectoryNotFoundException)
                {
                    Console.Error.WriteLine("Could not locate file: " + (string)reader.background + " Using default.");
                    backgroundTexture = singlePix;
                }

            }
            else
            {
                backgroundTexture = singlePix;
            }
            //create player
            humanAnimatedTexture = new AnimatedSprite(humanTexture, constants.HUMAN_NEUTRAL_FRAME,
                constants.HUMAN_NEUTRAL_FRAME, constants.MAX_HUMAN_FRAMES, constants.HUMAN_SPRITE_WIDTH,
                constants.HUMAN_SPRITE_HEIGHT);

            human = new Player(humanAnimatedTexture, shotTexture, constants.HUMAN_START_X, constants.HUMAN_START_Y,
                constants.MAX_HUMAN_SPEED);

            base.Initialize();
        }
Exemple #4
0
 /// <summary>
 /// Sets important values if created using the blank constructor
 /// </summary>
 /// <param name="sprite">The sprite to be used</param>
 /// <param name="shotSprite">The sprite to be used for shots</param>
 /// <param name="spriteHeight">The sprite height</param>
 /// <param name="spriteWidth">The sprite width</param>
 public void init(Texture2D sprite, Texture2D shotSprite, Constants constants)
 {
     this.sprite = sprite;
     this.shotSprite = shotSprite;
     this.constants = constants;
     this.spriteHeight = constants.GRUNT_SPRITE_HEIGHT;
     this.spriteWidth = constants.GRUNT_SPRITE_WIDTH;
     this.hitBox = new Rectangle(xPos, yPos, spriteWidth, spriteHeight);
 }