Changeset 4452 for 2013/27


Ignore:
Timestamp:
2013-07-05 00:57:59 (10 years ago)
Author:
jumakall
Message:
 
Location:
2013/27/TeemuM/Game/Game/Game
Files:
3 edited

Legend:

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

    r4420 r4452  
    99using Jypeli.Widgets; 
    1010 
    11 public class Zombie : PhysicsObject 
     11public class Enemy : PhysicsObject 
    1212{ 
     13    public delegate void EmptyHandler(); 
     14    public event EmptyHandler Dying; 
    1315 
    14     private static Image[] Images = { Game.LoadImage("Zombie1"), Game.LoadImage("Zombie2"), Game.LoadImage("Zombie3"), Game.LoadImage("Zombie4") }; 
    15  
     16    private PhysicsObject follow; 
    1617    private int health; 
    1718 
    18     public Zombie(double widht, double height, double x, double y, int health) : base(widht, height) 
     19    public Enemy(PhysicsObject follow, int health, double widht, double height) : base(widht, height) 
    1920    { 
    20         this.X = x; 
    21         this.Y = y; 
    22         this.Shape = Shape.Circle; 
    2321        this.health = health; 
    24         RandomTexture();  
    25         CreateBrain(); 
    26  
     22        this.follow = follow; 
    2723        this.IsUpdated = true; 
    28     } 
    29  
    30     public void RandomTexture() 
    31     { 
    32         this.Image = Images[RandomGen.NextInt(Images.Length)]; 
    3324    } 
    3425 
     
    3728        health += healtChange; 
    3829        if (health <= 0) 
     30        { 
     31            if (Dying != null) 
     32                Dying(); 
    3933            this.Destroy(); 
    40     } 
    41  
    42     private void CreateBrain() 
    43     { 
    44         FollowerBrain brain = new FollowerBrain("player"); 
    45         brain.Speed = 200; 
    46         brain.Active = true; 
    47         this.Brain = brain; 
     34        } 
    4835    } 
    4936 
     
    5441    } 
    5542} 
     43 
     44public class Zombie : Enemy 
     45{ 
     46    private static Image[] Images = { Game.LoadImage("Zombie1"), Game.LoadImage("Zombie2"), Game.LoadImage("Zombie3"), Game.LoadImage("Zombie4") }; 
     47    PhysicsObject follow; 
     48 
     49    public Zombie(PhysicsObject follow, double widht, double height, double x, double y, int health) : base(follow, health, widht, height) 
     50    { 
     51        this.follow = follow; 
     52        this.X = x; 
     53        this.Y = y; 
     54        this.Shape = Shape.Circle; 
     55        RandomTexture();  
     56        CreateBrain(); 
     57    } 
     58 
     59    public void RandomTexture() 
     60    { 
     61        this.Image = Images[RandomGen.NextInt(Images.Length)]; 
     62    } 
     63 
     64    private void CreateBrain() 
     65    { 
     66        FollowerBrain brain = new FollowerBrain(follow); 
     67        brain.Speed = 200; 
     68        brain.Active = true; 
     69        this.Brain = brain; 
     70    } 
     71} 
  • 2013/27/TeemuM/Game/Game/Game/Game.cs

    r4449 r4452  
    190190        Keyboard.Listen(Key.Tab, ButtonState.Pressed, DeveloperCommand, null); 
    191191 
    192         player = new Player(50, 50, 10, true); 
     192        player = new Player(this, 50, 50, 10, true); 
     193        player.Dying += GameOver; 
    193194        Add(player); 
    194195        Camera.Follow(player); 
     
    224225            y = RandomGen.SelectOne(Screen.Bottom - i, Screen.Top + i); 
    225226        } 
    226         Zombie zombie = new Zombie(50, 50, x + player.X, y + player.Y, 100); 
     227        Zombie zombie = new Zombie(player, 50, 50, x + player.X, y + player.Y, 100); 
    227228        enemies.Add(zombie); 
    228229        Add(zombie); 
     
    314315    private void GameOver() 
    315316    { 
    316         GameObject layer = new GameObject(Game.Screen.Width, Game.Screen.Height); 
     317        GameObject layer = new GameObject(Game.Screen.Width + 100, Game.Screen.Height + 100); 
    317318        layer.Color = Color.Transparent; 
    318319        layer.Position = player.Position; 
     
    326327 
    327328        Timer.SingleShot(1, delegate { IsPaused = true; }); 
     329        MessageDisplay.Clear(); 
    328330    } 
    329331} 
  • 2013/27/TeemuM/Game/Game/Game/Player.cs

    r4449 r4452  
    1010{ 
    1111    private static Image playerImage = Game.LoadImage("Player"); 
     12 
     13    private G game; 
    1214 
    1315 
     
    2729    public event EmptyHandler Dying; 
    2830 
    29     public Player(double width, double height, int health, bool addDefaultControls) : base(width, height) 
     31    public Player(G game, double width, double height, int health, bool addDefaultControls) 
     32        : base(width, height) 
    3033    { 
     34        this.game = game; 
    3135        this.health = new IntMeter(health, 0, health); 
    32         this.health.LowerLimit += delegate 
    33         { 
    34              
    35  
    36             this.Destroy(); 
    37         }; 
     36        this.health.LowerLimit += delegate { if (Dying != null) Dying(); this.Destroy(); }; 
    3837        this.Tag = "player"; 
    3938        this.Shape = Shape.Rectangle; 
     
    5251    private void PlayerCollisionHanlder(PhysicsObject player, PhysicsObject target) 
    5352    { 
    54         if (target is Zombie) 
     53        if (target is Enemy) 
    5554        { 
    5655            health.Value -= 1; 
     
    6059    private void ProjectileHanlder(PhysicsObject projectile, PhysicsObject target) //ToDo: Set collisions 
    6160    { 
    62         if (target is Zombie) 
     61        if (target is Enemy) 
    6362        { 
    6463            if (weapon is Cannon) 
    65             { 
    66                 ((Zombie)target).Health(-100); 
    67             } 
     64                ((Enemy)target).Health(-100); 
    6865            else if (weapon is PlasmaCannon) 
    69             { 
    70                 ((Zombie)target).Health(-50); 
    71             } 
    72         } 
    73         else if (target is Player) 
    74         { 
    75             Game.MessageDisplay.Add("Achievement get!"); 
     66                ((Enemy)target).Health(-50); 
     67            else if (weapon is LaserGun) 
     68                ((Enemy)target).Health(-50); 
     69            else if (weapon is AssaultRifle) 
     70                ((Enemy)target).Health(-50); 
    7671        } 
    7772        projectile.Destroy(); 
    7873    } 
    7974 
    80 #endregion 
     75    #endregion 
    8176 
    8277    public bool PowerUp(String type, double value) 
     
    10398        else if (itemName.ToLower() == "plasmacannon") 
    10499            weapon = new PlasmaCannon(75, 25); 
     100        else if (itemName.ToLower() == "lasergun") 
     101            weapon = new LaserGun(75, 25); 
     102        else if (itemName.ToLower() == "assaultrifle") 
     103            weapon = new AssaultRifle(75, 25); 
    105104 
    106105        if (weapon != null) 
     
    137136    private void MovePlayer(Vector force) 
    138137    { 
    139         if (canMove) 
     138        if (canMove && !IsDestroyed) 
    140139            this.Push(force); 
    141140    } 
     
    143142    public void Shoot() 
    144143    { 
    145         if (weapon != null) 
     144        if (!IsDestroyed) 
    146145        { 
    147             weapon.Power.Value = power; 
    148             weapon.Shoot(); 
     146            if (weapon != null) 
     147            { 
     148                weapon.Power.Value = power; 
     149                weapon.Shoot(); 
     150            } 
     151            else 
     152                Game.MessageDisplay.Add("PEW PEW!"); 
    149153        } 
    150         else 
    151             Game.MessageDisplay.Add("PEW PEW!"); 
    152154    } 
    153155 
Note: See TracChangeset for help on using the changeset viewer.