Changeset 6549
- Timestamp:
- 2015-06-30 07:49:44 (6 years ago)
- 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 48 48 } 49 49 50 p rotectedvoid SetWalkAnimation()50 public void SetWalkAnimation() 51 51 { 52 52 Animation newAnim; -
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/LevelCreation.cs
r6548 r6549 54 54 Add(player, 1); 55 55 56 player.ActiveItem = new Sword(player); 57 56 58 AddCollisionHandler(player, "exit", CollidesWithExit); 57 59 } -
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/Player.cs
r6548 r6549 4 4 class Player : Creature 5 5 { 6 public bool IsSwingingSword { get; set; }7 8 public Direction SwingDirection { get; set; }9 10 6 public Dictionary<Direction, Animation> SwingAnimations { get; set; } 11 7 12 public PhysicsObject Sword { get; set; } 13 14 private readonly Angle[] swordAngles; 8 public Item ActiveItem { get; set; } 15 9 16 10 public Player() … … 18 12 { 19 13 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 26 14 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 += delegate46 {47 IsSwingingSword = false;48 SetWalkAnimation();49 Sword.Destroy();50 };51 Animation.Start(1);52 15 } 53 16 54 17 protected override void UpdateAnimations() 55 18 { 56 if (!IsSwingingSword) 57 base.UpdateAnimations(); 19 if (!(ActiveItem != null && ActiveItem.OverrideAnimation)) 20 { 21 base.UpdateAnimations(); 22 } 58 23 } 59 24 60 25 public override void UpdateCreature(Time time) 61 26 { 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); 76 29 base.UpdateCreature(time); 77 30 } -
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.cs
r6548 r6549 22 22 #region Resources 23 23 24 public static Image gunImage = LoadImage("gun"); 24 public static Image GunImage = LoadImage("gun"); 25 26 public static Image SmallSwordImage = LoadImage("smallsword"); 25 27 26 28 [AssetName("walkright")] … … 91 93 Keyboard.Listen(Key.Down, ButtonState.Down, player.Move, null, Direction.Down); 92 94 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); 94 98 95 99 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, null); -
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.csproj
r6548 r6549 114 114 <Compile Include="Creature.cs" /> 115 115 <Compile Include="Exit.cs" /> 116 <Compile Include="Item.cs" /> 116 117 <Compile Include="LevelCreation.cs" /> 117 118 <Compile Include="Ohjelma.cs" /> -
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabrielContent/TheLegendOfGabrielContent.contentproj
r6548 r6549 148 148 </Compile> 149 149 </ItemGroup> 150 <ItemGroup> 151 <Compile Include="smallsword.png"> 152 <Name>smallsword</Name> 153 <Importer>TextureImporter</Importer> 154 <Processor>TextureProcessor</Processor> 155 </Compile> 156 </ItemGroup> 150 157 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 151 158 <!-- 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.