# NewGamePhysics.GraphicalElements.ShootingGalleryTarget Class Reference

Encapsulates a shooting gallery target which can move on a horizontal conveyor or fall under the influence of gravity. More...

Inheritance diagram for NewGamePhysics.GraphicalElements.ShootingGalleryTarget:

List of all members.

## Public Member Functions
| ShootingGalleryTarget (ScreenManager screenManager, ShootingGalleryTargetType type, double gravity, double atmosphereDensity, double simulationWidth, double simulationHeight, Vector2 screenOrigin, double screenScale)
| Creates an instance of the target if the specified type and gravity environment. Center is set to (0,0) initially, target is visible and not animated.
void | Move (double horizontalDisplacement)
| Move the target by the specified amount if visible.
bool | ShootAtTarget (Vector2 shotCenter, double bulletSize)
| Shoot at the target. Sets target to animated if hit.
void | Update ()
| Update (animate) a target object if visible and animated. May make target invisible if it leaves the screen.
void | Draw (GameTime gameTime)
| Draw a target object if visible.
## Properties
bool | Animated`[get, set]`
| Gets of sets a flag indicating if the target is animated (falling).
bool | Visible`[get, set]`
| Gets of sets a flag indicating if the target is visible.
Vector2 | Position`[get, set]`
| Sets or sets the center of the animated target object in simulation space.

## Detailed Description

Encapsulates a shooting gallery target which can move on a horizontal conveyor or fall under the influence of gravity.

Definition at line 49 of file ShootingGalleryTarget.cs.

## Constructor & Destructor Documentation

NewGamePhysics.GraphicalElements.ShootingGalleryTarget.ShootingGalleryTarget | ( | ScreenManager | screenManager,
|  | ShootingGalleryTargetType | type,
|  | double | gravity,
|  | double | atmosphereDensity,
|  | double | simulationWidth,
|  | double | simulationHeight,
|  | Vector2 | screenOrigin,
|  | double | screenScale |
| ) |  |  |

Creates an instance of the target if the specified type and gravity environment. Center is set to (0,0) initially, target is visible and not animated.

Parameters:

  | screenManager | The screen manager to use for drawing.
  | type | The type of the target.
  | atmosphereDensity | The density of the atmosphere.
  | gravity | The gravity of the simulation.
  | simulationWidth | The width of the simulated target.
  | simulationHeight | The height of the simulated target.
  | screenOrigin | The origin for mapping simulation space to the screen.
  | screenScale | The scale for mapping simulation space to the screen.

Reference: http://en.wikipedia.org/wiki/Copper (g·cm−3)

Reference: http://en.wikipedia.org/wiki/Silver (g·cm−3)

Reference: http://en.wikipedia.org/wiki/Gold (g·cm−3)

Definition at line 123 of file ShootingGalleryTarget.cs.

    00132             : base(screenManager)
    00133         {
    00134             this.width = simulationWidth;
    00135             this.height = simulationHeight;
    00136             this.screenOrigin = screenOrigin;
    00137             this.screenScale = screenScale;
    00138             this.radius = Math.Min(width, height) / 2;
    00139             double diameter = 2.0 * this.radius;
    00140             this.screenPosition = new Vector2();
    00141
    00142             this.visible = true;
    00143             this.animated = false;
    00144
    00145             string textureName = string.Empty;
    00146             switch (type)
    00147             {
    00148                 case ShootingGalleryTargetType.CopperBall:
    00150                     this.animatedCircularObject =
    00151                         new CircularObjectSimulation(diameter, 8.94, gravity, atmosphereDensity);
    00152                     textureName = "copperball";
    00153                     break;
    00154                 case ShootingGalleryTargetType.SilverBall:
    00156                     this.animatedCircularObject =
    00157                         new CircularObjectSimulation(diameter, 10.49, gravity, atmosphereDensity);
    00158                     textureName = "silverball";
    00159                     break;
    00160                 case ShootingGalleryTargetType.GoldBall:
    00162                     this.animatedCircularObject =
    00163                         new CircularObjectSimulation(diameter, 19.30, gravity, atmosphereDensity);
    00164                     textureName = "goldball";
    00165                     break;
    00166             }
    00167
    00168             // Prepare texture
    00169             if (screenManager.Textures.ContainsKey(textureName))
    00170             {
    00171                 this.targetTexture = screenManager.Textures[textureName];
    00172             }
    00173             else
    00174             {
    00175                 throw new ArgumentException("Texture with name " + textureName + " not found");
    00176             }
    00177
    00178             float spriteScaleX = (float)(this.width * this.screenScale / this.targetTexture.Width);
    00179             float spriteScaleY = (float)(this.height * this.screenScale / this.targetTexture.Height);
    00180             this.spriteScale = new Vector2(spriteScaleX, spriteScaleY);
    00181             this.spriteOrigin = new Vector2();
    00182         }

## Member Function Documentation

void NewGamePhysics.GraphicalElements.ShootingGalleryTarget.Draw | ( | GameTime | gameTime | ) |

Draw a target object if visible.

Parameters:

  | gameTime | The game time for drawing.

Definition at line 277 of file ShootingGalleryTarget.cs.

    00278         {
    00279             if (this.visible)
    00280             {
    00281                 // Get fresh screen coordinates
    00282                 UpdateScreenPosition();
    00283
    00284                 // Draw target
    00285                 this.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend);
    00286                 this.SpriteBatch.Draw(
    00287                     this.targetTexture,
    00288                     this.screenPosition,
    00289                     null,
    00290                     Color.White,
    00291                     0.0f,
    00292                     this.spriteOrigin,
    00293                     this.spriteScale,
    00294                     SpriteEffects.None,
    00295                     0.0f);
    00296                 this.SpriteBatch.End();
    00297             }
    00298         }

void NewGamePhysics.GraphicalElements.ShootingGalleryTarget.Move | ( | double | horizontalDisplacement | ) |

Move the target by the specified amount if visible.

Parameters:

  | displacement | The horizontal displacement in simulation space.

Definition at line 215 of file ShootingGalleryTarget.cs.

    00216         {
    00217             if (this.visible)
    00218             {
    00219                 Vector2 position =
    00220                     this.animatedCircularObject.GetPosition();
    00221                 position.X += (float)horizontalDisplacement;
    00222                 this.animatedCircularObject.SetPosition(position);
    00223             }
    00224         }

bool NewGamePhysics.GraphicalElements.ShootingGalleryTarget.ShootAtTarget | ( | Vector2 | shotCenter,
|  | double | bulletSize |
| ) |  |  |

Shoot at the target. Sets target to animated if hit.

Parameters:

  | shotCenter | Position of the shot in simulation space.
  | bulletSize | Size of the bullet in simulation space.

Returns:
  Flag indicating a hit.

Definition at line 232 of file ShootingGalleryTarget.cs.

    00233         {
    00234             if (this.visible)
    00235             {
    00236                 Vector2 targetPosition =
    00237                     this.animatedCircularObject.GetPosition();
    00238
    00239                 if (IntersectionTest.CircleInCircle2D(
    00240                     targetPosition,
    00241                     this.radius,
    00242                     shotCenter,
    00243                     bulletSize))
    00244                 {
    00245                     this.animated = true;
    00246                     return true;
    00247                 }
    00248             }
    00249
    00250             return false;
    00251         }

void NewGamePhysics.GraphicalElements.ShootingGalleryTarget.Update | ( |  | ) |

Update (animate) a target object if visible and animated. May make target invisible if it leaves the screen.

Definition at line 257 of file ShootingGalleryTarget.cs.

    00258         {
    00259             if (this.visible && this.animated)
    00260             {
    00261                 // Let target fall
    00262                 this.animatedCircularObject.Animate();
    00263
    00264                 // Check if we left the screen
    00265                 UpdateScreenPosition();
    00266                 if (this.screenPosition.Y > (this.Viewport.Height + this.radius * this.screenScale))
    00267                 {
    00268                     this.visible = false;
    00269                 }
    00270             }
    00271         }

## Property Documentation

bool NewGamePhysics.GraphicalElements.ShootingGalleryTarget.Animated`[get, set]`

Gets of sets a flag indicating if the target is animated (falling).

Definition at line 188 of file ShootingGalleryTarget.cs.

Vector2 NewGamePhysics.GraphicalElements.ShootingGalleryTarget.Position`[get, set]`

Sets or sets the center of the animated target object in simulation space.

Definition at line 206 of file ShootingGalleryTarget.cs.

bool NewGamePhysics.GraphicalElements.ShootingGalleryTarget.Visible`[get, set]`

Gets of sets a flag indicating if the target is visible.

Definition at line 197 of file ShootingGalleryTarget.cs.

The documentation for this class was generated from the following file:

- C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/NewGamePhysics/GraphicalElements/ShootingGalleryTarget.cs