Changeset 4424


Ignore:
Timestamp:
2013-07-04 10:34:21 (10 years ago)
Author:
jumakall
Message:
 
Location:
2013/27/TeemuM/Game/Game/Game
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • 2013/27/TeemuM/Game/Game/Game/Game.cs

    r4423 r4424  
    1313    public Player player { get; private set; } 
    1414    private List<Zombie> enemies = new List<Zombie>(); 
    15     //DoubleMeter LifeMeter; <-- Huono yritykseni tehdä elämä laskuria, aika loppui niin en kerennyt viimeistellä ja en ois osannukkaan, loput tohon liittyvä löytyy tiedoston pohjalta. -Aqua 
    1615 
    1716    public override void Begin() 
     
    115114                } 
    116115            } 
     116            else if (commands[0] == "health") 
     117            { 
     118                if (commands[1] == "add") 
     119                { 
     120                    player.health.Value += int.Parse(commands[2]); 
     121                    MessageDisplay.Add("+" + commands[2] + " health"); 
     122                } 
     123                else if (commands[1] == "reduce") 
     124                { 
     125                    player.health.Value -= int.Parse(commands[2]); 
     126                    MessageDisplay.Add("-" + commands[2] + " health"); 
     127                } 
     128            } 
    117129            else if (commands[0] == "exit") 
    118130            { 
     
    133145        AddScoreMeter(); 
    134146 
    135         player = new Player(50, 50, 1, true); 
     147        player = new Player(50, 50, 10, true); 
    136148        Camera.Follow(player); 
    137149        Add(player); 
    138150        SpawnZombie(); 
     151        CreateLifeMeter(); 
    139152    } 
    140153 
     
    222235    } 
    223236 
    224     /*void CreateLifeMeter() 
    225     { 
    226         LifeMeter = new DoubleMeter(10); 
    227         LifeMeter.MaxValue = 10; 
    228         LifeMeter.LowerLimit += HealthDepleated; 
    229  
     237    void CreateLifeMeter() 
     238    { 
    230239        ProgressBar LifeBar = new ProgressBar(150, 20); 
    231         LifeBar.X = Screen.Left + 150; 
    232         LifeBar.Y = Screen.Top - 20; 
    233         LifeBar.BindTo(LifeMeter); 
     240        LifeBar.X = Screen.Right - LifeBar.Width / 2 - 10; 
     241        LifeBar.Y = Screen.Bottom + LifeBar.Height / 2 + 10; 
     242        LifeBar.BorderColor = Color.Black; 
     243        LifeBar.BindTo(player.health); 
    234244        Add(LifeBar); 
    235245    } 
    236  
    237     void HealthDepleated() 
    238     { 
    239         MessageDisplay.Add("Elämät loppuivat, voi voi."); 
    240     } */ 
    241246} 
  • 2013/27/TeemuM/Game/Game/Game/Game.csproj

    r4378 r4424  
    116116    <Compile Include="Player.cs" /> 
    117117    <Compile Include="Properties\AssemblyInfo.cs" /> 
     118    <Compile Include="UI.cs" /> 
    118119  </ItemGroup> 
    119120  <ItemGroup> 
  • 2013/27/TeemuM/Game/Game/Game/Player.cs

    r4420 r4424  
    1515    private Weapon weapon; 
    1616    private double speed = defaultSpeed; 
    17     private int health; 
     17    public IntMeter health; 
    1818    private double power = defaultPower; 
    1919 
    2020    public Player(double width, double height, int health, bool addDefaultControls) : base(width, height) 
    2121    { 
    22         this.health = health; 
     22        this.health = new IntMeter(health, 0, health); 
     23        //this.health.LowerLimit =  
    2324        this.Tag = "player"; 
    2425        this.Shape = Shape.Rectangle; 
     
    2930            SetControls(Key.W, Key.S, Key.D, Key.A, MouseButton.Left); 
    3031 
     32        G.game.AddCollisionHandler(this, PlayerCollisionHanlder); 
    3133        this.IsUpdated = true; 
    3234    } 
    3335 
    34     public void Health(int healthChange) //ToDo: Game over, if no more health. 
     36    #region Collision handlers 
     37 
     38    private void PlayerCollisionHanlder(PhysicsObject player, PhysicsObject target) 
    3539    { 
    36         health += healthChange; 
     40        if (target is Zombie) 
     41        { 
     42            health.Value -= 1; 
     43        } 
    3744    } 
     45 
     46    private void ProjectileHanlder(PhysicsObject projectile, PhysicsObject target) //ToDo: Set collisions 
     47    { 
     48        if (target is Zombie) 
     49        { 
     50            if (weapon is Cannon) 
     51            { 
     52                ((Zombie)target).Health(-100); 
     53            } 
     54            else if (weapon is PlasmaCannon) 
     55            { 
     56                ((Zombie)target).Health(-50); 
     57            } 
     58        } 
     59        else if (target is Player) 
     60        { 
     61            Game.MessageDisplay.Add("Achievement get!"); 
     62        } 
     63        projectile.Destroy(); 
     64    } 
     65 
     66#endregion 
    3867 
    3968    public bool PowerUp(String type, double value) 
     
    6695            weapon.ProjectileCollision = ProjectileHanlder; 
    6796            weapon.Angle = Angle.FromDegrees(90); 
     97            weapon.CanHitOwner = true; 
    6898            this.Add(weapon); 
    6999            return true; 
    70100        } 
    71101        return false; 
    72     } 
    73  
    74     private void ProjectileHanlder(PhysicsObject projectile, PhysicsObject target) //ToDo: Set collisions 
    75     { 
    76         if (target is Zombie) 
    77         { 
    78             if (weapon is Cannon) 
    79             { 
    80                 ((Zombie)target).Health(-100); 
    81             } 
    82             else if (weapon is PlasmaCannon) 
    83             { 
    84                 ((Zombie)target).Health(-50); 
    85             } 
    86         } 
    87         projectile.Destroy(); 
    88102    } 
    89103 
Note: See TracChangeset for help on using the changeset viewer.