- Timestamp:
- 2013-07-05 00:57:59 (10 years ago)
- Location:
- 2013/27/TeemuM/Game/Game/Game
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/27/TeemuM/Game/Game/Game/Enemies.cs
r4420 r4452 9 9 using Jypeli.Widgets; 10 10 11 public class Zombie: PhysicsObject11 public class Enemy : PhysicsObject 12 12 { 13 public delegate void EmptyHandler(); 14 public event EmptyHandler Dying; 13 15 14 private static Image[] Images = { Game.LoadImage("Zombie1"), Game.LoadImage("Zombie2"), Game.LoadImage("Zombie3"), Game.LoadImage("Zombie4") }; 15 16 private PhysicsObject follow; 16 17 private int health; 17 18 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) 19 20 { 20 this.X = x;21 this.Y = y;22 this.Shape = Shape.Circle;23 21 this.health = health; 24 RandomTexture(); 25 CreateBrain(); 26 22 this.follow = follow; 27 23 this.IsUpdated = true; 28 }29 30 public void RandomTexture()31 {32 this.Image = Images[RandomGen.NextInt(Images.Length)];33 24 } 34 25 … … 37 28 health += healtChange; 38 29 if (health <= 0) 30 { 31 if (Dying != null) 32 Dying(); 39 33 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 } 48 35 } 49 36 … … 54 41 } 55 42 } 43 44 public 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 190 190 Keyboard.Listen(Key.Tab, ButtonState.Pressed, DeveloperCommand, null); 191 191 192 player = new Player(50, 50, 10, true); 192 player = new Player(this, 50, 50, 10, true); 193 player.Dying += GameOver; 193 194 Add(player); 194 195 Camera.Follow(player); … … 224 225 y = RandomGen.SelectOne(Screen.Bottom - i, Screen.Top + i); 225 226 } 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); 227 228 enemies.Add(zombie); 228 229 Add(zombie); … … 314 315 private void GameOver() 315 316 { 316 GameObject layer = new GameObject(Game.Screen.Width , Game.Screen.Height);317 GameObject layer = new GameObject(Game.Screen.Width + 100, Game.Screen.Height + 100); 317 318 layer.Color = Color.Transparent; 318 319 layer.Position = player.Position; … … 326 327 327 328 Timer.SingleShot(1, delegate { IsPaused = true; }); 329 MessageDisplay.Clear(); 328 330 } 329 331 } -
2013/27/TeemuM/Game/Game/Game/Player.cs
r4449 r4452 10 10 { 11 11 private static Image playerImage = Game.LoadImage("Player"); 12 13 private G game; 12 14 13 15 … … 27 29 public event EmptyHandler Dying; 28 30 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) 30 33 { 34 this.game = game; 31 35 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(); }; 38 37 this.Tag = "player"; 39 38 this.Shape = Shape.Rectangle; … … 52 51 private void PlayerCollisionHanlder(PhysicsObject player, PhysicsObject target) 53 52 { 54 if (target is Zombie)53 if (target is Enemy) 55 54 { 56 55 health.Value -= 1; … … 60 59 private void ProjectileHanlder(PhysicsObject projectile, PhysicsObject target) //ToDo: Set collisions 61 60 { 62 if (target is Zombie)61 if (target is Enemy) 63 62 { 64 63 if (weapon is Cannon) 65 { 66 ((Zombie)target).Health(-100); 67 } 64 ((Enemy)target).Health(-100); 68 65 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); 76 71 } 77 72 projectile.Destroy(); 78 73 } 79 74 80 #endregion75 #endregion 81 76 82 77 public bool PowerUp(String type, double value) … … 103 98 else if (itemName.ToLower() == "plasmacannon") 104 99 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); 105 104 106 105 if (weapon != null) … … 137 136 private void MovePlayer(Vector force) 138 137 { 139 if (canMove )138 if (canMove && !IsDestroyed) 140 139 this.Push(force); 141 140 } … … 143 142 public void Shoot() 144 143 { 145 if ( weapon != null)144 if (!IsDestroyed) 146 145 { 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!"); 149 153 } 150 else151 Game.MessageDisplay.Add("PEW PEW!");152 154 } 153 155
Note: See TracChangeset
for help on using the changeset viewer.