public static void Stop(BHEntity mEntity, Vector2i mDirection, Rectangle mBounds, int mBoundsOffset)
 {
     if (mDirection.X == -1) mEntity.Position = new Vector2i(mBounds.X + mBoundsOffset, mEntity.Position.Y);
     if (mDirection.X == 1) mEntity.Position = new Vector2i(mBounds.X + mBounds.Width - mBoundsOffset, mEntity.Position.Y);
     if (mDirection.Y == -1) mEntity.Position = new Vector2i(mEntity.Position.X, mBounds.Y + mBoundsOffset);
     if (mDirection.Y == 1) mEntity.Position = new Vector2i(mEntity.Position.X, mBounds.Y - mBoundsOffset + mBounds.Height);
 }
Пример #2
0
 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 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);
        }
Пример #4
0
        public static BHEntity Bullet(BHGame mGame, Vector2i mPosition = default(Vector2i), float mAngle = 0, int mSpeed = 0, long mRadius = 0)
        {
            var result = new BHEntity(mGame, "deadlytoplayer", "bullet") {Position = mPosition, Velocity = BHUtils.CalculateVelocity(mAngle, mSpeed)};
            result.CollisionShape = new BHCSCircle(result, mRadius*mRadius);

            result.OnOutOfBounds += BHPresetOutOfBounds.Destroy;

            return result;
        }
Пример #5
0
        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;
        }
Пример #6
0
        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);
        }
Пример #7
0
        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;
        }
Пример #8
0
        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);
        }
Пример #9
0
        public static BHEntity PlayerBullet(BHGame mGame, Vector2i mPosition = default(Vector2i), float mAngle = 0, int mSpeed = 0)
        {
            var result = new BHEntity(mGame, "playerbullet") {Position = mPosition, Velocity = BHUtils.CalculateVelocity(mAngle, mSpeed)};
            result.CollisionShape = new BHCSPoint(result);
            result.CollisionAgainstGroups.Add("enemy");

            result.OnCollision += (entity, group) =>
                                  {
                                      if (group == "enemy")
                                      {
                                          entity.Sprite.Color = new Color((byte) Utils.Random.Next(0, 255), (byte) Utils.Random.Next(0, 255), (byte) Utils.Random.Next(0, 255));
                                          entity.Parameters["health"] = (int) entity.Parameters["health"] - 1;
                                          result.Destroy();
                                          Assets.GetSound("se_damage00").Play();
                                      }
                                  };

            result.OnOutOfBounds += BHPresetOutOfBounds.Destroy;

            return result;
        }
Пример #10
0
 public BHCSCircle(BHEntity mParent, long mRadiusSquared)
 {
     Parent = mParent;
     RadiusSquared = mRadiusSquared;
 }
Пример #11
0
        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;
        }
Пример #12
0
 public BHCSLine(BHEntity mParent, float mDegrees, int mLength, long mRadiusSquared)
 {
     Parent = mParent;
     Degrees = mDegrees;
     Length = mLength;
     RadiusSquared = mRadiusSquared;
 }
Пример #13
0
 public BHCSPolygon(BHEntity mParent, params Vector2i[] mVertices)
 {
     Parent = mParent;
     Vertices = mVertices.ToList();
 }
Пример #14
0
        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 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);
        }
Пример #16
0
        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;
        }
Пример #17
0
 public void InvokeOnCollision(BHEntity mEntity, string mGroup)
 {
     CollisionEvent handler = OnCollision;
     if (handler != null) handler(mEntity, mGroup);
 }
Пример #18
0
        public static void EnemyMidboss1SpellCard2(BHGame mGame, BHEntity mBoss)
        {
            var spellcardTimeline = new Timeline();
            spellcardTimeline.AddCommand(new Do(() => EnemyMidboss1SpellCardAttack3(mGame, mBoss.Position)));
            spellcardTimeline.AddCommand(new Wait(21));
            spellcardTimeline.AddCommand(new Do(() => BHPresetTimelines.MovementLerp(mBoss,
                                                                                     new Vector2i(Utils.Random.Next(mGame.Bounds.Left + 5.ToUnits(), mGame.Bounds.Right - 5.ToUnits()), mBoss.Position.Y))));
            spellcardTimeline.AddCommand(new Goto(0));

            var continueTimeline = new Timeline();
            continueTimeline.AddCommand(new Wait(25));
            continueTimeline.AddCommand(new Do(() => BHPresetTimelines.MovementLerp(mBoss, new Vector2i(mGame.Center.X, mBoss.Position.Y))));
            continueTimeline.AddCommand(new Wait(75));
            continueTimeline.AddCommand(new Do(mBoss.Destroy));
            continueTimeline.AddCommand(new Do(() => Assets.GetSound("enep01").Play()));

            BHPresetStageControl.CutIn(mGame, mGame.CurrentStage, Assets.GetTexture("face07bs"), true, "u mad bro?",
                                       new Vector2i(6.ToUnits(), 1.ToUnits()), new Vector2i(-10.ToUnits(), 5.ToUnits()), 150);
            BHPresetStageControl.SpellCard(mGame, mGame.CurrentStage, mBoss, "HERE ARE SOME BULLETS 4 U", 150, 1000, 10000, continueTimeline, spellcardTimeline);
        }
 public static void Destroy(BHEntity mEntity, Vector2i mDirection, Rectangle mBounds, int mBoundsOffset)
 {
     mEntity.Destroy();
 }
Пример #20
0
 public static float GetAngleTowards(BHEntity mStart, BHEntity mEnd)
 {
     return (float) Math.Atan2(mEnd.Position.Y - mStart.Position.Y, mEnd.Position.X - mStart.Position.X)*57.3f;
 }
Пример #21
0
 public BHCSPoint(BHEntity mParent)
 {
     Parent = mParent;
 }