Changeset 6546
- Timestamp:
- 2015-06-29 22:50:18 (6 years ago)
- Location:
- 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/LevelCreation.cs
r6544 r6546 31 31 player.MovementSpeed = 2300; 32 32 player.Position = position; 33 player.MoveAnimations[Direction.Left] = playerWalkLeft; 34 player.MoveAnimations[Direction.Right] = playerWalkRight; 35 player.MoveAnimations[Direction.Up] = playerWalkUp; 36 player.MoveAnimations[Direction.Down] = playerWalkDown; 37 player.Image = playerWalkDown.CurrentFrame; 33 38 Add(player, 1); 34 39 -
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.cs
r6545 r6546 39 39 public double MovementSpeed { get; set; } 40 40 41 public Dictionary<Direction, Animation> MoveAnimations { get; set; } 42 41 43 public Creature(double width, double height) 42 44 : base(width, height) 43 45 { 46 MoveAnimations = new Dictionary<Direction, Animation>(); 44 47 LinearDamping = 0.5; 45 48 } … … 49 52 if (!Game.IsPaused) 50 53 Push(direction.GetVector() * MovementSpeed); 54 } 55 56 public override void Update(Time time) 57 { 58 if (Velocity.MagnitudeSquared > 10.0) 59 { 60 // Animaation vaihto nopeuden suunnan perusteella. 61 Animation newAnim; 62 var dir = Velocity.Angle.MainDirection; 63 if (MoveAnimations.TryGetValue(dir, out newAnim)) 64 { 65 if (Animation != newAnim) 66 { 67 Animation = newAnim; 68 } 69 } 70 71 // Käynnistetään animaatio jos se ei ole jo käynnissä. 72 if (!Animation.IsPlaying) 73 Animation.Resume(); 74 } 75 else if (Animation != null && Animation.IsPlaying) 76 { 77 // Paikallaan ollessa pysäytetään animaatio. 78 Animation.Pause(); 79 } 80 base.Update(time); 51 81 } 52 82 } … … 68 98 [AssetName("walkright", mirror: true)] 69 99 private Animation playerWalkLeft; 100 [AssetName("walkup")] 101 private Animation playerWalkUp; 102 [AssetName("walkdown")] 103 private Animation playerWalkDown; 70 104 71 105 #endregion … … 259 293 } 260 294 } 295 296 protected override void Update(Time time) 297 { 298 player.Update(time); 299 base.Update(time); 300 } 261 301 }
Note: See TracChangeset
for help on using the changeset viewer.