public BindObject(MazeObject mazeObj) { this.obj = mazeObj; binded = new GameObject("MazeObject"); transform = binded.transform; int x = obj.PositOnScene.X.value; int y = obj.PositOnScene.Y.value; transform.position = new Vector2(x, y); spriteRenderer = binded.AddComponent <SpriteRenderer>(); spriteRenderer.sprite = obj.GetSprite(); spriteRenderer.color = obj.GetColor(); spriteRenderer.sortingLayerName = "object"; if (obj is Creater) { // 因為當 Creater 變大時,會有重疊問題,所以要分圖層。 spriteRenderer.sortingLayerName = "creater"; binded.transform.localScale = obj.GetScale(); } obj.InitEvents(); // 為了做滑鼠移入觸發. binded.AddComponent <CircleCollider2D>().isTrigger = true; binded.AddComponent <ShowMessage>().refer = this.obj; // 明滅閃爍. this.beAttack = binded.AddComponent <BeAttack>(); }
// 把格子內的東西拿出來. // 回傳拿出來的物件. public MazeObject TakeOutObj() { MazeObject ret = this.Obj; this.Obj = null; return(ret); }
// 創造 MazeObject 的綁定物件. private BindObject CreateObj(MazeObject obj) { BindObject bindObject = new BindObject(obj); objs.Add(bindObject); obj.InitEvents(); return(bindObject); }
// obj 是否已存在場上的 buffer ? private bool BufferHaveObj(MazeObject obj) { foreach (var each in objs) { if (each.obj == obj) { return(true); } } return(false); }
// 把物件放入這個格子內. // false : 格子內已經有東西了. public bool InsertObj(MazeObject obj) { if (this.Obj == null) { this.Obj = obj; return(true); } else { return(false); } }
// obj 的位置是否在 buffer 外? private bool IsOutOfBuffer(MazeObject obj) { if (!obj.position.IsOnPlain(GlobalAsset.player.Plain)) { return(true); } Point2D position = obj.PositOnScene; return( position.X.value < center.X.value - extra || position.X.value > center.X.value + extra || position.Y.value < center.Y.value - extra || position.Y.value > center.Y.value + extra); }
// 若為自己的村民,增加能量. // 若為敵人,減少能量. // 將同顏色的生物拉為自己村民. // 吸收比自己弱的生成器. // 消除石頭. private void UpdateByObj(MazeObject obj) { if (obj == null || obj == this) { return; } if (obj is Animal) { Animal animal = (Animal)obj; if (animal.Hometown == this) { energy.Add(1); ++animalsCount; } else if (!animal.Color.Equals(this.Color)) { energy.Add(-1); } else { animal.ChangeHomeTown(this); } } else if (obj is Creater) { Creater creater = (Creater)obj; if (creater.Color.Equals(this.Color)) { EatCreater(creater); } else { energy.Add(-creater.Level); } } else if (obj is Stone) { obj.Destroy(); } }
public Map3D(int widthX, int widthY, int layers) { MazeObject.SetMaze(this); map = new Grid[widthX][][]; for (int i = 0; i < widthX; ++i) { map[i] = new Grid[widthY][]; for (int j = 0; j < widthY; ++j) { map[i][j] = new Grid[layers]; for (int k = 0; k < layers; ++k) { map[i][j][k] = new Grid(); map[i][j][k].Sprite = GlobalAsset.gridSprites[k]; } } } InitMap(); }
// 將 a,b 兩位置上的物件交換. // 也會修正物件的位置. public void Swap(Point3D a, Point3D b) { if (!IsInThisMap(a) || !IsInThisMap(b)) { return; } MazeObject temp = GetAt(a).TakeOutObj(); GetAt(a).InsertObj(GetAt(b).TakeOutObj()); GetAt(b).InsertObj(temp); if (GetAt(a).Obj != null) { GetAt(a).Obj.position.SetBy(a); } if (GetAt(b).Obj != null) { GetAt(b).Obj.position.SetBy(b); } }
// 把格子內的東西移除丟掉. // 回傳此格子. public Grid RemoveObj() { this.Obj = null; return(this); }