1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | using Microsoft.CSharp; |
---|
9 | using Microsoft.Xna.Framework; |
---|
10 | using Microsoft.Xna.Framework.Graphics; |
---|
11 | |
---|
12 | public class JRPG : PhysicsGame |
---|
13 | { |
---|
14 | public static JRPG Game { get; set; } |
---|
15 | |
---|
16 | public static BattleView BattleView { get; set; } |
---|
17 | |
---|
18 | public Player Player { get; set; } |
---|
19 | |
---|
20 | public SpriteFont MainFont { get; set; } |
---|
21 | |
---|
22 | public bool UseShaders = false; |
---|
23 | bool RandomEncounterAnim = false; |
---|
24 | float WarpAmount = 0.0f; |
---|
25 | double FadeSpeed = 0.5; |
---|
26 | Effect Shader; |
---|
27 | Effect Twirl; |
---|
28 | public Effect Wave; |
---|
29 | SpriteBatch spriteBatch; |
---|
30 | RenderTarget2D renderTarget; |
---|
31 | |
---|
32 | Widget Fade { get; set; } |
---|
33 | |
---|
34 | public override void Begin() |
---|
35 | { |
---|
36 | SoundEffect.MasterVolume = 0.4; |
---|
37 | MediaPlayer.Volume = 0.3; |
---|
38 | |
---|
39 | MainFont = Content.Load<SpriteFont>("MainFont"); |
---|
40 | |
---|
41 | spriteBatch = new SpriteBatch(GraphicsDevice); |
---|
42 | Shader = Content.Load<Effect>("Shader"); |
---|
43 | Twirl = Content.Load<Effect>("Twirl"); |
---|
44 | Wave = Content.Load<Effect>("Wave"); |
---|
45 | |
---|
46 | Game = this; |
---|
47 | |
---|
48 | Window.Width = GameValues.SCREEN_WIDTH; |
---|
49 | Window.Height = GameValues.SCREEN_HEIGHT; |
---|
50 | |
---|
51 | SmoothTextures = false; |
---|
52 | IsMouseVisible = true; |
---|
53 | |
---|
54 | LoadTitleScreen(); |
---|
55 | } |
---|
56 | |
---|
57 | void LoadTitleScreen() |
---|
58 | { |
---|
59 | MediaPlayer.Play("Music//PresentingV"); |
---|
60 | |
---|
61 | _Background Background = new _Background(JRPG.Game.Content.Load<Texture2D>("Space")); |
---|
62 | JRPG.Game.Add(Background, -1); |
---|
63 | |
---|
64 | Widget TitleHeader = new Widget(Images.TitleHeader); |
---|
65 | TitleHeader.Size = new Vector(Images.TitleHeader.Width, Images.TitleHeader.Height); |
---|
66 | TitleHeader.Position = new Vector(0, 200); |
---|
67 | Add(TitleHeader); |
---|
68 | |
---|
69 | TextMenu StartMenu = new TextMenu(); |
---|
70 | StartMenu.SetTextBases(MainFont, TextAlignment.Center); |
---|
71 | StartMenu.AddMenuElement("Start Game"); |
---|
72 | StartMenu.AddMenuElement("Quit"); |
---|
73 | StartMenu.Offset = 40; |
---|
74 | StartMenu.Position = new Vector(0, -100); |
---|
75 | StartMenu.ActionWhenSelected += delegate(int selection) |
---|
76 | { |
---|
77 | switch (selection) |
---|
78 | { |
---|
79 | case 0: |
---|
80 | FadeMusicOut(); |
---|
81 | LoadGame(); |
---|
82 | Background.Destroy(); |
---|
83 | TitleHeader.Destroy(); |
---|
84 | break; |
---|
85 | case 1: |
---|
86 | System.Diagnostics.Process.Start("https://www.youtube.com/watch?v=e9ixL-aVRCI"); |
---|
87 | Exit(); |
---|
88 | break; |
---|
89 | } |
---|
90 | }; |
---|
91 | |
---|
92 | StartMenu.LoadMenuElements(); |
---|
93 | } |
---|
94 | |
---|
95 | void Ending() |
---|
96 | { |
---|
97 | FadeMusicIn("Music//Sensual"); |
---|
98 | |
---|
99 | string Text = "\"Nuorten peliohjelmointikurssi was a mistake\" \n - Antti-Jussi Lakanen, 2017"; |
---|
100 | BetterLabel EndSlate = new BetterLabel(MainFont, Vector.Zero, Text, TextAlignment.Center); |
---|
101 | EndSlate.BorderType = TextBorderType.Thin; |
---|
102 | EndSlate.IsFlashing = true; |
---|
103 | Timer.SingleShot(1, |
---|
104 | delegate |
---|
105 | { |
---|
106 | Add(EndSlate); |
---|
107 | }); |
---|
108 | |
---|
109 | Gravity = new Vector(0, -200); |
---|
110 | |
---|
111 | Timer AJParticleGen = new Timer(); |
---|
112 | AJParticleGen.Interval = 0.05; |
---|
113 | AJParticleGen.Timeout += |
---|
114 | delegate |
---|
115 | { |
---|
116 | Particle_AJ(); |
---|
117 | }; |
---|
118 | AJParticleGen.Start(); |
---|
119 | } |
---|
120 | |
---|
121 | void Particle_AJ() |
---|
122 | { |
---|
123 | PhysicsObject AJ = new PhysicsObject(LoadImage("aj2")); |
---|
124 | AJ.Size = new Vector(AJ.Image.Width, AJ.Image.Height); |
---|
125 | AJ.Y = Screen.TopSafe + AJ.Height / 2 + RandomGen.NextDouble(0, AJ.Height*3); |
---|
126 | AJ.X = RandomGen.NextDouble(Screen.LeftSafe - AJ.Width / 2, Screen.RightSafe + AJ.Width / 2); |
---|
127 | AJ.Position += Camera.Position; |
---|
128 | AJ.MaximumLifetime = TimeSpan.FromSeconds(10); |
---|
129 | Add(AJ); |
---|
130 | } |
---|
131 | |
---|
132 | void LoadGame() |
---|
133 | { |
---|
134 | OverworldView.LoadOverworldView("00"); |
---|
135 | Level.Size = OverworldView.CurrentMap.Size; |
---|
136 | Level.Background.Color = Jypeli.Color.FromHexCode("000000"); |
---|
137 | |
---|
138 | LoadOWPlayer(new Vector(3, 3)); |
---|
139 | LoadOWControlsKeyboard(); |
---|
140 | LoadOWControlsXboxController(); |
---|
141 | |
---|
142 | CheckWhereCanMove(); |
---|
143 | |
---|
144 | Camera.Follow(Player); |
---|
145 | Camera.ZoomFactor = 1.0f; |
---|
146 | Camera.StayInLevel = true; |
---|
147 | } |
---|
148 | |
---|
149 | public void LoadOWPlayer(Vector PositionInTiles) |
---|
150 | { |
---|
151 | Player = new Player(new Vector(28, 40)); |
---|
152 | Player.Position = PositionInTiles * 40 + new Vector(20, 30); |
---|
153 | Player.PositionInTiles = PositionInTiles; |
---|
154 | Player.Color = Jypeli.Color.Blue; |
---|
155 | Add(Player); |
---|
156 | SetAnimations(); |
---|
157 | } |
---|
158 | public void SetAnimations() |
---|
159 | { |
---|
160 | if (Movement.FacingDir == Movement.Direction.Up && JRPG.Game.Keyboard.GetKeyState(Key.Up) == ButtonState.Pressed && !Movement.IsMoving) |
---|
161 | { |
---|
162 | Player.Animation = new Animation(Images.Characters.Overworld.Sonic_WalkingUp); |
---|
163 | Player.Animation.FPS = 10; |
---|
164 | Player.Animation.Start(); |
---|
165 | } |
---|
166 | else if (Movement.FacingDir == Movement.Direction.Down && JRPG.Game.Keyboard.GetKeyState(Key.Down) == ButtonState.Pressed && !Movement.IsMoving) |
---|
167 | { |
---|
168 | Player.Animation = new Animation(Images.Characters.Overworld.Sonic_WalkingDown); |
---|
169 | Player.Animation.FPS = 10; |
---|
170 | Player.Animation.Start(); |
---|
171 | } |
---|
172 | else if (Movement.FacingDir == Movement.Direction.Left && JRPG.Game.Keyboard.GetKeyState(Key.Left) == ButtonState.Pressed && !Movement.IsMoving) |
---|
173 | { |
---|
174 | Player.Animation = new Animation(Images.Characters.Overworld.Sonic_WalkingLeft); |
---|
175 | Player.Animation.FPS = 10; |
---|
176 | Player.Animation.Start(); |
---|
177 | } |
---|
178 | else if (Movement.FacingDir == Movement.Direction.Right && JRPG.Game.Keyboard.GetKeyState(Key.Right) == ButtonState.Pressed && !Movement.IsMoving) |
---|
179 | { |
---|
180 | Player.Animation = new Animation(Images.Characters.Overworld.Sonic_WalkingRight); |
---|
181 | Player.Animation.FPS = 10; |
---|
182 | Player.Animation.Start(); |
---|
183 | } |
---|
184 | else if (Movement.FacingDir == Movement.Direction.Up && JRPG.Game.Keyboard.GetKeyState(Key.Up) == ButtonState.Down && !Movement.IsMoving) |
---|
185 | { |
---|
186 | Player.Animation = new Animation(Images.Characters.Overworld.Sonic_WalkingUp); |
---|
187 | Player.Animation.FPS = 10; |
---|
188 | Player.Animation.Start(); |
---|
189 | } |
---|
190 | else if (Movement.FacingDir == Movement.Direction.Down && JRPG.Game.Keyboard.GetKeyState(Key.Down) == ButtonState.Down && !Movement.IsMoving) |
---|
191 | { |
---|
192 | Player.Animation = new Animation(Images.Characters.Overworld.Sonic_WalkingDown); |
---|
193 | Player.Animation.FPS = 10; |
---|
194 | Player.Animation.Start(); |
---|
195 | } |
---|
196 | else if (Movement.FacingDir == Movement.Direction.Left && JRPG.Game.Keyboard.GetKeyState(Key.Left) == ButtonState.Down && !Movement.IsMoving) |
---|
197 | { |
---|
198 | Player.Animation = new Animation(Images.Characters.Overworld.Sonic_WalkingLeft); |
---|
199 | Player.Animation.FPS = 10; |
---|
200 | Player.Animation.Start(); |
---|
201 | } |
---|
202 | else if (Movement.FacingDir == Movement.Direction.Right && JRPG.Game.Keyboard.GetKeyState(Key.Right) == ButtonState.Down && !Movement.IsMoving) |
---|
203 | { |
---|
204 | Player.Animation = new Animation(Images.Characters.Overworld.Sonic_WalkingRight); |
---|
205 | Player.Animation.FPS = 10; |
---|
206 | Player.Animation.Start(); |
---|
207 | } |
---|
208 | else if (Movement.FacingDir == Movement.Direction.Up && !Movement.IsMoving) |
---|
209 | { |
---|
210 | Player.Animation = null; |
---|
211 | Player.Image = Images.Characters.Overworld.Sonic_Standing_Up; |
---|
212 | } |
---|
213 | else if (Movement.FacingDir == Movement.Direction.Down && !Movement.IsMoving) |
---|
214 | { |
---|
215 | Player.Animation = null; |
---|
216 | Player.Image = Images.Characters.Overworld.Sonic_Standing_Down; |
---|
217 | } |
---|
218 | else if (Movement.FacingDir == Movement.Direction.Left && !Movement.IsMoving) |
---|
219 | { |
---|
220 | Player.Animation = null; |
---|
221 | Player.Image = Images.Characters.Overworld.Sonic_Standing_Left; |
---|
222 | } |
---|
223 | else if (Movement.FacingDir == Movement.Direction.Right && !Movement.IsMoving) |
---|
224 | { |
---|
225 | Player.Animation = null; |
---|
226 | Player.Image = Images.Characters.Overworld.Sonic_Standing_Right; |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | #region Controls/Movement |
---|
231 | |
---|
232 | public void LoadOWControlsKeyboard() |
---|
233 | { |
---|
234 | Keyboard.Listen(Key.Delete, ButtonState.Pressed, delegate |
---|
235 | { |
---|
236 | renderTarget = new RenderTarget2D(GraphicsDevice, |
---|
237 | GraphicsDevice.PresentationParameters.BackBufferWidth, |
---|
238 | GraphicsDevice.PresentationParameters.BackBufferHeight); |
---|
239 | }, null); |
---|
240 | Keyboard.Listen(Key.Insert, ButtonState.Pressed, delegate { |
---|
241 | UseShaders = !UseShaders; |
---|
242 | }, null); |
---|
243 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
244 | |
---|
245 | Keyboard.Listen(Key.Left, ButtonState.Down, delegate { if(Keyboard.GetKeyState(Key.LeftShift) != ButtonState.Down) MoveLeft(GameValues.TILE_SIZE); }, null); |
---|
246 | Keyboard.Listen(Key.Right, ButtonState.Down, delegate { if (Keyboard.GetKeyState(Key.LeftShift) != ButtonState.Down) MoveRight(GameValues.TILE_SIZE); }, null); |
---|
247 | Keyboard.Listen(Key.Up, ButtonState.Down, delegate { if (Keyboard.GetKeyState(Key.LeftShift) != ButtonState.Down) MoveUp(GameValues.TILE_SIZE); }, null); |
---|
248 | Keyboard.Listen(Key.Down, ButtonState.Down, delegate { if (Keyboard.GetKeyState(Key.LeftShift) != ButtonState.Down) MoveDown(GameValues.TILE_SIZE); }, null); |
---|
249 | |
---|
250 | Keyboard.Listen(Key.Left, ButtonState.Pressed, delegate { Movement.FacingDir = Movement.Direction.Left; }, null); |
---|
251 | Keyboard.Listen(Key.Right, ButtonState.Pressed, delegate { Movement.FacingDir = Movement.Direction.Right; }, null); |
---|
252 | Keyboard.Listen(Key.Up, ButtonState.Pressed, delegate { Movement.FacingDir = Movement.Direction.Up; }, null); |
---|
253 | Keyboard.Listen(Key.Down, ButtonState.Pressed, delegate {Movement.FacingDir = Movement.Direction.Down; }, null); |
---|
254 | |
---|
255 | |
---|
256 | Keyboard.Listen(Key.PageDown, ButtonState.Pressed, FadeOut, null); |
---|
257 | Keyboard.Listen(Key.PageUp, ButtonState.Pressed, FadeIn, null); |
---|
258 | } |
---|
259 | public void LoadOWControlsXboxController() |
---|
260 | { |
---|
261 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, delegate { if (ControllerOne.GetButtonState(Button.LeftShoulder) != ButtonState.Down && ControllerOne.GetButtonState(Button.RightShoulder) != ButtonState.Down) MoveLeft(GameValues.TILE_SIZE); }, null); |
---|
262 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, delegate { if (ControllerOne.GetButtonState(Button.LeftShoulder) != ButtonState.Down && ControllerOne.GetButtonState(Button.RightShoulder) != ButtonState.Down) MoveRight(GameValues.TILE_SIZE); }, null); |
---|
263 | ControllerOne.Listen(Button.DPadUp, ButtonState.Down, delegate { if (ControllerOne.GetButtonState(Button.LeftShoulder) != ButtonState.Down && ControllerOne.GetButtonState(Button.RightShoulder) != ButtonState.Down) MoveUp(GameValues.TILE_SIZE); }, null); |
---|
264 | ControllerOne.Listen(Button.DPadDown, ButtonState.Down, delegate { if (ControllerOne.GetButtonState(Button.LeftShoulder) != ButtonState.Down && ControllerOne.GetButtonState(Button.RightShoulder) != ButtonState.Down) MoveDown(GameValues.TILE_SIZE); }, null); |
---|
265 | |
---|
266 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Pressed, delegate { Movement.FacingDir = Movement.Direction.Left; }, null); |
---|
267 | ControllerOne.Listen(Button.DPadRight, ButtonState.Pressed, delegate { Movement.FacingDir = Movement.Direction.Right; }, null); |
---|
268 | ControllerOne.Listen(Button.DPadUp, ButtonState.Pressed, delegate { Movement.FacingDir = Movement.Direction.Up; }, null); |
---|
269 | ControllerOne.Listen(Button.DPadDown, ButtonState.Pressed, delegate { Movement.FacingDir = Movement.Direction.Down; }, null); |
---|
270 | } |
---|
271 | |
---|
272 | void MoveLeft(double Distance) |
---|
273 | { |
---|
274 | SetAnimations(); |
---|
275 | |
---|
276 | if (Keyboard.GetKeyState(Key.Right) != ButtonState.Down && Movement.FacingDir == Movement.Direction.Left |
---|
277 | || CheckIfAnotherArrowKeyIsDown(Key.Left, Key.Right) && Movement.FacingDir == Movement.Direction.Left |
---|
278 | || !CheckIfAnotherArrowKeyIsDown(Key.Left) && Keyboard.GetKeyState(Key.Left) == ButtonState.Down) |
---|
279 | { |
---|
280 | if (Movement.CanMoveLeft && Keyboard.GetKeyState(Key.Left) == ButtonState.Down) |
---|
281 | { |
---|
282 | Player.Move(new Vector(-Distance, 0), GameValues.MOVE_SPEED); |
---|
283 | } |
---|
284 | } |
---|
285 | } |
---|
286 | void MoveRight(double Distance) |
---|
287 | { |
---|
288 | SetAnimations(); |
---|
289 | |
---|
290 | if (Keyboard.GetKeyState(Key.Left) != ButtonState.Down && Movement.FacingDir == Movement.Direction.Right |
---|
291 | || CheckIfAnotherArrowKeyIsDown(Key.Right, Key.Left) && Movement.FacingDir == Movement.Direction.Right |
---|
292 | || !CheckIfAnotherArrowKeyIsDown(Key.Right) && Keyboard.GetKeyState(Key.Right) == ButtonState.Down) |
---|
293 | { |
---|
294 | if (Movement.CanMoveRight) |
---|
295 | { |
---|
296 | Player.Move(new Vector(Distance, 0), GameValues.MOVE_SPEED); |
---|
297 | } |
---|
298 | } |
---|
299 | } |
---|
300 | void MoveUp(double Distance) |
---|
301 | { |
---|
302 | SetAnimations(); |
---|
303 | |
---|
304 | if (Keyboard.GetKeyState(Key.Down) != ButtonState.Down && Movement.FacingDir == Movement.Direction.Up |
---|
305 | || CheckIfAnotherArrowKeyIsDown(Key.Up, Key.Down) && Movement.FacingDir == Movement.Direction.Up |
---|
306 | || !CheckIfAnotherArrowKeyIsDown(Key.Up) && Keyboard.GetKeyState(Key.Up) == ButtonState.Down) |
---|
307 | { |
---|
308 | if (Movement.CanMoveUp) |
---|
309 | { |
---|
310 | Player.Move(new Vector(0, Distance), GameValues.MOVE_SPEED); |
---|
311 | } |
---|
312 | } |
---|
313 | } |
---|
314 | void MoveDown(double Distance) |
---|
315 | { |
---|
316 | SetAnimations(); |
---|
317 | |
---|
318 | if (Keyboard.GetKeyState(Key.Up) != ButtonState.Down && Movement.FacingDir == Movement.Direction.Down |
---|
319 | || CheckIfAnotherArrowKeyIsDown(Key.Down, Key.Up) && Movement.FacingDir == Movement.Direction.Down |
---|
320 | || !CheckIfAnotherArrowKeyIsDown(Key.Down) && Keyboard.GetKeyState(Key.Down) == ButtonState.Down) |
---|
321 | { |
---|
322 | if (Movement.CanMoveDown) |
---|
323 | { |
---|
324 | Player.Move(new Vector(0, -Distance), GameValues.MOVE_SPEED);; |
---|
325 | } |
---|
326 | } |
---|
327 | } |
---|
328 | |
---|
329 | public void CheckWhereCanMove() |
---|
330 | { |
---|
331 | Tile LeftTile = (Tile)OverworldView.CurrentCollisionMap.CollisionMapArray.GetValue((int)Math.Max(Player.PositionInTiles.X - 1,0),(int)(Player.PositionInTiles.Y)); |
---|
332 | Tile RightTile = (Tile)OverworldView.CurrentCollisionMap.CollisionMapArray.GetValue((int)Math.Min(Player.PositionInTiles.X + 1, OverworldView.CurrentCollisionMap.CollisionMapArray.GetLength(0) - 1) , (int)Player.PositionInTiles.Y); |
---|
333 | Tile TopTile = (Tile)OverworldView.CurrentCollisionMap.CollisionMapArray.GetValue((int)Player.PositionInTiles.X, (int)Math.Min(Player.PositionInTiles.Y + 1, OverworldView.CurrentCollisionMap.CollisionMapArray.GetLength(1) - 1)); |
---|
334 | Tile BottomTile = (Tile)OverworldView.CurrentCollisionMap.CollisionMapArray.GetValue((int)Player.PositionInTiles.X, (int)Math.Max(Player.PositionInTiles.Y - 1, 0)); |
---|
335 | |
---|
336 | if (LeftTile.IsWalkable) Movement.CanMoveLeft = true; |
---|
337 | else Movement.CanMoveLeft = false; |
---|
338 | if (RightTile.IsWalkable) Movement.CanMoveRight = true; |
---|
339 | else Movement.CanMoveRight = false; |
---|
340 | if (TopTile.IsWalkable) Movement.CanMoveUp = true; |
---|
341 | else Movement.CanMoveUp = false; |
---|
342 | if (BottomTile.IsWalkable) Movement.CanMoveDown = true; |
---|
343 | else Movement.CanMoveDown = false; |
---|
344 | } |
---|
345 | |
---|
346 | bool CheckIfAnotherArrowKeyIsDown(Key Key) |
---|
347 | { |
---|
348 | if (Keyboard.GetKeyState(Key.Left) == ButtonState.Down) |
---|
349 | { |
---|
350 | if (Key != Key.Left) return true; |
---|
351 | } |
---|
352 | if (Keyboard.GetKeyState(Key.Right) == ButtonState.Down) |
---|
353 | { |
---|
354 | if (Key != Key.Right) return true; |
---|
355 | } |
---|
356 | if (Keyboard.GetKeyState(Key.Up) == ButtonState.Down) |
---|
357 | { |
---|
358 | if (Key != Key.Up) return true; |
---|
359 | } |
---|
360 | if (Keyboard.GetKeyState(Key.Down) == ButtonState.Down) |
---|
361 | { |
---|
362 | if (Key != Key.Down) return true; |
---|
363 | } |
---|
364 | |
---|
365 | return false; |
---|
366 | } |
---|
367 | bool CheckIfAnotherArrowKeyIsDown(Key Key, Key Key2) |
---|
368 | { |
---|
369 | if (Keyboard.GetKeyState(Key.Left) == ButtonState.Down) |
---|
370 | { |
---|
371 | if (Key != Key.Left && Key2 != Key.Left) return true; |
---|
372 | } |
---|
373 | if (Keyboard.GetKeyState(Key.Right) == ButtonState.Down) |
---|
374 | { |
---|
375 | if (Key != Key.Right && Key2 != Key.Right) return true; |
---|
376 | } |
---|
377 | if (Keyboard.GetKeyState(Key.Up) == ButtonState.Down) |
---|
378 | { |
---|
379 | if (Key != Key.Up && Key2 != Key.Up) return true; |
---|
380 | } |
---|
381 | if (Keyboard.GetKeyState(Key.Down) == ButtonState.Down) |
---|
382 | { |
---|
383 | if (Key != Key.Down && Key2 != Key.Down) return true; |
---|
384 | } |
---|
385 | |
---|
386 | return false; |
---|
387 | } |
---|
388 | |
---|
389 | #endregion |
---|
390 | |
---|
391 | |
---|
392 | |
---|
393 | public void FadeOut() |
---|
394 | { |
---|
395 | if (Fade != null && Fade.IsAddedToGame) Fade.Destroy(); |
---|
396 | |
---|
397 | Fade = new Widget(Screen.WidthSafe, Screen.HeightSafe); |
---|
398 | Fade.Color = Jypeli.Color.Transparent; |
---|
399 | Add(Fade); |
---|
400 | Fade.FadeColorTo(Jypeli.Color.Black, FadeSpeed); |
---|
401 | } |
---|
402 | public void FadeIn() |
---|
403 | { |
---|
404 | if (Fade != null && Fade.IsAddedToGame) Fade.Destroy(); |
---|
405 | |
---|
406 | Fade = new Widget(Screen.WidthSafe, Screen.HeightSafe); |
---|
407 | Fade.Color = Jypeli.Color.Black; |
---|
408 | Add(Fade); |
---|
409 | Fade.FadeColorTo(Jypeli.Color.Transparent, FadeSpeed); |
---|
410 | } |
---|
411 | |
---|
412 | public void FadeMusicOut() |
---|
413 | { |
---|
414 | double CurrentVolume = MediaPlayer.Volume; |
---|
415 | |
---|
416 | Timer Fade = new Timer(); |
---|
417 | Fade.Interval = 0.001; |
---|
418 | Fade.Timeout += delegate |
---|
419 | { |
---|
420 | MediaPlayer.Volume -= CurrentVolume / 500; |
---|
421 | |
---|
422 | if (MediaPlayer.Volume <= 0) |
---|
423 | { |
---|
424 | MediaPlayer.Stop(); |
---|
425 | MediaPlayer.Volume = CurrentVolume; |
---|
426 | Fade.Stop(); |
---|
427 | } |
---|
428 | }; |
---|
429 | Fade.Start(); |
---|
430 | } |
---|
431 | public void FadeMusicIn(string Music) |
---|
432 | { |
---|
433 | MediaPlayer.Play(Music); |
---|
434 | double TargetVolume = MediaPlayer.Volume; |
---|
435 | |
---|
436 | Timer Fade = new Timer(); |
---|
437 | Fade.Interval = 0.001; |
---|
438 | Fade.Timeout += delegate |
---|
439 | { |
---|
440 | MediaPlayer.Volume += TargetVolume / 500; |
---|
441 | |
---|
442 | if (MediaPlayer.Volume >= TargetVolume) |
---|
443 | { |
---|
444 | MediaPlayer.Volume = TargetVolume; |
---|
445 | Fade.Stop(); |
---|
446 | } |
---|
447 | }; |
---|
448 | Fade.Start(); |
---|
449 | } |
---|
450 | |
---|
451 | public void RandomEncounterAnimation(Action AfterAnimation, Action OnFadingOut) |
---|
452 | { |
---|
453 | if (!RandomEncounterAnim) |
---|
454 | { |
---|
455 | renderTarget = new RenderTarget2D(GraphicsDevice, |
---|
456 | GraphicsDevice.PresentationParameters.BackBufferWidth, |
---|
457 | GraphicsDevice.PresentationParameters.BackBufferHeight); |
---|
458 | |
---|
459 | RandomEncounterAnim = true; |
---|
460 | SoundEffects.Battle.Encounter.Play(); |
---|
461 | |
---|
462 | Timer.SingleShot(1, delegate |
---|
463 | { |
---|
464 | FadeOut(); |
---|
465 | if (OnFadingOut != null) OnFadingOut.Invoke(); |
---|
466 | Timer.SingleShot(FadeSpeed + 1, delegate |
---|
467 | { |
---|
468 | RandomEncounterAnim = false; |
---|
469 | |
---|
470 | Camera.ZoomFactor = 1.0f; |
---|
471 | UseShaders = false; |
---|
472 | WarpAmount = 0.0f; |
---|
473 | |
---|
474 | FadeIn(); |
---|
475 | |
---|
476 | Camera.StayInLevel = false; |
---|
477 | Camera.Position = Player.Position; |
---|
478 | |
---|
479 | if (AfterAnimation != null) AfterAnimation.Invoke(); |
---|
480 | }); |
---|
481 | }); |
---|
482 | } |
---|
483 | |
---|
484 | } |
---|
485 | |
---|
486 | protected override void Update(Time time) |
---|
487 | { |
---|
488 | base.Update(time); |
---|
489 | |
---|
490 | if (Flags.InBattle) |
---|
491 | { |
---|
492 | BattleView.Update(time); |
---|
493 | } |
---|
494 | |
---|
495 | if (RandomEncounterAnim) |
---|
496 | { |
---|
497 | float deltaTime = (float)Time.SinceLastUpdate.TotalSeconds; |
---|
498 | WarpAmount += deltaTime * 3; |
---|
499 | |
---|
500 | Camera.ZoomFactor += deltaTime * 3; |
---|
501 | } |
---|
502 | } |
---|
503 | |
---|
504 | protected override void Draw(GameTime gameTime) |
---|
505 | { |
---|
506 | GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.Black); |
---|
507 | |
---|
508 | if (UseShaders) GraphicsDevice.SetRenderTarget(renderTarget); |
---|
509 | |
---|
510 | base.Draw(gameTime); |
---|
511 | if (UseShaders) GraphicsDevice.SetRenderTarget(null); |
---|
512 | |
---|
513 | if (UseShaders) |
---|
514 | { |
---|
515 | GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.Black); |
---|
516 | |
---|
517 | spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); |
---|
518 | if (Twirl == Content.Load<Effect>("Twirl")) |
---|
519 | { |
---|
520 | Twirl.Parameters["Rotation"].SetValue(new Vector2(WarpAmount, WarpAmount)); |
---|
521 | Twirl.Parameters["CenterRadius"].SetValue(new Vector4(0.5f, 0.5f, 0.5f, 0.5f)); |
---|
522 | Twirl.CurrentTechnique.Passes[0].Apply(); |
---|
523 | } |
---|
524 | else if (Shader == Content.Load<Effect>("Shader") || Shader == Content.Load<Effect>("Wave")) |
---|
525 | { |
---|
526 | Shader.Parameters["parameter1"].SetValue((float)Time.SinceStartOfGame.TotalMilliseconds); |
---|
527 | Shader.CurrentTechnique.Passes[0].Apply(); |
---|
528 | } |
---|
529 | spriteBatch.Draw(renderTarget, new Vector2(0, 0), Microsoft.Xna.Framework.Color.White); |
---|
530 | spriteBatch.End(); |
---|
531 | } |
---|
532 | } |
---|
533 | } |
---|