Changeset 6549 for 2015/27


Ignore:
Timestamp:
2015-06-30 07:49:44 (4 years ago)
Author:
sieerinn
Message:

Miekan heiluttelu kirjoitettu uusiksi.

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

Legend:

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

    r6548 r6549  
    4848    } 
    4949 
    50     protected void SetWalkAnimation() 
     50    public void SetWalkAnimation() 
    5151    { 
    5252        Animation newAnim; 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/LevelCreation.cs

    r6548 r6549  
    5454        Add(player, 1); 
    5555 
     56        player.ActiveItem = new Sword(player); 
     57 
    5658        AddCollisionHandler(player, "exit", CollidesWithExit); 
    5759    } 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/Player.cs

    r6548 r6549  
    44class Player : Creature 
    55{ 
    6     public bool IsSwingingSword { get; set; } 
    7  
    8     public Direction SwingDirection { get; set; } 
    9  
    106    public Dictionary<Direction, Animation> SwingAnimations { get; set; } 
    117 
    12     public PhysicsObject Sword { get; set; } 
    13  
    14     private readonly Angle[] swordAngles; 
     8    public Item ActiveItem { get; set; } 
    159 
    1610    public Player() 
     
    1812    { 
    1913        SwingAnimations = new Dictionary<Direction, Animation>(); 
    20         swordAngles = new Angle[5]; 
    21         for (var i = 0; i < 5; i++) 
    22         { 
    23             swordAngles[i] = Angle.FromDegrees(45 + -45 * 0.5 * i); 
    24         } 
    25  
    2614        CollisionIgnoreGroup = 1; 
    27     } 
    28  
    29     public void SwingSword() 
    30     { 
    31         IsSwingingSword = true; 
    32  
    33         if (Sword != null) 
    34             Sword.Destroy(); 
    35  
    36         Sword = PhysicsObject.CreateStaticObject(10, 10); 
    37         Sword.CollisionIgnoreGroup = CollisionIgnoreGroup; 
    38         Sword.Position = Position; 
    39         Sword.Image = TheLegendOfGabriel.gunImage; 
    40         Game.Instance.Add(Sword); 
    41  
    42         SwingDirection = Velocity.Angle.MainDirection; 
    43         Animation = new Animation(SwingAnimations[SwingDirection]); 
    44         Animation.StopOnLastFrame = true; 
    45         Animation.Played += delegate 
    46         { 
    47             IsSwingingSword = false; 
    48             SetWalkAnimation(); 
    49             Sword.Destroy(); 
    50         }; 
    51         Animation.Start(1); 
    5215    } 
    5316 
    5417    protected override void UpdateAnimations() 
    5518    { 
    56         if (!IsSwingingSword) 
    57             base.UpdateAnimations(); 
     19        if (!(ActiveItem != null && ActiveItem.OverrideAnimation)) 
     20        { 
     21            base.UpdateAnimations();    
     22        } 
    5823    } 
    5924 
    6025    public override void UpdateCreature(Time time) 
    6126    { 
    62         if (Sword != null && Sword.IsDestroyed) 
    63         { 
    64             Sword = null; 
    65         } 
    66         if (Sword != null && IsSwingingSword) 
    67         { 
    68             var dir = SwingDirection; 
    69             var swordAngle = swordAngles[Animation.CurrentFrameIndex]; 
    70             if (dir == Direction.Left) 
    71                 swordAngle = Angle.FromDegrees(swordAngle.Degrees * -1); 
    72             Sword.Position = Position + (dir.Angle + swordAngle).GetVector() * 15; 
    73             Sword.Angle = swordAngle + Angle.FromDegrees(dir == Direction.Left || dir == Direction.Right ? 90 : 0); 
    74             Sword.Angle += Angle.FromDegrees(dir == Direction.Right || dir == Direction.Down ? 180 : 0); 
    75         } 
     27        if (ActiveItem != null) 
     28            ActiveItem.UpdateItem(time); 
    7629        base.UpdateCreature(time); 
    7730    } 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.cs

    r6548 r6549  
    2222    #region Resources 
    2323 
    24     public static Image gunImage = LoadImage("gun"); 
     24    public static Image GunImage = LoadImage("gun"); 
     25 
     26    public static Image SmallSwordImage = LoadImage("smallsword"); 
    2527 
    2628    [AssetName("walkright")] 
     
    9193        Keyboard.Listen(Key.Down, ButtonState.Down, player.Move, null, Direction.Down); 
    9294 
    93         Keyboard.Listen(Key.Space, ButtonState.Pressed, player.SwingSword, null); 
     95        Keyboard.Listen(Key.Space, ButtonState.Pressed, delegate { if (player.ActiveItem != null) player.ActiveItem.UseKeyPressed(); }, null); 
     96        Keyboard.Listen(Key.Space, ButtonState.Released, delegate { if (player.ActiveItem != null) player.ActiveItem.UseKeyReleased(); }, null); 
     97        Keyboard.Listen(Key.Space, ButtonState.Down, delegate { if (player.ActiveItem != null) player.ActiveItem.UseKeyDown(); }, null); 
    9498 
    9599        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, null); 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.csproj

    r6548 r6549  
    114114    <Compile Include="Creature.cs" /> 
    115115    <Compile Include="Exit.cs" /> 
     116    <Compile Include="Item.cs" /> 
    116117    <Compile Include="LevelCreation.cs" /> 
    117118    <Compile Include="Ohjelma.cs" /> 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabrielContent/TheLegendOfGabrielContent.contentproj

    r6548 r6549  
    148148    </Compile> 
    149149  </ItemGroup> 
     150  <ItemGroup> 
     151    <Compile Include="smallsword.png"> 
     152      <Name>smallsword</Name> 
     153      <Importer>TextureImporter</Importer> 
     154      <Processor>TextureProcessor</Processor> 
     155    </Compile> 
     156  </ItemGroup> 
    150157  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    151158  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.