Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region using
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using V2 = Microsoft.Xna.Framework.Vector2;
- using MH = Microsoft.Xna.Framework.MathHelper;
- using V3 = Microsoft.Xna.Framework.Vector3;
- using MX = Microsoft.Xna.Framework.Matrix;
- #endregion
- namespace aidrivers
- {
- class Map : Drawable
- {
- #region GroundType
- public enum GroundType
- {
- Road,
- Wall,
- Water
- }
- #endregion
- private GroundType[,] grounds;
- public GroundType this[float x, float y]
- {
- get
- {
- x /= Scale.X;
- y /= Scale.X;
- if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
- return GroundType.Wall;
- return grounds[(int)(x), (int)(y)];
- }
- }
- public V2 calc_ray_to_wall(V2 drc, V2 position)
- {
- V2 ray = V2.Zero;
- int nx = (int)(position.X + ray.X);
- int ny = (int)(position.Y + ray.Y);
- while (this[nx, ny] != GroundType.Wall)
- {
- ray += drc;
- nx = (int)(position.X + ray.X);
- ny = (int)(position.Y + ray.Y);
- }
- return ray+position;
- }
- public float? find_road_x(float y)
- {
- int yi = (int)(y / Scale.Y);
- for (int x = 0; x < grounds.GetLength(1); x++)
- {
- if (grounds[x, yi] == GroundType.Road)
- {
- return x * Scale.X;
- }
- }
- return null;
- }
- public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
- {
- meetPoint = position + lookTo;
- float maxlength = lookTo.Length();
- lookTo.Normalize();
- V2 rayPos = position;
- while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
- {
- if ((rayPos - position).Length() > maxlength)
- return false;
- rayPos += lookTo;
- }
- meetPoint = rayPos;
- return true;
- }
- #region CTORS
- public Map(string path)
- : this(S.cm.Load<Texture2D>(path))
- {
- }
- public Map(Texture2D tex)
- : base(V2.Zero, V2.Zero, tex, true)
- {
- grounds = new GroundType[tex.Width, tex.Height];
- Color[] texColor = new Color[tex.Width * tex.Height];
- tex.GetData<Color>(texColor);
- #region FILL GROUND ARRAY BY TEX
- for (int x = 0; x < tex.Width; x++)
- {
- for (int y = 0; y < tex.Height; y++)
- {
- grounds[x, y] = GroundType.Wall; //default is wall
- if (texColor[x + y * tex.Width] == GroundColors.Road)
- grounds[x, y] = GroundType.Road;
- if (texColor[x + y * tex.Width] == GroundColors.Water)
- grounds[x, y] = GroundType.Water;
- }
- }
- #endregion
- }
- #endregion
- }
- }
- #region using
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using V2 = Microsoft.Xna.Framework.Vector2;
- using MH = Microsoft.Xna.Framework.MathHelper;
- using V3 = Microsoft.Xna.Framework.Vector3;
- using MX = Microsoft.Xna.Framework.Matrix;
- #endregion
- namespace aidrivers
- {
- class Map : Drawable
- {
- #region GroundType
- public enum GroundType
- {
- Road,
- Wall,
- Water
- }
- #endregion
- private GroundType[,] grounds;
- public GroundType this[float x, float y]
- {
- get
- {
- x /= Scale.X;
- y /= Scale.X;
- if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
- return GroundType.Wall;
- return grounds[(int)(x), (int)(y)];
- }
- }
- public V2 calc_ray_to_wall(V2 drc, V2 position)
- {
- V2 ray = V2.Zero;
- int nx = (int)(position.X + ray.X);
- int ny = (int)(position.Y + ray.Y);
- while (this[nx, ny] != GroundType.Wall)
- {
- ray += drc;
- nx = (int)(position.X + ray.X);
- ny = (int)(position.Y + ray.Y);
- }
- return ray+position;
- }
- public float? find_road_x(float y)
- {
- int yi = (int)(y / Scale.Y);
- for (int x = 0; x < grounds.GetLength(1); x++)
- {
- if (grounds[x, yi] == GroundType.Road)
- {
- return x * Scale.X;
- }
- }
- return null;
- }
- public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
- {
- meetPoint = position + lookTo;
- float maxlength = lookTo.Length();
- lookTo.Normalize();
- V2 rayPos = position;
- while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
- {
- if ((rayPos - position).Length() > maxlength)
- return false;
- rayPos += lookTo;
- }
- meetPoint = rayPos;
- return true;
- }
- #region CTORS
- public Map(string path)
- : this(S.cm.Load<Texture2D>(path))
- {
- }
- public Map(Texture2D tex)
- : base(V2.Zero, V2.Zero, tex, true)
- {
- grounds = new GroundType[tex.Width, tex.Height];
- Color[] texColor = new Color[tex.Width * tex.Height];
- tex.GetData<Color>(texColor);
- #region FILL GROUND ARRAY BY TEX
- for (int x = 0; x < tex.Width; x++)
- {
- for (int y = 0; y < tex.Height; y++)
- {
- grounds[x, y] = GroundType.Wall; //default is wall
- if (texColor[x + y * tex.Width] == GroundColors.Road)
- grounds[x, y] = GroundType.Road;
- if (texColor[x + y * tex.Width] == GroundColors.Water)
- grounds[x, y] = GroundType.Water;
- }
- }
- #endregion
- }
- #endregion
- }
- }
- #region using
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using V2 = Microsoft.Xna.Framework.Vector2;
- using MH = Microsoft.Xna.Framework.MathHelper;
- using V3 = Microsoft.Xna.Framework.Vector3;
- using MX = Microsoft.Xna.Framework.Matrix;
- #endregion
- namespace aidrivers
- {
- class Map : Drawable
- {
- #region GroundType
- public enum GroundType
- {
- Road,
- Wall,
- Water
- }
- #endregion
- private GroundType[,] grounds;
- public GroundType this[float x, float y]
- {
- get
- {
- x /= Scale.X;
- y /= Scale.X;
- if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
- return GroundType.Wall;
- return grounds[(int)(x), (int)(y)];
- }
- }
- public V2 calc_ray_to_wall(V2 drc, V2 position)
- {
- V2 ray = V2.Zero;
- int nx = (int)(position.X + ray.X);
- int ny = (int)(position.Y + ray.Y);
- while (this[nx, ny] != GroundType.Wall)
- {
- ray += drc;
- nx = (int)(position.X + ray.X);
- ny = (int)(position.Y + ray.Y);
- }
- return ray+position;
- }
- public float? find_road_x(float y)
- {
- int yi = (int)(y / Scale.Y);
- for (int x = 0; x < grounds.GetLength(1); x++)
- {
- if (grounds[x, yi] == GroundType.Road)
- {
- return x * Scale.X;
- }
- }
- return null;
- }
- public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
- {
- meetPoint = position + lookTo;
- float maxlength = lookTo.Length();
- lookTo.Normalize();
- V2 rayPos = position;
- while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
- {
- if ((rayPos - position).Length() > maxlength)
- return false;
- rayPos += lookTo;
- }
- meetPoint = rayPos;
- return true;
- }
- #region CTORS
- public Map(string path)
- : this(S.cm.Load<Texture2D>(path))
- {
- }
- public Map(Texture2D tex)
- : base(V2.Zero, V2.Zero, tex, true)
- {
- grounds = new GroundType[tex.Width, tex.Height];
- Color[] texColor = new Color[tex.Width * tex.Height];
- tex.GetData<Color>(texColor);
- #region FILL GROUND ARRAY BY TEX
- for (int x = 0; x < tex.Width; x++)
- {
- for (int y = 0; y < tex.Height; y++)
- {
- grounds[x, y] = GroundType.Wall; //default is wall
- if (texColor[x + y * tex.Width] == GroundColors.Road)
- grounds[x, y] = GroundType.Road;
- if (texColor[x + y * tex.Width] == GroundColors.Water)
- grounds[x, y] = GroundType.Water;
- }
- }
- #endregion
- }
- #endregion
- }
- }
- #region using
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using V2 = Microsoft.Xna.Framework.Vector2;
- using MH = Microsoft.Xna.Framework.MathHelper;
- using V3 = Microsoft.Xna.Framework.Vector3;
- using MX = Microsoft.Xna.Framework.Matrix;
- #endregion
- namespace aidrivers
- {
- class Map : Drawable
- {
- #region GroundType
- public enum GroundType
- {
- Road,
- Wall,
- Water
- }
- #endregion
- private GroundType[,] grounds;
- public GroundType this[float x, float y]
- {
- get
- {
- x /= Scale.X;
- y /= Scale.X;
- if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
- return GroundType.Wall;
- return grounds[(int)(x), (int)(y)];
- }
- }
- public V2 calc_ray_to_wall(V2 drc, V2 position)
- {
- V2 ray = V2.Zero;
- int nx = (int)(position.X + ray.X);
- int ny = (int)(position.Y + ray.Y);
- while (this[nx, ny] != GroundType.Wall)
- {
- ray += drc;
- nx = (int)(position.X + ray.X);
- ny = (int)(position.Y + ray.Y);
- }
- return ray+position;
- }
- public float? find_road_x(float y)
- {
- int yi = (int)(y / Scale.Y);
- for (int x = 0; x < grounds.GetLength(1); x++)
- {
- if (grounds[x, yi] == GroundType.Road)
- {
- return x * Scale.X;
- }
- }
- return null;
- }
- public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
- {
- meetPoint = position + lookTo;
- float maxlength = lookTo.Length();
- lookTo.Normalize();
- V2 rayPos = position;
- while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
- {
- if ((rayPos - position).Length() > maxlength)
- return false;
- rayPos += lookTo;
- }
- meetPoint = rayPos;
- return true;
- }
- #region CTORS
- public Map(string path)
- : this(S.cm.Load<Texture2D>(path))
- {
- }
- public Map(Texture2D tex)
- : base(V2.Zero, V2.Zero, tex, true)
- {
- grounds = new GroundType[tex.Width, tex.Height];
- Color[] texColor = new Color[tex.Width * tex.Height];
- tex.GetData<Color>(texColor);
- #region FILL GROUND ARRAY BY TEX
- for (int x = 0; x < tex.Width; x++)
- {
- for (int y = 0; y < tex.Height; y++)
- {
- grounds[x, y] = GroundType.Wall; //default is wall
- if (texColor[x + y * tex.Width] == GroundColors.Road)
- grounds[x, y] = GroundType.Road;
- if (texColor[x + y * tex.Width] == GroundColors.Water)
- grounds[x, y] = GroundType.Water;
- }
- }
- #endregion
- }
- #endregion
- }
- }
- #region using
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using V2 = Microsoft.Xna.Framework.Vector2;
- using MH = Microsoft.Xna.Framework.MathHelper;
- using V3 = Microsoft.Xna.Framework.Vector3;
- using MX = Microsoft.Xna.Framework.Matrix;
- #endregion
- namespace aidrivers
- {
- class Map : Drawable
- {
- #region GroundType
- public enum GroundType
- {
- Road,
- Wall,
- Water
- }
- #endregion
- private GroundType[,] grounds;
- public GroundType this[float x, float y]
- {
- get
- {
- x /= Scale.X;
- y /= Scale.X;
- if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
- return GroundType.Wall;
- return grounds[(int)(x), (int)(y)];
- }
- }
- public V2 calc_ray_to_wall(V2 drc, V2 position)
- {
- V2 ray = V2.Zero;
- int nx = (int)(position.X + ray.X);
- int ny = (int)(position.Y + ray.Y);
- while (this[nx, ny] != GroundType.Wall)
- {
- ray += drc;
- nx = (int)(position.X + ray.X);
- ny = (int)(position.Y + ray.Y);
- }
- return ray+position;
- }
- public float? find_road_x(float y)
- {
- int yi = (int)(y / Scale.Y);
- for (int x = 0; x < grounds.GetLength(1); x++)
- {
- if (grounds[x, yi] == GroundType.Road)
- {
- return x * Scale.X;
- }
- }
- return null;
- }
- public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
- {
- meetPoint = position + lookTo;
- float maxlength = lookTo.Length();
- lookTo.Normalize();
- V2 rayPos = position;
- while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
- {
- if ((rayPos - position).Length() > maxlength)
- return false;
- rayPos += lookTo;
- }
- meetPoint = rayPos;
- return true;
- }
- #region CTORS
- public Map(string path)
- : this(S.cm.Load<Texture2D>(path))
- {
- }
- public Map(Texture2D tex)
- : base(V2.Zero, V2.Zero, tex, true)
- {
- grounds = new GroundType[tex.Width, tex.Height];
- Color[] texColor = new Color[tex.Width * tex.Height];
- tex.GetData<Color>(texColor);
- #region FILL GROUND ARRAY BY TEX
- for (int x = 0; x < tex.Width; x++)
- {
- for (int y = 0; y < tex.Height; y++)
- {
- grounds[x, y] = GroundType.Wall; //default is wall
- if (texColor[x + y * tex.Width] == GroundColors.Road)
- grounds[x, y] = GroundType.Road;
- if (texColor[x + y * tex.Width] == GroundColors.Water)
- grounds[x, y] = GroundType.Water;
- }
- }
- #endregion
- }
- #endregion
- }
- }
- #region using
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using V2 = Microsoft.Xna.Framework.Vector2;
- using MH = Microsoft.Xna.Framework.MathHelper;
- using V3 = Microsoft.Xna.Framework.Vector3;
- using MX = Microsoft.Xna.Framework.Matrix;
- #endregion
- namespace aidrivers
- {
- class Map : Drawable
- {
- #region GroundType
- public enum GroundType
- {
- Road,
- Wall,
- Water
- }
- #endregion
- private GroundType[,] grounds;
- public GroundType this[float x, float y]
- {
- get
- {
- x /= Scale.X;
- y /= Scale.X;
- if (x < 0 || x >= grounds.GetLength(0) || y < 0 || y >= grounds.GetLength(1))
- return GroundType.Wall;
- return grounds[(int)(x), (int)(y)];
- }
- }
- public V2 calc_ray_to_wall(V2 drc, V2 position)
- {
- V2 ray = V2.Zero;
- int nx = (int)(position.X + ray.X);
- int ny = (int)(position.Y + ray.Y);
- while (this[nx, ny] != GroundType.Wall)
- {
- ray += drc;
- nx = (int)(position.X + ray.X);
- ny = (int)(position.Y + ray.Y);
- }
- return ray+position;
- }
- public float? find_road_x(float y)
- {
- int yi = (int)(y / Scale.Y);
- for (int x = 0; x < grounds.GetLength(1); x++)
- {
- if (grounds[x, yi] == GroundType.Road)
- {
- return x * Scale.X;
- }
- }
- return null;
- }
- public bool isWallClose(V2 position, V2 lookTo,out V2 meetPoint)
- {
- meetPoint = position + lookTo;
- float maxlength = lookTo.Length();
- lookTo.Normalize();
- V2 rayPos = position;
- while (this[rayPos.X, rayPos.Y] != GroundType.Wall)
- {
- if ((rayPos - position).Length() > maxlength)
- return false;
- rayPos += lookTo;
- }
- meetPoint = rayPos;
- return true;
- }
- #region CTORS
- public Map(string path)
- : this(S.cm.Load<Texture2D>(path))
- {
- }
- public Map(Texture2D tex)
- : base(V2.Zero, V2.Zero, tex, true)
- {
- grounds = new GroundType[tex.Width, tex.Height];
- Color[] texColor = new Color[tex.Width * tex.Height];
- tex.GetData<Color>(texColor);
- #region FILL GROUND ARRAY BY TEX
- for (int x = 0; x < tex.Width; x++)
- {
- for (int y = 0; y < tex.Height; y++)
- {
- grounds[x, y] = GroundType.Wall; //default is wall
- if (texColor[x + y * tex.Width] == GroundColors.Road)
- grounds[x, y] = GroundType.Road;
- if (texColor[x + y * tex.Width] == GroundColors.Water)
- grounds[x, y] = GroundType.Water;
- }
- }
- #endregion
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement