protected GameEntity(IHitbox area, Texture2D texture, int layer, int rotation = 0) { Area = area; this.texture = texture; Layer = layer; this.rotation = rotation; }
protected void CheckHitboxes() { collisionDictionary.Clear(); //Create dictionary of hitboxes that hit fighters to sort them with hitbox id foreach (IHitbox hitbox in list) { List <GameObject> collisions = hitbox.GetCollisionList(); foreach (GameObject collider in collisions) { if (collisionDictionary.ContainsKey(collider)) { collisionDictionary[collider].Add(hitbox); } else { List <IHitbox> value = new List <IHitbox>(); value.Add(hitbox); collisionDictionary.Add(collider, value); } } } //Remove Fighters who have shield collision List <GameObject> shieldingFighters = new List <GameObject>(); foreach (KeyValuePair <GameObject, List <IHitbox> > p in collisionDictionary) { if (p.Key.tag == "Shield") { shieldingFighters.Add(p.Key.transform.root.gameObject); victims.Add(p.Key.transform.root.gameObject); } } foreach (GameObject fighter in shieldingFighters) { collisionDictionary.Remove(fighter); } //Remove all but Hitbox with lowest ID for each fighter and process the highest ID hitbox foreach (KeyValuePair <GameObject, List <IHitbox> > p in collisionDictionary) { //Find hitbox with lowest ID IHitbox topIDHitbox = p.Value[0]; int topID = 10; foreach (IHitbox hitbox in p.Value) { if (hitbox.ID < topID) { topIDHitbox = hitbox; topID = hitbox.ID; } } //Debug.Log("Fighter: " + p.Key.name + ", Hitbox Chosen: " + topID); //Add to the victims list to prevent hitting again if (victims.Contains(p.Key)) { continue; } victims.Add(p.Key); topIDHitbox.OnHit(p.Key); } }
private void Start() { gameObject.tag = "Hitbox"; if (hitController == null) { hitController = GetComponent <IHitbox>(); } }
protected LivingGameEntity(IHitbox area, Texture2D texture, Texture2D armoredTexture, Texture2D shieldedTexture, int hull, int armor, int shields, int layer) : base(area, texture, layer) { ShouldDie = false; this.armoredTexture = armoredTexture; this.shieldedTexture = shieldedTexture; Hull = hull; Armor = armor; Shields = shields; }
public bool DetectCollision(IHitbox other) { if (other is RectHitbox otherR) { return (X1 < otherR.X2 && X2 > otherR.X1 && Y2 > otherR.Y1 && Y1 < otherR.Y2); } else if (other is TriHitbox) { // Defer the work to avoid duplicate code return(other.DetectCollision(this)); } return(false); }
public bool Intersects(IHitbox hitbox) { if (hitbox is null) { return(false); } if (hitbox is CircleHitbox c) { return(c.IsPointInside(Point)); } else if (hitbox is PointHitbox p) { return(IsPointInside(p.Point)); } throw new NotImplementedException(); }
protected Enemy(IHitbox area, Texture2D texture, Texture2D armoredTexture, Texture2D shieldedTexture, int hull, int armor, int shields, int layer) : base(area, texture, armoredTexture, shieldedTexture, hull, armor, shields, layer) { }
public bool DetectCollision(IHitbox other) { if (other is RectHitbox otherR) { if (ContainsPoint(new Point(otherR.X1, otherR.X2))) { return(true); } Line[] rectLines = { new Line(otherR.X1, otherR.Y1, otherR.X1, otherR.Y2), new Line(otherR.X1, otherR.Y1, otherR.X2, otherR.Y1), new Line(otherR.X2, otherR.Y2, otherR.X1, otherR.Y2), new Line(otherR.X2, otherR.Y2, otherR.X2, otherR.Y1), }; Line[] triLines = { new Line(R, S), new Line(S, T), new Line(T, R) }; foreach (Line l in rectLines) { foreach (Line l2 in triLines) { if (LinesIntersect(l.a, l.b, l2.a, l2.b)) { return(true); } } } } else if (other is TriHitbox otherT) { if (ContainsPoint(otherT.R)) { return(true); } Line[] tri1Lines = { new Line(R, S), new Line(S, T), new Line(T, R) }; Line[] tri2Lines = { new Line(otherT.R, otherT.S), new Line(otherT.S, otherT.T), new Line(otherT.T, otherT.R) }; foreach (Line l in tri1Lines) { foreach (Line l2 in tri2Lines) { if (LinesIntersect(l.a, l.b, l2.a, l2.b)) { return(true); } } } } return(false); }
internal Player(IHitbox area, Texture2D texture, Texture2D armoredTexture, Texture2D shieldedTexture) : base(area, texture, armoredTexture, shieldedTexture, 100, 100, 100, 3) { rectArea = (RectHitbox)area; }
protected Attack(int power, DamageType damageType, IHitbox area, Texture2D texture, int layer) : base(area, texture, layer) { Power = power; DamageType = damageType; }
public HitboxEventArgs(IHitbox hitbox) { Hitbox = hitbox; }