source: 2012/23/RamiP/YAG2DSSBase/YAG2DSS/YAG2DSS/ALTKHandler.cs @ 2883

Revision 2883, 6.7 KB checked in by ramipasa, 7 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using Microsoft.Xna.Framework;
5using Microsoft.Xna.Framework.Audio;
6using Microsoft.Xna.Framework.Content;
7using Microsoft.Xna.Framework.GamerServices;
8using Microsoft.Xna.Framework.Graphics;
9using Microsoft.Xna.Framework.Input;
10using Microsoft.Xna.Framework.Media;
11using ALTK;
12
13namespace ALTK
14{
15    /// <summary>
16    /// This is a game component that implements IUpdateable.
17    /// </summary>
18    public class ALTKHandler : Microsoft.Xna.Framework.GameComponent
19    {
20        public ALTKHandler(Game game)
21            : base(game)
22        {
23            // TODO: Construct any child components here
24        }
25
26        public static GUI.Dialogs.ExitWindow ExitWindow;
27        public static GUI.Dialogs.GameSettingsWindow GameSettingsWindow;
28
29        public static Loader Loader;
30        public static Cursor Cursor;
31        public static StaticAnimHandler StaticAnimHandler;
32        public static GUI.AMessageDisplay MessageDisplay;
33        public static List<GUI.ALineBar> HealthBars = new List<GUI.ALineBar>();
34        public static List<GUI.AScoreDisplay> ScoreDisplayers = new List<GUI.AScoreDisplay>();
35        public static List<GUI.AScoreRatioDisplay> ScoreRatioDisplayers = new List<GUI.AScoreRatioDisplay>();
36        public static Audio.MusicPlayer MusicPlayer;
37        public static Audio.SoundPlayer SoundPlayer;
38
39        /// <summary>
40        /// Allows the game component to perform any initialization it needs to before starting
41        /// to run.  This is where it can query for any required services and load content.
42        /// </summary>
43        public override void Initialize()
44        {
45            // TODO: Add your initialization code here
46
47            GameSettings.SetInitialSettings();
48
49            base.Initialize();
50
51            Loader = new Loader(Game);
52            Loader.Initialize();
53
54            StaticAnimHandler = new ALTK.StaticAnimHandler(Game);
55            StaticAnimHandler.Initialize();
56            Game.Components.Add(StaticAnimHandler);
57
58            Cursor = new Cursor(Game);
59            Cursor.Initialize();
60            //Cursor.Visible = false;
61            Game.Components.Add(Cursor);
62
63            ExitWindow = new GUI.Dialogs.ExitWindow(Game);
64            ExitWindow.Initialize();
65            ExitWindow.Visible = false;
66            ExitWindow.Enabled = false;
67            Game.Components.Add(ExitWindow);
68
69            GameSettingsWindow = new GUI.Dialogs.GameSettingsWindow(Game);
70            GameSettingsWindow.Initialize();
71            GameSettingsWindow.Visible = true;
72            GameSettingsWindow.Enabled = true;
73            Game.Components.Add(GameSettingsWindow);
74
75            MessageDisplay = new GUI.AMessageDisplay(Game);
76            MessageDisplay.backgroundTextureColor = new Color(0, 192, 0, 128);
77            MessageDisplay.Width = ALTKConstants.WindowWidth;
78            MessageDisplay.TextColor = Color.Blue;
79            MessageDisplay.FontPath = "aMainFont";
80            MessageDisplay.UpdateFont("");
81            MessageDisplay.Initialize();
82            MessageDisplay.CreateBackgroundTexture(ALTKConstants.WindowWidth);
83            Game.Components.Add(MessageDisplay);
84
85            HealthBars.Add(CreateHealthBar(new Vector2(ALTKConstants.WindowWidth - 36.0f, ALTKConstants.WindowHeight - 110.0f)));
86            HealthBars.Add(CreateHealthBar(new Vector2(10.0f, ALTKConstants.WindowHeight - 110.0f)));
87            Game.Components.Add(HealthBars[0]);
88            Game.Components.Add(HealthBars[1]);
89
90            ScoreDisplayers.Add(CreateScoreDisplayer(new Vector2(ALTKConstants.WindowWidth - 105.0f, 5.0f)));
91            ScoreDisplayers.Add(CreateScoreDisplayer(new Vector2(5.0f, 5.0f)));
92            ScoreDisplayers.Add(CreateScoreDisplayer(new Vector2((ALTKConstants.WindowWidth / 2.0f) - 50.0f, 5.0f)));
93            ScoreDisplayers[2].Color = Color.Gold;
94            Game.Components.Add(ScoreDisplayers[0]);
95            Game.Components.Add(ScoreDisplayers[1]);
96            Game.Components.Add(ScoreDisplayers[2]);
97
98            ScoreRatioDisplayers.Add(CreateScoreRatioDisplayer(new Vector2(ALTKConstants.WindowWidth - 145.0f, 5.0f)));
99            ScoreRatioDisplayers.Add(CreateScoreRatioDisplayer(new Vector2(105.0f, 5.0f)));
100            Game.Components.Add(ScoreRatioDisplayers[0]);
101            Game.Components.Add(ScoreRatioDisplayers[1]);
102
103            MusicPlayer = new Audio.MusicPlayer(Game);
104            MusicPlayer.Initialize();
105            MusicPlayer.LoadTrack("INTRO", false);
106
107            SoundPlayer = new Audio.SoundPlayer(Game);
108            SoundPlayer.Initialize();
109        }
110
111        private GUI.AScoreRatioDisplay CreateScoreRatioDisplayer(Vector2 position)
112        {
113            GUI.AScoreRatioDisplay ScoreRatioDisplayer = new GUI.AScoreRatioDisplay(Game);
114            ScoreRatioDisplayer.Position = position;
115            ScoreRatioDisplayer.Value = 1.0;
116            ScoreRatioDisplayer.Size = new Vector2(40.0f, 30.0f);
117            ScoreRatioDisplayer.Color = Color.Pink;
118            ScoreRatioDisplayer.Initialize();
119            return ScoreRatioDisplayer;
120        }
121
122        private GUI.AScoreDisplay CreateScoreDisplayer(Vector2 position)
123        {
124            GUI.AScoreDisplay ScoreDisplayer = new GUI.AScoreDisplay(Game);
125            ScoreDisplayer.Position = position;
126            ScoreDisplayer.Value = 0;
127            ScoreDisplayer.Size = new Vector2(100.0f, 30.0f);
128            ScoreDisplayer.Color = Color.Purple;
129            ScoreDisplayer.Initialize();
130            return ScoreDisplayer;
131        }
132
133        private GUI.ALineBar CreateHealthBar(Vector2 position)
134        {
135            GUI.ALineBar returnValue = new GUI.ALineBar(Game);
136            returnValue.Position = position;
137            returnValue.Value = 100;
138            returnValue.Enabled = true;
139            returnValue.Initialize();
140            return returnValue;
141        }
142
143        public static Vector2 AdjustJypeliVectorToXna(double x, double y)
144        {
145            return CreateXNAVectorFromDoubles(x * ALTKConstants.JypeliToXNARatioX, y * ALTKConstants.JypeliToXNARatioY);
146        }
147
148        private static Vector2 CreateXNAVectorFromDoubles(double x, double y)
149        {
150            return new Vector2(Convert.ToSingle(x), Convert.ToSingle(y));
151        }
152
153        /// <summary>
154        /// Allows the game component to update itself.
155        /// </summary>
156        /// <param name="gameTime">Provides a snapshot of timing values.</param>
157        public override void Update(GameTime gameTime)
158        {
159            // TODO: Add your update code here
160
161            base.Update(gameTime);
162        }
163    }
164}
Note: See TracBrowser for help on using the repository browser.