source: 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/EntityTemplates.cs @ 3624

Revision 3624, 10.7 KB checked in by dezhidki, 11 years ago (diff)

Animations added!
Every mob has a texture!
The first (and the last because the lack of time) boss!
Main menu!
Death menu!
Boss room has own door!
Possibility to do damage to health!
Almost last release for now!
Some sound is added!

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Jypeli;
6using Jypeli.Assets;
7
8namespace Entity
9{
10    public class EntityFly : EntityBase
11    {
12        public EntityFly(TheDungeonGame game, Vector pos, Vector size, Shape shape)
13            : base(game, pos, size, shape)
14        {
15            damage = 1;
16            FollowerBrain brains = new FollowerBrain(game.Player, 100);
17            Brain = brains;
18            Brain.Active = false;
19            CollisionIgnoreGroup = CollisionGroups.Rocks;
20            Image[] frames = new Image[3];
21            for (int i = 0; i < frames.Length; i++)
22            {
23                frames[i] = TheDungeonGame.LoadImage("animations/fly/fly" + (i + 1));
24            }
25            Animation animation = new Animation(frames);
26            animation.FPS = 30;
27            Animation = animation;
28            Animation.Start();
29            CanRotate = false;
30        }
31
32        public override void init()
33        {
34
35        }
36
37    }
38
39    public class EntityZombie : EntityBase
40    {
41        public EntityZombie(TheDungeonGame game, Vector pos, Vector size, Shape shape)
42            : base(game, pos, size, shape)
43        {
44            damage = 2;
45            Color = Color.Red;
46            Brain = new FollowerBrain(game.Player, 100);
47            Brain.Active = false;
48            CanRotate = false;
49
50            Image[] frames = new Image[4];
51            for (int i = 0; i < frames.Length - 1; i++)
52            {
53                frames[i] = TheDungeonGame.LoadImage("animations/zombie/frame" + (i + 1));
54            }
55            frames[3] = TheDungeonGame.LoadImage("animations/zombie/frame2");
56            Animation animation = new Animation(frames);
57            animation.FPS = 8;
58            Animation = animation;
59            Animation.Start();
60        }
61    }
62
63    public class EntityDerpFace : EntityBase
64    {
65        public EntityDerpFace(TheDungeonGame game, Vector pos, Vector size, Shape shape)
66            : base(game, pos, size, shape)
67        {
68            damage = 2;
69            Color = Color.Green;
70            RandomMoverBrain brains = new RandomMoverBrain(10000);
71            brains.ChangeMovementSeconds = 0.5;
72            Brain = brains;
73            Brain.Active = false;
74            CanRotate = false;
75
76            Image[] frames = new Image[2];
77            for (int i = 0; i < frames.Length; i++)
78            {
79                frames[i] = TheDungeonGame.LoadImage("animations/zombie2/frame" + (i + 1));
80            }
81            Animation animation = new Animation(frames);
82            animation.FPS = 8;
83            Animation = animation;
84            Animation.Start();
85        }
86    }
87
88    public class EntityDerpFly : EntityBase
89    {
90        public EntityDerpFly(TheDungeonGame game, Vector pos, Vector size, Shape shape)
91            : base(game, pos, size, shape)
92        {
93            damage = 1;
94            Color = Color.Blue;
95            RandomMoverBrain brains = new RandomMoverBrain(10000);
96            brains.ChangeMovementSeconds = 0.5;
97            Brain = brains;
98            Brain.Active = false;
99            CollisionIgnoreGroup = CollisionGroups.Rocks;
100
101            Image[] frames = new Image[3];
102            for (int i = 0; i < frames.Length; i++)
103            {
104                frames[i] = TheDungeonGame.LoadImage("animations/fly2/fly" + (i + 1));
105            }
106            Animation animation = new Animation(frames);
107            animation.FPS = 30;
108            Animation = animation;
109            Animation.Start();
110            CanRotate = false;
111        }
112    }
113
114
115    public class EntityBossMario : EntityBase
116    {
117        private FollowerBrain followerBrain;
118        private RandomMoverBrain randomBrain;
119        private Timer brainTimer, randomMoveTimer;
120        private bool isPowerUpped = false;
121        private bool usedTurtles = false;
122        private double followingSpeed, randomSpeed;
123
124        private Image[] normalWalking = new Image[2];
125        private Image marioIdle, marioAttack;
126        private Image[] powerupWalking = new Image[2];
127        private Image marioPowerupIdle, marioPowerupAttack;
128        private Image turtleTexture, turtleTexturePowerup;
129
130        private Animation normalWalkingAnimation, powerupWalkingAnimation;
131
132        public EntityBossMario(TheDungeonGame game, Vector pos, Vector size, Shape shape)
133            : base(game, pos, size, shape)
134        {
135            damage = 1;
136            health = 75;
137            followingSpeed = 150;
138            randomSpeed = 10000;
139            brainTimer = new Timer();
140            brainTimer.Interval = 5;
141            brainTimer.Timeout += changeBrains;
142            randomMoveTimer = new Timer();
143            randomMoveTimer.Interval = 3;
144            randomMoveTimer.Timeout += perfomAttack1;
145
146            for (int i = 0; i < normalWalking.Length; i++)
147            {
148                normalWalking[i] = TheDungeonGame.LoadImage("animations/mario/normal/walk" + (i + 1));
149                powerupWalking[i] = TheDungeonGame.LoadImage("animations/mario/powerup/walk" + (i + 1));
150            }
151            marioIdle = TheDungeonGame.LoadImage("animations/mario/normal/idle");
152            marioAttack = TheDungeonGame.LoadImage("animations/mario/normal/attack");
153            marioPowerupIdle = TheDungeonGame.LoadImage("animations/mario/powerup/normal");
154            marioPowerupAttack = TheDungeonGame.LoadImage("animations/mario/powerup/attack");
155            turtleTexture = TheDungeonGame.LoadImage("animations/mario/turtle/turtle");
156            turtleTexturePowerup = TheDungeonGame.LoadImage("animations/mario/turtle/poweredTurtle");
157            normalWalkingAnimation = new Animation(normalWalking);
158            normalWalkingAnimation.FPS = 10;
159            powerupWalkingAnimation = new Animation(powerupWalking);
160            powerupWalkingAnimation.FPS = 10;
161
162            followerBrain = new FollowerBrain(game.Player, followingSpeed);
163            followerBrain.TargetCloseDistance = 100.0;
164            followerBrain.TargetClose += delegate { spawnDyingTurtles(5); };
165            randomBrain = new RandomMoverBrain(randomSpeed);
166            randomBrain.ChangeMovementSeconds = 0.8;
167
168            Brain = randomBrain;
169            Brain.Active = true;
170            CanRotate = false;
171            Animation = normalWalkingAnimation;
172            Animation.Start();
173            brainTimer.Start();
174            Collided += collided;
175        }
176
177        public override void Destroy()
178        {
179            base.Destroy();
180            brainTimer.Stop();
181            randomMoveTimer.Stop();
182            game.gui.destroyBossGauge();
183        }
184
185        public override bool hit(int damage)
186        {
187            if (health <= 35 && !isPowerUpped)
188                upgradeMario();
189            game.gui.bossHealth.Value -= damage;
190            return base.hit(damage);
191        }
192
193        private void upgradeMario()
194        {
195            Console.WriteLine("Upgrading...");
196            if (isPowerUpped) return;
197
198            damage = 2;
199            isPowerUpped = true;
200            Animation = powerupWalkingAnimation;
201            Animation.Start();
202            randomMoveTimer = new Timer();
203            randomMoveTimer.Interval = 3;
204            randomMoveTimer.Timeout += perfomAttack2;
205            followingSpeed = 220;
206            randomSpeed = 1500;
207        }
208
209        private void changeBrains()
210        {
211            usedTurtles = false;
212            if (Brain == followerBrain)
213            {
214                Brain.Active = false;
215                randomBrain = new RandomMoverBrain(randomSpeed);
216                randomBrain.ChangeMovementSeconds = 0.8;
217                Brain = randomBrain;
218                Brain.Active = true;
219                randomMoveTimer.Start();
220            }
221            else if (Brain == randomBrain)
222            {
223                Brain.Active = false;
224                randomMoveTimer.Stop();
225                followerBrain = new FollowerBrain(game.Player, followingSpeed);
226                followerBrain.TargetCloseDistance = 100.0;
227                followerBrain.TargetClose += delegate { spawnDyingTurtles(5); };
228                Brain = followerBrain;
229                Brain.Active = true;
230            }
231        }
232
233        private void turtleCollided(IPhysicsObject turtle, IPhysicsObject target)
234        {
235            if (target.Tag.Equals("Player"))
236            {
237                Player player = (Player)target;
238                if (isPowerUpped)
239                    player.hit(2);
240                else player.hit(1);
241            }
242        }
243
244        private void perfomAttack1()
245        {
246            Animation = null;
247            Brain.Active = false;
248            Stop();
249            if (isPowerUpped)
250                Image = marioPowerupAttack;
251            else Image = marioAttack;
252            Timer idleTimer = new Timer();
253            idleTimer.Interval = 1.0;
254            idleTimer.TimesLimited = true;
255            idleTimer.Times.Value = 1;
256            idleTimer.Timeout += delegate
257            {
258                Image = null;
259                if (isPowerUpped) Animation = powerupWalkingAnimation;
260                else Animation = normalWalkingAnimation;
261                spawnDyingTurtles(10);
262                Brain.Active = true;
263            };
264            idleTimer.Start();
265        }
266
267        private void perfomAttack2()
268        {
269            Animation = null;
270            Brain.Active = false;
271            Stop();
272            Image = marioPowerupAttack;
273            Timer idleTimer = new Timer();
274            idleTimer.Interval = 1.0;
275            idleTimer.TimesLimited = true;
276            idleTimer.Times.Value = 1;
277            idleTimer.Timeout += delegate
278            {
279                Image = null;
280                Animation = powerupWalkingAnimation;
281                spawnDyingTurtles(15);
282                Brain.Active = true;
283            };
284            idleTimer.Start();
285        }
286
287        private void spawnDyingTurtles(int amount)
288        {
289            if (usedTurtles) return;
290
291            int turtleAmount = amount;
292            for (int i = 0; i < turtleAmount; i++)
293            {
294                PhysicsObject turtle = new PhysicsObject(50, 50);
295                turtle.Position = Position + RandomGen.NextVector(-20, 20);
296                if (isPowerUpped)
297                    turtle.Image = turtleTexturePowerup;
298                else turtle.Image = turtleTexture;
299                turtle.LifetimeLeft = TimeSpan.FromSeconds(3);
300                turtle.Hit(RandomGen.NextVector(-300, 300));
301                turtle.Collided += turtleCollided;
302                game.Add(turtle, 3);
303            }
304            usedTurtles = true;
305        }
306    }
307
308}
Note: See TracBrowser for help on using the repository browser.