public void Init(InputPlayerType playerType, ClsnType type, float x, float y, float w, float h) { m_Type = type; m_PlayerType = playerType; m_CreateTimer = Time.realtimeSinceStartup; BoxCollider2D box = this.Box; float rw = w / 100f; if (rw < 0) { rw = -rw; } float rh = h / 100f; if (rh < 0) { rh = -rh; } box.offset = Vector2.zero; box.size = new Vector2(rw, rh); var trans = this.transform; Vector2 pos = new Vector2((x + w / 2f) / 100f, -(y + h / 2f) / 100f); trans.localPosition = pos; trans.localRotation = Quaternion.identity; }
public Collision(Entity lhs, ClsnType lhstype, Entity rhs, ClsnType rhstype) { if (lhs == null) { throw new ArgumentNullException("lhs"); } if (rhs == null) { throw new ArgumentNullException("rhs"); } m_lhs = lhs; m_lhsclsntype = lhstype; m_rhs = rhs; m_rhsclsntype = rhstype; m_type = CollisionType.None; if (Left is Player && LeftClsnType == ClsnType.Type2Normal && Right is Player && RightClsnType == ClsnType.Type2Normal) { m_type = CollisionType.PlayerPush; } else if (Left is Character && LeftClsnType == ClsnType.Type1Attack && Right is Character && RightClsnType == ClsnType.Type2Normal) { m_type = CollisionType.CharacterHit; } else if (Left is Projectile && LeftClsnType == ClsnType.Type1Attack && Right is Character && RightClsnType == ClsnType.Type2Normal) { m_type = CollisionType.ProjectileHit; } else if (Left is Projectile && LeftClsnType == ClsnType.Type1Attack && Right is Projectile && RightClsnType == ClsnType.Type1Attack) { m_type = CollisionType.ProjectileCollision; } }
/// <summary> /// Creates a new collision box. /// </summary> /// <param name="line">A line of text representing a collision box.</param> /// <param name="overridetype">The type of collision box to be created.</param> /// <returns>A new instance of the Clsn class if it could be created; null otherwise.</returns> Clsn?CreateClsn(String line, ClsnType overridetype) { if (String.Compare(line, 0, "Clsn", 0, 4, StringComparison.OrdinalIgnoreCase) != 0) { return(null); } Match match = m_clsnlineregex.Match(line); if (match.Success == false) { return(null); } //if (String.Equals(match.Groups[1].Value, "1") == true) clsn.Type = ClsnType.Type1Attack; //if (String.Equals(match.Groups[1].Value, "2") == true) clsn.Type = ClsnType.Type2Normal; Int32 x1 = Int32.Parse(match.Groups[3].Value); Int32 y1 = Int32.Parse(match.Groups[4].Value); Int32 x2 = Int32.Parse(match.Groups[5].Value); Int32 y2 = Int32.Parse(match.Groups[6].Value); if (x1 > x2) { Misc.Swap(ref x1, ref x2); } if (y1 > y2) { Misc.Swap(ref y1, ref y2); } return(new Clsn(overridetype, new Rectangle(x1, y1, x2 - x1, y2 - y1))); }
public Clsn CreateClsnBox(InputPlayerType playerType, string name, Transform parent, float x, float y, float w, float h, bool isClsn2 = true) { Clsn r = GetClsnColliderFromPool(name); if (r == null) { return(r); } var trans = r.transform; if (trans.parent != parent) { trans.SetParent(parent, false); } ClsnType tt = isClsn2 ? ClsnType.def: ClsnType.attack; r.Init(playerType, tt, x, y, w, h); if (!r.gameObject.activeSelf) { r.gameObject.SetActive(true); } return(r); }
public Collision(Entity lhs, ClsnType lhstype, Entity rhs, ClsnType rhstype) { if (lhs == null) throw new ArgumentNullException("lhs"); if (rhs == null) throw new ArgumentNullException("rhs"); m_lhs = lhs; m_lhsclsntype = lhstype; m_rhs = rhs; m_rhsclsntype = rhstype; m_type = CollisionType.None; if (Left is Player && LeftClsnType == ClsnType.Type2Normal && Right is Player && RightClsnType == ClsnType.Type2Normal) { m_type = CollisionType.PlayerPush; } else if (Left is Character && LeftClsnType == ClsnType.Type1Attack && Right is Character && RightClsnType == ClsnType.Type2Normal) { m_type = CollisionType.CharacterHit; } else if (Left is Projectile && LeftClsnType == ClsnType.Type1Attack && Right is Character && RightClsnType == ClsnType.Type2Normal) { m_type = CollisionType.ProjectileHit; } else if (Left is Projectile && LeftClsnType == ClsnType.Type1Attack && Right is Projectile && RightClsnType == ClsnType.Type1Attack) { m_type = CollisionType.ProjectileCollision; } }
public static Boolean HasCollision(Entity lhs, ClsnType lhstype, Entity rhs, ClsnType rhstype) { if (lhs == null) { throw new ArgumentNullException("lhs"); } if (rhs == null) { throw new ArgumentNullException("rhs"); } foreach (Animations.Clsn lhs_clsn in lhs.AnimationManager.CurrentElement) { if (lhs_clsn.ClsnType != lhstype) { continue; } Rectangle lhs_rect = lhs_clsn.MakeRect(lhs.CurrentLocation, lhs.CurrentScale, lhs.CurrentFacing); foreach (Animations.Clsn rhs_clsn in rhs.AnimationManager.CurrentElement) { if (rhs_clsn.ClsnType != rhstype) { continue; } Rectangle rhs_rect = rhs_clsn.MakeRect(rhs.CurrentLocation, rhs.CurrentScale, rhs.CurrentFacing); if (lhs_rect.Intersects(rhs_rect) == true) { return(true); } } } return(false); }
public static Boolean HasCollision(Entity lhs, ClsnType lhstype, Entity rhs, ClsnType rhstype) { if (lhs == null) throw new ArgumentNullException("lhs"); if (rhs == null) throw new ArgumentNullException("rhs"); foreach (Animations.Clsn lhs_clsn in lhs.AnimationManager.CurrentElement) { if (lhs_clsn.ClsnType != lhstype) continue; Rectangle lhs_rect = lhs_clsn.MakeRect(lhs.CurrentLocation, lhs.CurrentScale, lhs.CurrentFacing); foreach (Animations.Clsn rhs_clsn in rhs.AnimationManager.CurrentElement) { if (rhs_clsn.ClsnType != rhstype) continue; Rectangle rhs_rect = rhs_clsn.MakeRect(rhs.CurrentLocation, rhs.CurrentScale, rhs.CurrentFacing); if (lhs_rect.Intersects(rhs_rect) == true) return true; } } return false; }
/// <summary> /// Returns a string representation of this object. /// </summary> /// <returns>A string representation of this object.</returns> public override String ToString() { return(ClsnType.ToString() + " - " + Rectangle.ToString()); }
/// <summary> /// Creates a new instance of this class. /// </summary> /// <param name="clsntype">The type of collision box.</param> /// <param name="rectangle">The Rectangle defining the dimensions of the collision box.</param> public Clsn(ClsnType clsntype, Rectangle rectangle) { m_clsntype = clsntype; m_rect = rectangle; }
/// <summary> /// Creates a new Animation. /// </summary> /// <param name="section">The information used to intialize the Animation.</param> /// <returns>A new instance of the Animation class if it could be created; null otherwise.</returns> Animation CreateAnimation(TextSection section) { if (section == null) { throw new ArgumentNullException("section"); } Match titlematch = m_animationtitleregex.Match(section.Title); if (titlematch.Success == false) { return(null); } StringComparer sc = StringComparer.OrdinalIgnoreCase; Int32 animationnumber = Int32.Parse(titlematch.Groups[1].Value); Int32 loopstart = 0; Int32 starttick = 0; List <AnimationElement> elements = new List <AnimationElement>(); List <Clsn> loading_type1 = new List <Clsn>(); List <Clsn> loading_type2 = new List <Clsn>(); List <Clsn> default_type1 = new List <Clsn>(); List <Clsn> default_type2 = new List <Clsn>(); Boolean loaddefault = false; ClsnType loadtype = ClsnType.None; Int32 loadcount = 0; foreach (String line in section.Lines) { if (loadcount > 0) { Clsn?clsn = CreateClsn(line, loadtype); if (clsn != null) { if (loaddefault == true) { if (loadtype == ClsnType.Type1Attack) { default_type1.Add(clsn.Value); } if (loadtype == ClsnType.Type2Normal) { default_type2.Add(clsn.Value); } } else { if (loadtype == ClsnType.Type1Attack) { loading_type1.Add(clsn.Value); } if (loadtype == ClsnType.Type2Normal) { loading_type2.Add(clsn.Value); } } } else { Log.Write(LogLevel.Warning, LogSystem.AnimationSystem, "Could not create Clsn from line: {0}", line); } --loadcount; continue; } Match clsnmatch = m_clsnregex.Match(line); if (clsnmatch.Success == true) { ClsnType clsntype = ClsnType.None; if (sc.Equals(clsnmatch.Groups[1].Value, "1") == true) { clsntype = ClsnType.Type1Attack; } if (sc.Equals(clsnmatch.Groups[1].Value, "2") == true) { clsntype = ClsnType.Type2Normal; } Boolean isdefault = sc.Equals(clsnmatch.Groups[2].Value, "default"); if (isdefault == true) { if (clsntype == ClsnType.Type1Attack) { default_type1.Clear(); } if (clsntype == ClsnType.Type2Normal) { default_type2.Clear(); } } loadcount = Int32.Parse(clsnmatch.Groups[3].Value); loaddefault = isdefault; loadtype = clsntype; continue; } if (sc.Equals(line, "Loopstart") == true) { loopstart = elements.Count; continue; } AnimationElement element = CreateElement(line, elements.Count, starttick, default_type1, default_type2, loading_type1, loading_type2); if (element != null) { if (element.Gameticks == -1) { starttick = -1; } else { starttick += element.Gameticks; } elements.Add(element); loading_type1.Clear(); loading_type2.Clear(); } else { Log.Write(LogLevel.Warning, LogSystem.AnimationSystem, "Error parsing element for Animation #{0} - {1}", animationnumber, line); } } if (elements.Count == 0) { Log.Write(LogLevel.Warning, LogSystem.AnimationSystem, "No elements defined for Animation #{0}", animationnumber); return(null); } else { if (loopstart == elements.Count) { loopstart = 0; } return(new Animation(animationnumber, loopstart, elements)); } }
/// <summary> /// Creates a new instance of this class. /// </summary> /// <param name="clsntype">The type of collision box.</param> /// <param name="rectangle">The Rectangle defining the dimensions of the collision box.</param> public Clsn(ClsnType clsntype, Rectangle rectangle) { m_clsntype = clsntype; m_rect = rectangle; }
/// <summary> /// Creates a new collision box. /// </summary> /// <param name="line">A line of text representing a collision box.</param> /// <param name="overridetype">The type of collision box to be created.</param> /// <returns>A new instance of the Clsn class if it could be created; null otherwise.</returns> Clsn? CreateClsn(String line, ClsnType overridetype) { if (String.Compare(line, 0, "Clsn", 0, 4, StringComparison.OrdinalIgnoreCase) != 0) return null; Match match = m_clsnlineregex.Match(line); if (match.Success == false) return null; //if (String.Equals(match.Groups[1].Value, "1") == true) clsn.Type = ClsnType.Type1Attack; //if (String.Equals(match.Groups[1].Value, "2") == true) clsn.Type = ClsnType.Type2Normal; Int32 x1 = Int32.Parse(match.Groups[3].Value); Int32 y1 = Int32.Parse(match.Groups[4].Value); Int32 x2 = Int32.Parse(match.Groups[5].Value); Int32 y2 = Int32.Parse(match.Groups[6].Value); if (x1 > x2) Misc.Swap(ref x1, ref x2); if (y1 > y2) Misc.Swap(ref y1, ref y2); return new Clsn(overridetype, new Rectangle(x1, y1, x2 - x1, y2 - y1)); }