Changeset 6383 for 2015/26


Ignore:
Timestamp:
2015-06-25 16:35:24 (8 years ago)
Author:
empaheik
Message:

Parannukset voi pudotella + poimia uudelleen epämääräisillä painikkeilla.

Location:
2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun.cs

    r6382 r6383  
    4242    private HillBilly owner; 
    4343 
    44     public virtual void DoTheThing() { } 
     44    public virtual void DoTheThing(HillbillyRun game) { } 
    4545 
    4646    public SoundEffect sound; 
     47 
     48    public void Rid() 
     49    { 
     50        Owner.AnimWalk = Owner.Animations[0]; 
     51        Owner.AnimIdle = Owner.Animations[1]; 
     52        Owner.Improvement = null; 
     53        Owner = null; 
     54    } 
    4755} 
    4856 
    4957public class MilkImprovement : Improvement 
    5058{ 
    51     public override void DoTheThing() 
    52     { 
    53         HillbillyRun game = this.Game as HillbillyRun; 
     59    public override void DoTheThing(HillbillyRun game) 
     60    { 
     61        //HillbillyRun game = this.Game as HillbillyRun; 
    5462        Owner.PlayAnimation(Animations[1]); 
    5563        game.CreateMilkParticles(this.Owner, 10, 200, 300, new Vector(0, -30), "milkparticle"); 
    5664        this.sound.Play(); 
    57  
    5865    } 
    5966 
     
    6875public class PitchForkImprovement : Improvement 
    6976{ 
    70     public override void DoTheThing() 
    71     { 
    72         HillbillyRun game = this.Game as HillbillyRun; 
    73         Owner.PlayAnimation(Animations[1]); 
     77    public override void DoTheThing(HillbillyRun game) 
     78    { 
     79        //HillbillyRun game = this.Game as HillbillyRun; 
    7480        //game.CreateMilkParticles(this.Owner, 10, 200, 300, new Vector(0, -30), "milkparticle"); 
    7581        //TODO: hitting things w/ pitchfork 
    76  
     82        game.ForkThings(Owner); 
    7783    } 
    7884 
     
    8389    } 
    8490} 
    85  
    8691#endregion 
    8792 
    8893public class HillBilly : PlatformCharacter 
    8994{ 
     95    public List<Animation> Animations { get; set; } 
     96 
    9097    private IntMeter lifeCounter = new IntMeter(4, 0, 4); 
    9198    public IntMeter Life 
     
    108115    public void GainImprovement(Improvement improvement) 
    109116    { 
     117 
    110118        this.AnimWalk = improvement.Animations[0]; 
    111119        this.AnimIdle = new Animation(improvement.Animations[0].CurrentFrame); 
     
    116124    } 
    117125 
    118     public void UseImprovement(Improvement improvement) 
    119     { 
    120         if (Animation != improvement.Animations[1]) 
    121         { 
    122             improvement.DoTheThing(); 
    123              
     126    public void UseImprovement() 
     127    { 
     128        HillbillyRun game = this.Game as HillbillyRun; 
     129        if (this.Improvement == null) 
     130        { 
     131            game.CreateMilkParticles(this, 5, 100, 100, new Vector(0, Height / 3), "tears"); 
     132        } 
     133        else if (Animation != this.Improvement.Animations[1]) 
     134        { 
     135            this.Improvement.DoTheThing(game); 
    124136        } 
    125137    } 
     
    573585        brain.FallsOffPlatforms = false; 
    574586        worm.Brain = brain; 
     587 
     588        AddCollisionHandler(worm, "pitchfork", delegate(PhysicsObject w, PhysicsObject p) { w.Destroy(); }); 
    575589    } 
    576590 
     
    775789        player.AnimJump = new Animation(playerJump); 
    776790        player.AnimFall = new Animation(playerFall); 
     791        player.Animations = new List<Animation>(); 
     792        player.Animations.Add(normalWalk); 
     793        player.Animations.Add(playerIdle); 
    777794        player.AnimFall.StopOnLastFrame = true; 
    778795        players.Add(player); 
     
    809826                players.Remove(player); 
    810827 
    811                 if (player.Improvement != null) 
    812                 { 
    813                     Improvement parannus = player.Improvement; 
    814                     //parannus.Image = player.Improvement.Image; 
    815                     parannus.Position = player.Position; 
    816                     parannus.IsVisible = true; 
    817                     parannus.IgnoresCollisionResponse = false; 
    818                     parannus.Tag = "improvement"; 
    819                     //parannus.Animations = player.Improvement.Animations; 
    820                     //parannus.Tag = player.Improvement.Tag; 
    821                     //parannus.Size = new Vector(60, 60); 
    822                     //Add(parannus); 
    823                 } 
     828                //if (player.Improvement != null) 
     829                //{ 
     830                    GetRidOfImprovement(player); 
     831                    //Improvement parannus = player.Improvement; 
     832                    //parannus.Position = player.Position; 
     833                    //parannus.IsVisible = true; 
     834                    //parannus.IgnoresCollisionResponse = false; 
     835                    //parannus.Tag = "improvement"; 
     836                //} 
    824837 
    825838                player.Destroy(); 
     
    832845       // AddCollisionHandler(player, "improvement", CollectImprovement); 
    833846    } 
    834  
    835     //void CollectImprovement(PhysicsObject player, PhysicsObject fork) 
    836     //{ 
    837     //    //TODO: Collecting the fork 
    838     //    HillBilly billy = player as HillBilly; 
    839     //    if (billy == null) 
    840     //        return; 
    841  
    842     //    Improvement forkI = fork as Improvement; 
    843     //    billy.GainImprovement(forkI); 
    844  
    845     //    Remove(fork); 
    846     //} 
    847847 
    848848    void CreateGroundTop(Vector position, double width, double height) 
     
    890890        Keyboard.Listen(Key.D, ButtonState.Down, delegate { startingPlayers[0].Walk(PLAYER_SPEED); }, "Player 1 moves right"); 
    891891        Keyboard.Listen(Key.W, ButtonState.Down, delegate { startingPlayers[0].Jump(PLAYER_SPEED * 2); }, "Player 1 jumps");    //Just PLAYER_SPEED felt alright as well 
    892         Keyboard.Listen(Key.E, ButtonState.Pressed, UseImprovement, "Player 1 uses their tools", startingPlayers[0]); 
     892        Keyboard.Listen(Key.E, ButtonState.Pressed, delegate { startingPlayers[0].UseImprovement(); }, "Player 1 uses their tools"); 
     893        Keyboard.Listen(Key.Tab, ButtonState.Pressed, GetRidOfImprovement, "Player 1 throws their tools away", startingPlayers[0]); 
    893894 
    894895        Keyboard.Listen(Key.Left, ButtonState.Down, delegate { startingPlayers[1].Walk(-PLAYER_SPEED); }, "Player 2 moves left"); 
    895896        Keyboard.Listen(Key.Right, ButtonState.Down, delegate { startingPlayers[1].Walk(PLAYER_SPEED); }, "Player 2 moves right"); 
    896897        Keyboard.Listen(Key.Up, ButtonState.Down, delegate { startingPlayers[1].Jump(PLAYER_SPEED * 2); }, "Player 2 jumps"); 
    897         Keyboard.Listen(Key.RightShift, ButtonState.Pressed, UseImprovement, "Player 2 uses their tools", startingPlayers[1]); 
     898        Keyboard.Listen(Key.RightShift, ButtonState.Pressed, delegate { startingPlayers[1].UseImprovement(); }, "Player 2 uses their tools"); 
     899        Keyboard.Listen(Key.Enter, ButtonState.Pressed, GetRidOfImprovement, "Player 1 throws their tools away", startingPlayers[1]); 
    898900 
    899901        Keyboard.Listen(Key.F12, ButtonState.Pressed, NextLevel, null); 
     
    902904        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Show help"); 
    903905        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Exit game"); 
     906    } 
     907 
     908    void GetRidOfImprovement(HillBilly player) 
     909    { 
     910        if(player.Improvement != null) 
     911        { 
     912            Improvement parannus = player.Improvement; 
     913            parannus.Position = player.Position + player.FacingDirection.GetVector() * 100; 
     914            parannus.IsVisible = true; 
     915            parannus.IgnoresCollisionResponse = false; 
     916            parannus.Tag = "improvement"; 
     917            player.Improvement.Rid(); 
     918        } 
    904919    } 
    905920 
     
    935950    } 
    936951 
    937     private void UseImprovement(HillBilly player) 
    938     { 
    939         if (player.Improvement == null) 
    940         { 
     952    //private void UseImprovement(HillBilly player) 
     953    //{ 
     954    //    if (player.Improvement == null) 
     955    //    { 
    941956             
    942             CreateMilkParticles(player, 5, 100, 100, new Vector(0, player.Height/3), "tears"); 
    943             return; 
    944         } 
    945  
    946         player.UseImprovement(player.Improvement); 
    947     } 
     957    //        CreateMilkParticles(player, 5, 100, 100, new Vector(0, player.Height/3), "tears"); 
     958    //        return; 
     959    //    } 
     960 
     961    //    player.UseImprovement(player.Improvement); 
     962    //} 
    948963 
    949964    void Loss() 
     
    956971    { 
    957972        HillBilly billy = player as HillBilly; 
    958         if (billy == null) 
     973        if (billy == null || billy.Improvement != null) 
    959974            return; 
    960975 
     
    9991014        } 
    10001015    } 
     1016 
     1017    public void ForkThings(HillBilly Owner) 
     1018    { 
     1019        PhysicsObject evilClone = new PhysicsObject(Owner.Width, Owner.Height * 0.7); 
     1020        evilClone.Position = Owner.Position + Owner.FacingDirection.GetVector() * 40 + new Vector(0, -(Owner.Height * 0.3)); 
     1021        evilClone.Color = Color.Red; 
     1022        evilClone.IsVisible = false; 
     1023        evilClone.Tag = "pitchfork"; 
     1024        evilClone.IgnoresCollisionResponse = true; 
     1025        evilClone.IgnoresPhysicsLogics = true; 
     1026        evilClone.LifetimeLeft = TimeSpan.FromSeconds(Owner.Animation.FPS * Owner.Animation.FrameCount); 
     1027        Add(evilClone); 
     1028 
     1029        Owner.PlayAnimation(Owner.Improvement.Animations[1], evilClone.Destroy); 
     1030    } 
     1031     
    10011032 
    10021033    protected override void Update(Time time) 
     
    10391070     */ 
    10401071    #endregion 
     1072 
     1073 
    10411074} 
Note: See TracChangeset for help on using the changeset viewer.