World.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // World.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using Microsoft.Xna.Framework;
  13. using Microsoft.Xna.Framework.Content;
  14. using Microsoft.Xna.Framework.GamerServices;
  15. using Microsoft.Xna.Framework.Graphics;
  16. using Microsoft.Xna.Framework.Input;
  17. using Microsoft.Xna.Framework.Net;
  18. #endregion
  19. namespace NetRumble
  20. {
  21. /// <summary>
  22. /// A container for the game-specific logic and code.
  23. /// </summary>
  24. public class World : IDisposable
  25. {
  26. #region Public Constants
  27. /// <summary>
  28. /// The maximum number of players in the game.
  29. /// </summary>
  30. public const int MaximumPlayers = 16;
  31. /// <summary>
  32. /// The different types of packets sent in the game.
  33. /// </summary>
  34. /// <remarks>Frequently used in packets to identify their type.</remarks>
  35. public enum PacketTypes
  36. {
  37. PlayerData,
  38. ShipData,
  39. WorldSetup,
  40. WorldData,
  41. ShipInput,
  42. PowerUpSpawn,
  43. ShipDeath,
  44. ShipSpawn,
  45. GameWon,
  46. };
  47. #endregion
  48. #region Constants
  49. /// <summary>
  50. /// The score required to win the game.
  51. /// </summary>
  52. const int winningScore = 5;
  53. /// <summary>
  54. /// The number of asteroids in the game.
  55. /// </summary>
  56. const int numberOfAsteroids = 15;
  57. /// <summary>
  58. /// The length of time it takes for another power-up to spawn.
  59. /// </summary>
  60. const float maximumPowerUpTimer = 10f;
  61. /// <summary>
  62. /// The size of all of the barriers in the game.
  63. /// </summary>
  64. const int barrierSize = 48;
  65. /// <summary>
  66. /// The number of updates between WorldData packets.
  67. /// </summary>
  68. const int updatesBetweenWorldDataSend = 30;
  69. /// <summary>
  70. /// The number of updates between ship status packets from this machine.
  71. /// </summary>
  72. const int updatesBetweenStatusPackets = MaximumPlayers;
  73. /// <summary>
  74. /// The number of barriers in each dimension.
  75. /// </summary>
  76. static readonly Point barrierCounts = new Point(50, 50);
  77. /// <summary>
  78. /// The dimensions of the game world.
  79. /// </summary>
  80. static readonly Rectangle dimensions = new Rectangle(0, 0,
  81. barrierCounts.X * barrierSize, barrierCounts.Y * barrierSize);
  82. #endregion
  83. #region State Data
  84. /// <summary>
  85. /// If true, the game has been initialized by receiving a WorldSetup packet.
  86. /// </summary>
  87. bool initialized = false;
  88. public bool Initialized
  89. {
  90. get { return initialized; }
  91. }
  92. /// <summary>
  93. /// If true, the game is over, and somebody has won.
  94. /// </summary>
  95. private bool gameWon = false;
  96. public bool GameWon
  97. {
  98. get { return gameWon; }
  99. set { gameWon = value; }
  100. }
  101. /// <summary>
  102. /// The index of the player who won the game.
  103. /// </summary>
  104. private int winnerIndex = -1;
  105. public int WinnerIndex
  106. {
  107. get { return winnerIndex; }
  108. }
  109. /// <summary>
  110. /// If true, the game is over, because the game ended before somebody won.
  111. /// </summary>
  112. /// <remarks></remarks>
  113. private bool gameExited = false;
  114. public bool GameExited
  115. {
  116. get { return gameExited; }
  117. set { gameExited = value; }
  118. }
  119. // presence support
  120. private List<int> highScorers = new List<int>();
  121. public List<int> HighScorers
  122. {
  123. get { return highScorers; }
  124. }
  125. #endregion
  126. #region Gameplay Data
  127. /// <summary>
  128. /// The number of asteroids in the game.
  129. /// </summary>
  130. Asteroid[] asteroids = new Asteroid[numberOfAsteroids];
  131. /// <summary>
  132. /// The current power-up in the game.
  133. /// </summary>
  134. PowerUp powerUp = null;
  135. /// <summary>
  136. /// The amount of time left until the next power-up spawns.
  137. /// </summary>
  138. float powerUpTimer = maximumPowerUpTimer / 2f;
  139. #endregion
  140. #region Graphics Data
  141. /// <summary>
  142. /// The sprite batch used to draw the objects in the world.
  143. /// </summary>
  144. private SpriteBatch spriteBatch;
  145. /// <summary>
  146. /// The corner-barrier texture.
  147. /// </summary>
  148. private Texture2D cornerBarrierTexture;
  149. /// <summary>
  150. /// The vertical-barrier texture.
  151. /// </summary>
  152. private Texture2D verticalBarrierTexture;
  153. /// <summary>
  154. /// The horizontal-barrier texture.
  155. /// </summary>
  156. private Texture2D horizontalBarrierTexture;
  157. /// <summary>
  158. /// The texture signifying that the player can chat.
  159. /// </summary>
  160. private Texture2D chatAbleTexture;
  161. /// <summary>
  162. /// The texture signifying that the player has been muted.
  163. /// </summary>
  164. private Texture2D chatMuteTexture;
  165. /// <summary>
  166. /// The texture signifying that the player is talking right now.
  167. /// </summary>
  168. private Texture2D chatTalkingTexture;
  169. /// <summary>
  170. /// The texture signifying that the player is ready
  171. /// </summary>
  172. private Texture2D readyTexture;
  173. /// <summary>
  174. /// The sprite used to draw the player names.
  175. /// </summary>
  176. private SpriteFont playerFont;
  177. public SpriteFont PlayerFont
  178. {
  179. get { return playerFont; }
  180. }
  181. /// <summary>
  182. /// The list of corner barriers in the game world.
  183. /// </summary>
  184. /// <remarks>This list is not owned by this object.</remarks>
  185. private List<Rectangle> cornerBarriers = new List<Rectangle>();
  186. /// <summary>
  187. /// The list of vertical barriers in the game world.
  188. /// </summary>
  189. /// <remarks>This list is not owned by this object.</remarks>
  190. private List<Rectangle> verticalBarriers = new List<Rectangle>();
  191. /// <summary>
  192. /// The list of horizontal barriers in the game world.
  193. /// </summary>
  194. /// <remarks>This list is not owned by this object.</remarks>
  195. private List<Rectangle> horizontalBarriers = new List<Rectangle>();
  196. /// <summary>
  197. /// The particle-effect manager for the game.
  198. /// </summary>
  199. ParticleEffectManager particleEffectManager;
  200. #endregion
  201. #region Networking Data
  202. /// <summary>
  203. /// The network session for the game.
  204. /// </summary>
  205. private NetworkSession networkSession;
  206. /// <summary>
  207. /// The packet writer for all of the data for the world.
  208. /// </summary>
  209. private PacketWriter packetWriter = new PacketWriter();
  210. /// <summary>
  211. /// The packet reader for all of the data for the world.
  212. /// </summary>
  213. private PacketReader packetReader = new PacketReader();
  214. /// <summary>
  215. /// The number of updates that have passed since the world data was sent.
  216. /// </summary>
  217. private int updatesSinceWorldDataSend = 0;
  218. /// <summary>
  219. /// The number of updates that have passed since a status packet was sent.
  220. /// </summary>
  221. private int updatesSinceStatusPacket = 0;
  222. #endregion
  223. #region Initialization
  224. /// <summary>
  225. /// Construct a new World object.
  226. /// </summary>
  227. /// <param name="graphicsDevice">The graphics device used for this game.</param>
  228. /// <param name="networkSession">The network session for this game.</param>
  229. public World(GraphicsDevice graphicsDevice, ContentManager contentManager,
  230. NetworkSession networkSession)
  231. {
  232. // safety-check the parameters, as they must be valid
  233. if (graphicsDevice == null)
  234. {
  235. throw new ArgumentNullException("graphicsDevice");
  236. }
  237. if (contentManager == null)
  238. {
  239. throw new ArgumentNullException("contentManager");
  240. }
  241. if (networkSession == null)
  242. {
  243. throw new ArgumentNullException("networkSession");
  244. }
  245. // apply the parameter values
  246. this.networkSession = networkSession;
  247. // set up the staggered status packet system
  248. // -- your first update happens based on where you are in the collection
  249. for (int i = 0; i < networkSession.AllGamers.Count; i++)
  250. {
  251. if (networkSession.AllGamers[i].IsLocal)
  252. {
  253. updatesSinceStatusPacket = i;
  254. break;
  255. }
  256. }
  257. // create the spritebatch
  258. spriteBatch = new SpriteBatch(graphicsDevice);
  259. // create and initialize the particle-effect manager
  260. particleEffectManager = new ParticleEffectManager(contentManager);
  261. particleEffectManager.RegisterParticleEffect(
  262. ParticleEffectType.LaserExplosion,
  263. "Particles/laserExplosion.xml", 40);
  264. particleEffectManager.RegisterParticleEffect(
  265. ParticleEffectType.MineExplosion,
  266. "Particles/mineExplosion.xml", 8);
  267. particleEffectManager.RegisterParticleEffect(
  268. ParticleEffectType.RocketExplosion,
  269. "Particles/rocketExplosion.xml", 24);
  270. particleEffectManager.RegisterParticleEffect(
  271. ParticleEffectType.RocketTrail,
  272. "Particles/rocketTrail.xml", 16);
  273. particleEffectManager.RegisterParticleEffect(
  274. ParticleEffectType.ShipExplosion,
  275. "Particles/shipExplosion.xml", 4);
  276. particleEffectManager.RegisterParticleEffect(
  277. ParticleEffectType.ShipSpawn,
  278. "Particles/shipSpawn.xml", 4);
  279. Ship.ParticleEffectManager = particleEffectManager;
  280. RocketProjectile.ParticleEffectManager = particleEffectManager;
  281. MineProjectile.ParticleEffectManager = particleEffectManager;
  282. LaserProjectile.ParticleEffectManager = particleEffectManager;
  283. // load the font
  284. playerFont = contentManager.Load<SpriteFont>("Fonts/NetRumbleFont");
  285. // load the gameplay-object textures
  286. Ship.LoadContent(contentManager);
  287. Asteroid.LoadContent(contentManager);
  288. LaserProjectile.LoadContent(contentManager);
  289. MineProjectile.LoadContent(contentManager);
  290. RocketProjectile.LoadContent(contentManager);
  291. DoubleLaserPowerUp.LoadContent(contentManager);
  292. TripleLaserPowerUp.LoadContent(contentManager);
  293. RocketPowerUp.LoadContent(contentManager);
  294. // load the non-gameplay-object textures
  295. chatAbleTexture = contentManager.Load<Texture2D>("Textures/chatAble");
  296. chatMuteTexture = contentManager.Load<Texture2D>("Textures/chatMute");
  297. chatTalkingTexture = contentManager.Load<Texture2D>("Textures/chatTalking");
  298. readyTexture = contentManager.Load<Texture2D>("Textures/ready");
  299. cornerBarrierTexture =
  300. contentManager.Load<Texture2D>("Textures/barrierEnd");
  301. verticalBarrierTexture =
  302. contentManager.Load<Texture2D>("Textures/barrierPurple");
  303. horizontalBarrierTexture =
  304. contentManager.Load<Texture2D>("Textures/barrierRed");
  305. // clear the collision manager
  306. CollisionManager.Collection.Clear();
  307. // add the collision version of the edge barriers
  308. CollisionManager.Barriers.Clear();
  309. CollisionManager.Barriers.Add(new Rectangle(dimensions.X, dimensions.Y,
  310. dimensions.Width, barrierSize)); // top edge
  311. CollisionManager.Barriers.Add(new Rectangle(
  312. dimensions.X, dimensions.Y + dimensions.Height,
  313. dimensions.Width, barrierSize)); // bottom edge
  314. CollisionManager.Barriers.Add(new Rectangle(dimensions.X, dimensions.Y,
  315. barrierSize, dimensions.Height)); // left edge
  316. CollisionManager.Barriers.Add(new Rectangle(
  317. dimensions.X + dimensions.Width, dimensions.Y,
  318. barrierSize, dimensions.Height)); // right edge
  319. // add the rendering version of the edge barriers
  320. cornerBarriers.Clear();
  321. cornerBarriers.Add(new Rectangle(dimensions.X, dimensions.Y,
  322. barrierSize, barrierSize)); // top-left corner
  323. cornerBarriers.Add(new Rectangle(
  324. dimensions.X + dimensions.Width, dimensions.Y,
  325. barrierSize, barrierSize)); // top-right corner
  326. cornerBarriers.Add(new Rectangle(
  327. dimensions.X, dimensions.Y + dimensions.Height,
  328. barrierSize, barrierSize)); // bottom-left corner
  329. cornerBarriers.Add(new Rectangle(
  330. dimensions.X + dimensions.Width, dimensions.Y + dimensions.Height,
  331. barrierSize, barrierSize)); // bottom-right corner
  332. verticalBarriers.Clear();
  333. for (int i = 1; i < barrierCounts.Y; i++)
  334. {
  335. verticalBarriers.Add(new Rectangle(
  336. dimensions.X, dimensions.Y + barrierSize * i,
  337. barrierSize, barrierSize)); // top edge
  338. verticalBarriers.Add(new Rectangle(
  339. dimensions.X + dimensions.Width, dimensions.Y + barrierSize * i,
  340. barrierSize, barrierSize)); // bottom edge
  341. }
  342. horizontalBarriers.Clear();
  343. for (int i = 1; i < barrierCounts.X; i++)
  344. {
  345. horizontalBarriers.Add(new Rectangle(
  346. dimensions.X + barrierSize * i, dimensions.Y,
  347. barrierSize, barrierSize)); // left edge
  348. horizontalBarriers.Add(new Rectangle(
  349. dimensions.X + barrierSize * i, dimensions.Y + dimensions.Width,
  350. barrierSize, barrierSize)); // right edge
  351. }
  352. }
  353. /// <summary>
  354. /// Generate the initial state of the game, and send it to everyone.
  355. /// </summary>
  356. public void GenerateWorld()
  357. {
  358. if ((networkSession != null) && (networkSession.LocalGamers.Count > 0))
  359. {
  360. // write the identification value
  361. packetWriter.Write((int)PacketTypes.WorldSetup);
  362. // place the ships
  363. // -- we always write the maximum number of players, making the packet
  364. // predictable, in case the player count changes on the client before
  365. // this packet is received
  366. for (int i = 0; i < MaximumPlayers; i++)
  367. {
  368. Vector2 position = Vector2.Zero;
  369. if (i < networkSession.AllGamers.Count)
  370. {
  371. PlayerData playerData = networkSession.AllGamers[i].Tag
  372. as PlayerData;
  373. if ((playerData != null) && (playerData.Ship != null))
  374. {
  375. playerData.Ship.Initialize();
  376. position = playerData.Ship.Position =
  377. CollisionManager.FindSpawnPoint(playerData.Ship,
  378. playerData.Ship.Radius * 5f);
  379. playerData.Ship.Score = 0;
  380. }
  381. }
  382. // write the ship position
  383. packetWriter.Write(position);
  384. }
  385. // place the asteroids
  386. // -- for simplicity, the same number of asteroids is always the same
  387. for (int i = 0; i < asteroids.Length; i++)
  388. {
  389. // choose one of three radii
  390. float radius = 32f;
  391. switch (RandomMath.Random.Next(3))
  392. {
  393. case 0:
  394. radius = 32f;
  395. break;
  396. case 1:
  397. radius = 60f;
  398. break;
  399. case 2:
  400. radius = 96f;
  401. break;
  402. }
  403. // create the asteroid
  404. asteroids[i] = new Asteroid(radius);
  405. // write the radius
  406. packetWriter.Write(asteroids[i].Radius);
  407. // choose a variation
  408. asteroids[i].Variation = i % Asteroid.Variations;
  409. // write the variation
  410. packetWriter.Write(asteroids[i].Variation);
  411. // initialize the asteroid and it's starting position
  412. asteroids[i].Initialize();
  413. asteroids[i].Position =
  414. CollisionManager.FindSpawnPoint(asteroids[i],
  415. asteroids[i].Radius);
  416. // write the starting position and velocity
  417. packetWriter.Write(asteroids[i].Position);
  418. packetWriter.Write(asteroids[i].Velocity);
  419. }
  420. // send the packet to everyone
  421. networkSession.LocalGamers[0].SendData(packetWriter,
  422. SendDataOptions.ReliableInOrder);
  423. }
  424. }
  425. /// <summary>
  426. /// Initialize the world with the data from the WorldSetup packet.
  427. /// </summary>
  428. /// <param name="packetReader">The packet reader with the world data.</param>
  429. public void Initialize()
  430. {
  431. // reset the game status
  432. gameWon = false;
  433. winnerIndex = -1;
  434. gameExited = false;
  435. // initialize the ships with the data from the packet
  436. for (int i = 0; i < MaximumPlayers; i++)
  437. {
  438. // read each of the positions
  439. Vector2 position = packetReader.ReadVector2();
  440. // use the position value if we know of that many players
  441. if (i < networkSession.AllGamers.Count)
  442. {
  443. PlayerData playerData = networkSession.AllGamers[i].Tag
  444. as PlayerData;
  445. if ((playerData != null) && (playerData.Ship != null))
  446. {
  447. // initialize the ship with the provided position
  448. playerData.Ship.Position = position;
  449. playerData.Ship.Score = 0;
  450. playerData.Ship.Initialize();
  451. }
  452. }
  453. }
  454. // initialize the ships with the data from the packet
  455. for (int i = 0; i < asteroids.Length; i++)
  456. {
  457. float radius = packetReader.ReadSingle();
  458. if (asteroids[i] == null)
  459. {
  460. asteroids[i] = new Asteroid(radius);
  461. }
  462. asteroids[i].Variation = packetReader.ReadInt32();
  463. asteroids[i].Position = packetReader.ReadVector2();
  464. asteroids[i].Initialize();
  465. asteroids[i].Velocity = packetReader.ReadVector2();
  466. }
  467. // set the initialized state
  468. initialized = true;
  469. }
  470. #endregion
  471. #region Updating Methods
  472. /// <summary>
  473. /// Update the world.
  474. /// </summary>
  475. /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
  476. /// <param name="paused">If true, the game is paused.</param>
  477. public void Update(float elapsedTime, bool paused)
  478. {
  479. if (gameWon)
  480. {
  481. // update the particle-effect manager
  482. particleEffectManager.Update(elapsedTime);
  483. // make sure the collision manager is empty
  484. CollisionManager.Collection.ApplyPendingRemovals();
  485. if (CollisionManager.Collection.Count > 0)
  486. {
  487. CollisionManager.Collection.Clear();
  488. }
  489. }
  490. else
  491. {
  492. // process all incoming packets
  493. ProcessPackets();
  494. // if the game is in progress, update the state of it
  495. if (initialized && (networkSession != null) &&
  496. (networkSession.SessionState == NetworkSessionState.Playing))
  497. {
  498. // presence support
  499. int highScore = int.MinValue;
  500. int highScoreIndex = -1;
  501. for (int i = 0; i < networkSession.AllGamers.Count; i++)
  502. {
  503. NetworkGamer networkGamer = networkSession.AllGamers[i];
  504. PlayerData playerData = networkGamer.Tag as PlayerData;
  505. if ((playerData != null) && (playerData.Ship != null))
  506. {
  507. int playerScore = playerData.Ship.Score;
  508. if (playerScore == highScore)
  509. {
  510. highScorers.Add(i);
  511. }
  512. else if (playerScore > highScore)
  513. {
  514. highScorers.Clear();
  515. highScorers.Add(i);
  516. highScore = playerScore;
  517. highScoreIndex = i;
  518. }
  519. }
  520. }
  521. // the host has singular responsibilities to the game world,
  522. // that need to be done once, by one authority
  523. if (networkSession.IsHost)
  524. {
  525. // get the local player, for frequent re-use
  526. LocalNetworkGamer localGamer = networkSession.Host
  527. as LocalNetworkGamer;
  528. // check for victory
  529. // if victory has been achieved, send a packet to everyone
  530. if (highScore >= winningScore)
  531. {
  532. packetWriter.Write((int)PacketTypes.GameWon);
  533. packetWriter.Write(highScoreIndex);
  534. localGamer.SendData(packetWriter,
  535. SendDataOptions.ReliableInOrder);
  536. }
  537. // respawn each player, if it is time to do so
  538. for (int i = 0; i < networkSession.AllGamers.Count; i++)
  539. {
  540. NetworkGamer networkGamer = networkSession.AllGamers[i];
  541. PlayerData playerData = networkGamer.Tag as PlayerData;
  542. if ((playerData != null) && (playerData.Ship != null) &&
  543. !playerData.Ship.Active &&
  544. (playerData.Ship.RespawnTimer <= 0f))
  545. {
  546. // write the ship-spawn packet
  547. packetWriter.Write((int)PacketTypes.ShipSpawn);
  548. packetWriter.Write(i);
  549. packetWriter.Write(CollisionManager.FindSpawnPoint(
  550. playerData.Ship, playerData.Ship.Radius));
  551. localGamer.SendData(packetWriter,
  552. SendDataOptions.ReliableInOrder);
  553. }
  554. }
  555. // respawn the power-up if it is time to do so
  556. if (powerUp == null)
  557. {
  558. powerUpTimer -= elapsedTime;
  559. if (powerUpTimer < 0)
  560. {
  561. // write the power-up-spawn packet
  562. packetWriter.Write((int)PacketTypes.PowerUpSpawn);
  563. packetWriter.Write(RandomMath.Random.Next(3));
  564. packetWriter.Write(CollisionManager.FindSpawnPoint(null,
  565. PowerUp.PowerUpRadius * 3f));
  566. localGamer.SendData(packetWriter,
  567. SendDataOptions.ReliableInOrder);
  568. }
  569. }
  570. else
  571. {
  572. powerUpTimer = maximumPowerUpTimer;
  573. }
  574. // send everyone an update on the state of the world
  575. if (updatesSinceWorldDataSend >= updatesBetweenWorldDataSend)
  576. {
  577. packetWriter.Write((int)PacketTypes.WorldData);
  578. // write each of the asteroids
  579. for (int i = 0; i < asteroids.Length; i++)
  580. {
  581. packetWriter.Write(asteroids[i].Position);
  582. packetWriter.Write(asteroids[i].Velocity);
  583. }
  584. localGamer.SendData(packetWriter,
  585. SendDataOptions.InOrder);
  586. updatesSinceWorldDataSend = 0;
  587. }
  588. else
  589. {
  590. updatesSinceWorldDataSend++;
  591. }
  592. }
  593. // update each asteroid
  594. foreach (Asteroid asteroid in asteroids)
  595. {
  596. if (asteroid.Active)
  597. {
  598. asteroid.Update(elapsedTime);
  599. }
  600. }
  601. // update the power-up
  602. if (powerUp != null)
  603. {
  604. if (powerUp.Active)
  605. {
  606. powerUp.Update(elapsedTime);
  607. }
  608. else
  609. {
  610. powerUp = null;
  611. }
  612. }
  613. // process the local player's input
  614. if (!paused)
  615. {
  616. ProcessLocalPlayerInput();
  617. }
  618. // update each ship
  619. foreach (NetworkGamer networkGamer in networkSession.AllGamers)
  620. {
  621. PlayerData playerData = networkGamer.Tag as PlayerData;
  622. if ((playerData != null) && (playerData.Ship != null))
  623. {
  624. if (playerData.Ship.Active)
  625. {
  626. playerData.Ship.Update(elapsedTime);
  627. // check for death
  628. // -- only check on local machines - the local player is
  629. // the authority on the death of their own ship
  630. if (networkGamer.IsLocal && (playerData.Ship.Life < 0))
  631. {
  632. SendLocalShipDeath();
  633. }
  634. }
  635. else if (playerData.Ship.RespawnTimer > 0f)
  636. {
  637. playerData.Ship.RespawnTimer -= elapsedTime;
  638. if (playerData.Ship.RespawnTimer < 0f)
  639. {
  640. playerData.Ship.RespawnTimer = 0f;
  641. }
  642. }
  643. }
  644. }
  645. // update the other players with the current state of the local ship
  646. if (updatesSinceStatusPacket >= updatesBetweenStatusPackets)
  647. {
  648. updatesSinceStatusPacket = 0;
  649. SendLocalShipData();
  650. }
  651. else
  652. {
  653. updatesSinceStatusPacket++;
  654. }
  655. // update the collision manager
  656. CollisionManager.Update(elapsedTime);
  657. // update the particle-effect manager
  658. particleEffectManager.Update(elapsedTime);
  659. }
  660. }
  661. }
  662. /// <summary>
  663. /// Process the local player's input.
  664. /// </summary>
  665. private void ProcessLocalPlayerInput()
  666. {
  667. if ((networkSession != null) && (networkSession.LocalGamers.Count > 0))
  668. {
  669. // create the new input structure
  670. ShipInput shipInput = new ShipInput(
  671. GamePad.GetState(
  672. networkSession.LocalGamers[0].SignedInGamer.PlayerIndex),
  673. Keyboard.GetState(
  674. networkSession.LocalGamers[0].SignedInGamer.PlayerIndex));
  675. // send it out
  676. // -- the local machine will receive and apply it from the network just
  677. // like the other clients
  678. shipInput.Serialize(packetWriter);
  679. networkSession.LocalGamers[0].SendData(packetWriter,
  680. SendDataOptions.InOrder);
  681. }
  682. }
  683. /// <summary>
  684. /// Send the current state of the ship to the other players.
  685. /// </summary>
  686. private void SendLocalShipData()
  687. {
  688. if ((networkSession != null) && (networkSession.LocalGamers.Count > 0))
  689. {
  690. PlayerData playerData = networkSession.LocalGamers[0].Tag as PlayerData;
  691. if ((playerData != null) && (playerData.Ship != null))
  692. {
  693. packetWriter.Write((int)World.PacketTypes.ShipData);
  694. packetWriter.Write(playerData.Ship.Position);
  695. packetWriter.Write(playerData.Ship.Velocity);
  696. packetWriter.Write(playerData.Ship.Rotation);
  697. packetWriter.Write(playerData.Ship.Life);
  698. packetWriter.Write(playerData.Ship.Shield);
  699. packetWriter.Write(playerData.Ship.Score);
  700. networkSession.LocalGamers[0].SendData(packetWriter,
  701. SendDataOptions.InOrder);
  702. }
  703. }
  704. }
  705. /// <summary>
  706. /// Send a notification of the death of the local ship to the other players.
  707. /// </summary>
  708. private void SendLocalShipDeath()
  709. {
  710. if ((networkSession != null) && (networkSession.LocalGamers.Count > 0))
  711. {
  712. LocalNetworkGamer localNetworkGamer = networkSession.LocalGamers[0]
  713. as LocalNetworkGamer;
  714. PlayerData playerData = localNetworkGamer.Tag as PlayerData;
  715. if ((playerData != null) && (playerData.Ship != null))
  716. {
  717. // send a ship-death notification
  718. packetWriter.Write((int)PacketTypes.ShipDeath);
  719. // determine the player behind the last damage taken
  720. int lastDamagedByPlayer = -1;
  721. Ship lastDamagedByShip = playerData.Ship.LastDamagedBy as Ship;
  722. if ((lastDamagedByShip != null) &&
  723. (lastDamagedByShip != playerData.Ship))
  724. {
  725. for (int i = 0; i < networkSession.AllGamers.Count; i++)
  726. {
  727. PlayerData sourcePlayerData =
  728. networkSession.AllGamers[i].Tag as PlayerData;
  729. if ((sourcePlayerData != null) &&
  730. (sourcePlayerData.Ship != null) &&
  731. (sourcePlayerData.Ship == lastDamagedByShip))
  732. {
  733. lastDamagedByPlayer = i;
  734. break;
  735. }
  736. }
  737. }
  738. packetWriter.Write(lastDamagedByPlayer);
  739. localNetworkGamer.SendData(packetWriter,
  740. SendDataOptions.ReliableInOrder);
  741. }
  742. }
  743. }
  744. #endregion
  745. #region Packet Handling Methods
  746. /// <summary>
  747. /// Process incoming packets on the local gamer.
  748. /// </summary>
  749. private void ProcessPackets()
  750. {
  751. if ((networkSession != null) && (networkSession.LocalGamers.Count > 0))
  752. {
  753. // process all packets found, every frame
  754. while (networkSession.LocalGamers[0].IsDataAvailable)
  755. {
  756. NetworkGamer sender;
  757. networkSession.LocalGamers[0].ReceiveData(packetReader, out sender);
  758. // read the type of packet...
  759. PacketTypes packetType = (PacketTypes)packetReader.ReadInt32();
  760. // ... and dispatch appropriately
  761. switch (packetType)
  762. {
  763. case PacketTypes.PlayerData:
  764. UpdatePlayerData(sender);
  765. break;
  766. case PacketTypes.WorldSetup:
  767. // apply the world setup data, but only once
  768. if (!Initialized)
  769. {
  770. Initialize();
  771. }
  772. break;
  773. case PacketTypes.ShipData:
  774. if ((sender != null) && !sender.IsLocal)
  775. {
  776. UpdateShipData(sender);
  777. }
  778. break;
  779. case PacketTypes.WorldData:
  780. if (!networkSession.IsHost && Initialized)
  781. {
  782. UpdateWorldData();
  783. }
  784. break;
  785. case PacketTypes.ShipInput:
  786. if (sender != null)
  787. {
  788. PlayerData playerData = sender.Tag as PlayerData;
  789. if ((playerData != null) && (playerData.Ship != null))
  790. {
  791. playerData.Ship.ShipInput =
  792. new ShipInput(packetReader);
  793. }
  794. }
  795. break;
  796. case PacketTypes.ShipSpawn:
  797. SpawnShip();
  798. break;
  799. case PacketTypes.PowerUpSpawn:
  800. SpawnPowerup();
  801. break;
  802. case PacketTypes.ShipDeath:
  803. KillShip(sender);
  804. break;
  805. case PacketTypes.GameWon:
  806. gameWon = true;
  807. winnerIndex = packetReader.ReadInt32();
  808. if (networkSession.IsHost && (networkSession.SessionState ==
  809. NetworkSessionState.Playing))
  810. {
  811. networkSession.EndGame();
  812. }
  813. break;
  814. }
  815. }
  816. }
  817. }
  818. /// <summary>
  819. /// Spawn a ship based on the data in the packet.
  820. /// </summary>
  821. private void SpawnShip()
  822. {
  823. int whichGamer = packetReader.ReadInt32();
  824. if (whichGamer < networkSession.AllGamers.Count)
  825. {
  826. NetworkGamer networkGamer = networkSession.AllGamers[whichGamer];
  827. PlayerData playerData = networkGamer.Tag as PlayerData;
  828. if ((playerData != null) && (playerData.Ship != null))
  829. {
  830. playerData.Ship.Position = packetReader.ReadVector2();
  831. playerData.Ship.Initialize();
  832. }
  833. }
  834. }
  835. /// <summary>
  836. /// Spawn a power-up based on the data in the packet.
  837. /// </summary>
  838. private void SpawnPowerup()
  839. {
  840. int whichPowerUp = packetReader.ReadInt32();
  841. if (powerUp == null)
  842. {
  843. switch (whichPowerUp)
  844. {
  845. case 0:
  846. powerUp = new DoubleLaserPowerUp();
  847. break;
  848. case 1:
  849. powerUp = new TripleLaserPowerUp();
  850. break;
  851. case 2:
  852. powerUp = new RocketPowerUp();
  853. break;
  854. }
  855. }
  856. if (powerUp != null)
  857. {
  858. powerUp.Position = packetReader.ReadVector2();
  859. powerUp.Initialize();
  860. }
  861. }
  862. /// <summary>
  863. /// Kill the sender's ship based on data in the packet.
  864. /// </summary>
  865. /// <param name="sender">The sender of the packet.</param>
  866. private void KillShip(NetworkGamer sender)
  867. {
  868. if (sender != null)
  869. {
  870. PlayerData playerData = sender.Tag as PlayerData;
  871. if ((playerData != null) && (playerData.Ship != null) &&
  872. playerData.Ship.Active)
  873. {
  874. GameplayObject source = null;
  875. // read the index of the source of the last damage taken
  876. int sourcePlayerIndex = packetReader.ReadInt32();
  877. if ((sourcePlayerIndex >= 0) &&
  878. (sourcePlayerIndex < networkSession.AllGamers.Count))
  879. {
  880. PlayerData sourcePlayerData =
  881. networkSession.AllGamers[sourcePlayerIndex].Tag
  882. as PlayerData;
  883. source = sourcePlayerData != null ? sourcePlayerData.Ship :
  884. null;
  885. }
  886. // kill the ship
  887. playerData.Ship.Die(source, false);
  888. }
  889. }
  890. }
  891. /// <summary>
  892. /// Update the player data for the sender based on the data in the packet.
  893. /// </summary>
  894. /// <param name="sender">The sender of the packet.</param>
  895. private void UpdatePlayerData(NetworkGamer sender)
  896. {
  897. if ((networkSession != null) && (networkSession.LocalGamers.Count > 0) &&
  898. (sender != null))
  899. {
  900. PlayerData playerData = sender.Tag as PlayerData;
  901. if (playerData != null)
  902. {
  903. playerData.Deserialize(packetReader);
  904. // see if we're still unique
  905. // -- this can happen legitimately as we receive introductory data
  906. foreach (LocalNetworkGamer localNetworkGamer in
  907. networkSession.LocalGamers)
  908. {
  909. PlayerData localPlayerData =
  910. localNetworkGamer.Tag as PlayerData;
  911. if ((localPlayerData != null) &&
  912. !Ship.HasUniqueColorIndex(localNetworkGamer,
  913. networkSession))
  914. {
  915. localPlayerData.ShipColor = Ship.GetNextUniqueColorIndex(
  916. localPlayerData.ShipColor, networkSession);
  917. packetWriter.Write((int)World.PacketTypes.PlayerData);
  918. localPlayerData.Serialize(packetWriter);
  919. networkSession.LocalGamers[0].SendData(packetWriter,
  920. SendDataOptions.ReliableInOrder);
  921. }
  922. }
  923. }
  924. }
  925. }
  926. /// <summary>
  927. /// Update ship state based on the data in the packet.
  928. /// </summary>
  929. /// <param name="sender">The sender of the packet.</param>
  930. private void UpdateShipData(NetworkGamer sender)
  931. {
  932. if (sender != null)
  933. {
  934. PlayerData playerData = sender.Tag as PlayerData;
  935. if ((playerData != null) && (playerData.Ship != null))
  936. {
  937. playerData.Ship.Position = packetReader.ReadVector2();
  938. playerData.Ship.Velocity = packetReader.ReadVector2();
  939. playerData.Ship.Rotation = packetReader.ReadSingle();
  940. playerData.Ship.Life = packetReader.ReadSingle();
  941. playerData.Ship.Shield = packetReader.ReadSingle();
  942. playerData.Ship.Score = packetReader.ReadInt32();
  943. }
  944. }
  945. }
  946. /// <summary>
  947. /// Update the world data based on the data in the packet.
  948. /// </summary>
  949. private void UpdateWorldData()
  950. {
  951. // safety-check the parameters, as they must be valid
  952. if (packetReader == null)
  953. {
  954. throw new ArgumentNullException("packetReader");
  955. }
  956. for (int i = 0; i < asteroids.Length; i++)
  957. {
  958. asteroids[i].Position = packetReader.ReadVector2();
  959. asteroids[i].Velocity = packetReader.ReadVector2();
  960. }
  961. }
  962. #endregion
  963. #region Drawing Methods
  964. /// <summary>
  965. /// Draws the objects in the world.
  966. /// </summary>
  967. /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
  968. /// <param name="center">The center of the current view.</param>
  969. public void Draw(float elapsedTime, Vector2 center)
  970. {
  971. Matrix transform = Matrix.CreateTranslation(
  972. new Vector3(-center.X, -center.Y, 0f));
  973. spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,
  974. null, null, null, null, transform);
  975. // draw the barriers
  976. foreach (Rectangle rectangle in cornerBarriers)
  977. {
  978. spriteBatch.Draw(cornerBarrierTexture, rectangle, Color.White);
  979. }
  980. foreach (Rectangle rectangle in verticalBarriers)
  981. {
  982. spriteBatch.Draw(verticalBarrierTexture, rectangle, Color.White);
  983. }
  984. foreach (Rectangle rectangle in horizontalBarriers)
  985. {
  986. spriteBatch.Draw(horizontalBarrierTexture, rectangle, Color.White);
  987. }
  988. // draw the asteroids
  989. foreach (Asteroid asteroid in asteroids)
  990. {
  991. if (asteroid.Active)
  992. {
  993. asteroid.Draw(elapsedTime, spriteBatch);
  994. }
  995. }
  996. // draw the powerup
  997. if ((powerUp != null) && powerUp.Active)
  998. {
  999. powerUp.Draw(elapsedTime, spriteBatch);
  1000. }
  1001. // draw the ships
  1002. foreach (NetworkGamer networkGamer in networkSession.AllGamers)
  1003. {
  1004. PlayerData playerData = networkGamer.Tag as PlayerData;
  1005. if ((playerData != null) && (playerData.Ship != null) &&
  1006. playerData.Ship.Active)
  1007. {
  1008. playerData.Ship.Draw(elapsedTime, spriteBatch);
  1009. }
  1010. }
  1011. // draw the alpha-blended particles
  1012. particleEffectManager.Draw(spriteBatch, SpriteBlendMode.AlphaBlend);
  1013. spriteBatch.End();
  1014. // draw the additive particles
  1015. spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive,
  1016. null, null, null, null, transform);
  1017. particleEffectManager.Draw(spriteBatch, SpriteBlendMode.Additive);
  1018. spriteBatch.End();
  1019. }
  1020. /// <summary>
  1021. /// Draw the specified player's data in the screen - gamertag, etc.
  1022. /// </summary>
  1023. /// <param name="totalTime">The total time spent in the game.</param>
  1024. /// <param name="networkGamer">The player to be drawn.</param>
  1025. /// <param name="position">The center of the desired location.</param>
  1026. /// <param name="spriteBatch">The SpriteBatch object used to draw.</param>
  1027. /// <param name="lobby">If true, drawn "lobby style"</param>
  1028. public void DrawPlayerData(float totalTime, NetworkGamer networkGamer,
  1029. Vector2 position, SpriteBatch spriteBatch, bool lobby)
  1030. {
  1031. // safety-check the parameters, as they must be valid
  1032. if (networkGamer == null)
  1033. {
  1034. throw new ArgumentNullException("networkGamer");
  1035. }
  1036. if (spriteBatch == null)
  1037. {
  1038. throw new ArgumentNullException("spriteBatch");
  1039. }
  1040. // get the player data
  1041. PlayerData playerData = networkGamer.Tag as PlayerData;
  1042. if (playerData == null)
  1043. {
  1044. return;
  1045. }
  1046. // draw the gamertag
  1047. float playerStringScale = 1.0f;
  1048. if (networkGamer.IsLocal)
  1049. {
  1050. // pulse the scale of local gamers
  1051. playerStringScale = 1f + 0.08f * (1f + (float)Math.Sin(totalTime * 4f));
  1052. }
  1053. string playerString = networkGamer.Gamertag;
  1054. Color playerColor = playerData.Ship == null ?
  1055. Ship.ShipColors[playerData.ShipColor] : playerData.Ship.Color;
  1056. Vector2 playerStringSize = playerFont.MeasureString(playerString);
  1057. Vector2 playerStringPosition = position;
  1058. spriteBatch.DrawString(playerFont, playerString, playerStringPosition,
  1059. playerColor, 0f,
  1060. new Vector2(playerStringSize.X / 2f, playerStringSize.Y / 2f),
  1061. playerStringScale, SpriteEffects.None, 0f);
  1062. // draw the chat texture
  1063. Texture2D chatTexture = null;
  1064. if (networkGamer.IsMutedByLocalUser)
  1065. {
  1066. chatTexture = chatMuteTexture;
  1067. }
  1068. else if (networkGamer.IsTalking)
  1069. {
  1070. chatTexture = chatTalkingTexture;
  1071. }
  1072. else if (networkGamer.HasVoice)
  1073. {
  1074. chatTexture = chatAbleTexture;
  1075. }
  1076. if (chatTexture != null)
  1077. {
  1078. float chatTextureScale = 0.9f * playerStringSize.Y /
  1079. (float)chatTexture.Height;
  1080. Vector2 chatTexturePosition = new Vector2(playerStringPosition.X -
  1081. 1.2f * playerStringSize.X / 2f -
  1082. 1.1f * chatTextureScale * (float)chatTexture.Width / 2f,
  1083. playerStringPosition.Y);
  1084. spriteBatch.Draw(chatTexture, chatTexturePosition, null,
  1085. Color.White, 0f, new Vector2((float)chatTexture.Width / 2f,
  1086. (float)chatTexture.Height / 2f), chatTextureScale,
  1087. SpriteEffects.None, 0f);
  1088. }
  1089. // if we're in "lobby mode", draw a sample version of the ship,
  1090. // and the ready texture
  1091. if (lobby)
  1092. {
  1093. // draw the ship
  1094. if (playerData.Ship != null)
  1095. {
  1096. float oldShipShield = playerData.Ship.Shield;
  1097. float oldShipRadius = playerData.Ship.Radius;
  1098. Vector2 oldShipPosition = playerData.Ship.Position;
  1099. float oldShipRotation = playerData.Ship.Rotation;
  1100. playerData.Ship.Shield = 0f;
  1101. playerData.Ship.Radius = 0.6f * (float)playerStringSize.Y;
  1102. playerData.Ship.Position = new Vector2(playerStringPosition.X +
  1103. 1.2f * playerStringSize.X / 2f + 1.1f * playerData.Ship.Radius,
  1104. playerStringPosition.Y);
  1105. playerData.Ship.Rotation = 0f;
  1106. playerData.Ship.Draw(0f, spriteBatch);
  1107. playerData.Ship.Rotation = oldShipRotation;
  1108. playerData.Ship.Position = oldShipPosition;
  1109. playerData.Ship.Shield = oldShipShield;
  1110. playerData.Ship.Radius = oldShipRadius;
  1111. }
  1112. // draw the ready texture
  1113. if ((readyTexture != null) && networkGamer.IsReady)
  1114. {
  1115. float readyTextureScale = 0.9f * playerStringSize.Y /
  1116. (float)readyTexture.Height;
  1117. Vector2 readyTexturePosition = new Vector2(playerStringPosition.X +
  1118. 1.2f * playerStringSize.X / 2f +
  1119. 2.2f * playerData.Ship.Radius +
  1120. 1.1f * readyTextureScale * (float)readyTexture.Width / 2f,
  1121. playerStringPosition.Y);
  1122. spriteBatch.Draw(readyTexture, readyTexturePosition, null,
  1123. Color.White, 0f, new Vector2((float)readyTexture.Width / 2f,
  1124. (float)readyTexture.Height / 2f), readyTextureScale,
  1125. SpriteEffects.None, 0f);
  1126. }
  1127. }
  1128. else
  1129. {
  1130. // if we're not in "lobby mode", draw the score
  1131. if (playerData.Ship != null)
  1132. {
  1133. string scoreString = String.Empty;
  1134. if (playerData.Ship.Active)
  1135. {
  1136. scoreString = playerData.Ship.Score.ToString();
  1137. }
  1138. else
  1139. {
  1140. int respawnTimer =
  1141. (int)Math.Ceiling(playerData.Ship.RespawnTimer);
  1142. scoreString = "Respawning in: " + respawnTimer.ToString();
  1143. }
  1144. Vector2 scoreStringSize = playerFont.MeasureString(scoreString);
  1145. Vector2 scoreStringPosition = new Vector2(position.X,
  1146. position.Y + 0.9f * playerStringSize.Y);
  1147. spriteBatch.DrawString(playerFont, scoreString, scoreStringPosition,
  1148. playerColor, 0f, new Vector2(scoreStringSize.X / 2f,
  1149. scoreStringSize.Y / 2f), 1f, SpriteEffects.None, 0f);
  1150. }
  1151. }
  1152. }
  1153. #endregion
  1154. #region IDisposable Implementation
  1155. /// <summary>
  1156. /// Finalizes the World object, calls Dispose(false)
  1157. /// </summary>
  1158. ~World()
  1159. {
  1160. Dispose(false);
  1161. }
  1162. /// <summary>
  1163. /// Disposes the World object.
  1164. /// </summary>
  1165. public void Dispose()
  1166. {
  1167. Dispose(true);
  1168. GC.SuppressFinalize(this);
  1169. }
  1170. /// <summary>
  1171. /// Disposes this object.
  1172. /// </summary>
  1173. /// <param name="disposing">
  1174. /// True if this method was called as part of the Dispose method.
  1175. /// </param>
  1176. protected virtual void Dispose(bool disposing)
  1177. {
  1178. if (disposing)
  1179. {
  1180. lock (this)
  1181. {
  1182. if (packetReader != null)
  1183. {
  1184. packetReader.Close();
  1185. packetReader = null;
  1186. }
  1187. if (packetWriter != null)
  1188. {
  1189. packetWriter.Close();
  1190. packetWriter = null;
  1191. }
  1192. if (spriteBatch != null)
  1193. {
  1194. spriteBatch.Dispose();
  1195. spriteBatch = null;
  1196. }
  1197. cornerBarrierTexture = null;
  1198. verticalBarrierTexture = null;
  1199. horizontalBarrierTexture = null;
  1200. Ship.UnloadContent();
  1201. Asteroid.UnloadContent();
  1202. LaserProjectile.UnloadContent();
  1203. MineProjectile.UnloadContent();
  1204. RocketProjectile.UnloadContent();
  1205. DoubleLaserPowerUp.UnloadContent();
  1206. TripleLaserPowerUp.UnloadContent();
  1207. Ship.ParticleEffectManager = null;
  1208. RocketProjectile.ParticleEffectManager = null;
  1209. MineProjectile.ParticleEffectManager = null;
  1210. LaserProjectile.ParticleEffectManager = null;
  1211. particleEffectManager.UnregisterParticleEffect(
  1212. ParticleEffectType.MineExplosion);
  1213. particleEffectManager.UnregisterParticleEffect(
  1214. ParticleEffectType.RocketExplosion);
  1215. particleEffectManager.UnregisterParticleEffect(
  1216. ParticleEffectType.RocketTrail);
  1217. particleEffectManager.UnregisterParticleEffect(
  1218. ParticleEffectType.ShipExplosion);
  1219. particleEffectManager.UnregisterParticleEffect(
  1220. ParticleEffectType.ShipSpawn);
  1221. }
  1222. }
  1223. }
  1224. #endregion
  1225. }
  1226. }