public override bool Control( GameEntity control, TimeSpan gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyState )
 {
     if ( control == Owner && ( gameTime - spawnTime ).TotalMilliseconds > lifeTime && lifeTime > 0 )
     {
         Owner.RemoveTankController();
         StopControl();
     }
     return true;
 }
 /// <summary>
 /// Makes changes to the entity according to what is required.
 /// </summary>
 /// <param name="control">The entity to change.</param>
 /// <param name="gameTime">The current game time.</param>
 /// <returns>True the entity should keep updating, otherwise false.</returns>
 public abstract bool Control( GameEntity control, TimeSpan gameTime, KeyboardState keyState );
 /// <summary>
 /// Determines whether or not the controller should stick to the given entity.
 /// </summary>
 /// <param name="entity">The entity to check.</param>
 /// <returns>True if the controller needs to stick to the entity, false otherwise.</returns>
 public abstract bool AddEntity( GameEntity entity );
Example #4
0
 /// <summary>
 /// Returns the angle between two GameEntities.
 /// </summary>
 /// <param name="FromPosition">The entity to measure the angle from.</param>
 /// <param name="ToPosition">The entity to measure the angle to.</param>
 /// <returns>The angle between the two entities.</returns>
 public static float Angle( GameEntity FromEntity, GameEntity ToEntity )
 {
     return Tools.Mod( MathHelper.ToDegrees( ( float )Math.Atan2( FromEntity.Position.Y - ToEntity.Position.Y, FromEntity.Position.X - ToEntity.Position.X ) ) + 180, 360 );
 }
Example #5
0
 /// <summary>
 /// Removes an existing entity from the game.
 /// </summary>
 /// <param name="entity">The entity to remove.</param>
 /// <returns>True if the entity was removed, otherwise false.</returns>
 public bool RemoveEntity( GameEntity entity )
 {
     return Entities.Remove( entity );
 }
Example #6
0
 public override bool Control( GameEntity control, TimeSpan gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyState )
 {
     return false;
 }
Example #7
0
 public override bool AddEntity( GameEntity entity )
 {
     return false;
 }
Example #8
0
        /// <summary>
        /// Returns true if the entity collides with the other entity, AFTER the current entity has undergone the given transformation.
        /// </summary>
        /// <param name="otherEntity">The entity to check collision with.</param>
        /// <param name="Transformation">The transformation to apply.</param>
        /// <returns></returns>
        protected bool CollidesWith( GameEntity otherEntity, Matrix Transformation )
        {
            int thisWidth = Texture.Width;
            int thisHeight = Texture.Height;
            if ( SourceRectangle.HasValue )
            {
                thisWidth = SourceRectangle.Value.Width;
                thisHeight = SourceRectangle.Value.Height;
            }

            int otherWidth = otherEntity.Texture.Width;
            int otherHeight = otherEntity.Texture.Height;

            if ( otherEntity.SourceRectangle.HasValue )
            {
                otherWidth = otherEntity.SourceRectangle.Value.Width;
                otherHeight = otherEntity.SourceRectangle.Value.Height;
            }

            Matrix thisTransform = Transformation;

            Rectangle thisRect = CalculateBoundingRectangle( new Rectangle( 0, 0, thisWidth, thisHeight ), thisTransform );

            // Build the other entity's transform
            Matrix otherTransform =
                Matrix.CreateTranslation( new Vector3( -otherEntity.Origin, 0.0f ) ) *
                Matrix.CreateScale( otherEntity.Scale ) *
                Matrix.CreateRotationZ( otherEntity.AngleInRadians ) *
                Matrix.CreateTranslation( new Vector3( otherEntity.Position, 0.0f ) );

            // Calculate the bounding rectangle of the other entity in world space
            Rectangle otherRect = CalculateBoundingRectangle( new Rectangle( 0, 0, otherWidth, otherHeight ), otherTransform );

            // The per-pixel check is expensive, so check the bounding rectangles
            // first to prevent testing pixels when collisions are impossible.
            if ( thisRect.Intersects( otherRect ) )
            {
                // Check collision with entity
                return IntersectPixels( thisTransform, thisWidth,
                                    thisHeight, TextureData,
                                    otherTransform, otherWidth,
                                    otherHeight, otherEntity.TextureData );
            }
            return false;
        }
Example #9
0
 public bool CollisionCheck( GameEntity otherEntity )
 {
     return CollisionCheck( otherEntity, Texture, TextureData, SourceRectangle );
 }
Example #10
0
 public bool CollidesWith( GameEntity otherEntity )
 {
     Tuple<int, int> key = Tuple.Create<int, int>( Math.Min( ID, otherEntity.ID ), Math.Max( ID, otherEntity.ID ) );
     if ( Game.Collisions.ContainsKey( key ) )
     {
         return Game.Collisions[ key ];
     }
     else
     {
         bool result = CollisionCheck( otherEntity );
         Game.Collisions[ key ] = result;
         return result;
     }
 }
Example #11
0
 public override bool Control( GameEntity control, TimeSpan gameTime, KeyboardState keyState )
 {
     if ( keyState.IsKeyDown( shoot ) && prevKeyState.IsKeyUp( shoot ) )
     {
         missile.Destroy( gameTime );
     }
     if ( conCount >= 1 )
     {
         conCount++;
         if ( conCount > 5 )
         {
             owner.Keys.KeyShoot = shoot;
             control.RemoveController( this );
         }
     }
     prevKeyState = keyState;
     return true;
 }
Example #12
0
 public override bool AddEntity( GameEntity entity )
 {
     return entity == owner;
 }