Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.71 KB | None | 0 0
  1. #region using
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Audio;
  7. using Microsoft.Xna.Framework.Content;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. using V2 = Microsoft.Xna.Framework.Vector2;
  12. using MH = Microsoft.Xna.Framework.MathHelper;
  13. using V3 = Microsoft.Xna.Framework.Vector3;
  14. using MX = Microsoft.Xna.Framework.Matrix;
  15. #endregion
  16.  
  17. namespace aidrivers
  18. {
  19. class Map : Drawable
  20. {
  21. #region GroundType
  22. public enum GroundType
  23. {
  24. Road,
  25. Wall,
  26. Water
  27. }
  28. #endregion
  29.  
  30. private GroundType[,] grounds;
  31. public GroundType this[float x, float y]
  32. {
  33. get
  34. {
  35. x /= Scale.X;
  36. y /= Scale.X;
  37. if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
  38. return GroundType.Wall;
  39. return grounds[(int)(x), (int)(y)];
  40. }
  41. }
  42. public V2 calc_ray_to_wall(V2 drc, V2 position)
  43. {
  44. V2 ray = V2.Zero;
  45.  
  46. int nx = (int)(position.X + ray.X);
  47. int ny = (int)(position.Y + ray.Y);
  48.  
  49. while (this[nx, ny] != GroundType.Wall)
  50. {
  51. ray += drc;
  52. nx = (int)(position.X + ray.X);
  53. ny = (int)(position.Y + ray.Y);
  54. }
  55. return ray+position;
  56. }
  57. public float? find_road_x(float y)
  58. {
  59. int yi = (int)(y / Scale.Y);
  60. for (int x = 0; x < grounds.GetLength(1); x++)
  61. {
  62. if (grounds[x, yi] == GroundType.Road)
  63. {
  64. return x * Scale.X;
  65. }
  66. }
  67. return null;
  68. }
  69. public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
  70. {
  71. meetPoint = position + lookTo;
  72. float maxlength = lookTo.Length();
  73. lookTo.Normalize();
  74. V2 rayPos = position;
  75. while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
  76. {
  77. if ((rayPos - position).Length() > maxlength)
  78. return false;
  79. rayPos += lookTo;
  80. }
  81. meetPoint = rayPos;
  82. return true;
  83. }
  84. #region CTORS
  85. public Map(string path)
  86. : this(S.cm.Load<Texture2D>(path))
  87. {
  88.  
  89. }
  90. public Map(Texture2D tex)
  91. : base(V2.Zero, V2.Zero, tex, true)
  92. {
  93. grounds = new GroundType[tex.Width, tex.Height];
  94.  
  95. Color[] texColor = new Color[tex.Width * tex.Height];
  96. tex.GetData<Color>(texColor);
  97.  
  98. #region FILL GROUND ARRAY BY TEX
  99. for (int x = 0; x < tex.Width; x++)
  100. {
  101. for (int y = 0; y < tex.Height; y++)
  102. {
  103. grounds[x, y] = GroundType.Wall; //default is wall
  104.  
  105. if (texColor[x + y * tex.Width] == GroundColors.Road)
  106. grounds[x, y] = GroundType.Road;
  107. if (texColor[x + y * tex.Width] == GroundColors.Water)
  108. grounds[x, y] = GroundType.Water;
  109. }
  110. }
  111. #endregion
  112.  
  113. }
  114. #endregion
  115. }
  116. }
  117.  
  118.  
  119. #region using
  120. using System;
  121. using System.Collections.Generic;
  122. using System.Linq;
  123. using Microsoft.Xna.Framework;
  124. using Microsoft.Xna.Framework.Audio;
  125. using Microsoft.Xna.Framework.Content;
  126. using Microsoft.Xna.Framework.Graphics;
  127. using Microsoft.Xna.Framework.Input;
  128. using Microsoft.Xna.Framework.Media;
  129. using V2 = Microsoft.Xna.Framework.Vector2;
  130. using MH = Microsoft.Xna.Framework.MathHelper;
  131. using V3 = Microsoft.Xna.Framework.Vector3;
  132. using MX = Microsoft.Xna.Framework.Matrix;
  133. #endregion
  134.  
  135. namespace aidrivers
  136. {
  137. class Map : Drawable
  138. {
  139. #region GroundType
  140. public enum GroundType
  141. {
  142. Road,
  143. Wall,
  144. Water
  145. }
  146. #endregion
  147.  
  148. private GroundType[,] grounds;
  149. public GroundType this[float x, float y]
  150. {
  151. get
  152. {
  153. x /= Scale.X;
  154. y /= Scale.X;
  155. if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
  156. return GroundType.Wall;
  157. return grounds[(int)(x), (int)(y)];
  158. }
  159. }
  160. public V2 calc_ray_to_wall(V2 drc, V2 position)
  161. {
  162. V2 ray = V2.Zero;
  163.  
  164. int nx = (int)(position.X + ray.X);
  165. int ny = (int)(position.Y + ray.Y);
  166.  
  167. while (this[nx, ny] != GroundType.Wall)
  168. {
  169. ray += drc;
  170. nx = (int)(position.X + ray.X);
  171. ny = (int)(position.Y + ray.Y);
  172. }
  173. return ray+position;
  174. }
  175. public float? find_road_x(float y)
  176. {
  177. int yi = (int)(y / Scale.Y);
  178. for (int x = 0; x < grounds.GetLength(1); x++)
  179. {
  180. if (grounds[x, yi] == GroundType.Road)
  181. {
  182. return x * Scale.X;
  183. }
  184. }
  185. return null;
  186. }
  187. public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
  188. {
  189. meetPoint = position + lookTo;
  190. float maxlength = lookTo.Length();
  191. lookTo.Normalize();
  192. V2 rayPos = position;
  193. while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
  194. {
  195. if ((rayPos - position).Length() > maxlength)
  196. return false;
  197. rayPos += lookTo;
  198. }
  199. meetPoint = rayPos;
  200. return true;
  201. }
  202. #region CTORS
  203. public Map(string path)
  204. : this(S.cm.Load<Texture2D>(path))
  205. {
  206.  
  207. }
  208. public Map(Texture2D tex)
  209. : base(V2.Zero, V2.Zero, tex, true)
  210. {
  211. grounds = new GroundType[tex.Width, tex.Height];
  212.  
  213. Color[] texColor = new Color[tex.Width * tex.Height];
  214. tex.GetData<Color>(texColor);
  215.  
  216. #region FILL GROUND ARRAY BY TEX
  217. for (int x = 0; x < tex.Width; x++)
  218. {
  219. for (int y = 0; y < tex.Height; y++)
  220. {
  221. grounds[x, y] = GroundType.Wall; //default is wall
  222.  
  223. if (texColor[x + y * tex.Width] == GroundColors.Road)
  224. grounds[x, y] = GroundType.Road;
  225. if (texColor[x + y * tex.Width] == GroundColors.Water)
  226. grounds[x, y] = GroundType.Water;
  227. }
  228. }
  229. #endregion
  230.  
  231. }
  232. #endregion
  233. }
  234. }
  235.  
  236.  
  237.  
  238. #region using
  239. using System;
  240. using System.Collections.Generic;
  241. using System.Linq;
  242. using Microsoft.Xna.Framework;
  243. using Microsoft.Xna.Framework.Audio;
  244. using Microsoft.Xna.Framework.Content;
  245. using Microsoft.Xna.Framework.Graphics;
  246. using Microsoft.Xna.Framework.Input;
  247. using Microsoft.Xna.Framework.Media;
  248. using V2 = Microsoft.Xna.Framework.Vector2;
  249. using MH = Microsoft.Xna.Framework.MathHelper;
  250. using V3 = Microsoft.Xna.Framework.Vector3;
  251. using MX = Microsoft.Xna.Framework.Matrix;
  252. #endregion
  253.  
  254. namespace aidrivers
  255. {
  256. class Map : Drawable
  257. {
  258. #region GroundType
  259. public enum GroundType
  260. {
  261. Road,
  262. Wall,
  263. Water
  264. }
  265. #endregion
  266.  
  267. private GroundType[,] grounds;
  268. public GroundType this[float x, float y]
  269. {
  270. get
  271. {
  272. x /= Scale.X;
  273. y /= Scale.X;
  274. if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
  275. return GroundType.Wall;
  276. return grounds[(int)(x), (int)(y)];
  277. }
  278. }
  279. public V2 calc_ray_to_wall(V2 drc, V2 position)
  280. {
  281. V2 ray = V2.Zero;
  282.  
  283. int nx = (int)(position.X + ray.X);
  284. int ny = (int)(position.Y + ray.Y);
  285.  
  286. while (this[nx, ny] != GroundType.Wall)
  287. {
  288. ray += drc;
  289. nx = (int)(position.X + ray.X);
  290. ny = (int)(position.Y + ray.Y);
  291. }
  292. return ray+position;
  293. }
  294. public float? find_road_x(float y)
  295. {
  296. int yi = (int)(y / Scale.Y);
  297. for (int x = 0; x < grounds.GetLength(1); x++)
  298. {
  299. if (grounds[x, yi] == GroundType.Road)
  300. {
  301. return x * Scale.X;
  302. }
  303. }
  304. return null;
  305. }
  306. public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
  307. {
  308. meetPoint = position + lookTo;
  309. float maxlength = lookTo.Length();
  310. lookTo.Normalize();
  311. V2 rayPos = position;
  312. while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
  313. {
  314. if ((rayPos - position).Length() > maxlength)
  315. return false;
  316. rayPos += lookTo;
  317. }
  318. meetPoint = rayPos;
  319. return true;
  320. }
  321. #region CTORS
  322. public Map(string path)
  323. : this(S.cm.Load<Texture2D>(path))
  324. {
  325.  
  326. }
  327. public Map(Texture2D tex)
  328. : base(V2.Zero, V2.Zero, tex, true)
  329. {
  330. grounds = new GroundType[tex.Width, tex.Height];
  331.  
  332. Color[] texColor = new Color[tex.Width * tex.Height];
  333. tex.GetData<Color>(texColor);
  334.  
  335. #region FILL GROUND ARRAY BY TEX
  336. for (int x = 0; x < tex.Width; x++)
  337. {
  338. for (int y = 0; y < tex.Height; y++)
  339. {
  340. grounds[x, y] = GroundType.Wall; //default is wall
  341.  
  342. if (texColor[x + y * tex.Width] == GroundColors.Road)
  343. grounds[x, y] = GroundType.Road;
  344. if (texColor[x + y * tex.Width] == GroundColors.Water)
  345. grounds[x, y] = GroundType.Water;
  346. }
  347. }
  348. #endregion
  349.  
  350. }
  351. #endregion
  352. }
  353. }
  354.  
  355.  
  356. #region using
  357. using System;
  358. using System.Collections.Generic;
  359. using System.Linq;
  360. using Microsoft.Xna.Framework;
  361. using Microsoft.Xna.Framework.Audio;
  362. using Microsoft.Xna.Framework.Content;
  363. using Microsoft.Xna.Framework.Graphics;
  364. using Microsoft.Xna.Framework.Input;
  365. using Microsoft.Xna.Framework.Media;
  366. using V2 = Microsoft.Xna.Framework.Vector2;
  367. using MH = Microsoft.Xna.Framework.MathHelper;
  368. using V3 = Microsoft.Xna.Framework.Vector3;
  369. using MX = Microsoft.Xna.Framework.Matrix;
  370. #endregion
  371.  
  372. namespace aidrivers
  373. {
  374. class Map : Drawable
  375. {
  376. #region GroundType
  377. public enum GroundType
  378. {
  379. Road,
  380. Wall,
  381. Water
  382. }
  383. #endregion
  384.  
  385. private GroundType[,] grounds;
  386. public GroundType this[float x, float y]
  387. {
  388. get
  389. {
  390. x /= Scale.X;
  391. y /= Scale.X;
  392. if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
  393. return GroundType.Wall;
  394. return grounds[(int)(x), (int)(y)];
  395. }
  396. }
  397. public V2 calc_ray_to_wall(V2 drc, V2 position)
  398. {
  399. V2 ray = V2.Zero;
  400.  
  401. int nx = (int)(position.X + ray.X);
  402. int ny = (int)(position.Y + ray.Y);
  403.  
  404. while (this[nx, ny] != GroundType.Wall)
  405. {
  406. ray += drc;
  407. nx = (int)(position.X + ray.X);
  408. ny = (int)(position.Y + ray.Y);
  409. }
  410. return ray+position;
  411. }
  412. public float? find_road_x(float y)
  413. {
  414. int yi = (int)(y / Scale.Y);
  415. for (int x = 0; x < grounds.GetLength(1); x++)
  416. {
  417. if (grounds[x, yi] == GroundType.Road)
  418. {
  419. return x * Scale.X;
  420. }
  421. }
  422. return null;
  423. }
  424. public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
  425. {
  426. meetPoint = position + lookTo;
  427. float maxlength = lookTo.Length();
  428. lookTo.Normalize();
  429. V2 rayPos = position;
  430. while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
  431. {
  432. if ((rayPos - position).Length() > maxlength)
  433. return false;
  434. rayPos += lookTo;
  435. }
  436. meetPoint = rayPos;
  437. return true;
  438. }
  439. #region CTORS
  440. public Map(string path)
  441. : this(S.cm.Load<Texture2D>(path))
  442. {
  443.  
  444. }
  445. public Map(Texture2D tex)
  446. : base(V2.Zero, V2.Zero, tex, true)
  447. {
  448. grounds = new GroundType[tex.Width, tex.Height];
  449.  
  450. Color[] texColor = new Color[tex.Width * tex.Height];
  451. tex.GetData<Color>(texColor);
  452.  
  453. #region FILL GROUND ARRAY BY TEX
  454. for (int x = 0; x < tex.Width; x++)
  455. {
  456. for (int y = 0; y < tex.Height; y++)
  457. {
  458. grounds[x, y] = GroundType.Wall; //default is wall
  459.  
  460. if (texColor[x + y * tex.Width] == GroundColors.Road)
  461. grounds[x, y] = GroundType.Road;
  462. if (texColor[x + y * tex.Width] == GroundColors.Water)
  463. grounds[x, y] = GroundType.Water;
  464. }
  465. }
  466. #endregion
  467.  
  468. }
  469. #endregion
  470. }
  471. }
  472.  
  473.  
  474. #region using
  475. using System;
  476. using System.Collections.Generic;
  477. using System.Linq;
  478. using Microsoft.Xna.Framework;
  479. using Microsoft.Xna.Framework.Audio;
  480. using Microsoft.Xna.Framework.Content;
  481. using Microsoft.Xna.Framework.Graphics;
  482. using Microsoft.Xna.Framework.Input;
  483. using Microsoft.Xna.Framework.Media;
  484. using V2 = Microsoft.Xna.Framework.Vector2;
  485. using MH = Microsoft.Xna.Framework.MathHelper;
  486. using V3 = Microsoft.Xna.Framework.Vector3;
  487. using MX = Microsoft.Xna.Framework.Matrix;
  488. #endregion
  489.  
  490. namespace aidrivers
  491. {
  492. class Map : Drawable
  493. {
  494. #region GroundType
  495. public enum GroundType
  496. {
  497. Road,
  498. Wall,
  499. Water
  500. }
  501. #endregion
  502.  
  503. private GroundType[,] grounds;
  504. public GroundType this[float x, float y]
  505. {
  506. get
  507. {
  508. x /= Scale.X;
  509. y /= Scale.X;
  510. if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
  511. return GroundType.Wall;
  512. return grounds[(int)(x), (int)(y)];
  513. }
  514. }
  515. public V2 calc_ray_to_wall(V2 drc, V2 position)
  516. {
  517. V2 ray = V2.Zero;
  518.  
  519. int nx = (int)(position.X + ray.X);
  520. int ny = (int)(position.Y + ray.Y);
  521.  
  522. while (this[nx, ny] != GroundType.Wall)
  523. {
  524. ray += drc;
  525. nx = (int)(position.X + ray.X);
  526. ny = (int)(position.Y + ray.Y);
  527. }
  528. return ray+position;
  529. }
  530. public float? find_road_x(float y)
  531. {
  532. int yi = (int)(y / Scale.Y);
  533. for (int x = 0; x < grounds.GetLength(1); x++)
  534. {
  535. if (grounds[x, yi] == GroundType.Road)
  536. {
  537. return x * Scale.X;
  538. }
  539. }
  540. return null;
  541. }
  542. public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
  543. {
  544. meetPoint = position + lookTo;
  545. float maxlength = lookTo.Length();
  546. lookTo.Normalize();
  547. V2 rayPos = position;
  548. while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
  549. {
  550. if ((rayPos - position).Length() > maxlength)
  551. return false;
  552. rayPos += lookTo;
  553. }
  554. meetPoint = rayPos;
  555. return true;
  556. }
  557. #region CTORS
  558. public Map(string path)
  559. : this(S.cm.Load<Texture2D>(path))
  560. {
  561.  
  562. }
  563. public Map(Texture2D tex)
  564. : base(V2.Zero, V2.Zero, tex, true)
  565. {
  566. grounds = new GroundType[tex.Width, tex.Height];
  567.  
  568. Color[] texColor = new Color[tex.Width * tex.Height];
  569. tex.GetData<Color>(texColor);
  570.  
  571. #region FILL GROUND ARRAY BY TEX
  572. for (int x = 0; x < tex.Width; x++)
  573. {
  574. for (int y = 0; y < tex.Height; y++)
  575. {
  576. grounds[x, y] = GroundType.Wall; //default is wall
  577.  
  578. if (texColor[x + y * tex.Width] == GroundColors.Road)
  579. grounds[x, y] = GroundType.Road;
  580. if (texColor[x + y * tex.Width] == GroundColors.Water)
  581. grounds[x, y] = GroundType.Water;
  582. }
  583. }
  584. #endregion
  585.  
  586. }
  587. #endregion
  588. }
  589. }
  590.  
  591.  
  592. #region using
  593. using System;
  594. using System.Collections.Generic;
  595. using System.Linq;
  596. using Microsoft.Xna.Framework;
  597. using Microsoft.Xna.Framework.Audio;
  598. using Microsoft.Xna.Framework.Content;
  599. using Microsoft.Xna.Framework.Graphics;
  600. using Microsoft.Xna.Framework.Input;
  601. using Microsoft.Xna.Framework.Media;
  602. using V2 = Microsoft.Xna.Framework.Vector2;
  603. using MH = Microsoft.Xna.Framework.MathHelper;
  604. using V3 = Microsoft.Xna.Framework.Vector3;
  605. using MX = Microsoft.Xna.Framework.Matrix;
  606. #endregion
  607.  
  608. namespace aidrivers
  609. {
  610. class Map : Drawable
  611. {
  612. #region GroundType
  613. public enum GroundType
  614. {
  615. Road,
  616. Wall,
  617. Water
  618. }
  619. #endregion
  620.  
  621. private GroundType[,] grounds;
  622. public GroundType this[float x, float y]
  623. {
  624. get
  625. {
  626. x /= Scale.X;
  627. y /= Scale.X;
  628. if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
  629. return GroundType.Wall;
  630. return grounds[(int)(x), (int)(y)];
  631. }
  632. }
  633. public V2 calc_ray_to_wall(V2 drc, V2 position)
  634. {
  635. V2 ray = V2.Zero;
  636.  
  637. int nx = (int)(position.X + ray.X);
  638. int ny = (int)(position.Y + ray.Y);
  639.  
  640. while (this[nx, ny] != GroundType.Wall)
  641. {
  642. ray += drc;
  643. nx = (int)(position.X + ray.X);
  644. ny = (int)(position.Y + ray.Y);
  645. }
  646. return ray+position;
  647. }
  648. public float? find_road_x(float y)
  649. {
  650. int yi = (int)(y / Scale.Y);
  651. for (int x = 0; x < grounds.GetLength(1); x++)
  652. {
  653. if (grounds[x, yi] == GroundType.Road)
  654. {
  655. return x * Scale.X;
  656. }
  657. }
  658. return null;
  659. }
  660. public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
  661. {
  662. meetPoint = position + lookTo;
  663. float maxlength = lookTo.Length();
  664. lookTo.Normalize();
  665. V2 rayPos = position;
  666. while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
  667. {
  668. if ((rayPos - position).Length() > maxlength)
  669. return false;
  670. rayPos += lookTo;
  671. }
  672. meetPoint = rayPos;
  673. return true;
  674. }
  675. #region CTORS
  676. public Map(string path)
  677. : this(S.cm.Load<Texture2D>(path))
  678. {
  679.  
  680. }
  681. public Map(Texture2D tex)
  682. : base(V2.Zero, V2.Zero, tex, true)
  683. {
  684. grounds = new GroundType[tex.Width, tex.Height];
  685.  
  686. Color[] texColor = new Color[tex.Width * tex.Height];
  687. tex.GetData<Color>(texColor);
  688.  
  689. #region FILL GROUND ARRAY BY TEX
  690. for (int x = 0; x < tex.Width; x++)
  691. {
  692. for (int y = 0; y < tex.Height; y++)
  693. {
  694. grounds[x, y] = GroundType.Wall; //default is wall
  695.  
  696. if (texColor[x + y * tex.Width] == GroundColors.Road)
  697. grounds[x, y] = GroundType.Road;
  698. if (texColor[x + y * tex.Width] == GroundColors.Water)
  699. grounds[x, y] = GroundType.Water;
  700. }
  701. }
  702. #endregion
  703.  
  704. }
  705. #endregion
  706. }
  707. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement