예제 #1
0
파일: player.cs 프로젝트: fhrach4/danmaku
        /// <summary>
        /// Creates a new human controlled player
        /// </summary>
        /// <param name="sprite">The animatedSprite to be used</param>
        /// <param name="shotSprite">The sprite to be used for shots</param>
        /// <param name="xPos">The starting x position of the player</param>
        /// <param name="yPos">The starting y position of the player</param>
        /// <param name="maxSpeed">The maximum moving speed of the player</param>
        public Player(AnimatedSprite sprite,Texture2D shotSprite, int xPos, int yPos, int maxSpeed)
        {
            //set location variables
            this.xPos = xPos;
            this.yPos = yPos;
            this.spawnX = xPos;
            this.spawnY = yPos;

            // handle shots
            this.sprite = sprite;
            this.shotSprite = shotSprite;

            // handle speed
            this.currentXSpeed = 0;
            this.currentYSpeed = 0;
            this.maxSpeed = maxSpeed;

            // create hitbox
            hitBoxOffset = this.xPos + 10;
            this.hitBox = new Rectangle(hitBoxOffset, yPos, sprite.spriteWidth - 10, sprite.spriteHeight - 10);

            // set lives
            this.lives = 3;

            // start timer
            shotTimer.Start();

            //eventually change so player  can define keys
        }
예제 #2
0
파일: Game1.cs 프로젝트: fhrach4/danmaku
        /// <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();
        }