public static bool IsVisible(Vector2w posStart, Vector2w posEnd, Map map, BlockInfo blockInfo) { Vector2f startPos = new Vector2f(posStart.x + 0.5f, posStart.y + 0.5f); Vector2f endPos = new Vector2f(posEnd.x + 0.5f, posEnd.y + 0.5f); return(TraceRayVisible(startPos, endPos, posStart.GetR(posEnd), map, blockInfo)); }
public GameActionRotateUnit(uint unitUid, int dir, Vector2w pos) { actionType = EGameAction.rotateUnit; unitUID = unitUid; this.pos = new Vector2w(pos); this.dir = dir; }
public MsgServerCreateBattle(uint userId, int seed, Vector2w size) : base(EMsgNetServer.createBattle) { id = userId; this.seed = seed; this.size = size; json = JsonWriter.Serialize(this); }
public bool IsMap(Vector2w pos) { if (pos.x < 0 || pos.y < 0 || pos.x >= size.x || pos.y >= size.y) { return(false); } return(true); }
public Vector2w GetFreeStartPos(Random rnd) { int idx = rnd.Next(0, map.unitPoint.Count); Vector2w p = map.unitPoint[idx]; map.unitPoint.RemoveAt(idx); return(p); }
public bool IsVisibleBlock(Vector2w pos, BlockInfo blockInfo) { if (map[pos.x, pos.y].block == null) { return(true); } return(blockInfo[map[pos.x, pos.y].block.type].isVisible); }
public int GetR(Vector2w inVec) { if (Math.Abs(x - inVec.x) > Math.Abs(y - inVec.y)) { return(Math.Abs(x - inVec.x)); } return(Math.Abs(y - inVec.y)); }
public GameActionVisible(Unit unit, bool visible) { actionType = EGameAction.visibleUnit; this.visible = visible; unitUID = unit.uid; pos = unit.pos; dir = unit.dir; unitType = unit.id; }
public void Create(Vector2w size) { this.size = size; map = new MapItem[size.x, size.y]; for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { map[x, y] = new MapItem(); } } }
static bool IsShotFree(Vector2w pos, bool isThrow, Map map, BlockInfo blockInfo) { if (!isThrow && map.IsUnitPos(pos)) { return(true); } if (!map.IsMoveBlock(pos, blockInfo)) { return(false); } return(true); }
public bool IsBeside(Vector2w p) { if (p.x != x && p.y != y) { return(false); } if (GetR(p) != 1) { return(false); } return(true); }
public Map Create(int seed, Vector2w size, BlockInfo blockInfo) { this.blockInfo = blockInfo; moveMap = new int[size.x, size.y]; rnd = new Random(seed); map = new Map(); map.Create(size); GenerateTile(); GenerateBlocks(); GenerateUnitPoint(); return(map); }
private bool SetStartPoint(int idx) { for (int x = 0; x < map.Size.x; x++) { for (int y = 0; y < map.Size.y; y++) { Vector2w p = new Vector2w(x, y); if (map.IsMove(p, blockInfo) && moveMap[p.x, p.y] == 0) { moveMap[p.x, p.y] = idx; return(true); } } } return(false); }
private bool FillAround(int x, int y, int idx, Dictionary <int, int> cnt) { bool res = false; for (int i = 0; i < 4; i++) { Vector2w p = new Vector2w(x, y) + offset[i]; if (map.IsMap(p) && map.IsMove(p, blockInfo) && moveMap[p.x, p.y] == 0) { moveMap[p.x, p.y] = idx; cnt[idx]++; res = true; } } return(res); }
public bool IsMove(Vector2w pos, BlockInfo blockInfo) { if (IsUnitPos(pos)) { return(false); } if (map[pos.x, pos.y].block == null) { return(true); } if (blockInfo[map[pos.x, pos.y].block.type].isMove) { return(true); } return(false); }
/* * public override string ToString() * { * return x.ToString() + "," + y; * } */ public void MoveTo1(Vector2w inTarget) { if (x < inTarget.x) { x++; } else if (x > inTarget.x) { x--; } if (y < inTarget.y) { y++; } else if (y > inTarget.y) { y--; } }
public void Create(PrepareBattle prepareBattle, int seed) { mode = prepareBattle.mode; this.seed = seed; MapGenerator generator = new MapGenerator(); int s = 24; if (prepareBattle.users.Count > 2) { s = 32; } size = new Vector2w(s, s); map = generator.Create(seed, size, GameData.blockInfo); data = new BattleData(); data.Init(prepareBattle); findRoad = new FindRoad(size); }
private Vector2w OffsetUnitPoint(Vector2w pos) { int r = 1; do { for (int x = 0; x < r * 2 + 1; x++) { for (int y = 0; y < r * 2 + 1; y++) { Vector2w p = new Vector2w(pos.x + x - 1, pos.y + y - 1); if (map.IsMap(p) && moveMap[p.x, p.y] != 0) { return(p); } } } r++; } while (true); }
private void GenerateBlocks() { int percent = 20; int count = map.Size.x * map.Size.y * percent / 100; for (int i = 0; i < count; i++) { Vector2w pos; do { pos = new Vector2w(rnd.Next(0, map.Size.x), rnd.Next(0, map.Size.x)); } while (map.IsBlock(pos)); int idxBlock = rnd.Next(0, blocks.Length); Block block = new Block() { health = blockInfo[blocks[idxBlock]].health, type = blocks[idxBlock] }; map.SetBlock(pos, block); } }
public static int GetDir(Vector2w pos, Vector2w target) { if (pos == target) { return(0); } int dirX = target.x - pos.x; int dirY = target.y - pos.y; if (dirY > 0) { return(0); } if (dirY < 0) { return(2); } if (dirX > 0) { return(1); } return(3); }
public static bool TraceRayShot(Vector2f posStart, Vector2f posEnd, int length, out List <Vector2f> outPosCollisions, bool isThrow, Map map, BlockInfo blockInfo) { outPosCollisions = new List <Vector2f>(); Vector2f aDir = posEnd - posStart; float ax; float ay; if (Math.Abs(aDir.x) > Math.Abs(aDir.y)) { if (Math.Abs(aDir.y) > 0.001f) { ay = aDir.y / Math.Abs(aDir.x); } else { ay = 0; } ax = 1.0f; if (aDir.x < 0) { ax = -1.0f; } } else { if (Math.Abs(aDir.x - 0.0f) > 0.001f) { ax = aDir.x / Math.Abs(aDir.y); } else { ax = 0; } ay = 1.0f; if (aDir.y < 0) { ay = -1.0f; } } Vector2f aCurPos = new Vector2f(posStart.x, posStart.y); int aCountLen = 0; while (true) { aCurPos.x += ax; aCurPos.y += ay; Vector2w pos = new Vector2w((int)Math.Floor(aCurPos.x), (int)Math.Floor(aCurPos.y)); if (!map.IsMap(pos)) { if (isThrow) { aCurPos.x -= ax; aCurPos.y -= ay; } outPosCollisions.Add(aCurPos); return(false); } if (!IsShotFree(pos, isThrow, map, blockInfo)) { if (!isThrow) { outPosCollisions.Add(aCurPos); return(true); } else { aCurPos.x -= ax; aCurPos.y -= ay; outPosCollisions.Add(aCurPos); return(true); } } if (map.IsUnitPos(pos)) { outPosCollisions.Add(aCurPos); } aCountLen++; if (aCountLen >= length) { outPosCollisions.Add(aCurPos); return(false); } } }
public GameActionDamagePos(int damage, Vector2w pos) { actionType = EGameAction.damagePos; this.damage = damage; this.pos = pos; }
public GameActionShotUnit(uint unitUid, Vector2w pos) { actionType = EGameAction.shotUnit; unitUID = unitUid; this.pos = pos; }
public GameActionMoveUnit(uint unitUid, Vector2w pos) { actionType = EGameAction.moveUnit; unitUID = unitUid; this.pos = new Vector2w(pos); }
public MsgClientUnitMove(Vector2w pos) : base(EMsgNetClient.unitMove) { this.pos = pos; }
public MsgClientUnitShot(Vector2w pos) : base(EMsgNetClient.unitShot) { this.pos = pos; }
public bool Find(Vector2w startPos, Vector2w endPos, Map map, BlockInfo blockInfo, List <Vector2w> outRoad) { for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { findMap[x, y] = 1001; } } findMap[startPos.x, startPos.y] = 1000; findMap[endPos.x, endPos.y] = 0; int index = 0; bool res = false; bool exit = false; do { res = false; for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { if (findMap[x, y] == index) { for (int i = 0; i < 4; i++) { Vector2w p = new Vector2w(x + offset[i].x, y + offset[i].y); if (map.IsMap(p)) { if (findMap[p.x, p.y] == 1000) { exit = true; break; } if (findMap[x, y] == 1001 && map.IsMove(p, blockInfo)) { findMap[p.x, p.y] = index + 1; res = true; } } } } if (exit) { break; } } if (exit) { break; } } if (exit) { break; } index++; } while (res); outRoad.Add(startPos); int memIndex = 1000; Vector2w pos = new Vector2w(startPos); do { int memDir = -1; for (int i = 0; i < 4; i++) { Vector2w p = pos + offset[i]; if (map.IsMap(p)) { if (findMap[p.x, p.y] < memIndex) { memIndex = findMap[p.x, p.y]; memDir = i; } } } if (memDir == -1) { return(false); } pos = pos + offset[memDir]; outRoad.Add(new Vector2w(pos)); if (outRoad.Count > 500) { return(true); } } while (memIndex != 0); return(true); }
public FindRoad(Vector2w size) { this.size = size; findMap = new int[size.x, size.y]; }
public bool Equals(Vector2w other) { return(other.x == x && other.y == y); }
private static bool TraceRayVisible(Vector2f inStart, Vector2f inEnd, int inLength, Map map, BlockInfo blockInfo) { Vector2f aDir = inEnd - inStart; float ax; float ay; if (Math.Abs(aDir.x) > Math.Abs(aDir.y)) { if (Math.Abs(aDir.y) > 0.001f) { ay = aDir.y / Math.Abs(aDir.x); } else { ay = 0; } ax = 1.0f; if (aDir.x < 0) { ax = -1.0f; } } else { if (Math.Abs(aDir.x - 0.0f) > 0.001f) { ax = aDir.x / Math.Abs(aDir.y); } else { ax = 0; } ay = 1.0f; if (aDir.y < 0) { ay = -1.0f; } } Vector2f aCurPos = new Vector2f(inStart.x, inStart.y); int aCountLen = 0; while (true) { aCurPos.x += ax; aCurPos.y += ay; Vector2w aPos = new Vector2w((int)Math.Floor(aCurPos.x), (int)Math.Floor(aCurPos.y)); if (!map.IsMap(aPos)) { return(false); } aCountLen++; if (aCountLen >= inLength) { return(true); } if (!map.IsVisibleBlock(aPos, blockInfo)) { return(false); } } }