World.cs 53 KB

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