public static void Display(Vector2 position, bool horizontal, float length) { int numEffects = (int)(length / 20); float posScale = length / numEffects; Vector2 posFactor = (horizontal ? new Vector2(1f, 0f) : new Vector2(0f, -1f)) * posScale; lock (_defaultCommands) for (int i = 0; i < numEffects; i++) { Instance.Run(position * (i + 1), x => { float randScale = CDGMath.RandomFloat(0.5f, 0.8f); var cmd = _defaultCommands[1]; cmd.Properties[1] = CDGMath.RandomFloat(-30f, 30f).ToString(); cmd = _defaultCommands[2]; cmd.Properties[1] = CDGMath.RandomInt(-10, 10).ToString(); cmd.Properties[3] = CDGMath.RandomInt(-20, 0).ToString(); cmd = _defaultCommands[3]; cmd.Properties[1] = randScale.ToString(); cmd.Properties[3] = randScale.ToString(); }); } }
public override void Initialize() { m_bossTitle1 = new TextObj(Game.JunicodeFont); m_bossTitle1.Text = "The Forsaken"; m_bossTitle1.OutlineWidth = 2; m_bossTitle1.FontSize = 18f; m_bossTitle2 = new TextObj(Game.JunicodeLargeFont); m_bossTitle2.Text = "Alexander"; m_bossTitle2.OutlineWidth = 2; m_bossTitle2.FontSize = 40f; m_bossDivider = new SpriteObj("Blank_Sprite"); m_bossDivider.OutlineWidth = 2; foreach (var current in DoorList) { m_roomFloor = current.Bounds.Bottom; } m_bossChest = new ChestObj(null); m_bossChest.Position = new Vector2(Bounds.Center.X - m_bossChest.Width / 2f, Bounds.Center.Y); GameObjList.Add(m_bossChest); m_rainFG = new List <RaindropObj>(); for (var i = 0; i < 50; i++) { var raindropObj = new RaindropObj(new Vector2(CDGMath.RandomFloat(X - Width, X), CDGMath.RandomFloat(Y, Y + Height))); m_rainFG.Add(raindropObj); raindropObj.ChangeToParticle(); } base.Initialize(); }
public static void Display(int numEntities) { float step = 1320f / numEntities; lock (_defaultCommands) for (int i = 0; i < numEntities; i++) { Instance.Run(new Vector2(step * i, 720f), x => { x.Sprite.ForceDraw = true; var cmd = _defaultCommands[0]; cmd.Properties[1] = "0.8"; cmd = _defaultCommands[1]; cmd.Properties[1] = CDGMath.RandomFloat(-180f, 180f).ToString(); cmd = _defaultCommands[2]; cmd.Properties[1] = CDGMath.RandomInt(-50, 50).ToString(); cmd.Properties[3] = CDGMath.RandomInt(-50, 0).ToString(); cmd = _defaultCommands[3]; cmd.Duration = 0.5f; cmd.InitialValues[0] = 0.8f; }); } }
public void ItemSpinAnimation3() { var scale = m_itemSprite.Scale; m_itemSprite.Scale = Vector2.One; var num = 130f / m_itemSprite.Height; m_itemSprite.Scale = scale; Tween.To(m_itemSprite, 0.2f, Tween.EaseNone, "ScaleX", num.ToString(), "ScaleY", num.ToString()); Tween.To(m_itemSprite, 0.2f, Tween.EaseNone, "X", 660.ToString(), "Y", 390.ToString()); Tween.To(m_itemFoundText, 0.3f, Back.EaseOut, "ScaleX", "1", "ScaleY", "1"); Tween.To(m_continueText, 0.3f, Linear.EaseNone, "Opacity", "1"); scale = m_tripStat1.Scale; m_tripStat1.Scale = Vector2.One; num = 130f / m_tripStat1.Height; m_tripStat1.Scale = scale; Tween.To(m_tripStat1, 0.2f, Tween.EaseNone, "ScaleX", num.ToString(), "ScaleY", num.ToString()); Tween.To(m_tripStat1, 0.2f, Tween.EaseNone, "X", 830.ToString(), "Y", 390.ToString()); scale = m_tripStat2.Scale; m_tripStat2.Scale = Vector2.One; num = 130f / m_tripStat2.Height; m_tripStat2.Scale = scale; Tween.To(m_tripStat2, 0.2f, Tween.EaseNone, "ScaleX", num.ToString(), "ScaleY", num.ToString()); Tween.To(m_tripStat2, 0.2f, Tween.EaseNone, "X", 490.ToString(), "Y", 390.ToString()); Tween.To(m_tripStat1FoundText, 0.3f, Back.EaseOut, "ScaleX", "1", "ScaleY", "1"); Tween.To(m_tripStat2FoundText, 0.3f, Back.EaseOut, "ScaleX", "1", "ScaleY", "1"); for (var i = 0; i < m_levelUpParticles.Length; i++) { m_levelUpParticles[i].AnimationDelay = 0f; m_levelUpParticles[i].Visible = true; m_levelUpParticles[i].Scale = new Vector2(0.1f, 0.1f); m_levelUpParticles[i].Opacity = 0f; m_levelUpParticles[i].Position = new Vector2(660f, 360f); m_levelUpParticles[i].Position += new Vector2(CDGMath.RandomInt(-100, 100), CDGMath.RandomInt(-50, 50)); var duration = CDGMath.RandomFloat(0f, 0.5f); Tween.To(m_levelUpParticles[i], 0.2f, Linear.EaseNone, "delay", duration.ToString(), "Opacity", "1"); Tween.To(m_levelUpParticles[i], 0.5f, Linear.EaseNone, "delay", duration.ToString(), "ScaleX", "2", "ScaleY", "2"); Tween.To(m_levelUpParticles[i], duration, Linear.EaseNone); Tween.AddEndHandlerToLastTween(m_levelUpParticles[i], "PlayAnimation", false); } m_itemFoundSprite.Position = new Vector2(660f, 190f); m_itemFoundSprite.Scale = Vector2.Zero; m_itemFoundSprite.Visible = true; Tween.To(m_itemFoundSprite, 0.5f, Back.EaseOut, "delay", "0.05", "ScaleX", "1", "ScaleY", "1"); m_levelUpBGImage.Position = m_itemFoundSprite.Position; m_levelUpBGImage.Y += 30f; m_levelUpBGImage.Scale = Vector2.Zero; m_levelUpBGImage.Visible = true; Tween.To(m_levelUpBGImage, 0.5f, Back.EaseOut, "ScaleX", "1", "ScaleY", "1"); Tween.To(this, 0.5f, Linear.EaseNone, "BackBufferOpacity", "0.5"); if (m_itemSpinning) { m_itemSprite.Rotation = -25f; } m_itemSpinning = false; Tween.RunFunction(0.5f, this, "UnlockControls"); }
public void ChangeToRainDrop() { m_isSnowflake = false; m_isParticle = false; MaxYSpeed = new Vector2(800f, 1200f); MaxXSpeed = new Vector2(-200f, -200f); Rotation = 5f; m_speedY = CDGMath.RandomFloat(MaxYSpeed.X, MaxYSpeed.Y); m_speedX = CDGMath.RandomFloat(MaxXSpeed.X, MaxXSpeed.Y); }
public void Update(GameTime gameTime) { if (m_hammerAnimCounter <= 0f && !m_hammerSprite.IsAnimating) { m_hammerSprite.PlayAnimation(false); m_hammerAnimCounter = CDGMath.RandomFloat(0.5f, 3f); return; } m_hammerAnimCounter -= (float)gameTime.ElapsedGameTime.TotalSeconds; }
public RaindropObj(Vector2 startingPos) : base("Raindrop_Sprite") { ChangeToRainDrop(); m_speedY = CDGMath.RandomFloat(MaxYSpeed.X, MaxYSpeed.Y); m_speedX = CDGMath.RandomFloat(MaxXSpeed.X, MaxXSpeed.Y); IsCollidable = true; m_startingPos = startingPos; Position = m_startingPos; AnimationDelay = 0.0333333351f; Scale = new Vector2(2f, 2f); }
public void UpdateShake() { if (m_horizontalShake) { m_gateSprite.X = CDGMath.RandomPlusMinus() * (CDGMath.RandomFloat(0f, 1f) * m_screenShakeMagnitude); } if (m_verticalShake) { m_gateSprite.Y = CDGMath.RandomPlusMinus() * (CDGMath.RandomFloat(0f, 1f) * m_screenShakeMagnitude); } }
public void ChangeToSnowflake() { ChangeSprite("Snowflake_Sprite"); m_isSnowflake = true; m_isParticle = false; Rotation = 0f; MaxYSpeed = new Vector2(200f, 400f); MaxXSpeed = new Vector2(-200f, 0f); Position = m_startingPos; m_speedY = CDGMath.RandomFloat(MaxYSpeed.X, MaxYSpeed.Y); m_speedX = CDGMath.RandomFloat(MaxXSpeed.X, MaxXSpeed.Y); }
public void ChangeToParticle() { m_isSnowflake = false; m_isParticle = true; MaxYSpeed = new Vector2(0f, 0f); MaxXSpeed = new Vector2(500f, 1500f); Rotation = -90f; m_speedY = CDGMath.RandomFloat(MaxYSpeed.X, MaxYSpeed.Y); m_speedX = CDGMath.RandomFloat(MaxXSpeed.X, MaxXSpeed.Y); var num = CDGMath.RandomFloat(2f, 8f); Scale = new Vector2(num, num); }
private void ShowSilhouette(bool showSanta) { if (m_levelScreen != null) { m_silhouetteFlying = true; m_silhouette.Rotation = 0f; m_silhouette.Flip = SpriteEffects.None; var flag = false; if (CDGMath.RandomInt(0, 1) > 0) { flag = true; } string[] array = { "GardenBat_Sprite", "GardenCrow_Sprite", "GardenBat_Sprite", "GardenCrow_Sprite", "GardenPerson_Sprite" }; if (!showSanta) { m_silhouette.ChangeSprite(array[CDGMath.RandomInt(0, 4)]); } else { m_silhouette.ChangeSprite("GardenSanta_Sprite"); } m_silhouette.PlayAnimation(); var arg_A7_0 = Vector2.Zero; if (flag) { m_silhouette.X = -(float)m_silhouette.Width; } else { m_silhouette.Flip = SpriteEffects.FlipHorizontally; m_silhouette.X = m_levelScreen.CurrentRoom.Width + m_silhouette.Width; } m_silhouette.Y = CDGMath.RandomFloat(100f, 500f); var num = m_levelScreen.CurrentRoom.Bounds.Width + m_silhouette.Width * 2; if (!flag) { num = -num; } Tween.By(m_silhouette, CDGMath.RandomFloat(10f, 15f), Tween.EaseNone, "X", num.ToString(), "Y", CDGMath.RandomInt(-200, 200).ToString()); Tween.AddEndHandlerToLastTween(this, "SilhouetteComplete"); } }
public void UpdateShake() { if (m_horizontalShake) { Player.AttachedLevel.Camera.X = m_shakeStartingPos.X + CDGMath.RandomPlusMinus() * (CDGMath.RandomFloat(0f, 1f) * m_screenShakeMagnitude); } if (m_verticalShake) { Player.AttachedLevel.Camera.Y = m_shakeStartingPos.Y + CDGMath.RandomPlusMinus() * (CDGMath.RandomFloat(0f, 1f) * m_screenShakeMagnitude); } }
public static void Display(Vector2 position) { lock (_defaultCommands) Instance.Run(position, x => { float delay = CDGMath.RandomFloat(0.4f, 0.7f); var cmd = _defaultCommands[2]; cmd.Duration = delay + 0.2f; cmd.Properties[1] = CDGMath.RandomInt(-20, -5).ToString(); cmd = _defaultCommands[3]; cmd.Properties[1] = delay.ToString(); }); }
public void KillDrop() { m_splashing = false; GoToFrame(1); Rotation = 5f; X = m_startingPos.X; Y = CDGMath.RandomInt(-100, 0); if (m_isParticle) { Y = m_startingPos.Y; Rotation = -90f; } m_speedY = CDGMath.RandomFloat(MaxYSpeed.X, MaxYSpeed.Y); m_speedX = CDGMath.RandomFloat(MaxXSpeed.X, MaxXSpeed.Y); Opacity = 1f; }
public static void Display(Vector2 position) { lock (_defaultCommands) Instance.Run(position, x => { var fadeDelay = CDGMath.RandomFloat(0.4f, 0.7f); var cmd = _defaultCommands[1]; cmd.Duration = 0.2f + fadeDelay; cmd.Properties[1] = CDGMath.RandomInt(5, 20).ToString(); cmd = _defaultCommands[3]; cmd.Properties[1] = (CDGMath.RandomInt(10, 45) * CDGMath.RandomPlusMinus()).ToString(); cmd = _defaultCommands[4]; cmd.Properties[1] = fadeDelay.ToString(); }); }
protected static void InitializeTweens(IList <TweenCommand> tweens, int rotationRange = 180) { var scale = CDGMath.RandomFloat(2f, 4f); var cmd = tweens[1]; cmd.Properties[1] = CDGMath.RandomInt(-rotationRange, rotationRange).ToString(); cmd = tweens[2]; cmd.Properties[1] = CDGMath.RandomInt(-20, 20).ToString(); cmd.Properties[3] = CDGMath.RandomInt(-50, -30).ToString(); cmd = tweens[3]; cmd.Properties[1] = scale.ToString(); cmd.Properties[3] = scale.ToString(); cmd = tweens[4]; cmd.Properties[1] = CDGMath.RandomFloat(1f, 2f).ToString(); }
public void DropItemWide(Vector2 position, int dropType, float amount) { var itemDropObj = m_itemDropPool.CheckOutReturnNull(); if (itemDropObj == null) { return; } itemDropObj.ConvertDrop(dropType, amount); m_physicsManager.AddObject(itemDropObj); itemDropObj.Position = position; itemDropObj.AccelerationY = CDGMath.RandomFloat(-1200f, -300f); itemDropObj.AccelerationX = CDGMath.RandomFloat(-600f, 600f); itemDropObj.Visible = true; itemDropObj.IsWeighted = true; itemDropObj.IsCollidable = true; itemDropObj.AnimationDelay = 0.05f; itemDropObj.Opacity = 1f; itemDropObj.CollectionCounter = 0.2f; }
public static void Display(Vector2 position) { float cumulativeDelay = 0.1f; lock (_defaultTweens) for (int i = 0; i < 5; i++) { Instance.Run(new Vector2(position.X + CDGMath.RandomFloat(-70f, 70f), position.Y + CDGMath.RandomInt(-50, -30)), x => { x.Sprite.ChangeSprite("TeleportRock" + (i + 1) + "_Sprite"); var cmdList = x.TweenCommands; cmdList[0].Properties[1] = cumulativeDelay.ToString(); cmdList[1].Properties[1] = cumulativeDelay.ToString(); cmdList[2].Properties[1] = (cumulativeDelay + 0.5f).ToString(); }); cumulativeDelay += CDGMath.RandomFloat(0.1f, 0.3f); } }
public void DropItem(Vector2 position, int dropType, float amount) { var itemDropObj = m_itemDropPool.CheckOutReturnNull(); if (itemDropObj == null) { return; } itemDropObj.ConvertDrop(dropType, amount); m_physicsManager.AddObject(itemDropObj); itemDropObj.Position = position; itemDropObj.AccelerationY = CDGMath.RandomFloat(-720f, -480f); itemDropObj.AccelerationX = CDGMath.RandomFloat(-120f, 120f); itemDropObj.Visible = true; itemDropObj.IsWeighted = true; itemDropObj.IsCollidable = true; itemDropObj.AnimationDelay = 0.05f; itemDropObj.Opacity = 1f; itemDropObj.CollectionCounter = 0.2f; SoundManager.Play3DSound(itemDropObj, Game.ScreenManager.Player, "CoinCollect1", "CoinCollect2", "CoinCollect3"); }
public static void Display(Vector2 position) { float angle = 0f; float angleStep = 24f; lock (_defaultCommands) for (int i = 0; i < 15; i++, angle += angleStep) { Instance.Run(position, x => { int drift = CDGMath.RandomInt(50, 200); Vector2 angleFactor = CDGMath.AngleToVector(angle); var cmd = _defaultCommands[0]; cmd.Properties[1] = (angleFactor.X * drift).ToString(); cmd.Properties[3] = (angleFactor.Y * drift).ToString(); cmd = _defaultCommands[1]; cmd.Properties[1] = CDGMath.RandomFloat(0.5f, 1.1f).ToString(); }); } }
protected static void Initialize(EffectDisplayEvent evt) { float duration = CDGMath.RandomFloat(0.5f, 1f); float scaleTo = CDGMath.RandomFloat(0f, 0.1f); var cmd = _defaultTweens[0]; cmd.Duration = duration; cmd.Properties[1] = scaleTo.ToString(); cmd.Properties[3] = scaleTo.ToString(); cmd = _defaultTweens[1]; cmd.Duration = duration; cmd.Properties[1] = CDGMath.RandomInt(-50, 50).ToString(); cmd.Properties[3] = CDGMath.RandomInt(-50, 50).ToString(); cmd = _defaultTweens[2]; cmd.Duration = duration - 0.1f; cmd.Properties[1] = CDGMath.RandomInt(145, 190).ToString(); cmd = _defaultTweens[3]; cmd.Duration = duration - 0.2f; }
public override void HitEnemy(int damage, Vector2 position, bool isPlayer) { if (m_target != null && m_target.CurrentHealth > 0 && m_currentActiveLB != m_basicTeleportAttackLB && m_currentActiveLB != m_expertTeleportAttackLB && CDGMath.RandomFloat(0f, 1f) <= ChanceToTeleport && m_closestCeiling != null) { m_closestCeiling = FindClosestCeiling(); var num = TerrainBounds.Top - m_closestCeiling.Bounds.Bottom; if (m_closestCeiling != null && num > 150 && num < 700) { m_currentActiveLB.StopLogicBlock(); if (Difficulty == GameTypes.EnemyDifficulty.EXPERT) { RunLogicBlock(false, m_expertTeleportAttackLB, 100); } else { RunLogicBlock(false, m_basicTeleportAttackLB, 100); } damage = (int)Math.Round(damage * (1f - m_teleportDamageReduc), MidpointRounding.AwayFromZero); } } base.HitEnemy(damage, position, isPlayer); }
public override void CollisionResponse(CollisionBox thisBox, CollisionBox otherBox, int collisionResponseType) { IPhysicsObj absParent = otherBox.AbsParent as IPhysicsObj; if (collisionResponseType == Consts.COLLISIONRESPONSE_FIRSTBOXHIT) { if ((absParent.CollisionTypeTag == GameTypes.CollisionType_PLAYER || absParent.CollisionTypeTag == GameTypes.CollisionType_GLOBAL_DAMAGE_WALL || absParent.CollisionTypeTag == GameTypes.CollisionType_GLOBAL_DAMAGE_WALL && IsWeighted) && (!(otherBox.AbsParent is RogueAPI.Projectiles.ProjectileObj) && m_invincibleCounter <= 0f || otherBox.AbsParent is RogueAPI.Projectiles.ProjectileObj && (m_invincibleCounterProjectile <= 0f || (otherBox.AbsParent as RogueAPI.Projectiles.ProjectileObj).IgnoreInvincibleCounter)) ) { //Show demented question mark and return if (IsDemented) { m_invincibleCounter = InvincibilityTime; m_invincibleCounterProjectile = InvincibilityTime; RogueAPI.Effects.QuestionMarkEffect.Display(this); //m_levelScreen.ImpactEffectPool.DisplayQuestionMark(new Vector2(X, Bounds.Top)); return; } int damage; if (absParent is RogueAPI.Projectiles.ProjectileObj) { damage = (absParent as RogueAPI.Projectiles.ProjectileObj).Damage; } else { damage = (absParent as IDealsDamageObj).Damage; } //Apply critical damage bool isPlayer = absParent == m_target; if (isPlayer) { if (CDGMath.RandomFloat(0f, 1f) <= m_target.TotalCritChance && !NonKillable) { RogueAPI.Effects.CriticalTextEffect.Display(this); //m_levelScreen.ImpactEffectPool.DisplayCriticalText(new Vector2(X, Bounds.Top)); damage = (int)(damage * m_target.TotalCriticalDamage); } m_invincibleCounter = InvincibilityTime; } //Destroy projectile var projectileObj = otherBox.AbsParent as RogueAPI.Projectiles.ProjectileObj; if (projectileObj != null) { m_invincibleCounterProjectile = InvincibilityTime; if (projectileObj.DestroysWithEnemy && !NonKillable) { projectileObj.RunDestroyAnimation(false); } } if (projectileObj != null || absParent.CollisionTypeTag != GameTypes.CollisionType_GLOBAL_DAMAGE_WALL || absParent.CollisionTypeTag == GameTypes.CollisionType_GLOBAL_DAMAGE_WALL && IsWeighted) { var allow = true; if (projectileObj != null) { var kbAmount = CanBeKnockedBack && !IsPaused ? (KnockBack != Vector2.Zero ? KnockBack : m_target.EnemyKnockBack) : Vector2.Zero; allow = projectileObj != null?projectileObj.OnCollision(this, false, kbAmount) : true; } if (allow) { Point center = (thisBox.AbsRotation != 0f || otherBox.AbsRotation != 0f) ? Rectangle.Intersect(thisBox.AbsParent.Bounds, otherBox.AbsParent.Bounds).Center : Rectangle.Intersect(thisBox.AbsRect, otherBox.AbsRect).Center; HitEnemy(damage, new Vector2(center.X, center.Y), isPlayer); } } ////Apply shout knockback //if (projectileObj != null && projectileObj.Spell == SpellType.Shout) //{ // if (CanBeKnockedBack && !IsPaused) // { // float inertia = 3f; // var knockback = KnockBack != Vector2.Zero ? KnockBack : m_target.EnemyKnockBack; // CurrentSpeed = 0f; // AccelerationX = knockback.X * (X >= m_target.X ? inertia : -inertia); // AccelerationY = -knockback.Y * inertia; // } //} //else if (projectileObj != null || absParent.CollisionTypeTag != GameTypes.CollisionType_GLOBAL_DAMAGE_WALL || absParent.CollisionTypeTag == GameTypes.CollisionType_GLOBAL_DAMAGE_WALL && IsWeighted) //{ // Point center = (thisBox.AbsRotation != 0f || otherBox.AbsRotation != 0f) // ? Rectangle.Intersect(thisBox.AbsParent.Bounds, otherBox.AbsParent.Bounds).Center // : Rectangle.Intersect(thisBox.AbsRect, otherBox.AbsRect).Center; // HitEnemy(damage, new Vector2(center.X, center.Y), isPlayer); //} } } else if (collisionResponseType == Consts.COLLISIONRESPONSE_TERRAIN) { if ((absParent.CollisionTypeTag == GameTypes.CollisionType_WALL || absParent.CollisionTypeTag == GameTypes.CollisionType_WALL_FOR_ENEMY || absParent.CollisionTypeTag == GameTypes.CollisionType_GLOBAL_DAMAGE_WALL) && CollisionTypeTag != GameTypes.CollisionType_ENEMYWALL) { Vector2 vector2 = CollisionMath.CalculateMTD(thisBox.AbsRect, otherBox.AbsRect); if (CurrentSpeed != 0f && vector2.X != 0f && Math.Abs(vector2.X) > 10f && (vector2.X > 0f && absParent.CollidesRight || vector2.X < 0f && absParent.CollidesLeft)) { CurrentSpeed = 0f; } if (m_numTouchingGrounds <= 1 && CurrentSpeed != 0f && vector2.Y < 0f && !CanFallOffLedges) { if (Bounds.Left < absParent.Bounds.Left && HeadingX < 0f) { X = absParent.Bounds.Left + (AbsX - Bounds.Left); CurrentSpeed = 0f; } else if (Bounds.Right > absParent.Bounds.Right && HeadingX > 0f) { X = absParent.Bounds.Right - (Bounds.Right - AbsX); CurrentSpeed = 0f; } m_isTouchingGround = true; } if (AccelerationX != 0f && m_isTouchingGround) { AccelerationX = 0f; } bool flag1 = false; if (Math.Abs(vector2.X) < 10f && vector2.X != 0f && Math.Abs(vector2.Y) < 10f && vector2.Y != 0f) { flag1 = true; } if (m_isTouchingGround && !absParent.CollidesBottom && absParent.CollidesTop && absParent.TerrainBounds.Top < TerrainBounds.Bottom - 30) { flag1 = true; } if (!absParent.CollidesRight && !absParent.CollidesLeft && absParent.CollidesTop && absParent.CollidesBottom) { flag1 = true; } Vector2 vector22 = CollisionMath.RotatedRectIntersectsMTD(thisBox.AbsRect, thisBox.AbsRotation, Vector2.Zero, otherBox.AbsRect, otherBox.AbsRotation, Vector2.Zero); if (!flag1) { base.CollisionResponse(thisBox, otherBox, collisionResponseType); } if (vector22.Y < 0f && otherBox.AbsRotation != 0f && IsWeighted) { X -= vector22.X; } } } }
public static void Display(Vector2 position, int xRange = 40, int yRange = 40, float scale = 1f, bool?flipDrift = null, bool furtherDrift = false, bool longerDuration = false, bool randomDelay = false) { lock (_defaultCommands) { var pos = position; if (xRange != 0) { pos.X += CDGMath.RandomInt(-xRange, xRange); } if (yRange != 0) { pos.Y += CDGMath.RandomInt(-yRange, yRange); } Instance.Run(pos, x => { x.Sprite.Scale = new Vector2(scale); int xDrift, yDrift; if (furtherDrift) { xDrift = CDGMath.RandomInt(50, 100); yDrift = CDGMath.RandomInt(-100, 100); } else { xDrift = CDGMath.RandomInt(-50, 50); yDrift = CDGMath.RandomInt(-50, 50); } if (flipDrift != null) { if (CDGMath.RandomPlusMinus() < 0) { x.Sprite.Flip = SpriteEffects.FlipHorizontally; } if (CDGMath.RandomPlusMinus() < 0) { x.Sprite.Flip = SpriteEffects.FlipVertically; } if (flipDrift.Value) { xDrift = -xDrift; } } TweenCommand cmd0 = x.TweenCommands[0], cmd1 = x.TweenCommands[1], cmd2 = x.TweenCommands[2]; cmd1.Properties[3] = xDrift.ToString(); cmd1.Properties[5] = yDrift.ToString(); if (longerDuration) { cmd0.Duration = 0.4f; cmd1.Duration = 1.5f; cmd2.Duration = 1f; } else { cmd0.Duration = 0.2f; cmd1.Duration = 1f; cmd2.Duration = 0.5f; } float delay = randomDelay ? CDGMath.RandomFloat(0f, 0.2f) : 0f; cmd0.Properties[1] = delay.ToString(); cmd1.Properties[1] = delay.ToString(); cmd2.Properties[1] = (delay + 0.5f).ToString(); cmd1.Properties[7] = CDGMath.RandomInt(-45, 45).ToString(); }); } }
public void Prepare() { float rotation = 0f; if (Target == null) { rotation = (InitAngleRange.X != InitAngleRange.Y) ? CDGMath.RandomFloat(InitAngleRange.X, InitAngleRange.Y) : InitAngleRange.X; rotation += InitAngleOffset; if (Source.Flip != SpriteEffects.None) { if (Source.Rotation == 0f) { rotation = 180f - rotation; } else { rotation -= 180f; } } } else { var distanceX = Target.X - Source.X; var angleOffset = InitAngleOffset; if (Source.Flip == SpriteEffects.FlipHorizontally) { distanceX += InitSourceAnchor.X; angleOffset = -angleOffset; } rotation = MathHelper.ToDegrees((float)Math.Atan2(Target.Y - Source.Y - InitSourceAnchor.Y, distanceX)) + angleOffset; if (Source.Flip == SpriteEffects.FlipHorizontally && ChaseTarget) { Orientation = MathHelper.ToRadians(180f); } } if (!InitLockPosition) { Rotation = rotation; } rotation = MathHelper.ToRadians(rotation); Core.AttachPhysicsObject(this); if (Source.Flip == SpriteEffects.None) { X = Source.AbsX + InitSourceAnchor.X; } else { X = Source.AbsX - InitSourceAnchor.X; } Y = Source.AbsY + InitSourceAnchor.Y; Vector2 vector2 = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)); float speed = (InitSpeedRange.X != InitSpeedRange.Y) ? CDGMath.RandomFloat(InitSpeedRange.X, InitSpeedRange.Y) : InitSpeedRange.X; AccelerationX = vector2.X * speed; AccelerationY = vector2.Y * speed; CurrentSpeed = speed; if (Source.IsPlayer()) { if (LifeSpan == 0f) { LifeSpan = 10f; } CollisionType = CollisionType.Player; new ProjectileFireEvent(Source, Definition, this).Trigger(); } else { if (LifeSpan == 0f) { LifeSpan = 15f; } CollisionType = CollisionType.Enemy; } PlayAnimation(true); }
public ProjectileObj FireProjectile(ProjectileData data) { if (data.Source == null) { throw new Exception("Cannot have a projectile with no source"); } var projectileObj = m_projectilePool.CheckOut(); projectileObj.Reset(); projectileObj.LifeSpan = data.Lifespan; var source = data.Source; projectileObj.ChaseTarget = data.ChaseTarget; projectileObj.Source = source; projectileObj.Target = data.Target; projectileObj.UpdateHeading(); projectileObj.TurnSpeed = data.TurnSpeed; projectileObj.CollidesWithTerrain = data.CollidesWithTerrain; projectileObj.DestroysWithTerrain = data.DestroysWithTerrain; projectileObj.DestroysWithEnemy = data.DestroysWithEnemy; projectileObj.FollowArc = data.FollowArc; projectileObj.Orientation = MathHelper.ToRadians(data.StartingRotation); projectileObj.ShowIcon = data.ShowIcon; projectileObj.IsCollidable = data.IsCollidable; projectileObj.CollidesWith1Ways = data.CollidesWith1Ways; projectileObj.DestroyOnRoomTransition = data.DestroyOnRoomTransition; projectileObj.CanBeFusRohDahed = data.CanBeFusRohDahed; projectileObj.IgnoreInvincibleCounter = data.IgnoreInvincibleCounter; projectileObj.WrapProjectile = data.WrapProjectile; var num = 0f; if (data.Target != null) { var num2 = data.Target.X - source.X; var num3 = data.Target.Y - source.Y - data.SourceAnchor.Y; if (source.Flip == SpriteEffects.FlipHorizontally) { num = 180f - num; num2 += data.SourceAnchor.X; num = MathHelper.ToDegrees((float)Math.Atan2(num3, num2)); num -= data.AngleOffset; } else { num = MathHelper.ToDegrees((float)Math.Atan2(num3, num2)); num2 -= data.SourceAnchor.X; num += data.AngleOffset; } } else { num = data.Angle.X + data.AngleOffset; if (data.Angle.X != data.Angle.Y) { num = CDGMath.RandomFloat(data.Angle.X, data.Angle.Y) + data.AngleOffset; } if (source.Flip != SpriteEffects.None && source.Rotation != 0f) { num -= 180f; } else if (source.Flip != SpriteEffects.None && source.Rotation == 0f) { num = 180f - num; } } if (!data.LockPosition) { projectileObj.Rotation = num; } num = MathHelper.ToRadians(num); projectileObj.Damage = data.Damage; m_levelScreen.PhysicsManager.AddObject(projectileObj); projectileObj.ChangeSprite(data.SpriteName); projectileObj.RotationSpeed = data.RotationSpeed; projectileObj.Visible = true; if (source.Flip != SpriteEffects.None) { projectileObj.X = source.AbsX - data.SourceAnchor.X; } else { projectileObj.X = source.AbsX + data.SourceAnchor.X; } projectileObj.Y = source.AbsY + data.SourceAnchor.Y; projectileObj.IsWeighted = data.IsWeighted; var vector = new Vector2((float)Math.Cos(num), (float)Math.Sin(num)); var num4 = data.Speed.X; if (data.Speed.X != data.Speed.Y) { num4 = CDGMath.RandomFloat(data.Speed.X, data.Speed.Y); } projectileObj.AccelerationX = vector.X * num4; projectileObj.AccelerationY = vector.Y * num4; projectileObj.CurrentSpeed = num4; if (source is PlayerObj) { if (projectileObj.LifeSpan == 0f) { projectileObj.LifeSpan = (source as PlayerObj).ProjectileLifeSpan; } projectileObj.CollisionTypeTag = 2; projectileObj.Scale = data.Scale; } else { if (projectileObj.LifeSpan == 0f) { projectileObj.LifeSpan = 15f; } projectileObj.CollisionTypeTag = 3; projectileObj.Scale = data.Scale; } if (data.Target != null && data.Source.Flip == SpriteEffects.FlipHorizontally && data.ChaseTarget) { projectileObj.Orientation = MathHelper.ToRadians(180f); } if (data.Source is PlayerObj && (Game.PlayerStats.Traits.X == 22f || Game.PlayerStats.Traits.Y == 22f)) { projectileObj.AccelerationX *= -1f; if (!data.LockPosition) { if (data.Source.Flip == SpriteEffects.FlipHorizontally) { projectileObj.Flip = SpriteEffects.None; } else { projectileObj.Flip = SpriteEffects.FlipHorizontally; } } } projectileObj.PlayAnimation(); return(projectileObj); }
public static void StoreSwappedObj(GameObj obj, GameTypes.LevelType levelType, RoomObj currentRoom) { string[] array; switch (levelType) { case GameTypes.LevelType.GARDEN: array = LevelEV.GARDEN_ASSETSWAP_LIST; break; case GameTypes.LevelType.DUNGEON: array = LevelEV.DUNGEON_ASSETSWAP_LIST; break; case GameTypes.LevelType.TOWER: array = LevelEV.TOWER_ASSETSWAP_LIST; break; default: throw new Exception("Cannot find asset swaplist for leveltype " + levelType); } var breakableObj = obj as BreakableObj; if (breakableObj != null && breakableObj.SpriteName.Contains("CastleAssetUrn")) { breakableObj.CollidesTop = false; } var flag = false; var animateableObj = obj.Clone() as IAnimateableObj; if (animateableObj != null) { var i = 0; while (i < LevelEV.CASTLE_ASSETSWAP_LIST.Length) { if (animateableObj.SpriteName == LevelEV.CASTLE_ASSETSWAP_LIST[i]) { var text = array[i]; if (text.Contains("RANDOM")) { var max = int.Parse(Convert.ToString(text[text.IndexOf("RANDOM") + 6])); var num = CDGMath.RandomInt(1, max); text = text.Replace("RANDOM" + max, num.ToString()); if (text.Contains("TowerHole")) { (animateableObj as GameObj).X += CDGMath.RandomInt(-50, 50); (animateableObj as GameObj).Y += CDGMath.RandomInt(-50, 50); if (CDGMath.RandomInt(1, 100) > 70) { (animateableObj as GameObj).Visible = false; } } if (text.Contains("GardenFloatingRock")) { animateableObj = new HoverObj(text) { Position = (animateableObj as GameObj).Position, Amplitude = CDGMath.RandomFloat(-50f, 50f), HoverSpeed = CDGMath.RandomFloat(-2f, 2f), Scale = (animateableObj as GameObj).Scale, Layer = (animateableObj as GameObj).Layer }; } } if (text == "CastleAssetFrame_Sprite") { text = "FramePicture" + CDGMath.RandomInt(1, 16) + "_Sprite"; } if (!(text != "")) { break; } animateableObj.ChangeSprite(text); flag = true; if (text.Contains("GardenFairy")) { (animateableObj as GameObj).X += CDGMath.RandomInt(-25, 25); (animateableObj as GameObj).Y += CDGMath.RandomInt(-25, 25); (animateableObj as GameObj).Opacity = 0.8f; } break; } i++; } } if (flag) { StoreObj(animateableObj as GameObj, currentRoom); } }
public LightSourceObj() : base("LightSource_Sprite") { m_growthRate = 0.7f + CDGMath.RandomFloat(-0.1f, 0.1f); m_growthDifference = 0.05f + CDGMath.RandomFloat(0f, 0.05f); Opacity = 1f; }