public void Add(SimplePhysics physics) { if (!physicsList.Contains(physics)) { physicsList.Add(physics); } }
public void UpdateSectors(SimplePhysics physics, bool @new = false) { if (physics.IsEmpty) { return; } var oldSectors = physics.Sectors; physics.Sectors = GetSectors(physics); if (!@new) { foreach (var sector in oldSectors) { if (!physics.Sectors.Contains(sector)) { sector.Remove(physics); } } } foreach (var sector in physics.Sectors) { sector.Add(physics); } }
/// <summary> /// Instantiate the item at a random nearby position /// </summary> /// <param name="name"></param> /// <param name="pos"></param> /// <param name="amount"></param> public static bool InstantiateItem(Item item, Vector3 pos, float amount) { GameObject g; int x = UnityEngine.Random.Range(-1, 1); int z = UnityEngine.Random.Range(-1, 1); //Try to instantiate the item at a random nearby position g = Instantiate(item.ItemObject, new Vector3(pos.x + x, pos.y + 0.2f, pos.z + z), Quaternion.identity) as GameObject; Collider col = g.GetComponent <Collider>(); for (int i = 0; i < 10; i++) { if (!SimplePhysics.CanPlaceItem(col)) { x = UnityEngine.Random.Range(-2, 2); z = UnityEngine.Random.Range(-2, 2); g.transform.position = new Vector3(pos.x + x, pos.y + 1, pos.z + z); } else { g.SetActive(true); g.GetComponent <ItemReference>().Amount = amount; return(true); } } Destroy(g); return(false); }
public Logo(string image, Color color, Vector2D position, Size size, SimplePhysics.Data data) : base(image, color, position, size) { RenderLayer = (int)GameRenderLayer.Logos; sideStatus = Sides.None; Add(data); Start<TrajectoryEntityHandler>(); Start<SimplePhysics.Rotate>(); }
/// <summary> /// Unpauses the game and hides the pause menu /// </summary> public void Unpause() { if (!Paused) { return; } Paused = false; Game.Ctx.UI.Unpause(); SimplePhysics.Unpause(); }
/// <summary> /// Pauses the game and displays the pause menu /// </summary> public void Pause() { if (Paused || Game.Ctx.UI.InMainMenu) { return; } // doesn't make sense to pause in the main menu Paused = true; Game.Ctx.UI.Pause(); SimplePhysics.Pause(); }
public bool CheckCollision(SimplePhysics physics) { if (physics.IsEmpty) { return(false); } var top = PhysicsLayer.Bounds.Y; var left = PhysicsLayer.Bounds.X; var bot = 0; var right = 0; foreach (var p in physics.Sectors) { if (p.CheckIntersection(physics)) { return(true); } if (p.Position.X < left) { left = p.Position.X; } if (p.Position.Y < top) { top = p.Position.Y; } if (p.Position.X > right) { right = p.Position.X; } if (p.Position.Y > bot) { bot = p.Position.Y; } } var walls = WallLayer.WallList.Where( w => (w.TerrainPosition.X >= left * PhysicsLayer.SectorSize - 2) && (w.TerrainPosition.X < (right + 1) * PhysicsLayer.SectorSize + 2) && (w.TerrainPosition.Y >= top * PhysicsLayer.SectorSize - 1) && (w.TerrainPosition.Y < (bot + 1) * PhysicsLayer.SectorSize + 1)); foreach (var wall in walls) { if (physics.Intersects(wall.Physics)) { return(true); } } return(false); }
public override void Init(eEntityType type, eEntityLookDir baseDir, int subType) { base.Init(type, baseDir, subType); _physics = new SimplePhysics(_rigidbody, _node); _physics.AttackColliderList += OnHitColliderList; _physics.SomethingCollide += OnSomethingCollide; _physics.SetGrivityModify(0); _speed = 5; _dameageType = eDameageType.Magic; _dameageValue = 50; SetForward(Util.Dir2DConvert3D(baseDir)); }
public override void Init(eEntityType type, eEntityLookDir baseDir, int subType) { base.Init(type, baseDir, subType); var stat = TempData.GetCharacterData(type, subType); if (stat != null) { _stat = stat; } IsActive = true; _stateManager = new AnimationStateManager(); _stateManager.Init(this); _physics = new SimplePhysics(_rigidbody, _node); _physics.AttackColliderList += OnAttackCollider; _aniControl.OnAnimationPlayEnd += OnAnimationPlayEnd; _aniControl.OnAnimationEvent += OnAnimationEvent; _conditionEffectDic = new Dictionary <eCondition, ConditionEffect>(); _conditionList = new List <ConditionEffect>(); _curHP = stat.MaxHp; SetForward(Util.Dir2DConvert3D(baseDir)); }
/// <summary> /// Instantiate the item at a random nearby position /// </summary> /// <param name="name"></param> /// <param name="pos"></param> /// <param name="amount"></param> public static bool InstantiateItem(string name, Vector3 pos, float amount) { GameObject g; int x = UnityEngine.Random.Range(-1, 1); int y = UnityEngine.Random.Range(-1, 1); //Try to instantiate the item at a random nearby position try{ g = Instantiate(Resources.Load("Items/" + name, typeof(GameObject)), new Vector3(pos.x + x, pos.y + y, pos.z + 1), Quaternion.identity) as GameObject; } catch (System.Exception) { Debug.Log("Invalid item! Every item must be placed on the SimpleCraft/Items/ folder!"); throw; } Collider col = g.GetComponent <Collider>(); for (int i = 0; i < 10; i++) { if (!SimplePhysics.CanPlaceItem(col)) { x = UnityEngine.Random.Range(-1, 1); y = UnityEngine.Random.Range(-1, 1); g.transform.position = new Vector3(pos.x + x, pos.y + y, pos.z + 1); } else { g.SetActive(true); g.GetComponent <Item>().Amount = amount; return(true); } } Destroy(g); return(false); }
public PhysicsSector[] GetSectors(SimplePhysics physics) { if (physics.IsEmpty) { return(new PhysicsSector[0]); } var position = physics.Position - Map.Offset; // Add margin to be sure. var radiusX = physics.Type.RadiusX + 10; var radiusY = physics.Type.RadiusY + 10; var points = new MPos[4]; // Corner points points[0] = new MPos(position.X + radiusX, position.Y + radiusY); // Sector 1 ( x| y) points[1] = new MPos(position.X + radiusX, position.Y - radiusY); // Sector 2 ( x|-y) points[2] = new MPos(position.X - radiusX, position.Y - radiusY); // Sector 3 (-x|-y) points[3] = new MPos(position.X - radiusX, position.Y + radiusY); // Sector 4 (-x| y) // Corner sectors var sectorPositions = new MPos[4]; for (int i = 0; i < 4; i++) { var point = points[i]; var x = point.X / (SectorSize * 1024f); if (x < 0) { x = 0; } if (x >= Bounds.X) { x = Bounds.X - 1; } var y = point.Y / (SectorSize * 1024f); if (y < 0) { y = 0; } if (y >= Bounds.Y) { y = Bounds.Y - 1; } sectorPositions[i] = new MPos((int)Math.Floor(x), (int)Math.Floor(y)); } // Determine Size of the Sector field to enter and the sector with the smallest value (sector 3) var startPosition = sectorPositions[2]; // Difference plus one to have the field (e.g. 1 and 2 -> diff. 1 + 1 = 2 fields) var xSize = (sectorPositions[1].X - sectorPositions[2].X) + 1; var ySize = (sectorPositions[3].Y - sectorPositions[2].Y) + 1; var sectors = new List <PhysicsSector>(); for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { var sector = Sectors[startPosition.X + x, startPosition.Y + y]; if (!sectors.Contains(sector)) { sectors.Add(sector); } } } return(sectors.ToArray()); }
public bool CheckIntersection(SimplePhysics physics) { return(physicsList.Any((o) => o != physics && o.Intersects(physics))); }
public void Remove(SimplePhysics physics) { physicsList.Remove(physics); }
/// <summary> /// Check if there is any obstruction /// </summary> /// <returns><c>true</c> if this instance can build; otherwise, <c>false</c>.</returns> public bool CanBuild() { return(SimplePhysics.CanPlaceItem(DetectionCollider)); }