Represents a collection of moving circular object in 2D space under gravity influence which can be release (shot down). More...
Public Member Functions | |
| ShootingGallery (ScreenManager screenManager, Vector2 simulationOrigin, double width, double height, Vector2 screenOrigin, double screenScale) | |
| Instantiate an empty shooting gallery. | |
| void | Reset (string[] targetTypes, double gravity, double atmosphereDensity) |
| Reset the shooting gallery. | |
| int | ShootAtTargets (Vector2 shotCenter, double bulletSize) |
| Shoot at targets. | |
| void | Update (GameTime gameTime) |
| Update (animate) the shooting gallery. Tracks targets that become invisible because they were shot off the screen. | |
| void | Draw (GameTime gameTime) |
| Draw the shooting gallery. | |
Properties | |
| double | TargetConveyerSpeed [get, set] |
| Target conveyer animation: horizontal speed. Default: dX = 0.01. | |
| int | NumTargets [get] |
| Gets the total number of game targets. | |
| int | NumActiveTargets [get] |
| Gets the number of active (hittable) targets. | |
Represents a collection of moving circular object in 2D space under gravity influence which can be release (shot down).
Definition at line 27 of file ShootingGallery.cs.
| NewGamePhysics.GraphicalElements.ShootingGallery.ShootingGallery | ( | ScreenManager | screenManager, | |
| Vector2 | simulationOrigin, | |||
| double | width, | |||
| double | height, | |||
| Vector2 | screenOrigin, | |||
| double | screenScale | |||
| ) |
Instantiate an empty shooting gallery.
| screenManager | The screen manager to use. | |
| simulationOrigin | The origin for gallery in simulation space. | |
| width | The width of the gallery in simulation space. | |
| height | The height of the gallery in simulation space. | |
| screenOrigin | The origin for mapping simulation space to the screen. | |
| screenScale | The scale for mapping simulation space to the screen. |
Definition at line 110 of file ShootingGallery.cs.
| void NewGamePhysics.GraphicalElements.ShootingGallery.Draw | ( | GameTime | gameTime | ) |
Draw the shooting gallery.
| gameTime | The game time for drawing. |
Definition at line 249 of file ShootingGallery.cs.
| void NewGamePhysics.GraphicalElements.ShootingGallery.Reset | ( | string[] | targetTypes, | |
| double | gravity, | |||
| double | atmosphereDensity | |||
| ) |
Reset the shooting gallery.
| numTargets | Number of new targets in gallery. | |
| gravity | Gravity environment for gallery. | |
| atmosphereDensity | Density of the atmosphere. |
Definition at line 132 of file ShootingGallery.cs.
00133 { 00134 if (targetTypes == null || targetTypes.Length == 0) 00135 { 00136 throw new ArgumentException( 00137 "Can reset only to one or more targets", 00138 "targetTypes"); 00139 } 00140 00141 this.numTargets = targetTypes.Length; 00142 00143 if (gravity == 0.0) 00144 { 00145 throw new ArgumentException( 00146 "Gravity must be non-zero.", 00147 "gravity"); 00148 } 00149 00150 // Separation of targets 00151 double stepX = this.width / this.numTargets; 00152 if (stepX <= this.height) 00153 { 00154 throw new ArgumentException( 00155 "Cannot fit that many targets into the width of the gallery without overlap.", 00156 "numTargets"); 00157 } 00158 00159 this.numActiveTargets = this.numTargets; 00160 this.shootingGalleryTargets = new ShootingGalleryTarget[this.numTargets]; 00161 for (int i = 0; i < this.numTargets; i++) 00162 { 00163 this.shootingGalleryTargets[i] = new ShootingGalleryTarget( 00164 this.ScreenManager, 00165 (ShootingGalleryTargetType)Enum.Parse( 00166 typeof(ShootingGalleryTargetType), 00167 targetTypes[i]), 00168 gravity, 00169 atmosphereDensity, 00170 this.height, 00171 this.height, 00172 this.screenOrigin, 00173 this.screenScale); 00174 this.shootingGalleryTargets[i].Position = 00175 new Vector2( 00176 this.simulationOrigin.X + (float)(i * stepX), 00177 this.simulationOrigin.Y); 00178 } 00179 }
| int NewGamePhysics.GraphicalElements.ShootingGallery.ShootAtTargets | ( | Vector2 | shotCenter, | |
| double | bulletSize | |||
| ) |
Shoot at targets.
| shotCenter | Position of the shot in simulation space. | |
| bulletSize | Size of the bullet in simulation space. |
Definition at line 187 of file ShootingGallery.cs.
00188 { 00189 int numberHits = 0; 00190 00191 foreach (ShootingGalleryTarget shootingGalleryTarget in this.shootingGalleryTargets) 00192 { 00193 if (shootingGalleryTarget.Visible && !shootingGalleryTarget.Animated) 00194 { 00195 if (shootingGalleryTarget.ShootAtTarget(shotCenter, bulletSize)) 00196 { 00197 numberHits++; 00198 } 00199 } 00200 } 00201 00202 return numberHits; 00203 }
| void NewGamePhysics.GraphicalElements.ShootingGallery.Update | ( | GameTime | gameTime | ) |
Update (animate) the shooting gallery. Tracks targets that become invisible because they were shot off the screen.
| gameTime | The game time for updating. |
Definition at line 210 of file ShootingGallery.cs.
00211 { 00212 foreach (ShootingGalleryTarget shootingGalleryTarget in this.shootingGalleryTargets) 00213 { 00214 if (shootingGalleryTarget.Visible) 00215 { 00216 if (shootingGalleryTarget.Animated) 00217 { 00218 shootingGalleryTarget.Update(); 00219 if (!shootingGalleryTarget.Visible) 00220 { 00221 this.numActiveTargets--; 00222 } 00223 } 00224 else 00225 { 00226 shootingGalleryTarget.Move(this.targetConveyerSpeed); 00227 00228 // Wrap horizontal position around 00229 Vector2 position = shootingGalleryTarget.Position; 00230 if ((position.X - this.simulationOrigin.X) < 0.0) 00231 { 00232 position.X = this.simulationOrigin.X + (float)this.width; 00233 shootingGalleryTarget.Position = position; 00234 } 00235 else if ((position.X - this.simulationOrigin.X) > (float)this.width) 00236 { 00237 position.X = this.simulationOrigin.X; 00238 shootingGalleryTarget.Position = position; 00239 } 00240 } 00241 } 00242 } 00243 }
int NewGamePhysics.GraphicalElements.ShootingGallery.NumActiveTargets [get] |
Gets the number of active (hittable) targets.
Definition at line 97 of file ShootingGallery.cs.
int NewGamePhysics.GraphicalElements.ShootingGallery.NumTargets [get] |
Gets the total number of game targets.
Definition at line 89 of file ShootingGallery.cs.
double NewGamePhysics.GraphicalElements.ShootingGallery.TargetConveyerSpeed [get, set] |
Target conveyer animation: horizontal speed. Default: dX = 0.01.
Definition at line 80 of file ShootingGallery.cs.
1.6.2