Changeset 6546 for 2015/27/ohjaajat


Ignore:
Timestamp:
2015-06-29 22:50:18 (4 years ago)
Author:
sieerinn
Message:

Pelaajalla on animaatiot.

Location:
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/LevelCreation.cs

    r6544 r6546  
    3131        player.MovementSpeed = 2300; 
    3232        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; 
    3338        Add(player, 1); 
    3439 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.cs

    r6545 r6546  
    3939    public double MovementSpeed { get; set; } 
    4040 
     41    public Dictionary<Direction, Animation> MoveAnimations { get; set; } 
     42 
    4143    public Creature(double width, double height) 
    4244        : base(width, height) 
    4345    { 
     46        MoveAnimations = new Dictionary<Direction, Animation>(); 
    4447        LinearDamping = 0.5; 
    4548    } 
     
    4952        if (!Game.IsPaused) 
    5053            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); 
    5181    } 
    5282} 
     
    6898    [AssetName("walkright", mirror: true)] 
    6999    private Animation playerWalkLeft; 
     100    [AssetName("walkup")] 
     101    private Animation playerWalkUp; 
     102    [AssetName("walkdown")] 
     103    private Animation playerWalkDown; 
    70104 
    71105    #endregion 
     
    259293        } 
    260294    } 
     295 
     296    protected override void Update(Time time) 
     297    { 
     298        player.Update(time); 
     299        base.Update(time); 
     300    } 
    261301} 
Note: See TracChangeset for help on using the changeset viewer.