public void Dig(int cx, int cy, Tile surface, Tile border) { if (_layer1 != null) { _layer1.Dig(cx, cy, surface, border); } if (_layer2 != null) { _layer2.Dig(cx, cy, surface, border); } }
public SimpleBomb(int id, BombType type, Living owner, BaseGame game, BallInfo info, Tile shape, bool controled) : base(id, info.Mass, info.Weight, info.Wind, info.DragIndex) { m_owner = owner; m_game = game; m_info = info; m_shape = shape; m_type = type; m_power = info.Power; m_radius = info.Radii; m_controled = controled; m_bombed = false; m_lifeTime = 0; digMap = true; }
public Map(MapInfo info, Tile layer1, Tile layer2) { _info = info; _objects = new HashSet<Physics>(); _layer1 = layer1; _layer2 = layer2; if (_layer1 != null) { _bound = new Rectangle(0, 0, _layer1.Width, _layer1.Height); } else { _bound = new Rectangle(0, 0, _layer2.Width, _layer2.Height); } }
private static Dictionary<int, Tile> LoadFromFiles(Dictionary<int, BallInfo> list) { Dictionary<int, Tile> tiles = new Dictionary<int, Tile>(); foreach (BallInfo info in list.Values) { if (info.HasTunnel) { string file = string.Format("bomb\\{0}.bomb", info.ID); Tile shape = null; if (File.Exists(file)) { shape = new Tile(file, false); } tiles.Add(info.ID, shape); if (shape == null && info.ID != 1 && info.ID != 2 && info.ID != 3) { log.ErrorFormat("can't find bomb file:{0}", file); } } } return tiles; }
protected void Remove(int x, int y, Tile tile) { byte[] addData = tile._data; Rectangle rect = tile.Bound; rect.Offset(x, y); rect.Intersect(_rect); if (rect.Width != 0 && rect.Height != 0) { rect.Offset(-x, -y); int cx = rect.X / 8; int cx2 = (rect.X + x) / 8; int cy = rect.Y; //Tile中n列可以对src中n+1列产生影响,所以cw+1,防止溢出,过滤一下. int cw = rect.Width / 8 + 1; int ch = rect.Height; if (rect.X == 0) { if (cw + cx2 < _bw) { cw++; cw = cw > tile._bw ? tile._bw : cw; } int b_offset = (rect.X + x) % 8; int self_offset = 0; int tile_offset = 0; Int32 r_bits = 0; Int32 l_bits = 0; int src = 0; int target = 0; for (int j = 0; j < ch; j++) { r_bits = 0; l_bits = 0; for (int i = 0; i < cw; i++) { self_offset = (j + y + cy) * _bw + i + cx2; tile_offset = (j + cy) * tile._bw + i + cx; src = addData[tile_offset]; r_bits = src >> b_offset; target = _data[self_offset]; //把target中src为1的位设置位0. target &= ~(target & r_bits); if (l_bits != 0) { target &= ~(target & l_bits); } _data[self_offset] = (byte)target; l_bits = src << 8 - b_offset; } } } else { int b_offset = rect.X % 8; int self_offset = 0; int tile_offset = 0; Int32 r_bits = 0; Int32 l_bits = 0; int src = 0; int target = 0; for (int j = 0; j < ch; j++) { r_bits = 0; l_bits = 0; for (int i = 0; i < cw; i++) { self_offset = (j + y + cy) * _bw + i + cx2; tile_offset = (j + cy) * tile._bw + i + cx; src = addData[tile_offset]; l_bits = src << b_offset; if (i < cw - 1) { src = addData[tile_offset +1]; r_bits = src >> (8 - b_offset); } else { r_bits = 0; } target = _data[self_offset]; target &= ~(target & l_bits); if (r_bits != 0) { target &= ~(target & r_bits); } _data[self_offset] = (byte)target; } } } } }
protected void Add(int x, int y, Tile tile) { //需要重写,原来的逻辑不对,参照Remove // //byte[] addData = tile._data; //Rectangle rect = tile.Bound; //rect.Offset(x, y); //rect.Intersect(_rect); //if (rect.Width != 0 && rect.Height != 0) //{ // rect.Offset(-x, -y); // int cx = rect.X / 8; // int cx2 = (rect.X + x) / 8; // int cy = rect.Y; // int cw = (int)Math.Floor((double)rect.Width / 8); // int ch = rect.Height; // int b_offset = rect.X % 8; // int self_offset = 0; // int tile_offset = 0; // Int32 r_bits = 0; // Int32 l_bits = 0; // int src = 0; // int target = 0; // for (int j = 0; j < ch; j++) // { // r_bits = 0; // l_bits = 0; // for (int i = 0; i < cw; i++) // { // self_offset = (j + y + cy) * _bw + i + cx2; // tile_offset = (j + cy) * tile._bw + i + cx; // src = addData[tile_offset]; // r_bits = src >> b_offset; // _data[self_offset] |= (byte)r_bits; // _data[self_offset] |= (byte)l_bits; // l_bits = src << 8 - b_offset; // } // } //} }
public void Dig(int cx, int cy, Tile surface, Tile border) { if (_digable && surface != null) { int x1 = (int)(cx - surface.Width / 2); int y1 = (int)(cy - surface.Height / 2); Remove(x1, y1, surface); if (border != null) { x1 = (int)(cx - border.Width / 2); y1 = (int)(cy - border.Height / 2); Add(x1, y1, surface); } } }
public static bool LoadMap(Dictionary<int, MapPoint> maps, Dictionary<int, Map> mapInfos) { try { MapBussiness db = new MapBussiness(); MapInfo[] query = db.GetAllMap(); foreach (MapInfo m in query) { if (string.IsNullOrEmpty(m.PosX) )//|| string.IsNullOrEmpty(m.PosX1)) continue; if (!maps.Keys.Contains(m.ID)) { string[] tmp = m.PosX.Split('|'); string[] tmp1 = m.PosX1.Split('|'); //List<Point> pos = new List<Point>(); MapPoint pos = new MapPoint(); foreach (string s in tmp) { if (string.IsNullOrEmpty(s.Trim())) continue; string[] xy = s.Split(','); pos.PosX.Add(new Point(int.Parse(xy[0]), int.Parse(xy[1]))); //Point temp = new Point(int.Parse(xy[0]), int.Parse(xy[1])); //pos.Add(temp); } foreach (string s in tmp1) { if (string.IsNullOrEmpty(s.Trim())) continue; string[] xy = s.Split(','); pos.PosX1.Add(new Point(int.Parse(xy[0]), int.Parse(xy[1]))); //Point temp = new Point(int.Parse(xy[0]), int.Parse(xy[1])); //pos.Add(temp); } maps.Add(m.ID, pos); } if (!mapInfos.ContainsKey(m.ID)) { Tile force = null; string file = string.Format("map\\{0}\\fore.map", m.ID); if (File.Exists(file)) { force = new Tile(file, true); } Tile dead = null; file = string.Format("map\\{0}\\dead.map", m.ID); if (File.Exists(file)) { dead = new Tile(file, false); } if (force != null || dead != null) { mapInfos.Add(m.ID, new Map(m, force, dead)); } else { if (log.IsErrorEnabled) log.Error("Map's file is not exist!"); return false; } } } if (maps.Count == 0 || mapInfos.Count == 0) { if (log.IsErrorEnabled) log.Error("maps:" + maps.Count + ",mapInfos:" + mapInfos.Count); return false; } } catch (Exception e) { if (log.IsErrorEnabled) log.Error("MapMgr", e); return false; } return true; }
private static bool LoadBall(Dictionary<int, BallInfo> balls,Dictionary<int, Tile> ballTile) { using (ProduceBussiness db = new ProduceBussiness()) { BallInfo[] ballInfos = db.GetAllBall(); foreach (BallInfo b in ballInfos) { if (!balls.ContainsKey(b.ID)) { balls.Add(b.ID, b); Tile shape = null; string file = string.Format("bomb\\{0}.bomb", b.ID); if (File.Exists(file)) { shape = new Tile(file,false); } if (shape != null) { ballTile.Add(b.ID, shape); } else { if (b.ID != 1 && b.ID != 2 && b.ID != 3) { if (log.IsErrorEnabled) log.Error("Ball's file is not exist!"); return false; } } } } } if (!balls.ContainsKey(0)) { BallInfo temp = new BallInfo(); temp.ID = 0; temp.Power = 1; temp.Radii = 60; temp.Amount = 1; balls.Add(0, temp); } return true; }