예제 #1
0
 public Animation Clone()
 {
     var result = new Animation(IsLooped, IsPingPong);
     result.Steps = new List<Step>(Steps);
     result.CurrentStep = result.Steps[0];
     return result;
 }
예제 #2
0
파일: Assets.cs 프로젝트: Scellow/SFMLStart
        private static void LoadAnimation(FileInfo mFileInfo)
        {
            var streamReader = File.OpenText(mFileInfo.FullName);

            var fileText = Regex.Replace(streamReader.ReadToEnd(), Settings.Assets.Regex, "");
            var separationByGroups = fileText.Split(Settings.Assets.SeparatorGroup);
            var animationLooped = Int32.Parse(separationByGroups[0]) == 1;
            var animationPingpong = Int32.Parse(separationByGroups[1]) == 1;
            var separationByItems = separationByGroups[2].Split(Settings.Assets.SeparatorItem);

            var result = new Animation(animationLooped, animationPingpong);
            for (var i = 0; i < separationByItems.Length; i++)
                if ((i + 1)%2 == 0) result.AddStep(separationByItems[i - 1], Int32.Parse(separationByItems[i]));
            _animations.Add(GetAssetName(mFileInfo), result);
            Utils.Log(string.Format("animation <<{0}>> created", GetAssetName(mFileInfo)), "InitializeAnimations",
                      ConsoleColor.Yellow);
        }
예제 #3
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;
        }