1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using System.Text; |
---|
5 | using Jypeli; |
---|
6 | using Jypeli.Assets; |
---|
7 | |
---|
8 | namespace 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 = 75; |
---|
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 <= 35 && !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 | } |
---|
280 | } |
---|
281 | |
---|
282 | private void perfomAttack1() |
---|
283 | { |
---|
284 | Animation = null; |
---|
285 | Brain.Active = false; |
---|
286 | Stop(); |
---|
287 | if (isPowerUpped) |
---|
288 | Image = marioPowerupAttack; |
---|
289 | else Image = marioAttack; |
---|
290 | Timer idleTimer = new Timer(); |
---|
291 | idleTimer.Interval = 1.0; |
---|
292 | idleTimer.TimesLimited = true; |
---|
293 | idleTimer.Times.Value = 1; |
---|
294 | idleTimer.Timeout += delegate |
---|
295 | { |
---|
296 | Image = null; |
---|
297 | if (isPowerUpped) Animation = powerupWalkingAnimation; |
---|
298 | else Animation = normalWalkingAnimation; |
---|
299 | spawnDyingTurtles(10); |
---|
300 | Brain.Active = true; |
---|
301 | }; |
---|
302 | idleTimer.Start(); |
---|
303 | } |
---|
304 | |
---|
305 | private void perfomAttack2() |
---|
306 | { |
---|
307 | Animation = null; |
---|
308 | Brain.Active = false; |
---|
309 | Stop(); |
---|
310 | Image = marioPowerupAttack; |
---|
311 | Timer idleTimer = new Timer(); |
---|
312 | idleTimer.Interval = 1.0; |
---|
313 | idleTimer.TimesLimited = true; |
---|
314 | idleTimer.Times.Value = 1; |
---|
315 | idleTimer.Timeout += delegate |
---|
316 | { |
---|
317 | Image = null; |
---|
318 | Animation = powerupWalkingAnimation; |
---|
319 | spawnDyingTurtles(15); |
---|
320 | Brain.Active = true; |
---|
321 | }; |
---|
322 | idleTimer.Start(); |
---|
323 | } |
---|
324 | |
---|
325 | private void spawnDyingTurtles(int amount) |
---|
326 | { |
---|
327 | if (usedTurtles) return; |
---|
328 | |
---|
329 | attackSound.Play(); |
---|
330 | int turtleAmount = amount; |
---|
331 | for (int i = 0; i < turtleAmount; i++) |
---|
332 | { |
---|
333 | PhysicsObject turtle = new PhysicsObject(50, 50); |
---|
334 | turtle.Position = Position + RandomGen.NextVector(-20, 20); |
---|
335 | if (isPowerUpped) |
---|
336 | turtle.Image = turtleTexturePowerup; |
---|
337 | else turtle.Image = turtleTexture; |
---|
338 | turtle.LifetimeLeft = TimeSpan.FromSeconds(3); |
---|
339 | turtle.Hit(RandomGen.NextVector(-300, 300)); |
---|
340 | turtle.Collided += turtleCollided; |
---|
341 | game.Add(turtle, 3); |
---|
342 | } |
---|
343 | usedTurtles = true; |
---|
344 | } |
---|
345 | } |
---|
346 | |
---|
347 | } |
---|