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

Revision 3649, 11.9 KB checked in by dezhidki, 11 years ago (diff)

Talletus.

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