source: 2013/27/TeemuM/Game/Game/Game/Enemies.cs @ 10335

Revision 4502, 1.8 KB checked in by teematma, 7 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Jypeli;
6using Jypeli.Assets;
7using Jypeli.Controls;
8using Jypeli.Effects;
9using Jypeli.Widgets;
10
11public class Enemy : PhysicsObject
12{
13    public delegate void EmptyHandler();
14    public event EmptyHandler Dying;
15
16    private PhysicsObject follow;
17    private int health;
18
19    public Enemy(PhysicsObject follow, int health, double widht, double height) : base(widht, height)
20    {
21        this.health = health;
22        this.follow = follow;
23        this.IsUpdated = true;
24    }
25
26    public void Health(int healtChange)
27    {
28        health += healtChange;
29        if (health <= 0)
30        {
31            if (Dying != null)
32                Dying();
33            this.Destroy();
34        }
35    }
36
37    public override void Update(Time time)
38    {
39        this.Angle = (G.game.player.Position - this.AbsolutePosition).Normalize().Angle - Angle.FromDegrees(90);
40        base.Update(time);
41    }
42}
43
44public class Zombie : Enemy
45{
46    private static Image[] Images = { Game.LoadImage("Slime"), Game.LoadImage("Slime2"), Game.LoadImage("Slime3"), Game.LoadImage("Slime4") };
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 = 100;
68        brain.Active = true;
69        this.Brain = brain;
70    }
71}
Note: See TracBrowser for help on using the repository browser.