コード例 #1
0
ファイル: Game1.cs プロジェクト: aside6/TwinStick
        protected void AddEnemyBullet(Enemy enemy, bool healthbullet)
        {
            Animation bulletAnimation = new Animation();

            var bulletPosition = enemy.Position;
            var playerPosition = _player.Position;

            var direction = playerPosition - enemy.Position;

            direction.Normalize();

            bulletPosition.X += direction.X * enemy.enemyMoveSpeed;

            bulletPosition.X += (enemy.Width / 2f) - 7.5f;
            bulletPosition.Y += (enemy.Height / 2f) - 7.5f;

            // initlize the laser animation
            bulletAnimation.Initialize(healthbullet ? healthbulletTexture : enemybulletTexture,
                                       bulletPosition,
                                       15,
                                       15,
                                       1,
                                       30,
                                       Color.White,
                                       true, direction.X * enemy.enemyMoveSpeed, direction.Y * enemy.enemyMoveSpeed);

            Bullet bullet = new Bullet();

            bullet.laserMoveSpeed = .1f;

            // init the laser
            bullet.Initialize(bulletAnimation, bulletPosition);
            bullet.Friendly = healthbullet;

            EnemyBullets.Add(bullet);

            /* todo: add code to create a laser. */
            //laserSoundInstance.Play();
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: aside6/TwinStick
        /// <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);

            Rectangle titleSafeArea  = GraphicsDevice.Viewport.TitleSafeArea;
            var       playerPosition = new Vector2(titleSafeArea.X, titleSafeArea.Y + titleSafeArea.Height / 2);

            Texture2D playerTexture   = Content.Load <Texture2D>("player");
            Animation playerAnimation = new Animation();

            playerAnimation.Initialize(playerTexture, playerPosition, 50, 50, 1, 30, Color.White, true, 0, 0);

            _player.Initialize(playerAnimation, playerPosition);

            bulletTexture       = this.Content.Load <Texture2D>("bullet");
            enemybulletTexture  = this.Content.Load <Texture2D>("enemybullet");
            healthbulletTexture = this.Content.Load <Texture2D>("healthbullet");
            font = Content.Load <SpriteFont>("Font1");

            enemyTexture = Content.Load <Texture2D>("enemy");

            // TODO: use this.Content to load your game content here
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: aside6/TwinStick
        protected void AddEnemy()
        {
            // create the animation object
            Animation enemyAnimation = new Animation();

            // Init the animation with the correct
            // animation information
            enemyAnimation.Initialize(enemyTexture,
                                      Vector2.Zero,
                                      100,
                                      100,
                                      1,
                                      30,
                                      Color.White,
                                      true, 0, 0);

            // randomly generate the postion of the enemy
            Vector2 position;

            float directionX = 0;
            float directionY = 0;

            var rndNum = random.Next(99);

            if (rndNum < 25)
            {
                position = new Vector2(
                    -100,
                    random.Next(100, GraphicsDevice.Viewport.Height - 100));

                directionX = random.Next(100);
                directionY = position.Y < 200 ? random.Next(100) : (position.Y < (GraphicsDevice.Viewport.Height - 200) ? random.Next(-100, 0) : random.Next(-100, 100));
            }
            else if (rndNum >= 25 && rndNum < 50)
            {
                position = new Vector2(
                    random.Next(100, GraphicsDevice.Viewport.Width - 100),
                    -100);

                directionX = position.X < 200 ? random.Next(100) : (position.X < (GraphicsDevice.Viewport.Width - 200) ? random.Next(-100, 0) : random.Next(-100, 100));
                directionY = random.Next(100);
            }
            else if (rndNum >= 50 && rndNum < 75)
            {
                position = new Vector2(
                    GraphicsDevice.Viewport.Width,
                    random.Next(100, GraphicsDevice.Viewport.Height - 100));

                directionX = random.Next(-100, 0);
                directionY = position.Y < 200 ? random.Next(100) : (position.Y < (GraphicsDevice.Viewport.Height - 200) ? random.Next(-100, 0) : random.Next(-100, 100));
            }
            else
            {
                position = new Vector2(
                    random.Next(100, GraphicsDevice.Viewport.Width - 100),
                    GraphicsDevice.Viewport.Width);

                directionX = position.X < 200 ? random.Next(100) : (position.X < (GraphicsDevice.Viewport.Width - 200) ? random.Next(-100, 0) : random.Next(-100, 100));
                directionY = random.Next(-100, 0);
            }

            // create an enemy
            Enemy enemy = new Enemy();

            // init the enemy
            enemy.Initialize(enemyAnimation, position, directionX, directionY);

            // Add the enemy to the active enemies list
            enemies.Add(enemy);
        }