public static bool StrikeLightning(Vector2 position, Inpc npc, short damage) { if (npc.Friendly == false) { if (LineSegmentF.Lenght(npc.Boundary.Origin, position) < 256) { LineSegmentF _ray = new LineSegmentF(npc.Boundary.Origin, position); if (CompareF.LineVsMap(Game1.mapLive.MapTree, new LineObject(Game1.mapLive, _ray)).Count == 0) { Game1.mapLive.mapLightings.Add(new Lightning(npc.Boundary.Origin, position, Game1.debug_thin, 6)); Game1.mapLive.mapLightings.Add(new Lightning(npc.Boundary.Origin, position, Game1.debug_thin, 2)); npc.Stun(); npc.Push(new Vector2(0, -0.2f)); npc.KineticDamage(damage); Camera2DGame.Shake(5, position); Sound _strikeSound = new Sound(Game1.soundElectro, position); Game1.Sounds3D.Add(_strikeSound); Game1.Sounds3D[Game1.Sounds3D.IndexOf(_strikeSound)].Play(); } return(true); } } return(false); }
public void Update(Vector2 listenerPos) { if (soundEffectInstance.State == SoundState.Playing) { if (_position != null) { float pan = (_position.Value.X - listenerPos.X) / (2048f * 2); float volume = 1f - LineSegmentF.Lenght(listenerPos, _position.Value) / 2048; if (pan > _maxPan) { pan = _maxPan; } if (pan < -_maxPan) { pan = -_maxPan; } if (volume > 1f) { volume = 1f; } if (volume < 0) { volume = 0f; } Change(volume * MathHelper.Clamp(VolumeOveral, 0f, 1f), pan); } } IsNew = false; }
public static void Explode(Vector2 pos, short damage) { CircleF circle = new CircleF(pos, 128); foreach (IParticle prtcl in Game1.mapLive.mapParticles) { if (prtcl.Boundary != null) { LineSegmentF Temp = new LineSegmentF(pos, prtcl.Boundary.Origin); Vector2?_thru = CompareF.IntersectionLineWithOthers(Temp, Game1.mapLive.TileMapLines, null); if (_thru == null) { prtcl.Push(Vector2.Normalize(Temp.NormalizedWithZeroSolution() * (float)(Globals.GlobalRandom.NextDouble()) * 2)); } } } int j = 0; foreach (Inpc npc in Game1.mapLive.MapNpcs) { if (j < 8) { LineSegmentF Temp = new LineSegmentF(pos, npc.Boundary.Origin); Vector2?_thru = CompareF.IntersectionLineWithOthers(Temp, Game1.mapLive.TileMapLines, null); if (_thru == null && LineSegmentF.Lenght(pos, npc.Boundary.Origin) < 256) { if (npc.Friendly == false) { npc.KineticDamage(damage); } npc.Push(Vector2.Normalize(Temp.NormalizedWithZeroSolution() * (float)(Globals.GlobalRandom.NextDouble()) * 2)); j++; } } } int x = 4; for (int i = 0; i < x; i++) { Game1.mapLive.mapParticles.Add(new ParticleSmokeBig(circle.GenerateRandomPoint())); } for (int i = 0; i < x; i++) { Game1.mapLive.mapParticles.Add(new ParticleFireBig(circle.GenerateRandomPoint())); } for (int i = 0; i < x; i++) { Game1.mapLive.mapParticles.Add(new ParticleFireSmall(circle.GenerateRandomPoint())); } Camera2DGame.Shake(10, pos); Sound.PlaySoundPosition(pos, Game1.soundExplosion, CustomMath.RandomAroundZero(Globals.GlobalRandom) / 2f); }
new public void Draw(LineSegmentF rayBarrel) { if (Ammo > 0) { if (_IsOn) { if (_line != null) { Game1.SpriteBatchGlobal.Draw(Game1.debug_longTex, rayBarrel.End, null, new Rectangle(0, 0, (int)(_line.Lenght().Value - GunBarrel), 8), new Vector2(0, 4), _rotation, new Vector2(1, (float)(Math.Sin(Game1.Time * _timeMultiplier) * 0.5f) + 1), Color.Red, SpriteEffects.None); Game1.SpriteBatchGlobal.Draw(Game1.laserDest, _line.End, origin: new Vector2(64), scale: new Vector2((float)(Math.Sin(Game1.Time * _timeMultiplier) * 0.2f) + 0.5f), color: Color.White); } } } SimpleGunDrawModule.DrawLaserGun(rayBarrel, (int)OffsetKick); }
public static void Shake(int amount, Vector2 origin) { ShakeAmountTime = amount; ShakeAmountVelocity = (512 - (int)LineSegmentF.Lenght(Position + Globals.WinRenderSize / 2, origin)) / 32; if (ShakeAmountVelocity > 16) { ShakeAmountVelocity = 16; } if (ShakeAmountVelocity < 0) { ShakeAmountVelocity = 0; } }
public void Update(List <Inpc> npcs) { if (Tint < 1f) { Tint += Game1.Delta / 100; } if (Tint > 1f) { Tint = 1f; } _timeShoot.Update(); if (Health <= 0) { Kill(); } if (LineSegmentF.Lenght(Boundary.Origin, Game1.PlayerInstance.Boundary.Origin) < 800) { //----------- _angle = Vector2.Dot(new LineSegmentF(Boundary.Origin, Game1.PlayerInstance.Boundary.Origin).NormalizedWithZeroSolution(), CompareF.AngleToVector(_rotation)); _velocityOfRotation = 0f; if (_angle > 0.01f) { _velocityOfRotation = -0.001f; } if (_angle < -0.01f) { _velocityOfRotation = 0.001f; } //--------- _rotation += _velocityOfRotation * Game1.Delta; _destination = CompareF.AngleToVector((float)(_rotation + Math.PI / 2f)); _barrel = Boundary.Origin + Vector2.Normalize(_destination) * (24 + 6); _destination = CompareF.RotateVector2(_destination, (float)(Globals.GlobalRandom.NextDouble() - 0.5f) / 4f); if (_timeShoot.Ready == true) { _ammo--; Game1.mapLive.MapProjectiles.Add(new Projectile(5, _destination, _barrel, this)); Sound.PlaySoundPosition(Boundary.Origin, Game1.sound); _timeShoot.Reset(); } } }
public void Update() { if (On == false) { Speed = 0; } else { Speed = SpeedMax; if (from == 0) { _platform.Update(new LineSegmentF(Start, Nodes[0]).NormalizedWithZeroSolution() * Speed); if (LineSegmentF.Lenght(Start, Nodes[0]) < LineSegmentF.Lenght(Start, _platform.Boundary.Origin)) { _platform.Origin = Nodes[0]; from++; } } if (from > 0 && from < Nodes.Count) { _platform.Update(new LineSegmentF(Nodes[from - 1], Nodes[from]).NormalizedWithZeroSolution() * Speed); if (LineSegmentF.Lenght(Nodes[from - 1], Nodes[from]) < LineSegmentF.Lenght(Nodes[from - 1], _platform.Boundary.Origin)) { _platform.Origin = Nodes[from]; from++; } } if (from == Nodes.Count) { _platform.Update(new LineSegmentF(Nodes[from - 1], Start).NormalizedWithZeroSolution() * Speed); if (LineSegmentF.Lenght(Nodes[from - 1], Start) < LineSegmentF.Lenght(Nodes[from - 1], _platform.Boundary.Origin)) { _platform.Origin = Start; from = 0; } } } }
private void Direction() { if (Game1.PlayerInstance.Alive == true) { if (LineSegmentF.Lenght(Game1.PlayerInstance.Boundary.Origin, Boundary.Origin) < Sense) { if (Boundary.Origin.X > Game1.PlayerInstance.Boundary.Origin.X && Game1.PlayerInstance.Boundary.Origin.X - Boundary.Origin.X < -16f) { Goes = ZombieStates.left; } if (Boundary.Origin.X < Game1.PlayerInstance.Boundary.Origin.X && Game1.PlayerInstance.Boundary.Origin.X - Boundary.Origin.X > 16f) { Goes = ZombieStates.right; } } else { Goes = ZombieStates.stay; } } }
public static LineSegmentF ShortestLineSegment(List <LineSegmentF> segments) { if (segments != null) { LineSegmentF shortest = null; LineSegmentF shortestSegment = new LineSegmentF(0, 0, float.PositiveInfinity, float.PositiveInfinity); foreach (LineSegmentF segment in segments) { if (segment.Lenght() < shortestSegment.Lenght()) { shortestSegment = segment; shortest = segment; } } return(shortest); } else { return(null); } }
public static Vector2Object NearestVector(Vector2 origin, List <Vector2Object> vectors) { if (vectors != null) { Vector2Object nearest = null; float shortestDistance = float.PositiveInfinity; foreach (Vector2Object vector in vectors) { if (LineSegmentF.Lenght(origin, vector.Vector2) < shortestDistance) { shortestDistance = LineSegmentF.Lenght(origin, vector.Vector2); nearest = vector; } } return(nearest); } else { return(null); } }
private void Jump() { if (_resolver.TouchTop == true || _resolver.TouchBottomMovable == true) { if (Globals.GlobalRandom.Next(0, 128) == 1) { if (Goes == ZombieStates.left) { Push(new Vector2(-0.2f, -0.8f)); } if (Goes == ZombieStates.right) { Push(new Vector2(0.2f, -0.8f)); } } } if (Game1.PlayerInstance.Alive == true) { if (_resolver.TouchTop == true || _resolver.TouchBottomMovable == true) { if (Globals.GlobalRandom.Next(0, 128) == 1) { if (LineSegmentF.Lenght(Boundary.Origin, Game1.PlayerInstance.Boundary.Origin) < Sense) { if (Goes == ZombieStates.left) { Push(new Vector2(-0.2f, -0.8f)); } if (Goes == ZombieStates.right) { Push(new Vector2(0.2f, -0.8f)); } } } } } }
public PlayerTurret(Vector2 position) : base() { Boundary = new RectangleF(new Vector2(36, 64), position); _resolver = new CollisionResolver(Globals.TileSize); _weight = 1f; _time = new Timer(100, true); _target = null; _rotation = (float)Math.PI / 2f; _ammo = 0; _bubbleTime = new Timer(300, true); _kick = 0; if (_target == null || LineSegmentF.Lenght(HeadPos, _target.Boundary.Origin) > 512 || CompareF.IntersectionLineWithOthers(new LineObject(Game1.PlayerInstance, new LineSegmentF(HeadPos, _target.Boundary.Origin)), Game1.mapLive.TileMapLines, Game1.mapLive) != null) { foreach (Inpc npc in Game1.mapLive.MapNpcs) { if (npc.Friendly == false && !(npc is IUnkillable) && LineSegmentF.Lenght(HeadPos, npc.Boundary.Origin) <= 512 && CompareF.IntersectionLineWithOthers(new LineObject(Game1.PlayerInstance, new LineSegmentF(HeadPos, npc.Boundary.Origin)), Game1.mapLive.TileMapLines, Game1.mapLive) == null) { _target = npc; break; } } } }
public void DrawNormal() { Game1.EffectRotateNormals.Parameters["flip"].SetValue(new Vector2(1, 1)); Game1.EffectRotateNormals.Parameters["angle"].SetValue(new LineSegmentF(Start, Nodes[0]).ToAngle()); Game1.EffectRotateNormals.CurrentTechnique.Passes[0].Apply(); Game1.SpriteBatchGlobal.Draw(Game1.Textures["liftRailNormal"], position: Start, sourceRectangle: new Rectangle(0, 0, (int)LineSegmentF.Lenght(Start, Nodes[0]), 14 * 2), origin: new Vector2(0, 7 * 2), rotation: new LineSegmentF(Start, Nodes[0]).ToAngle()); if (Nodes.Count > 1) { for (int i = 0; i < Nodes.Count - 1; i++) { Game1.EffectRotateNormals.Parameters["angle"].SetValue(new LineSegmentF(Nodes[i], Nodes[i + 1]).ToAngle()); Game1.EffectRotateNormals.CurrentTechnique.Passes[0].Apply(); Game1.SpriteBatchGlobal.Draw(Game1.Textures["liftRailNormal"], position: Nodes[i], sourceRectangle: new Rectangle(0, 0, (int)LineSegmentF.Lenght(Nodes[i], Nodes[i + 1]), 14 * 2), origin: new Vector2(0, 7 * 2), rotation: new LineSegmentF(Nodes[i], Nodes[i + 1]).ToAngle()); } } if (Nodes.Count > 2) { Game1.EffectRotateNormals.Parameters["angle"].SetValue(new LineSegmentF(Nodes[Nodes.Count - 1], Start).ToAngle()); Game1.EffectRotateNormals.CurrentTechnique.Passes[0].Apply(); Game1.SpriteBatchGlobal.Draw(Game1.Textures["liftRailNormal"], position: Nodes[Nodes.Count - 1], sourceRectangle: new Rectangle(0, 0, (int)LineSegmentF.Lenght(Nodes[Nodes.Count - 1], Start), 14 * 2), origin: new Vector2(0, 7 * 2), rotation: new LineSegmentF(Nodes[Nodes.Count - 1], Start).ToAngle()); } Effects.ResetEffect3D(); Game1.SpriteBatchGlobal.Draw(Game1.Textures["liftEndNormal"], position: Start, origin: new Vector2(11 * 2)); foreach (Vector2 node in Nodes) { Game1.SpriteBatchGlobal.Draw(Game1.Textures["liftEndNormal"], position: node, origin: new Vector2(11 * 2)); } Game1.EffectRotateNormals.Parameters["angle"].SetValue(_platform.Velocity.ToAngle()); Game1.EffectRotateNormals.CurrentTechnique.Passes[0].Apply(); Game1.SpriteBatchGlobal.Draw(Game1.Textures["elevatorClawNormal"], _platform.Origin, origin: new Vector2(18 * 2), rotation: _platform.Velocity.ToAngle()); Effects.ResetEffect3D(); _platform.DrawNormal(Game1.Textures["platformNormal"]); }
public void Draw() { Game1.SpriteBatchGlobal.Draw(Game1.Textures["ElevatorClawBack"], _platform.Origin, origin: new Vector2(18 * 2), rotation: _platform.Velocity.ToAngle()); Game1.SpriteBatchGlobal.Draw(Game1.liftRail, position: Start, sourceRectangle: new Rectangle(0, 0, (int)LineSegmentF.Lenght(Start, Nodes[0]), 14 * 2), origin: new Vector2(0, 7 * 2), rotation: new LineSegmentF(Start, Nodes[0]).ToAngle()); if (Nodes.Count > 1) { for (int i = 0; i < Nodes.Count - 1; i++) { Game1.SpriteBatchGlobal.Draw(Game1.liftRail, position: Nodes[i], sourceRectangle: new Rectangle(0, 0, (int)LineSegmentF.Lenght(Nodes[i], Nodes[i + 1]), 14 * 2), origin: new Vector2(0, 7 * 2), rotation: new LineSegmentF(Nodes[i], Nodes[i + 1]).ToAngle()); } } if (Nodes.Count > 2) { Game1.SpriteBatchGlobal.Draw(Game1.liftRail, position: Nodes[Nodes.Count - 1], sourceRectangle: new Rectangle(0, 0, (int)LineSegmentF.Lenght(Nodes[Nodes.Count - 1], Start), 14 * 2), origin: new Vector2(0, 7 * 2), rotation: new LineSegmentF(Nodes[Nodes.Count - 1], Start).ToAngle()); } Game1.SpriteBatchGlobal.Draw(Game1.liftEnd, position: Start, origin: new Vector2(11 * 2)); foreach (Vector2 node in Nodes) { Game1.SpriteBatchGlobal.Draw(Game1.liftEnd, position: node, origin: new Vector2(11 * 2)); } Game1.SpriteBatchGlobal.Draw(Game1.Textures["ElevatorClaw"], _platform.Origin, origin: new Vector2(18 * 2), rotation: _platform.Velocity.ToAngle()); _platform.Draw(Game1.platformTex); }
public void Update(List <Inpc> npcs) { _time.Update(); _bubbleTime.Update(); if (_muzzleAlpha > 0) { _muzzleAlpha -= Game1.Delta / 50; } if (_kick > 0) { _kick--; } if (_resolver.InWater == true) { if (_bubbleTime.Ready == true) { Game1.mapLive.mapParticles.Add(new ParticleBubble(HeadPos)); _bubbleTime.Reset(); } } if (_target != null && _ammo > 0) { _angle = Vector2.Dot(new LineSegmentF(HeadPos, _target.Boundary.Origin).NormalizedWithZeroSolution(), CompareF.AngleToVector(_rotation)); _rotVelocity = 0f; if (_angle > 0.06f) { _rotVelocity = -(float)Math.PI / 720; } if (_angle < -0.06f) { _rotVelocity = (float)Math.PI / 720; } //--------- _rotation += _rotVelocity * Game1.Delta; _destination = CompareF.AngleToVector((float)(_rotation + Math.PI / 2f)); } else { _angle = Vector2.Dot(CompareF.AngleToVector(_rotation), CompareF.AngleToVector((float)Math.PI)); _rotVelocity = 0f; if (_angle > 0.02f) { _rotVelocity = -(float)Math.PI / 720; } if (_angle < -0.02f) { _rotVelocity = (float)Math.PI / 720; } _rotation += _rotVelocity * Game1.Delta; _destination = CompareF.AngleToVector((float)(_rotation + Math.PI / 2f)); } if (_time.Ready == true && _target != null && _ammo > 0 && Math.Abs(ExtensionMethods.AngleDifference(new LineSegmentF(HeadPos, _target.Boundary.Origin).ToAngle(), _rotation)) < 25f) { if (Locked == false) { _ammo--; } Game1.mapLive.MapProjectiles.Add(new Projectile(5, _destination, Barrel, Game1.PlayerInstance)); _kick = 4; _muzzleAlpha = 1f; Sound.PlaySoundPosition(HeadPos, Game1.sound); _time.Reset(); } if (Game1.mapLive.MapNpcs.Contains(_target) == false) { _target = null; } Pressure(this); _target = null; foreach (Inpc npc in Game1.mapLive.MapNpcs) { if (npc.Friendly == false && !(npc is IUnkillable) && LineSegmentF.Lenght(HeadPos, npc.Boundary.Origin) <= 512 && CompareF.WeaponRayObstruction(Boundary, new LineSegmentF(HeadPos, npc.Boundary.Origin), this).Object == null) { _target = npc; break; } } _resolver.move(ref _velocity, new Vector2(2f), Boundary, 0f, new Vector2(0.2f), new Vector2(0.02f), new Vector2(0.3f), Game1.mapLive.MapMovables); }