Exemplo n.º 1
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main( string[] args )
 {
     using( Game1 game = new Game1() )
     {
         game.Run();
     }
 }
 public override void Update( GameTime gameTime, Model model, Game1 game )
 {
     base.Update( gameTime, model, game );
     foreach( EntityEnemy enemy in model.Enemies )
         if( !_enemies.Contains( enemy ) && Collision( enemy ) )
         {
             _enemies.Add( enemy );
             enemy.DealDamage( this );
         }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the ammunition.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="model"></param>
        public virtual void Update( GameTime gameTime, Model model, Game1 game )
        {
            _sprite.X += _direction.X * _speed;
            _sprite.Y += _direction.Y * _speed;

            int width = game.Window.ClientBounds.Width;
            int height = game.Window.ClientBounds.Height;

            IsAlive = !(Position.X < 0 || Position.Y < 0 || Position.X > width || Position.Y > height);
        }
        public override void Update( GameTime gameTime, Model model, Game1 game )
        {
            if( model.DisplayingMessage )
                return;

            _updateTimer += gameTime.ElapsedGameTime.Milliseconds * 0.001f;

            if( _updateTimer >= _coolDown )
            {
                model.Add( new EntityEnemyZombee( new Vector2( Position.X, Position.Y ) ) );
                _updateTimer = 0f;
            }
        }
        public override void Update( GameTime gameTime, Model model, Game1 game )
        {
            base.Update( gameTime, model, game );

            foreach( EntityEnemy enemy in model.Enemies )
                if( !model.DisplayingMessage && Collision( enemy ) )
                {
                    IsAlive = false;
                    model.Bullets.Remove( this );
                    enemy.DealDamage( this );
                    return;
                }
        }
        public override void Update( GameTime gameTime, Model model, Game1 game )
        {
            UpdateMeleeTimer( gameTime );

            EntityPlayer player = model.Player;

            _rotation = (float) Math.Atan2( player.Position.Y - Position.Y, player.Position.X - Position.X );

            if( model.DisplayingMessage )
                return;

            if( Collision( player ) )
            {
                if( _canMeleeAttack )
                {
                    _canMeleeAttack = false;
                    player.DealDamage( (int) Entity.PLAYER_HEALTH / 20 );
                }

                return;
            }

            float xDifference = _speed * (float) Math.Cos( _rotation );
            float yDifference = _speed * (float) Math.Sin( _rotation );

            _sprite.X += xDifference;
            _sprite.Y += yDifference;

            // If there is a collision after the movement, undo the movement
            foreach( EntityEnemy enemy in model.Enemies )
                if( enemy.IsAlive && PlayingCollision( enemy ) )
                {
                    _sprite.X -= xDifference;
                    _sprite.Y -= yDifference;
                    return;
                }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Updates the entity.
 /// </summary>
 /// <param name="gameTime"></param>
 /// <param name="model"></param>
 /// <param name="game"></param>
 public abstract void Update( GameTime gameTime, Model model, Game1 game );
        public override void Update( GameTime gameTime, Model model, Game1 game )
        {
            _weapon.Update( gameTime );

            MouseState mouseState = Mouse.GetState();

            // Make sure that the mouse is inside the window!
            if( game.Window.ClientBounds.Contains( mouseState.X + game.Window.ClientBounds.X, mouseState.Y + game.Window.ClientBounds.Y ) )
            {
                _rotation = (float) Math.Atan2( mouseState.Y - _sprite.Y, mouseState.X - _sprite.X );

                // Check if the player wishes to shoot
                if ( mouseState.LeftButton == ButtonState.Pressed && !model.DisplayingMessage )
                {
                    float xSpeed = (float) Math.Cos( _rotation );
                    float ySpeed = (float) Math.Sin( _rotation );

                    Vector2 direction = new Vector2( xSpeed, ySpeed );
                    Vector2 position = new Vector2( Position.X + xSpeed * Size.X / 2,
                        Position.Y + ySpeed * Size.Y / 2 );
                    _weapon.Fire( model, direction, position );
                }
            }

            // The player wishes to change the current weapon
            if( mouseState.ScrollWheelValue > _currentScrollValue )
            {
                _currentScrollValue = mouseState.ScrollWheelValue;

                ++_currentWeaponIndex;

                if( _currentWeaponIndex == _weapons.Count )
                    _currentWeaponIndex = 0;
                _weapon = _weapons.ElementAt( _currentWeaponIndex );
            }
            else if( mouseState.ScrollWheelValue < _currentScrollValue )
            {
                _currentScrollValue = mouseState.ScrollWheelValue;

                --_currentWeaponIndex;

                if( _currentWeaponIndex < 0 )
                    _currentWeaponIndex = _weapons.Count - 1;
                _weapon = _weapons.ElementAt( _currentWeaponIndex );
            }

            // Check for keyboard input
            KeyboardState keyState = Keyboard.GetState();

            // Left
            if ( keyState.IsKeyDown( WEST_KEY ) && 0 < Position.X )
                _sprite.X -= _speed;
            // Right
            if( keyState.IsKeyDown( EAST_KEY ) && Position.X < game.Window.ClientBounds.Width )
                _sprite.X += _speed;
            // Up
            if( keyState.IsKeyDown( NORTH_KEY ) && 0 < Position.Y )
                _sprite.Y -= _speed;
            // Down
            if( keyState.IsKeyDown( SOUTH_KEY ) && Position.Y < game.Window.ClientBounds.Height )
                _sprite.Y += _speed;

            // Check if the player has collided with a power up
            foreach( PowerUp powerUp in new List<PowerUp>( model.PowerUps ) )
            {
                // The power up has been collided with, pick it up
                if( Collision( powerUp ) )
                {
                    Game1._soundBank.PlayCue( "powerup_pickup0" );
                    powerUp.Apply( this );
                    _powerUps.Add( powerUp );
                    model.Remove( powerUp );
                }
            }

            // Update the power ups that the player currently have
            foreach( PowerUp powerUp in new List<PowerUp>( _powerUps ) )
                powerUp.UpdateEffect( gameTime, this, _powerUps );
        }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a new Model.
 /// </summary>
 /// <param name="game"></param>
 public Model( Game1 game )
 {
     _game = game;
     _font = _game.Content.Load<SpriteFont>( "fonts/MenuItem" );
 }