/// <summary> /// 设定Layer对应的二维数组地图 /// </summary> /// /// <param name="map"></param> public void SetField2D(Field2D field) { if (isClose) { return; } if (field == null) { return; } if (tmpField != null) { if ((field.GetMap().Length == tmpField.GetMap().Length) && (field.GetTileWidth() == tmpField.GetTileWidth()) && (field.GetTileHeight() == tmpField.GetTileHeight())) { tmpField.Set(field.GetMap(), field.GetTileWidth(), field.GetTileHeight()); } } else { tmpField = field; } }
public void SetField2D(Field2D field) { if (field != null) { this.layerMap = field; } }
public Simulator(float width, float height, float unitDestroyRadius) { circles = new List <CircleData>(); halfWidth = width * 0.5f; halfHeight = height * 0.5f; fieldWithCells = new Field2D(-halfWidth, -halfHeight, width, height, 5, 5); destroyRadius = unitDestroyRadius; }
/// <summary> /// 以指定瓦片大小创建数组地图 /// </summary> /// /// <param name="tileWidth"></param> /// <param name="tileHeight"></param> /// <returns></returns> public Field2D CreateArrayMap(int tileWidth, int tileHeight) { if (isClose) { return(null); } tmpField = new Field2D((int[][])CollectionUtils.XNA_CreateJaggedArray(typeof(int), GetHeight() / tileHeight, GetWidth() / tileWidth), tileWidth, tileHeight); return(tmpField); }
public void Move_multiples(int direction, int multiples) { if (multiples <= 0) { multiples = 1; } Vector2f v = Field2D.GetDirection(direction); Move(v.X() * multiples, v.Y() * multiples); }
public Field2D GetField2D(string name, int width, int height, Field2D fallback) { int[][] arrays = GetArray2D(name, (fallback == null) ? null : fallback.GetMap()); if (arrays != null) { return(new Field2D(arrays, width, height)); } return(null); }
public MoveTo(Field2D map, int x, int y, bool flag_0) { this.pLocation = new Vector2f(); this.startLocation = new Vector2f(); this.endLocation = new Vector2f(x, y); this.layerMap = map; this.flag = flag_0; this.speed = 4; this.useCache = true; this.synchroLayerField = false; }
/// <summary> /// 让指定对象执行MoveTo事件 /// </summary> /// /// <param name="field"></param> /// <param name="o"></param> /// <param name="flag"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public MoveTo CallMoveTo(Field2D field, Loon.Action.ActionBind o, bool flag, int x, int y) { if (isClose) { return(null); } MoveTo move = new MoveTo(field, x, y, flag); AddActionEvent(move, o); return(move); }
public override void OnLoad() { this.startX = original.GetX(); this.startY = original.GetY(); float dx = endX - startX; float dy = endY - startY; this.vx = dx / speed; this.vy = 1 / speed * (dy - 1.0f / 2.0f * gravity * speed * speed); this.dir = Field2D.GetDirection(MathUtils.Atan2(endX - startX, endY - startY)); }
public void SetField2DBackground(Field2D field, Dictionary <object, object> pathMap, String fileName) { SetField2D(field); LPixmap background = null; if (fileName != null) { LPixmap tmp = new LPixmap(fileName); background = SetTileBackground(tmp, true); if (tmp != null) { tmp.Dispose(); tmp = null; } } else { background = new LPixmap(GetWidth(), GetHeight(), false); } for (int i = 0; i < field.GetWidth(); i++) { for (int j = 0; j < field.GetHeight(); j++) { int index = field.GetType(j, i); Object o = CollectionUtils.Get(pathMap, index); if (o != null) { if (o is LPixmap) { background.DrawPixmap(((LPixmap)o), field.TilesToWidthPixels(i), field.TilesToHeightPixels(j)); } else if (o is Actor) { AddObject(((Actor)o), field.TilesToWidthPixels(i), field.TilesToHeightPixels(j)); } } } } SetBackground(background.Texture); if (background != null) { background.Dispose(); background = null; } }
/// <summary> /// 让指定对象执行MoveTo事件 /// </summary> /// /// <param name="o"></param> /// <param name="flag"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="w"></param> /// <param name="h"></param> /// <returns></returns> public MoveTo CallMoveTo(Loon.Action.ActionBind o, bool flag, int x, int y, int w, int h) { if (isClose) { return(null); } if (tmpField == null) { tmpField = CreateArrayMap(w, h); } MoveTo move = new MoveTo(tmpField, x, y, flag); AddActionEvent(move, o); return(move); }
public bool JsonImport(string path, string name) { string FilePath = path + "/" + name + ".json"; if (!File.Exists(FilePath)) { return(false); } MapBuildingScriptForSerialization scr = JsonIO.JsonImport <MapBuildingScriptForSerialization>(path, name); Origin = scr.Origin; BuildingName = scr.BuildingName; Status = scr.Status; MapChipIDField_Width = scr.MapChipIDField_Width; MapChipIDField_Height = scr.MapChipIDField_Height; MapChipIDField = scr.MapChipIDField; CollisionField = scr.CollisionField; return(true); }
private void InstantiateMapChip()//MapChipの生成 { if (MapChipField == null) { MapChipField = new Field2D <MapChipScript>(MapChipIDField_Width, MapChipIDField_Height); } for (int i = 0; i < MapChipIDField_Width; i++) { for (int j = 0; j < MapChipIDField_Height; j++) { if (MapChipIDField.field [i] [j] != 0 && MapChipField.field[i][j] == null) { MapChipField.field [i] [j] = Instantiate(SystemVariables.MapChipPrefab, transform).GetComponent <MapChipScript> (); } else if (MapChipField.field [i] [j] != null) { Destroy(MapChipField.field [i] [j].gameObject); } } } ApplyInfoToMapChip(); }
public MoveTo(Field2D map, Vector2f pos, bool flag_0) : this(map, pos.X(), pos.Y(), flag_0) { }
public override void Update(long elapsedTime) { if (layerMap == null || original == null || pActorPath == null) { return; } lock (pActorPath) { if (synchroLayerField) { if (original != null) { Field2D field = original.GetField2D(); if (field != null && layerMap != field) { this.layerMap = field; } } } if (endX == startX && endY == startY) { if (pActorPath.Count > 1) { Vector2f moveStart = pActorPath[0]; Vector2f moveEnd = pActorPath[1]; startX = layerMap.TilesToWidthPixels(moveStart.X()); startY = layerMap.TilesToHeightPixels(moveStart.Y()); endX = moveEnd.X() * layerMap.GetTileWidth(); endY = moveEnd.Y() * layerMap.GetTileHeight(); moveX = moveEnd.X() - moveStart.X(); moveY = moveEnd.Y() - moveStart.Y(); if (moveX > -2 && moveY > -2 && moveX < 2 && moveY < 2) { direction = Loon.Action.Map.Field2D.GetDirection(moveX, moveY, direction); } } CollectionUtils.RemoveAt(pActorPath, 0); } switch (direction) { case Config.TUP: startY -= speed; if (startY < endY) { startY = endY; } break; case Config.TDOWN: startY += speed; if (startY > endY) { startY = endY; } break; case Config.TLEFT: startX -= speed; if (startX < endX) { startX = endX; } break; case Config.TRIGHT: startX += speed; if (startX > endX) { startX = endX; } break; case Config.UP: startX += speed; startY -= speed; if (startX > endX) { startX = endX; } if (startY < endY) { startY = endY; } break; case Config.DOWN: startX -= speed; startY += speed; if (startX < endX) { startX = endX; } if (startY > endY) { startY = endY; } break; case Config.LEFT: startX -= speed; startY -= speed; if (startX < endX) { startX = endX; } if (startY < endY) { startY = endY; } break; case Config.RIGHT: startX += speed; startY += speed; if (startX > endX) { startX = endX; } if (startY > endY) { startY = endY; } break; } lock (original) { original.SetLocation(startX + offsetX, startY + offsetY); } } }
public Vector2f GetDirectionValue() { return(Field2D.GetDirection(GetDirection())); }
public virtual void SetField2DBackground(Field2D field, Dictionary <object, object> pathMap, string fileName) { SetField2D(field); LImage background = null; if (fileName != null) { LImage tmp = LImage.CreateImage(fileName); background = SetTileBackground(tmp, true); if (tmp != null) { tmp.Dispose(); tmp = null; } } else { background = LImage.CreateImage(GetWidth(), GetHeight(), false); } int srcWidth = GetWidth(); int srcHeight = GetHeight(); //在C#环境下LGraphics采取像素渲染,得不到硬件加速,此处直接将像素操作方法粘过来了(虽然也快不了几毫秒……) int[] dstColors = background.GetIntPixels(); int[] srcColors = null; for (int i = 0; i < field.GetWidth(); i++) { for (int j = 0; j < field.GetHeight(); j++) { int index = field.GetType(j, i); object o = CollectionUtils.Get(pathMap, index); if (o != null) { if (o is LImage) { LImage img = (LImage)o; srcColors = img.GetIntPixels(); int w = img.Width; int h = img.Height; int y = field.TilesToHeightPixels(j); int x = field.TilesToWidthPixels(i); if (x < 0) { w += x; x = 0; } if (y < 0) { h += y; y = 0; } if (x + w > srcWidth) { w = srcWidth - x; } if (y + h > srcHeight) { h = srcHeight - y; } if (img.hasAlpha) { int findIndex = y * srcWidth + x; int drawIndex = 0; int moveFind = srcWidth - w; for (int col = 0; col < h; col++) { for (int row = 0; row < w;) { if (srcColors[drawIndex] != 0) { dstColors[findIndex] = srcColors[drawIndex]; } row++; findIndex++; drawIndex++; } findIndex += moveFind; } } else { for (int size = 0; size < h; size++) { System.Array.Copy(srcColors, size * w, dstColors, (y + size) * srcWidth + x, w); } } } else if (o is Actor) { AddObject(((Actor)o), field.TilesToWidthPixels(i), field.TilesToHeightPixels(j)); } } } } background.SetIntPixels(dstColors); background.SetFormat(Loon.Core.Graphics.Opengl.LTexture.Format.SPEED); SetBackground(background.GetTexture()); srcColors = null; dstColors = null; if (background != null) { background.Dispose(); background = null; } }
public void SetField2DBackground(Field2D field, Dictionary <object, object> pathMap) { SetField2DBackground(field, pathMap, null); }
public override void Update(long elapsedTime) { if (timer.Action(elapsedTime)) { isMoving = MoveState(); if (tiles == null || findPath == null) { return; } if (IsComplete()) { return; } lock (findPath) { if (endX == startX && endY == startY) { if (findPath != null) { if (findPath.Count > 1) { Vector2f moveStart = findPath[0]; Vector2f moveEnd = findPath[1]; startX = tiles.TilesToPixelsX(moveStart.X()); startY = tiles.TilesToPixelsY(moveStart.Y()); endX = moveEnd.X() * tiles.GetTileWidth(); endY = moveEnd.Y() * tiles.GetTileHeight(); moveX = moveEnd.X() - moveStart.X(); moveY = moveEnd.Y() - moveStart.Y(); direction = Field2D.GetDirection(moveX, moveY); findPath.RemoveAt(0); } else { findPath.Clear(); } } } switch (direction) { case Field2D.TUP: startY -= speed; if (startY < endY) { startY = endY; } break; case Field2D.TDOWN: startY += speed; if (startY > endY) { startY = endY; } break; case Field2D.TLEFT: startX -= speed; if (startX < endX) { startX = endX; } break; case Field2D.TRIGHT: startX += speed; if (startX > endX) { startX = endX; } break; case Field2D.UP: startX += speed; startY -= speed; if (startX > endX) { startX = endX; } if (startY < endY) { startY = endY; } break; case Field2D.DOWN: startX -= speed; startY += speed; if (startX < endX) { startX = endX; } if (startY > endY) { startY = endY; } break; case Field2D.LEFT: startX -= speed; startY -= speed; if (startX < endX) { startX = endX; } if (startY < endY) { startY = endY; } break; case Field2D.RIGHT: startX += speed; startY += speed; if (startX > endX) { startX = endX; } if (startY > endY) { startY = endY; } break; } Vector2f tile = tiles.GetTileCollision(this, startX, startY); if (tile != null) { int sx = tiles.TilesToPixelsX(tile.x); int sy = tiles.TilesToPixelsY(tile.y); if (sx > 0) { sx = sx - GetWidth(); } else if (sx < 0) { sx = tiles.TilesToPixelsX(tile.x); } if (sy > 0) { sy = sy - GetHeight(); } else if (sy < 0) { sy = tiles.TilesToPixelsY(tile.y); } } else { SetLocation(startX, startY); } } } }
public int GetDirection() { return(Field2D.GetDirection(end.X() - start.X(), end.Y() - start.Y(), Config.EMPTY)); }
/// <summary> /// 让指定对象执行MoveTo事件 /// </summary> /// /// <param name="field"></param> /// <param name="o"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public MoveTo CallMoveTo(Field2D field, Loon.Action.ActionBind o, int x, int y) { return(CallMoveTo(field, o, true, x, y)); }