Changeset 6279 for 2015


Ignore:
Timestamp:
2015-06-24 17:40:36 (4 years ago)
Author:
empaheik
Message:

Milk!

File:
1 edited

Legend:

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

    r6278 r6279  
    2525 
    2626 
     27public abstract class Improvement :PlatformCharacter 
     28{ 
     29    private List<Animation> animations; 
     30    public List<Animation> Animations 
     31    { 
     32        get { return animations; } 
     33        set { animations = value; } 
     34    } 
     35 
     36    protected Improvement(double width, double height) 
     37        : base(width, height) 
     38    { 
     39 
     40    } 
     41 
     42    public HillBilly Owner 
     43    { 
     44        get { return owner; } 
     45        set {  owner = value; } 
     46    } 
     47    private HillBilly owner; 
     48 
     49    public virtual void DoTheThing() { } 
     50} 
     51 
    2752//Luokka maajussien erikoisuuksille. 
    28 class HillBilly : PlatformCharacter 
     53public class MilkImprovement: Improvement 
    2954{ 
    30     private IntMeter lifeCounter = new IntMeter(2, 0, 2); 
     55 
     56 
     57    public override void DoTheThing() 
     58    { 
     59        HillbillyRun game = this.Game as HillbillyRun; 
     60        game.CreateMilkParticles(this.Owner); 
     61    } 
     62 
     63    public MilkImprovement(double width, double height) 
     64        :base(width, height) 
     65    { 
     66 
     67    } 
     68} 
     69 
     70 
     71public class HillBilly : PlatformCharacter 
     72{ 
     73    private IntMeter lifeCounter = new IntMeter(4, 0, 4); 
    3174    public IntMeter Life 
    3275    { 
     
    3578    } 
    3679 
    37  
     80    private Improvement improvement; 
     81    public Improvement Improvement 
     82    { 
     83        set { improvement = value;} 
     84        get { return improvement; } 
     85    } 
     86 
     87    public void GainImprovement(Improvement improvement) 
     88    { 
     89        this.AnimWalk = improvement.Animations[0]; 
     90        this.AnimIdle = new Animation(improvement.Animations[0].CurrentFrame); 
     91        this.Improvement = improvement; 
     92        improvement.Owner = this; 
     93 
     94        improvement.Destroy(); 
     95    } 
     96 
     97    public void UseImprovement(Improvement improvement) 
     98    { 
     99        this.PlayAnimation(improvement.Animations[1]); 
     100        improvement.DoTheThing(); 
     101    } 
    38102 
    39103    public HillBilly(double leveys, double korkeus) 
     
    56120 
    57121    private const double PLAYER_SPEED = 180; 
    58     private const double TILE_SIZE = 70; 
     122    public const double TILE_SIZE = 70; 
    59123 
    60124    private double cameraTargetX; // Sijainti jossa kameran pitäisi olla. 
     
    106170        //MainMenu(); 
    107171        StartGame(); 
     172    } 
     173 
     174    public void CreateMilkParticles(HillBilly billy)        //TODO: Tiny particles. 
     175    { 
     176        PhysicsObject milkParticle = new PhysicsObject(20, 20); 
     177        milkParticle.Position = billy.Position; 
     178        milkParticle.Tag = "milkparticle"; 
     179        Add(milkParticle); 
     180 
    108181    } 
    109182 
     
    262335        cameraTimer.Timeout += UpdateCamera; 
    263336        cameraTimer.Start(); 
    264     } 
    265  
    266     #region LevelCreation 
    267     void CreateLevel() 
    268     { 
     337 
     338 
    269339        //Background 
    270340        GameObject forestBackground = new GameObject(Level.Width, Level.Height); 
     
    274344        Layers[-3].RelativeTransition = new Vector(0.5, 1.0); 
    275345        Level.Background.CreateGradient(Color.Black, Color.SkyBlue); 
     346    } 
     347 
     348    #region LevelCreation 
     349    void CreateLevel() 
     350    { 
    276351 
    277352        Gravity = new Vector(0, -1000); 
     
    323398        Wind = new Vector(-10, 0); 
    324399        Add(savu); 
     400 
     401        AddCollisionHandler(flame, "milkparticle", delegate(PhysicsObject c, PhysicsObject particle) 
     402        { 
     403            particle.Destroy(); 
     404            flame.Destroy(); 
     405            savu.Destroy(); 
     406        }); 
    325407    } 
    326408 
     
    346428        double size = 30; 
    347429        double ratio = milkImage.Height / milkImage.Width; 
    348         PhysicsObject milk = new PhysicsObject(size, size * ratio); 
     430 
     431        Improvement milk = new MilkImprovement(size, size * ratio); 
    349432        milk.Image = milkImage; 
     433        milk.Animations = new List<Animation> { milkWalk, milkThrow }; 
    350434        milk.Position = position; 
    351435        milk.Tag = "milk"; 
    352436        Add(milk); 
     437 
     438        //PhysicsObject milk = new PhysicsObject(size, size * ratio); 
     439        //milk.Image = milkImage; 
     440        //milk.Position = position; 
     441        //milk.Tag = "milk"; 
     442        //Add(milk); 
    353443    } 
    354444 
     
    392482            particle.Destroy(); 
    393483            crawly.Brain = null; 
     484            crawly.Animation = new Animation(crawly.Animation.CurrentFrame); 
    394485            crawly.Tag = ""; 
    395486            flame.Destroy(); 
     
    526617        Keyboard.Listen(Key.A, ButtonState.Down, delegate { startingPlayers[0].Walk(-PLAYER_SPEED); }, "Player 1 moves left"); 
    527618        Keyboard.Listen(Key.D, ButtonState.Down, delegate { startingPlayers[0].Walk(PLAYER_SPEED); }, "Player 1 moves right"); 
    528         Keyboard.Listen(Key.W, ButtonState.Down, delegate { startingPlayers[0].Jump(PLAYER_SPEED); }, "Player 1 jumps"); 
     619        Keyboard.Listen(Key.W, ButtonState.Down, delegate { startingPlayers[0].Jump(PLAYER_SPEED * 2); }, "Player 1 jumps");    //Just PLAYER_SPEED felt alright as well 
     620        Keyboard.Listen(Key.E, ButtonState.Pressed, UseImprovement, "Player 1 uses their tools", startingPlayers[0]); 
    529621 
    530622        Keyboard.Listen(Key.Left, ButtonState.Down, delegate { startingPlayers[1].Walk(-PLAYER_SPEED); }, "Player 2 moves left"); 
    531623        Keyboard.Listen(Key.Right, ButtonState.Down, delegate { startingPlayers[1].Walk(PLAYER_SPEED); }, "Player 2 moves right"); 
    532         Keyboard.Listen(Key.Up, ButtonState.Down, delegate { startingPlayers[1].Jump(PLAYER_SPEED); }, "Player 2 jumps"); 
     624        Keyboard.Listen(Key.Up, ButtonState.Down, delegate { startingPlayers[1].Jump(PLAYER_SPEED * 2); }, "Player 2 jumps"); 
     625        Keyboard.Listen(Key.RightShift, ButtonState.Pressed, UseImprovement, "Player 2 uses their tools", startingPlayers[1]); 
    533626 
    534627        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Show help"); 
    535628        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Exit game"); 
     629    } 
     630 
     631    private void UseImprovement(HillBilly player) 
     632    { 
     633        if(player.Improvement == null) 
     634        { 
     635            player.Jump(200);   //TODO: CRY ALL THE TEARS 
     636            return; 
     637        } 
     638 
     639        player.UseImprovement(player.Improvement); 
    536640    } 
    537641 
     
    548652            return; 
    549653 
     654        Improvement milkI = milk as Improvement; 
     655        billy.GainImprovement(milkI); 
     656 
    550657        milk.Destroy(); 
    551         billy.AnimWalk = new Animation(milkWalk); 
    552         billy.AnimIdle = new Animation(milkWalk.CurrentFrame); 
     658        //billy.AnimWalk = new Animation(milkWalk); 
     659        //billy.AnimIdle = new Animation(milkWalk.CurrentFrame); 
    553660    } 
    554661 
Note: See TracChangeset for help on using the changeset viewer.