| @@ -0,0 +1,14 @@ | |||
| using System; | |||
| namespace Preparation.Utility | |||
| { | |||
| public class Debugger | |||
| { | |||
| static public void Output(object current, string str) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine(current.GetType() + " " + current.ToString() + " " + str); | |||
| #endif | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,96 @@ | |||
| | |||
| namespace Preparation.Utility | |||
| { | |||
| /// <summary> | |||
| /// 存放所有用到的枚举类型 | |||
| /// </summary> | |||
| public enum GameObjType | |||
| { | |||
| Null = 0, | |||
| Character = 1, | |||
| Prop = 2, | |||
| PickedProp = 3, | |||
| Bullet = 4, | |||
| BombedBullet = 5, | |||
| Wall = 6, | |||
| Grass = 7, | |||
| Generator = 8, // 发电机 | |||
| BirthPoint = 9, | |||
| Exit = 10, | |||
| EmergencyExit = 11, | |||
| OutOfBoundBlock = 12, // 范围外 | |||
| } | |||
| public enum ShapeType | |||
| { | |||
| Null = 0, | |||
| Circle = 1, // 子弹和人物为圆形,格子为方形 | |||
| Square = 2 | |||
| } | |||
| public enum PlaceType // 位置标志,包括陆地(一般默认为陆地,如墙体等),草丛。游戏中每一帧都要刷新各个物体的该属性 | |||
| { | |||
| Null = 0, | |||
| Land = 1, | |||
| Grass1 = 2, | |||
| Grass2 = 3, | |||
| Grass3 = 4, | |||
| Grass4 = 5, | |||
| Grass5 = 6, | |||
| } | |||
| public enum BulletType // 子弹类型 | |||
| { | |||
| Null = 0, | |||
| OrdinaryBullet = 1, // 普通子弹 | |||
| AtomBomb = 2, // 原子弹 | |||
| FastBullet = 3, // 快速子弹 | |||
| LineBullet = 4 // 直线子弹 | |||
| } | |||
| public enum PropType // 道具类型 | |||
| { | |||
| Null = 0, | |||
| addSpeed = 1, | |||
| addLIFE = 2, | |||
| Shield = 3, | |||
| Spear = 4, | |||
| Gem = 5, // 新增:宝石 | |||
| } | |||
| public enum PassiveSkillType // 被动技能 | |||
| { | |||
| Null = 0, | |||
| RecoverAfterBattle = 1, | |||
| SpeedUpWhenLeavingGrass = 2, | |||
| Vampire = 3, | |||
| PSkill3 = 4, | |||
| PSkill4 = 5, | |||
| PSkill5 = 6 | |||
| } | |||
| public enum ActiveSkillType // 主动技能 | |||
| { | |||
| Null = 0, | |||
| BecomeVampire = 1, | |||
| BecomeAssassin = 2, | |||
| NuclearWeapon = 3, | |||
| SuperFast = 4, | |||
| ASkill4 = 5, | |||
| ASkill5 = 6 | |||
| } | |||
| public enum BuffType // buff | |||
| { | |||
| Null = 0, | |||
| AddSpeed = 1, | |||
| AddLIFE = 2, | |||
| Shield = 3, | |||
| Spear = 4 | |||
| } | |||
| public enum GameObjIdx | |||
| { | |||
| None = 0, | |||
| Player = 1, | |||
| Bullet = 2, | |||
| Prop = 3, | |||
| Gem = 4, | |||
| Map = 5, | |||
| BombedBullet = 6, | |||
| PickedProp = 7 | |||
| } | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| using System; | |||
| namespace Preparation.Utility | |||
| { | |||
| public class MapEncoder | |||
| { | |||
| static public char Dec2Hex(int d) | |||
| { | |||
| return char.Parse(d.ToString("X")); | |||
| } | |||
| static public int Hex2Dec(char h) | |||
| { | |||
| string hexabet = "0123456789ABCDEF"; | |||
| return hexabet.IndexOf(h); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,20 @@ | |||
| using System; | |||
| namespace Preparation.Utility | |||
| { | |||
| public static class Tools | |||
| { | |||
| public static double CorrectAngle(double angle) // 将幅角转化为主值0~2pi | |||
| { | |||
| if (double.IsNaN(angle) || double.IsInfinity(angle)) | |||
| { | |||
| return 0.0; | |||
| } | |||
| while (angle < 0) | |||
| angle += 2 * Math.PI; | |||
| while (angle >= 2 * Math.PI) | |||
| angle -= 2 * Math.PI; | |||
| return angle; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,57 @@ | |||
| using System; | |||
| namespace Preparation.Utility | |||
| { | |||
| public struct Vector | |||
| { | |||
| public double angle; | |||
| public double length; | |||
| public static XYPosition VectorToXY(Vector v) | |||
| { | |||
| return new XYPosition((int)(v.length * Math.Cos(v.angle)), (int)(v.length * Math.Sin(v.angle))); | |||
| } | |||
| public Vector2 ToVector2() | |||
| { | |||
| return new Vector2((int)(this.length * Math.Cos(this.angle)), (int)(this.length * Math.Sin(this.angle))); | |||
| } | |||
| public static Vector XYToVector(double x, double y) | |||
| { | |||
| return new Vector(Math.Atan2(y, x), Math.Sqrt((x * x) + (y * y))); | |||
| } | |||
| public Vector(double angle, double length) | |||
| { | |||
| if (length < 0) | |||
| { | |||
| angle += Math.PI; | |||
| length = -length; | |||
| } | |||
| this.angle = Tools.CorrectAngle(angle); | |||
| this.length = length; | |||
| } | |||
| } | |||
| public struct Vector2 | |||
| { | |||
| public double x; | |||
| public double y; | |||
| public Vector2(double x, double y) | |||
| { | |||
| this.x = x; | |||
| this.y = y; | |||
| } | |||
| public static double operator*(Vector2 v1, Vector2 v2) | |||
| { | |||
| return (v1.x * v2.x) + (v1.y * v2.y); | |||
| } | |||
| public static Vector2 operator +(Vector2 v1, Vector2 v2) | |||
| { | |||
| return new Vector2(v1.x + v2.x, v1.y + v2.y); | |||
| } | |||
| public static Vector2 operator -(Vector2 v1, Vector2 v2) | |||
| { | |||
| return new Vector2(v1.x - v2.x, v1.y - v2.y); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,49 @@ | |||
| using System; | |||
| namespace Preparation.Utility | |||
| { | |||
| public struct XYPosition | |||
| { | |||
| public int x; | |||
| public int y; | |||
| public XYPosition(int x, int y) | |||
| { | |||
| this.x = x; | |||
| this.y = y; | |||
| } | |||
| public override string ToString() | |||
| { | |||
| return "(" + x.ToString() + "," + y.ToString() + ")"; | |||
| } | |||
| public static XYPosition operator +(XYPosition p1, XYPosition p2) | |||
| { | |||
| return new XYPosition(p1.x + p2.x, p1.y + p2.y); | |||
| } | |||
| public static XYPosition operator -(XYPosition p1, XYPosition p2) | |||
| { | |||
| return new XYPosition(p1.x - p2.x, p1.y - p2.y); | |||
| } | |||
| public static double Distance(XYPosition p1, XYPosition p2) | |||
| { | |||
| return Math.Sqrt(((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y))); | |||
| } | |||
| /*public static XYPosition[] GetSquareRange(uint edgeLen) // 从THUAI4的BULLET.CS移植而来,不知还有用否 | |||
| { | |||
| XYPosition[] range = new XYPosition[edgeLen * edgeLen]; | |||
| int offset = (int)(edgeLen >> 1); | |||
| for (int i = 0; i < (int)edgeLen; ++i) | |||
| { | |||
| for (int j = 0; j < (int)edgeLen; ++j) | |||
| { | |||
| range[i * edgeLen + j].x = i - offset; | |||
| range[i * edgeLen + j].y = j - offset; | |||
| } | |||
| } | |||
| return range; | |||
| }*/ | |||
| public Vector2 ToVector2() | |||
| { | |||
| return new Vector2(this.x, this.y); | |||
| } | |||
| } | |||
| } | |||