public void Update() { _oldPosition = _position; _offset = Vector2.Normalize(_velocity) * 32; _position += _velocity * Game1.Delta; _track.Line.Start = _oldPosition; _track.Line.End = _position + _offset; List <Vector2Object> intersectionsPlayer = CompareF.LineIntersectionRectangle(Game1.PlayerInstance.Boundary, new LineObject(Game1.PlayerInstance, _track.Line)); //if (intersectionsPlayer != null && intersectionsPlayer.Count > 0) //{ // Game1.mapLive.mapParticles.Remove(this); //} //foreach (Inpc npc in npcs) //{ // List<VectorObject> intersections = CompareF.LineIntersectionRectangle(npc, new LineObject(npc, _track.Line)); // if (intersections != null && intersections.Count > 0) // { // Game1.mapLive.mapParticles.Remove(this); // break; // } // else if (CompareF.RectangleVsVector2(npc.Boundary, _track.Line.End) == true) // { // Game1.mapLive.mapParticles.Remove(this); // break; // } //} if (CompareF.LineVsMap(Game1.mapLive.MapTree, _track).Count > 0) { Game1.mapLive.mapParticles.Remove(this); } //foreach (IRectangleGet rec in elevators) //{ // List<VectorObject> intersections = CompareF.LineIntersectionRectangle(rec,new LineObject(rec, _track.Line)); // if (intersections !=null && intersections.Count>0) // { // Game1.mapLive.mapParticles.Remove(this); // } // else if(CompareF.RectangleVsVector2(rec, _track.Line.End) == true) // { // Game1.mapLive.mapParticles.Remove(this); // } //} if (CompareF.LineIntersectionRectangle(Game1.mapLive.MapBoundary, _track).Count > 0) { Game1.mapLive.mapParticles.Remove(this); } if (CompareF.RectangleFVsRectangleF(Camera2DGame.Boundary, _track.Line.LineBoundingBox()) == false) { Game1.mapLive.mapParticles.Remove(this); } }
protected virtual void PlayerTakeDamage(ushort amount, IProjectile projectile) { List <Vector2Object> intersectionsPlayer = CompareF.LineIntersectionRectangle(Game1.PlayerInstance.Boundary, new LineObject(Game1.PlayerInstance, _track.Line)); if (intersectionsPlayer?.Count > 0 && (_from is Inpc)) { Game1.PlayerInstance.TakeDamage(amount); Game1.mapLive.MapProjectiles.Remove(projectile); } }
protected bool OutOfmap(IProjectile projectile, out Vector2Object hitPos) { hitPos = null; if (CompareF.LineIntersectionRectangle(Game1.mapLive.MapBoundary, _track).Count > 0) { hitPos = CompareF.NearestVector(_track.Line.Start, CompareF.LineIntersectionRectangle(Game1.mapLive.MapBoundary, _track)); Game1.mapLive.MapProjectiles.Remove(projectile); return(true); } return(false); }
protected virtual void DamageToNPC(Map map, IProjectile projectile) { foreach (Inpc npc in map.MapNpcs) { if (npc.Friendly == false) { List <Vector2Object> intersections = CompareF.LineIntersectionRectangle(npc, new LineObject(npc, _track.Line)); if ((intersections?.Count > 0 || CompareF.RectangleVsVector2(npc.Boundary, _track.Line.End) == true) && (_from is Player)) { Damage(npc, projectile); break; } } } }
public void Update(Map map) { base.Update(map, this); foreach (Inpc npc in map.MapNpcs) { if (npc.Friendly == false) { List <Vector2Object> intersections = CompareF.LineIntersectionRectangle(npc, new LineObject(npc, _track.Line)); if ((intersections?.Count > 0 || CompareF.RectangleVsVector2(npc.Boundary, _track.Line.End) == true) && (_from is Player)) { Damage(npc); AfterCollision(map, new Vector2Object(npc, _position)); map.MapProjectiles.Remove(this); break; } } } Vector2Object hitPos = null; if (OutOfmap(this, out hitPos) == true) { } if (RemoveOnMapCollision(map.MapTree, this, out hitPos) == true) { AfterCollision(map, hitPos); } if (CollisionWithMovables(map, this, out hitPos) == true) { AfterCollision(map, hitPos); } if (_wet == true) { _velocity /= 4; } }
//Test public List <Vector2Object> FindIntersectLine(LineSegmentF line) { List <Vector2Object> vectors = new List <Vector2Object>(); if (HasChilds == true) { if (CompareF.LineIntersectionRectangle(LeftBottom.Boundary, new LineObject(null, line)).Count > 0 || CompareF.RectangleVsVector2(LeftBottom.Boundary, line.End)) { vectors.AddRange(LeftBottom.FindIntersectLine(line)); } if (CompareF.LineIntersectionRectangle(LeftTop.Boundary, new LineObject(null, line)).Count > 0 || CompareF.RectangleVsVector2(LeftTop.Boundary, line.End)) { vectors.AddRange(LeftTop.FindIntersectLine(line)); } if (CompareF.LineIntersectionRectangle(RightBottom.Boundary, new LineObject(null, line)).Count > 0 || CompareF.RectangleVsVector2(RightBottom.Boundary, line.End)) { vectors.AddRange(RightBottom.FindIntersectLine(line)); } if (CompareF.LineIntersectionRectangle(RightTop.Boundary, new LineObject(null, line)).Count > 0 || CompareF.RectangleVsVector2(RightTop.Boundary, line.End)) { vectors.AddRange(RightTop.FindIntersectLine(line)); } return(vectors); } else { if (LevelSize == QuadTreeSizes.Size_32 && Holder != null && (CompareF.LineIntersectionRectangle(Boundary, new LineObject(null, line)).Count > 0 || CompareF.RectangleVsVector2(Boundary, line.End))) { vectors = CompareF.LineIntersectionRectangle(Boundary, new LineObject(null, line)); return(vectors); } return(vectors); } }
protected virtual bool CollisionWithMovables(Map map, IProjectile projectile, out Vector2Object hit) { foreach (IRectanglePhysics rec in map.MapMovables) { List <Vector2Object> intersections = CompareF.LineIntersectionRectangle(rec, new LineObject(rec, _track.Line)); if (intersections?.Count > 0) { Game1.mapLive.MapProjectiles.Remove(projectile); hit = CompareF.NearestVector(_track.Line.Start, intersections); return(true); } if (CompareF.RectangleVsVector2(rec, _track.Line.End) == true) { Game1.mapLive.MapProjectiles.Remove(projectile); hit = new Vector2Object(rec, _track.Line.End); return(true); } } hit = null; return(false); }
public void Update(Map map) { _size = (float)Math.Sin(Game1.Time * 32) / 8 + 0.5f; _particleTime.Update(); if (_ballTime.Ready) { _effects.Add(new EnerergyCircle(new CircleF(_position, 16), 16, _velocity)); _ballTime.Reset(); } List <Vector2> trackVectors = LineSegmentF.PointsOnLine(_position, _oldPosition, 64); if (_particleTime.Ready == true) { foreach (Vector2 vector in trackVectors) { Game1.mapLive.mapParticles.Add(new ParticleBlackDrop(vector, _velocity, Game1.Textures["BlackParticle"])); } _particleTime.Reset(); } UpdateLine(); _lightTime.Update(); _ballTime.Update(); GetWet(map); int j = 0; foreach (Inpc npc in map.MapNpcs.Reverse <Inpc>()) { if (j < 8) { if (npc.Friendly == false) { List <Vector2Object> intersections = CompareF.LineIntersectionRectangle(npc, new LineObject(npc, _track.Line)); if (intersections != null && intersections.Count > 0) { Damage(npc, this); break; } else if (CompareF.RectangleVsVector2(npc.Boundary, _track.Line.End) == true) { Damage(npc, this); break; } if (_lightTime.Ready) { if (LightningAttack.StrikeLightning(_position, npc, _damage) == true) { j++; } _lightTime.Reset(); } } } } Vector2Object hitPos = null; if (OutOfmap(this, out hitPos) == true) { AfterCollision(map, hitPos); } if (RemoveOnMapCollision(map.MapTree, this, out hitPos) == true) { AfterCollision(map, hitPos); } if (CollisionWithMovables(map, this, out hitPos) == true) { AfterCollision(map, hitPos); } if (_wet == true) { Game1.mapLive.MapProjectiles.Remove(this); } foreach (IEffect effect in _effects.Reverse <IEffect>()) { effect.Update(_effects); } }
public void Update(Map map) { if (_wet == false) { _trail.Update(_position, _velocity, 1); } UpdateLine(); _bubbleTime.Update(); _InWater = false; if (CompareF.LineBoundaryVsMap(map.WaterTree, _track).Count > 0) { _InWater = true; if (_bubbleTime.Ready == true) { Game1.mapLive.mapParticles.Add(new ParticleBubble(_position)); _bubbleTime.Reset(); } } if (_wet == true && _wet != _wetPreviousFrame) { _velocity /= 4; _trail.LeftParticle(); } foreach (Inpc npc in map.MapNpcs) { if (npc.Friendly == false) { List <Vector2Object> intersections = CompareF.LineIntersectionRectangle(npc, new LineObject(npc, _track.Line)); if ((intersections?.Count > 0 || CompareF.RectangleVsVector2(npc.Boundary, _track.Line.End) == true) && (_from is Player)) { Damage(new Vector2Object(npc, _position), npc); AfterCollision(map, new Vector2Object(npc, _position)); break; } } } Vector2Object hitPos = null; if (OutOfmap(this, out hitPos) == true) { AfterCollision(map, new Vector2Object(Game1.mapLive, _position)); } if (CollisionWithMovables(map, this, out hitPos) == true) { AfterCollision(map, hitPos); } if (RemoveOnMapCollision(map.MapTree, this, out hitPos) == true) { AfterCollision(map, hitPos); } _velocity = CompareF.RotateVector2(_velocity, (float)(Math.Sin(Game1.Time * 16) / 64f)); _timeTrail.Update(); if (_timeTrail.Ready == true || _wet == true) { if (_wet == false) { List <Vector2> vectors = LineSegmentF.PointsOnLine(_position.ShiftOverDistance(32, (float)(CompareF.VectorToAngle(_velocity) + Math.PI)), _oldInterpol, 64); foreach (Vector2 vector in vectors) { for (int i = 0; i < 3; i++) { Game1.mapLive.mapParticles.Add(new ParticleCircleSmoke(vector + new Vector2(Globals.GlobalRandom.Next(-8, 9), Globals.GlobalRandom.Next(-8, 9)), Game1.Textures["SmokeCircle"])); } } } _timeTrail.Reset(); _oldInterpol = _position; } _wetPreviousFrame = _wet; GetWet(map); }
public void Update(Map map) { UpdateLine(); _hurtTimer.Update(); List <Vector2Object> intersectionsPlayer = CompareF.LineIntersectionRectangle(Game1.PlayerInstance.Boundary, new LineObject(Game1.PlayerInstance, _track.Line)); if (intersectionsPlayer?.Count > 0 && (_from is Inpc)) { Game1.PlayerInstance.TakeDamage(5); } foreach (Inpc npc in map.MapNpcs) { if (npc.Friendly == false) { List <Vector2Object> intersections = CompareF.LineIntersectionRectangle(npc, new LineObject(npc, _track.Line)); if ((intersections != null && intersections.Count > 0 && (_from is Player)) || CompareF.RectangleVsVector2(npc.Boundary, _track.Line.End) == true) { if (_hurtTimer.Ready == true) { npc.Stun(); npc.KineticDamage(_damage); npc.Push(_velocity * 0.1f); _hurtTimer.Reset(); i++; } break; } if (i > 4) { Game1.mapLive.MapProjectiles.Remove(this); } } } Vector2Object hitPos = null; if (OutOfmap(this, out hitPos) == true) { BurstParticles(hitPos.Vector2); } if (RemoveOnMapCollision(map.MapTree, this, out hitPos) == true) { BurstParticles(hitPos.Vector2); } if (CollisionWithMovables(map, this, out hitPos) == true) { BurstParticles(hitPos.Vector2); } GetWet(map); if (_wet) { Game1.mapLive.MapProjectiles.Remove(this); } _velocity.Y += 0.03f; _trailTimer.Update(); if (_trailTimer.Ready == true) { List <Vector2> vectors = LineSegmentF.PointsOnLine(_position, _oldInterpol, 64); Vector2 random = new Vector2(Globals.GlobalRandom.Next(-_maximums, _maximums + 1), Globals.GlobalRandom.Next(-_maximums, _maximums + 1)); foreach (Vector2 vector in vectors) { for (int i = 0; i < 3; i++) { Game1.mapLive.mapParticles.Add(new ParticleCircleFlame(vector + new Vector2(Globals.GlobalRandom.Next(-16, 17), Globals.GlobalRandom.Next(-16, 17)), Game1.Textures["FlameCircle"])); } } _trailTimer.Reset(); _oldInterpol = _position + random; } _trail.Update(_position, _velocity, 1); }