public static void CutIn(BHGame mGame, BHStage mStage, Texture mTexture, bool mText = false, string mBackgroundText = "spell attack", Vector2i mVelocity = default(Vector2i), Vector2i mOffset = default(Vector2i), int mLength = 100) { var cutInTimeline = new Timeline(); var texts = new List<Text>(); var drawEvents = new List<Action>(); if (mText) { for (int iX = -2; iX < 3; iX++) { for (int i = 0; i < 35; i++) { var temp = new Text(mBackgroundText, Font.DefaultFont) { Position = new Vector2f(300 + (iX*84), (i*35) - 200), Color = Color.White, CharacterSize = 15, Rotation = 25 }; texts.Add(temp); Action drawEvent = () => mGame.GameWindow.RenderWindow.Draw(temp); drawEvents.Add(drawEvent); mGame.AddDrawAction(drawEvent); } } } var cutInSprite = new Sprite(mTexture) { Color = new Color(255, 255, 255, 0) }; var cutInEntity = new BHEntity(mGame) { DrawOrder = 100000, Sprite = cutInSprite, Position = mGame.Center + mOffset }; BHPresetTimelines.Fade(cutInEntity, 0, true, 16); BHPresetTimelines.Fade(cutInEntity, mLength, false, 16); cutInTimeline.Action(() => { foreach (var text in texts) text.Position -= new Vector2f(3, 1); }); cutInTimeline.Action(() => cutInEntity.Position += mVelocity); cutInTimeline.Wait(); cutInTimeline.Goto(mTimes: 200); cutInTimeline.Action(() => { foreach (var drawEvent in drawEvents) mGame.RemoveDrawAction(drawEvent); cutInEntity.Destroy(); }); mStage.TimelinesUpdate.Add(cutInTimeline); }
public static void Kill(BHEntity mEntity, int mFrames) { var timelineKill = new Timeline(); timelineKill.Wait(mFrames); timelineKill.Action(mEntity.Destroy); mEntity.TimelinesUpdate.Add(timelineKill); }
public static BHEntity Boss(BHGame mGame, int mRadius, int mHealth) { var deathTimeline = new Timeline(); var result = new BHEntity(mGame, "boss", "enemy", "character"); result.CollisionShape = new BHCSCircle(result, mRadius*mRadius); result.Parameters["health"] = mHealth; deathTimeline.Action(() => { if ((int) result.Parameters["health"] <= 0) {} }); deathTimeline.Wait(); deathTimeline.Goto(); result.TimelinesUpdate.Add(deathTimeline); return result; }
public static void MovementLerp(BHEntity mEntity, Vector2i mPosition, int mSteps = 100) { var startPosition = new SSVector2I(mEntity.Position.X, mEntity.Position.Y); var endPosition = new SSVector2I(mPosition.X, mPosition.Y); var timelineLerp = new Timeline(); for (int i = 0; i < mSteps; i++) { float value = i/100f; var lerp = Utils.Math.Vectors.Lerp(startPosition, endPosition, value); timelineLerp.Action(() => mEntity.Position = new Vector2i(lerp.X, lerp.Y)); // LAgs with 10000 test it out timelineLerp.Wait(); } mEntity.TimelinesUpdate.Add(timelineLerp); }
public static void Fade(BHEntity mEntity, int mDelay = 0, bool mFadeIn = true, int mSpeedMultiplier = 3) { int value = mSpeedMultiplier; if (!mFadeIn) value *= -1; var fadeTimeline = new Timeline(); fadeTimeline.Wait(mDelay); fadeTimeline.Action(() => { byte r = mEntity.Sprite.Color.R; byte g = mEntity.Sprite.Color.G; byte b = mEntity.Sprite.Color.B; if (mEntity.Sprite.Color.A + value > 255) mEntity.Sprite.Color = new Color(r, g, b, 255); else if (mEntity.Sprite.Color.A + value < 0) mEntity.Sprite.Color = new Color(r, g, b, 0); else mEntity.Sprite.Color = new Color(r, g, b, (byte) (mEntity.Sprite.Color.A + value)); } ); fadeTimeline.Wait(); fadeTimeline.Goto(1, 255/mSpeedMultiplier); mEntity.TimelinesUpdate.Add(fadeTimeline); }
public static BHEntity Enemy(BHGame mGame, int mRadius, int mHealth) { var deathTimeline = new Timeline(); var result = new BHEntity(mGame, "enemy", "character"); result.CollisionShape = new BHCSCircle(result, mRadius*mRadius); result.Parameters["health"] = mHealth; deathTimeline.Action(() => { if ((int) result.Parameters["health"] <= 0) { result.Destroy(); Assets.GetSound("se_enep00").Play(); } }); deathTimeline.Wait(); deathTimeline.Goto(); result.TimelinesUpdate.Add(deathTimeline); return result; }
public static BHEntity Reimu(BHGame mGame) { var fireTimeline = new Timeline(); BHEntity result = BHPresetBase.Player(mGame, 4.ToUnits(), 2.ToUnits(), Assets.GetAnimation("playerleft"), Assets.GetAnimation("playerright"), Assets.GetAnimation("playerstill")); result.Sprite = Assets.GetTileset("p_reimu").GetSprite("s1", Assets.GetTexture("p_reimu")); fireTimeline.Action(() => { if (Keyboard.IsKeyPressed(Keyboard.Key.Z)) { Assets.GetSound("se_plst00").Play(); BHPresetBase.PlayerBullet(mGame, result.Position - new Vector2i(8.ToUnits(), 17.ToUnits()), 270, 27.ToUnits()).Sprite = new Sprite(Assets.GetTexture("b_player_reimu1")); BHPresetBase.PlayerBullet(mGame, result.Position - new Vector2i(-8.ToUnits(), 17.ToUnits()), 270, 27.ToUnits()).Sprite = new Sprite(Assets.GetTexture("b_player_reimu1")); } }); fireTimeline.Wait(4); fireTimeline.Goto(); result.TimelinesUpdate.Add(fireTimeline); return result; }
public static void SpellCard(BHGame mGame, BHStage mStage, BHEntity mBoss, string mSpellCardName, int mHealth, int mTime, int mScore, Timeline mOnEnd, params Timeline[] mTimelines) { var spellCardTimeline = new Timeline(); mBoss.Parameters["health"] = mHealth; var drawEvents = new List<Action>(); var spellCardText = new Text(mSpellCardName, Font.DefaultFont) { Position = new Vector2f(32, 16), Color = Color.White, CharacterSize = 15, }; var mTimeText = new Text(mTime.ToString(), Font.DefaultFont) { Position = new Vector2f(384, 16), Color = Color.White, CharacterSize = 15 }; Action spellCardTextDrawEvent = () => mGame.GameWindow.RenderWindow.Draw(spellCardText); drawEvents.Add(spellCardTextDrawEvent); mGame.AddDrawAction(spellCardTextDrawEvent); Action timeTextDrawEvent = () => mGame.GameWindow.RenderWindow.Draw(mTimeText); drawEvents.Add(timeTextDrawEvent); mGame.AddDrawAction(timeTextDrawEvent); mStage.TimelinesUpdate.AddRange(mTimelines); Assets.GetSound("cat00").Play(); spellCardTimeline.Action(() => { mTime--; mTimeText.DisplayedString = mTime.ToString(); }); spellCardTimeline.Wait(); spellCardTimeline.AddCommand(new GotoConditional(() => mTime < 1 || (int) mBoss.Parameters["health"] < 1, 0, -1)); spellCardTimeline.Action(() => { foreach (var drawEvent in drawEvents) mGame.RemoveDrawAction(drawEvent); foreach (var timeline in mTimelines) timeline.Finished = true; ClearBullets(mGame, mStage); if (mOnEnd != null) mStage.TimelinesUpdate.Add(mOnEnd); }); mStage.TimelinesUpdate.Add(spellCardTimeline); }
public static BHEntity Laser(BHGame mGame, Sprite mSprite, Vector2i mPosition = default(Vector2i), float mAngle = 0, int mSpeed = 0, long mRadius = 0, int mLength = 0, bool mGrow = false, int mGrowSpeed = 0, bool mPrimed = false, int mPrimeTime = 50, int mPrimeSurviveTime = 50) { var primeTimeline = new Timeline(); var growTimeline = new Timeline(); var drawTimeline = new Timeline(); long radius = (mRadius/2)*(mRadius/2); var result = new BHEntity(mGame, "laser") {Position = mPosition, Velocity = BHUtils.CalculateVelocity(mAngle, mSpeed)}; if (!mPrimed) result.AddGroup("deadlytoplayer"); result.CollisionShape = mGrow ? new BHCSLine(result, mAngle, 0, radius) : new BHCSLine(result, mAngle, mLength, radius); result.BoundsOffset = -1000.ToUnits(); result.Sprite = mSprite; result.Sprite.Rotation = mAngle; result.Sprite.Transform.Scale(1, result.Sprite.Texture.Size.Y); result.Sprite.Origin = new Vector2f(0, result.Sprite.Origin.Y); //result.Sprite.BlendMode = BlendMode.Add; result.IsSpriteFixed = true; float height = (mRadius*2).ToPixels(); if (mPrimed) height = 1; // if (mPrimed) result.Sprite.BlendMode = BlendMode.Alpha; primeTimeline.Wait(mPrimeTime); primeTimeline.Action(() => { result.AddGroup("deadlytoplayer"); height = (mRadius*2).ToPixels(); // result.Sprite.BlendMode = BlendMode.Add; }); primeTimeline.Wait(mPrimeSurviveTime); primeTimeline.Action(result.Destroy); growTimeline.Action(() => { var lineShape = (BHCSLine) result.CollisionShape; if (lineShape.Length < mLength) { lineShape.Length += mGrowSpeed; result.Velocity = new Vector2i(0, 0); } else { result.Velocity = BHUtils.CalculateVelocity(mAngle, mSpeed); growTimeline.Finished = true; } }); growTimeline.Wait(); growTimeline.Goto(); drawTimeline.Action(() => { var lineShape = (BHCSLine) result.CollisionShape; result.Sprite.Rotation = lineShape.Degrees; result.Sprite.Transform.Scale(lineShape.Length.ToPixels(), height); result.Sprite.Origin = new Vector2f(0, result.Sprite.Origin.Y); }); drawTimeline.Wait(); drawTimeline.Goto(); if (mPrimed) result.TimelinesUpdate.Add(primeTimeline); result.TimelinesUpdate.Add(growTimeline); result.TimelinesDrawBefore.Add(drawTimeline); result.OnOutOfBounds += BHPresetOutOfBounds.Destroy; return result; }
public static BHEntity Polygon(BHGame mGame, List<Vector2i> mVertices) { var drawTimeline = new Timeline(); var result = new BHEntity(mGame, "deadlytoplayer") {Position = mGame.Center}; result.CollisionShape = new BHCSPolygon(result, mVertices.ToArray()); drawTimeline.Action(() => { var shape = (BHCSPolygon) result.CollisionShape; //foreach (Vector2i vertex in shape.Vertices) mGame.WindowManager.RenderWindow.Draw(new CircleShape(new Vector2f(vertex.X.ToPixels(), vertex.Y.ToPixels()), 2, Color.Red)); }); drawTimeline.Wait(); drawTimeline.Goto(); result.TimelinesDrawBefore.Add(drawTimeline); return result; }
public static BHEntity Player(BHGame mGame, int mSpeedNormal, int mSpeedFocus, Animation mAnimationLeft, Animation mAnimationRight, Animation mAnimationStill) { var updateTimeline = new Timeline(); var drawTimeline = new Timeline(); var hitboxSprite = new Sprite(Assets.GetTexture("p_hitbox")); var result = new BHEntity(mGame, "character", "player") {DrawOrder = -10000, IsSpriteFixed = true, BoundsOffset = 10.ToUnits(), Animation = mAnimationStill}; result.CollisionShape = new BHCSPoint(result); result.CollisionAgainstGroups.Add("deadlytoplayer"); result.OnOutOfBounds += BHPresetOutOfBounds.Stop; result.OnCollision += (entity, group) => { if (group == "deadlytoplayer") Assets.GetSound("pldead00").Play(); }; updateTimeline.Action(() => { int speed = mGame.Focus == 1 ? mSpeedFocus : mSpeedNormal; if (mGame.NextX != 0 && mGame.NextY != 0) speed = (int) (speed*0.7); if (mGame.NextX > 0 && mAnimationRight != null) result.Animation = mAnimationRight; else if (mGame.NextX < 0 && mAnimationLeft != null) result.Animation = mAnimationLeft; else if (mAnimationStill != null) result.Animation = mAnimationStill; result.Velocity = new Vector2i(mGame.NextX*speed, mGame.NextY*speed); hitboxSprite.Rotation++; }); updateTimeline.Wait(); updateTimeline.Goto(); drawTimeline.Action(() => { if (mGame.Focus == 0) return; hitboxSprite.Origin = new Vector2f(32, 32); hitboxSprite.Position = new Vector2f(result.Position.X.ToPixels(), result.Position.Y.ToPixels()); mGame.GameWindow.RenderWindow.Draw(hitboxSprite); }); drawTimeline.Wait(); drawTimeline.Goto(); result.TimelinesUpdate.Add(updateTimeline); result.TimelinesDrawAfter.Add(drawTimeline); return result; }
public static BHEntity EnemyFairyBig1(BHGame mGame, Vector2i mPosition, string mTexture) { BHEntity result = BHPresetBase.Enemy(mGame, 30.ToUnits(), 40); result.Sprite = new Sprite(Assets.GetTexture(mTexture)); result.IsSpriteFixed = true; result.Position = mPosition; BHPresetTimelines.Kill(result, 900); // MOVEMENT TIMELINES var timelineMovement = new Timeline(); timelineMovement.Action(() => result.Velocity = new Vector2i(0, 150)); timelineMovement.Wait(100); timelineMovement.Action(() => result.Velocity = new Vector2i(0, 0)); timelineMovement.Wait(500); timelineMovement.Action(() => result.Velocity = new Vector2i(0, -150)); // ------------------- // ATTACK TIMELINES var timelineAttack = new Timeline(); timelineAttack.Parameters["angle"] = 0; timelineAttack.AddCommand(new Do(() => { var angle = (int) timelineAttack.Parameters["angle"]; for (int i = 0; i < 24; i++) { BHPresetBullets.Glow1(mGame, result.Position, (360/24)*i + angle, 5.ToUnits()); BHPresetBullets.Glow1(mGame, result.Position, (360/24)*i - angle, 5.ToUnits()); } timelineAttack.Parameters["angle"] = angle + 20; })); timelineAttack.AddCommand(new Wait(25)); timelineAttack.AddCommand(new Goto(0, 50)); var timelineAttack2 = new Timeline(); timelineAttack2.AddCommand(new Do(() => { Assets.GetSound("tan00").Play(); for (int i = 0; i < 16; i++) { var bulletTimeline = new Timeline(); BHEntity bullet = BHPresetBullets.RoundSmall(mGame, result.Position, (360/16)*i, 1.ToUnits()); bulletTimeline.AddCommand(new Wait(50)); bulletTimeline.AddCommand(new Do(() => { Assets.GetSound("kira01").Play(); var player = (BHEntity) mGame.Manager.EntityDictionary["player"][0]; float angle = BHUtils.GetAngleTowards(bullet, player) + Utils.Random.Next(-8, 8); var newVelocity = Utils.Math.Angles.ToVectorDegrees(angle)*4.ToUnits(); bullet.Velocity = new Vector2i((int) newVelocity.X, (int) newVelocity.Y); })); bullet.TimelinesUpdate.Add(bulletTimeline); } })); timelineAttack2.AddCommand(new Wait(50)); timelineAttack2.AddCommand(new Goto(0, 50)); // ------------------- result.TimelinesUpdate.Add(timelineMovement); result.TimelinesUpdate.Add(timelineAttack); result.TimelinesUpdate.Add(timelineAttack2); return result; }
public static BHStage TestScriptStage2(BHGame mGame) { var result = new BHStage(); var stageTimeline = new Timeline(); // FIRST FAIRY WAVE for (int i = 0; i < 200; i++) { int i1 = i; var position = new Vector2i(); if (i%2 == 0) position = new Vector2i(mGame.Bounds.Right, 0); stageTimeline.Wait(5); stageTimeline.Action(() => EnemyFairy1(mGame, position, i1%2 != 0, "enemyfairy")); } // ------------------- // DISPLAY STAGE IMAGE stageTimeline.Wait(150); stageTimeline.Action(() => BHPresetStageControl.CutIn(mGame, result, Assets.GetTexture("st01logo"), mOffset: new Vector2i(0, -50000), mLength: 200)); // ------------------- // FIRST BIG FAIRY stageTimeline.Wait(50); stageTimeline.Action(() => EnemyFairyBig1(mGame, new Vector2i(mGame.Center.X, 0), "enemyfairybig")); // ------------------- // SECOND FAIRY WAVE stageTimeline.Wait(200); for (int i = 0; i < 50; i++) { int i1 = i; var position = new Vector2i(); if (i%2 == 0) position = new Vector2i(mGame.Bounds.Right, 0); stageTimeline.Wait(8); stageTimeline.Action(() => EnemyFairy1(mGame, position, i1%2 != 0, "enemyfairy", 2)); } // ------------------- // SECOND AND THIRD BIG FAIRIES stageTimeline.Wait(180); stageTimeline.Action(() => EnemyFairyBig1(mGame, new Vector2i(mGame.Center.X - 100.ToUnits(), 0), "enemyfairybig")); stageTimeline.Action(() => EnemyFairyBig1(mGame, new Vector2i(mGame.Center.X + 100.ToUnits(), 0), "enemyfairybig")); stageTimeline.Wait(500); // ------------------- // MIDBOSS WITH 1 SPELLCARD stageTimeline.Action(() => EnemyMidboss1(mGame, new Vector2i(mGame.Center.X, 0))); // ------------------- result.TimelinesUpdate.Add(stageTimeline); return result; }