Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Graphics;
  8. using Microsoft.Xna.Framework.Input;
  9. using XRpgLibrary.Controls;
  10.  
  11. using XRpgLibrary.AI;
  12.  
  13. //temporary until image is added to entity
  14. using Microsoft.Xna.Framework.Content;
  15. using XRpgLibrary.SpriteClasses;
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. namespace XRpgLibrary.CharacterClasses
  25. {
  26. public class Enemy
  27. {
  28. static public bool wobblyTest = true;
  29.  
  30.  
  31. Matrix worldMatrix;
  32. Matrix projectionMatrix;
  33.  
  34. BasicEffect basicEffect;
  35. VertexDeclaration vertexDeclaration;
  36. VertexBuffer vertexBuffer;
  37.  
  38. /*
  39. BasicEffect shadowBasicEffect;
  40. VertexDeclaration shadowVertexDeclaration;
  41. VertexBuffer shadowVertexBuffer;
  42.  
  43. int points = 4; //8
  44. //Texture2D texture;
  45. */
  46. enum PrimType
  47. {
  48. LineList,
  49. LineStrip,
  50. TriangleList,
  51. TriangleStrip
  52. };
  53.  
  54.  
  55. public enum Tilt
  56. {
  57. None,
  58. TiltForward,
  59. TiltForwardReverse,
  60. TiltBackward,
  61. TiltBackwardReverse,
  62. WobblyForward,
  63. WobblyForwardReverse,
  64. WobblyBackward,
  65. WobblyBackwardReverse,
  66. SideStepBackward,
  67. SideStepForward,
  68. Fall,
  69. Rise,
  70. SpinTo90,
  71. SpinTo180,
  72. SpinTo270,
  73. SpinTo360,
  74. FlyAwayTo90,
  75. FlyAwayTo180,
  76. FlyAwayTo270,
  77. FlyAwayTo360,
  78. SparkleTo90,
  79. SparkleTo180,
  80. SparkleTo270,
  81. SparkleTo360,
  82. HopUp1,
  83. HopDown1,
  84. HopUp2,
  85. HopDown2
  86.  
  87.  
  88.  
  89. }
  90.  
  91. //status hit
  92. public bool statusHitOn = false;
  93. public bool statusHitTurnOn = false;
  94. public string statusHit;
  95. public float statusHitInterval;
  96. public Vector2 statusHitPosition = new Vector2(0, 0);
  97.  
  98.  
  99. bool setPoints = false;
  100.  
  101. public Tilt currentTilt = Tilt.None;
  102.  
  103. //*public short[] edgeFaceList;
  104. public ushort[] edgeFaceList;
  105. public short[] shadowEdgeFaceList;
  106. private IndexBuffer indexBuffer;
  107. private IndexBuffer shadowIndexBuffer;
  108. VertexPositionColorTexture[] gpuVertices;
  109. VertexPositionColorTexture[] shadowVertices;
  110. Vector2[] startVertices;
  111. RasterizerState rasterizerState;
  112.  
  113. GraphicsDevice graphics;
  114. GraphicsDevice shadowGraphics;
  115.  
  116. Matrix viewMatrix = Matrix.CreateLookAt(
  117. new Vector3(0.0f, 0.0f, 1.0f),
  118. Vector3.Zero,
  119. Vector3.Up
  120. );
  121.  
  122.  
  123.  
  124. //Settings
  125. int tiltForwardFrames = 5;
  126. int tiltBackFrames = 4;
  127. int backFrames = 9;
  128. int spinFrames = 4;
  129. int tiltSpeed = 20;
  130. int riseSpeed = 20;
  131. int spinSpeed = 20;
  132. int bits = 8;
  133.  
  134. int screenWidth = 398;
  135. int screenHeight = 224;
  136.  
  137.  
  138. public bool powerSliverFlash = false;
  139.  
  140. float powerSliverWait = 0f;
  141.  
  142. TimeSpan transitionTimer = TimeSpan.FromSeconds(0.4);
  143. TimeSpan flyAwayTimer = TimeSpan.Zero;
  144. TimeSpan hopTimer = TimeSpan.Zero;
  145. public static TimeSpan flyAwayTime = TimeSpan.FromSeconds(.75);
  146. TimeSpan sparkleTimer = TimeSpan.Zero;
  147. public static TimeSpan sparkleTime = TimeSpan.FromSeconds(3.0); //4.0
  148. TimeSpan sideStepInterval = TimeSpan.FromSeconds(0.2); //0.2
  149.  
  150. TimeSpan tiltForwardInterval = TimeSpan.FromSeconds(0.4); //0.2
  151. TimeSpan tiltSpinInterval = TimeSpan.FromSeconds(0.05); //0.05
  152. TimeSpan sparkleSpinInterval = TimeSpan.FromSeconds(0.2); //0.05
  153. TimeSpan tiltWobblyInterval = TimeSpan.FromSeconds(0.4); //0.2
  154. public TimeSpan tiltFallInterval = TimeSpan.FromSeconds(1.0); //0.5
  155. public TimeSpan Interval;
  156.  
  157. float dipfactor = 4f;//4f;
  158. float sparkleStartSize = .2f;
  159. float maxSparkleWidth = 5f;
  160.  
  161. float spinDip = 5f;
  162.  
  163. public Entity[] targetedBy = new Entity[4];
  164. public bool[] hasFocus = new bool[4];
  165. public string[] playerAction = new string[4];
  166.  
  167. public Color Glow = Color.White;
  168.  
  169. Texture2D texture;
  170.  
  171. public bool TakingAction = false;
  172. public bool TakingReaction = false;
  173.  
  174. public static int flyAwayHeight = 100;
  175.  
  176. public static float hopHeight = .10f;//.25;
  177. TimeSpan hopInterval = TimeSpan.FromSeconds(0.12); //0.2
  178.  
  179. int sparkleAwayHeight = 200;
  180. public static int sparkleOffset = 70;
  181.  
  182. public bool Visible = true;
  183.  
  184. int mAlphaValue = 1;
  185. int mFadeIncrement = 3;
  186. double maxFadeDelay = .005; //.035
  187. double mFadeDelay = .000; //for some reason the source code sets this to the same as maxFadeDelay
  188.  
  189. bool TiltFinished = false;
  190.  
  191. float hitDelay = 0f;
  192. Texture2D image;
  193.  
  194. public Shadow shadow;
  195. protected Entity entity;
  196.  
  197. public AnimatedSprite sprite;
  198.  
  199. private Vector2 position;
  200.  
  201. public int positionZ;
  202.  
  203. public Vector2 Position
  204. {
  205. get { return position; }
  206. }
  207.  
  208. public Entity Entity
  209. {
  210. get { return entity; }
  211. }
  212.  
  213. public int Width
  214. {
  215. get { return entity.Width*bits; }
  216. }
  217.  
  218. public int Height
  219. {
  220. get { return entity.Height*bits; }
  221. }
  222.  
  223. public Vector2 Origin
  224. {
  225.  
  226. get { return new Vector2(Position.X + (Width / 2), Position.Y + (Height / 2)); }
  227. }
  228.  
  229. public Enemy(Entity Entity, int PositionX, int PositionY, int PositionZ, GraphicsDevice Graphics)
  230. {
  231. graphics = Graphics;
  232.  
  233. entity = Entity;
  234. image = entity.Sprite;
  235. //I subtracted 10 here to compensate for writing the reaciton stance //and now I took out the minus 10
  236. position = new Vector2(PositionX, PositionY);//-10);
  237.  
  238. positionZ = PositionZ;
  239.  
  240. Initialize();
  241.  
  242. shadow = new Shadow(Entity, Graphics, gpuVertices);
  243.  
  244. currentTilt = Tilt.Rise;
  245.  
  246. transitionTimer = new TimeSpan(tiltFallInterval.Ticks /3 );
  247.  
  248. TiltFinished = false;
  249.  
  250. for (int i = 0; i < targetedBy.Count(); i++)
  251. targetedBy[i] = null;
  252. }
  253.  
  254. public void MakeEnemyNormal()
  255. {
  256.  
  257. currentTilt = Tilt.None;
  258. Entity.PowerPoints.SetCurrent(0);
  259. Visible = true;
  260. transitionTimer = TimeSpan.Zero;
  261. TiltFinished = true;
  262.  
  263. ResetPosition();
  264. }
  265.  
  266.  
  267. private void Initialize()
  268. {
  269. InitializeTransform();
  270. InitializeEffect();
  271. InitializePoints();
  272. InitializeTriangleStrip();
  273.  
  274. rasterizerState = new RasterizerState();
  275. rasterizerState.CullMode = CullMode.None;
  276. }
  277.  
  278. private void InitializeEffect()
  279. {
  280.  
  281. vertexDeclaration = new VertexDeclaration(new VertexElement[]
  282. {
  283. new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
  284. new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0),
  285. new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
  286. }
  287. );
  288.  
  289. basicEffect = new BasicEffect(graphics);
  290. basicEffect.VertexColorEnabled = true;
  291.  
  292.  
  293. worldMatrix = Matrix.CreateTranslation(screenWidth / 2f,
  294. screenHeight / 2f, 0);
  295. basicEffect.World = worldMatrix;
  296. basicEffect.View = viewMatrix;
  297. basicEffect.Projection = projectionMatrix;
  298.  
  299. }
  300.  
  301.  
  302.  
  303. private void InitializeTransform()
  304. {
  305.  
  306. viewMatrix = Matrix.CreateLookAt(
  307. new Vector3(0.0f, 0.0f, 1.0f),
  308. Vector3.Zero,
  309. Vector3.Up
  310. );
  311.  
  312. projectionMatrix = Matrix.CreateOrthographicOffCenter(
  313. 0,
  314. screenWidth,
  315. screenHeight,
  316. 0,
  317. 1.0f, 1000.0f);
  318. }
  319.  
  320.  
  321.  
  322. private void InitializePoints()
  323. {
  324.  
  325. gpuVertices = new VertexPositionColorTexture[4];
  326.  
  327.  
  328. startVertices = new Vector2[4];
  329.  
  330. startVertices[0] = new Vector2(Position.X - (screenWidth / 2), Position.Y - (screenHeight / 2));
  331. gpuVertices[0].Color = Color.White;
  332. gpuVertices[0].TextureCoordinate = new Vector2((float)(entity.startingX * bits) / (float)image.Width, (float)(entity.startingY * bits) / (float)image.Height);
  333.  
  334. startVertices[1] = new Vector2(Position.X + entity.Width*bits - (screenWidth / 2), Position.Y - (screenHeight / 2));
  335. gpuVertices[1].Color = Color.White;
  336. gpuVertices[1].TextureCoordinate = new Vector2((float)(entity.startingX * bits + entity.Width * bits) / (float)image.Width, (float)(entity.startingY * bits) / (float)image.Height);
  337.  
  338. startVertices[2] = new Vector2(Position.X - (screenWidth / 2), Position.Y + entity.Height*bits - (screenHeight / 2f));
  339. gpuVertices[2].Color = Color.White;
  340. gpuVertices[2].TextureCoordinate = new Vector2((float)(entity.startingX * bits) / (float)image.Width, (float)(entity.startingY * bits + entity.Height * bits) / (float)image.Height);
  341.  
  342. startVertices[3] = new Vector2(Position.X + entity.Width*bits - (screenWidth / 2), Position.Y + entity.Height*bits - (screenHeight / 2f));
  343. gpuVertices[3].Color = Color.White;
  344. gpuVertices[3].TextureCoordinate = new Vector2((float)(entity.startingX * bits + entity.Width * bits) / (float)image.Width, (float)(entity.startingY * bits + entity.Height * bits) / (float)image.Height);
  345.  
  346. gpuVertices[0].Position.X = startVertices[0].X + (((float)entity.Width * (float)bits / 3f));
  347. gpuVertices[1].Position.X = startVertices[1].X + (((float)-entity.Width * (float)bits / 3f));
  348. gpuVertices[2].Position.X = startVertices[2].X;
  349. gpuVertices[3].Position.X = startVertices[3].X;
  350.  
  351. gpuVertices[0].Position.Y =startVertices[0].Y +(float)(entity.Height * bits);
  352. gpuVertices[1].Position.Y = gpuVertices[0].Position.Y;
  353. gpuVertices[2].Position.Y = startVertices[2].Y;
  354. gpuVertices[3].Position.Y = startVertices[3].Y;
  355.  
  356. gpuVertices[0].Position.Z = 0;
  357. gpuVertices[1].Position.Z = 0;
  358. gpuVertices[2].Position.Z = 0;
  359. gpuVertices[3].Position.Z = 0;
  360.  
  361.  
  362.  
  363. vertexBuffer = new DynamicVertexBuffer(graphics, typeof(VertexPositionColorTexture), gpuVertices.Length, BufferUsage.WriteOnly);
  364. vertexBuffer.SetData(0, gpuVertices, 0, gpuVertices.Length, 0);
  365.  
  366.  
  367.  
  368.  
  369. }
  370.  
  371.  
  372. private void InitializeTriangleStrip()
  373. {
  374.  
  375.  
  376. //edgeFaceList = new short[6];
  377. edgeFaceList = new ushort[6];
  378. edgeFaceList[0] = 0; // where 0 is the vertex 0 in your vertex array
  379. edgeFaceList[1] = 1; // 1 is vertex 1
  380. edgeFaceList[2] = 2; // 2 is vertex 2 , so 1 triangle is formed using vertices 0,1 and 2
  381.  
  382. edgeFaceList[3] = 1; // so for the 2nd triangle you will use vertex 0
  383. edgeFaceList[4] = 2; // vertex 2
  384. edgeFaceList[5] = 3; // and finally vertex 3, so the 2nd triangle is vertex 0,2 and 3.
  385.  
  386. //* indexBuffer = new DynamicIndexBuffer(graphics, typeof(short), edgeFaceList.Length, BufferUsage.WriteOnly); // indices;
  387. indexBuffer = new DynamicIndexBuffer(graphics, IndexElementSize.SixteenBits, edgeFaceList.Length, BufferUsage.WriteOnly); // indices;
  388.  
  389.  
  390. indexBuffer.SetData(edgeFaceList);
  391.  
  392.  
  393. }
  394.  
  395. public void ResetPosition()
  396. {
  397. gpuVertices[0].Position.X = startVertices[0].X;
  398. gpuVertices[1].Position.X = startVertices[1].X;
  399. gpuVertices[2].Position.X = startVertices[2].X;
  400. gpuVertices[3].Position.X = startVertices[3].X;
  401.  
  402. gpuVertices[0].Position.Y = startVertices[0].Y;
  403. gpuVertices[1].Position.Y = startVertices[1].Y;
  404. gpuVertices[2].Position.Y = startVertices[2].Y;
  405. gpuVertices[3].Position.Y = startVertices[3].Y;
  406.  
  407. }
  408.  
  409. public void Update(GameTime gameTime)
  410. {
  411. if(Entity.chargingAction != null && Entity.chargingAction.name != "Nothing")
  412. UpdatePowerSliver(gameTime);
  413.  
  414.  
  415. if (hitDelay > 0)
  416. {
  417. hitDelay -= (float)gameTime.ElapsedGameTime.TotalSeconds;
  418.  
  419. return;
  420. }
  421.  
  422.  
  423.  
  424. if (TiltFinished && currentTilt != Tilt.None)
  425. {
  426. switch (currentTilt)
  427. {
  428. case Tilt.Rise:
  429. TiltFinished = false;
  430. dipfactor = 10f;
  431. Interval = TimeSpan.FromSeconds(0.2);
  432. currentTilt = Tilt.TiltForward;
  433. break;
  434. case Tilt.TiltBackward:
  435. TiltFinished = false;
  436. currentTilt = Tilt.TiltBackwardReverse;
  437. break;
  438. case Tilt.TiltBackwardReverse:
  439. if (entity.Wobbly())
  440. {
  441. TiltFinished = false;
  442. currentTilt = Tilt.WobblyForward;
  443. }
  444. else
  445. {
  446. TiltFinished = false;
  447. currentTilt = Tilt.TiltForward;
  448. }
  449. break;
  450. case Tilt.TiltForward:
  451. TiltFinished = false;
  452. currentTilt = Tilt.TiltForwardReverse;
  453. break;
  454. case Tilt.SideStepBackward:
  455. TiltFinished = false;
  456. currentTilt = Tilt.SideStepForward;
  457. break;
  458. case Tilt.SideStepForward:
  459. if (entity.Wobbly())
  460. {
  461. TiltFinished = false;
  462. currentTilt = Tilt.WobblyBackward;
  463. }
  464. else
  465. {
  466. TiltFinished = true;
  467. currentTilt = Tilt.None;
  468. }
  469. break;
  470. case Tilt.TiltForwardReverse:
  471. if (entity.IsAlive)
  472. {
  473. if (entity.Wobbly())
  474. {
  475. TiltFinished = false;
  476. currentTilt = Tilt.WobblyBackward;
  477. }
  478. else
  479. {
  480. TiltFinished = true;
  481. currentTilt = Tilt.None;
  482. }
  483. }
  484. else
  485. {
  486. TiltFinished = false;
  487. currentTilt = Tilt.Fall;
  488. }
  489. break;
  490. case Tilt.WobblyForward:
  491. TiltFinished = false;
  492. currentTilt = Tilt.WobblyForwardReverse;
  493. break;
  494. case Tilt.WobblyForwardReverse:
  495. if (entity.Wobbly())
  496. {
  497. TiltFinished = false;
  498. currentTilt = Tilt.WobblyBackward;
  499. }
  500. else
  501. {
  502. TiltFinished = true;
  503. currentTilt = Tilt.None;
  504.  
  505. }
  506. break;
  507. case Tilt.WobblyBackward:
  508. TiltFinished = false;
  509. currentTilt = Tilt.WobblyBackwardReverse;
  510. break;
  511. case Tilt.WobblyBackwardReverse:
  512. if (entity.Wobbly())
  513. {
  514. TiltFinished = false;
  515. currentTilt = Tilt.WobblyForward;
  516. }
  517. else
  518. {
  519. TiltFinished = true;
  520. currentTilt = Tilt.None;
  521. }
  522. break;
  523. case Tilt.SpinTo90:
  524. TiltFinished = false;
  525. currentTilt = Tilt.SpinTo180;
  526. Interval = SpinTimerIncrease();
  527. break;
  528. case Tilt.SpinTo180:
  529. TiltFinished = false;
  530. currentTilt = Tilt.SpinTo270;
  531. Interval = SpinTimerIncrease();
  532. break;
  533. case Tilt.SpinTo270:
  534. TiltFinished = false;
  535. currentTilt = Tilt.SpinTo360;
  536. Interval = SpinTimerIncrease();
  537. break;
  538. case Tilt.SpinTo360:
  539. TiltFinished = false;
  540. if (Interval >= TimeSpan.FromSeconds(.4))
  541. {
  542. currentTilt = Tilt.None;
  543. if (entity.Wobbly())
  544. {
  545. TiltFinished = false;
  546. currentTilt = Tilt.WobblyBackward;
  547. }
  548. else
  549. {
  550. TiltFinished = true;
  551. currentTilt = Tilt.None;
  552. }
  553. }
  554. else
  555. {
  556. currentTilt = Tilt.SpinTo90;
  557. Interval = SpinTimerIncrease();
  558. }
  559. break;
  560. case Tilt.FlyAwayTo90:
  561. TiltFinished = false;
  562. currentTilt = Tilt.FlyAwayTo180;
  563. break;
  564. case Tilt.FlyAwayTo180:
  565. TiltFinished = false;
  566. currentTilt = Tilt.FlyAwayTo270;
  567. break;
  568. case Tilt.FlyAwayTo270:
  569. TiltFinished = false;
  570. currentTilt = Tilt.FlyAwayTo360;
  571. break;
  572. case Tilt.FlyAwayTo360:
  573. TiltFinished = false;
  574. if (flyAwayTimer >= flyAwayTime)
  575. {
  576. sparkleTimer = TimeSpan.Zero;
  577. Interval = sparkleSpinInterval;
  578. currentTilt = Tilt.SparkleTo90;
  579. sparkleAwayHeight = GetSparkleAwayHeight(flyAwayHeight);
  580. positionZ = 100;
  581. }
  582. else
  583. {
  584. currentTilt = Tilt.FlyAwayTo90;
  585. }
  586. break;
  587. case Tilt.SparkleTo90:
  588. TiltFinished = false;
  589. currentTilt = Tilt.SparkleTo180;
  590. break;
  591. case Tilt.SparkleTo180:
  592. TiltFinished = false;
  593. currentTilt = Tilt.SparkleTo270;
  594. break;
  595. case Tilt.SparkleTo270:
  596. TiltFinished = false;
  597. currentTilt = Tilt.SparkleTo360;
  598. break;
  599. case Tilt.SparkleTo360:
  600. if (sparkleTimer >= sparkleTime)
  601. {
  602. //Use Sparkle Animation
  603. TiltFinished = true;
  604. currentTilt = Tilt.None;
  605. Visible = false;
  606. }
  607. else
  608. {
  609. TiltFinished = false;
  610. currentTilt = Tilt.SparkleTo90;
  611. }
  612. break;
  613. case Tilt.HopUp1:
  614. TiltFinished = false;
  615. currentTilt = Tilt.HopDown1;
  616. hopTimer = TimeSpan.Zero;
  617. break;
  618. case Tilt.HopDown1:
  619. TiltFinished = false;
  620. currentTilt = Tilt.HopUp2;
  621. hopTimer = TimeSpan.Zero;
  622. break;
  623. case Tilt.HopUp2:
  624. TiltFinished = false;
  625. currentTilt = Tilt.HopDown2;
  626. hopTimer = TimeSpan.Zero;
  627. break;
  628. case Tilt.HopDown2:
  629. if (entity.Wobbly())
  630. {
  631. TiltFinished = false;
  632. currentTilt = Tilt.WobblyBackward;
  633. }
  634. else
  635. {
  636. TiltFinished = true;
  637. currentTilt = Tilt.None;
  638. }
  639. break;
  640. case Tilt.Fall:
  641. Visible = false;
  642. break;
  643. }
  644. }
  645. if (!TiltFinished)
  646. {
  647. if (currentTilt == Tilt.TiltForward)
  648. TiltForward(gameTime);
  649. else if (currentTilt == Tilt.TiltForwardReverse)
  650. TiltForwardReverse(gameTime);
  651. else if (currentTilt == Tilt.TiltBackward)
  652. TiltBackward(gameTime);
  653. else if (currentTilt == Tilt.TiltBackwardReverse)
  654. TiltBackwardReverse(gameTime);
  655. else if (currentTilt == Tilt.WobblyForward)
  656. WobblyForward(gameTime);
  657. else if (currentTilt == Tilt.WobblyForwardReverse)
  658. WobblyForwardReverse(gameTime);
  659. else if (currentTilt == Tilt.WobblyBackward)
  660. WobblyBackward(gameTime);
  661. else if (currentTilt == Tilt.WobblyBackwardReverse)
  662. WobblyBackwardReverse(gameTime);
  663. else if (currentTilt == Tilt.Fall)
  664. Fall(gameTime);
  665. else if (currentTilt == Tilt.Rise)
  666. Rise(gameTime);
  667. else if (currentTilt == Tilt.SideStepBackward)
  668. SideStepBackward(gameTime);
  669. else if (currentTilt == Tilt.SideStepForward)
  670. SideStepForward(gameTime);
  671. else if (currentTilt == Tilt.SpinTo90)
  672. {
  673.  
  674. SpinTo90(gameTime);
  675. }
  676. else if (currentTilt == Tilt.SpinTo180)
  677. SpinTo180(gameTime);
  678. else if (currentTilt == Tilt.SpinTo270)
  679. SpinTo270(gameTime);
  680. else if (currentTilt == Tilt.SpinTo360)
  681. SpinTo360(gameTime);
  682.  
  683. else if (currentTilt == Tilt.FlyAwayTo90)
  684. FlyAwayTo90(gameTime);
  685. else if (currentTilt == Tilt.FlyAwayTo180)
  686. FlyAwayTo180(gameTime);
  687. else if (currentTilt == Tilt.FlyAwayTo270)
  688. FlyAwayTo270(gameTime);
  689. else if (currentTilt == Tilt.FlyAwayTo360)
  690. FlyAwayTo360(gameTime);
  691. else if (currentTilt == Tilt.SparkleTo90)
  692. SparkleTo90(gameTime);
  693. else if (currentTilt == Tilt.SparkleTo180)
  694. SparkleTo180(gameTime);
  695. else if (currentTilt == Tilt.SparkleTo270)
  696. SparkleTo270(gameTime);
  697. else if (currentTilt == Tilt.SparkleTo360)
  698. SparkleTo360(gameTime);
  699. else if (currentTilt == Tilt.HopUp1)
  700. HopUp1(gameTime);
  701. else if (currentTilt == Tilt.HopDown1)
  702. HopDown1(gameTime);
  703. else if (currentTilt == Tilt.HopUp2)
  704. HopUp2(gameTime);
  705. else if (currentTilt == Tilt.HopDown2)
  706. HopDown2(gameTime);
  707. }
  708. else if (TiltFinished && currentTilt == Tilt.None && entity.Wobbly())
  709. {
  710. TiltFinished = false;
  711. currentTilt = Tilt.WobblyBackward;
  712. }
  713.  
  714.  
  715. if (TakingAction || TakingReaction)
  716. {
  717. mFadeDelay -= gameTime.ElapsedGameTime.TotalSeconds;
  718.  
  719. //If the Fade delays has dropped below zero, then it is time to
  720. //fade in/fade out the image a little bit more.
  721. if (mFadeDelay <= 0)
  722. {
  723. //Reset the Fade delay
  724. mFadeDelay = maxFadeDelay;
  725. //Increment/Decrement the fade value for the image
  726. mAlphaValue += mFadeIncrement;
  727. //If the AlphaValue is equal or above the max Alpha value or
  728. //has dropped below or equal to the min Alpha value, then
  729. //reverse the fade
  730. if (mAlphaValue >= 255 || mAlphaValue <= 0)
  731. {
  732. mFadeIncrement *= -1;
  733. }
  734. }
  735. if (TakingAction)
  736. OffensiveColor(gameTime);
  737. else if (TakingReaction)
  738. DefensiveColor(gameTime);
  739. }
  740. else
  741. {
  742. gpuVertices[0].Color = Color.White;
  743. }
  744. gpuVertices[1].Color = gpuVertices[0].Color;
  745. gpuVertices[2].Color = gpuVertices[0].Color;
  746. gpuVertices[3].Color = gpuVertices[0].Color;
  747.  
  748.  
  749. shadow.Update(gpuVertices);
  750. }
  751.  
  752.  
  753.  
  754.  
  755. public void Draw(SpriteBatch spriteBatch)
  756. {
  757.  
  758.  
  759.  
  760.  
  761.  
  762. if (Visible && !Entity.StanceActive(Equations.Hide) && !Entity.StanceActive(Equations.Burrow))//Entity.reactionStance != "Hide" && Entity.reactionStance != "Burrow")
  763. {
  764. spriteBatch.End();
  765.  
  766. basicEffect.Texture = image;
  767. basicEffect.VertexColorEnabled = true;
  768. basicEffect.TextureEnabled = true; //Will make colors black instead of red
  769.  
  770.  
  771.  
  772. graphics.Indices = indexBuffer;
  773. graphics.SetVertexBuffer(vertexBuffer);
  774.  
  775. graphics.RasterizerState = rasterizerState;
  776. foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
  777. {
  778. pass.Apply();
  779.  
  780.  
  781.  
  782. DrawTriangleStrip();
  783.  
  784. }
  785. spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null);
  786.  
  787.  
  788. }
  789.  
  790.  
  791. }
  792.  
  793.  
  794. private void DrawTriangleStrip()
  795. {
  796.  
  797.  
  798.  
  799.  
  800. graphics.DrawUserIndexedPrimitives<VertexPositionColorTexture>(
  801. PrimitiveType.TriangleList,
  802. gpuVertices,
  803. 0,
  804. gpuVertices.Length,
  805. shortUshortConversion(edgeFaceList),//*edgeFaceList,
  806. 0,
  807. 2);
  808.  
  809. }
  810.  
  811. short[] shortUshortConversion(ushort[] Ushort)
  812. {
  813. short[] NewShort = new short[Ushort.Length];
  814.  
  815. for(int i = 0; i < NewShort.Length; i++)
  816. {
  817. NewShort[i] = Ushort[i] > (ushort)short.MaxValue
  818. ? short.MaxValue
  819. : (short)Ushort[i];
  820. }
  821. return NewShort;
  822. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement