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

Revision 2854, 6.3 KB checked in by ramipasa, 9 years ago (diff)

laskuri, pup, efektit sun muuta roskaa;

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 Loader Loader;
27        public static Cursor Cursor;
28        public static StaticAnimHandler StaticAnimHandler;
29        public static GUI.Dialogs.ExitWindow ExitWindow;
30        public static GUI.AMessageDisplay MessageDisplay;
31        public static List<GUI.ALineBar> HealthBars = new List<GUI.ALineBar>();
32        public static List<GUI.AScoreDisplay> ScoreDisplayers = new List<GUI.AScoreDisplay>();
33        public static List<GUI.AScoreRatioDisplay> ScoreRatioDisplayers = new List<GUI.AScoreRatioDisplay>();
34        public static Audio.MusicPlayer MusicPlayer;
35        public static Audio.SoundPlayer SoundPlayer;
36
37        /// <summary>
38        /// Allows the game component to perform any initialization it needs to before starting
39        /// to run.  This is where it can query for any required services and load content.
40        /// </summary>
41        public override void Initialize()
42        {
43            // TODO: Add your initialization code here
44
45            base.Initialize();
46
47            Loader = new Loader(Game);
48            Loader.Initialize();
49
50            StaticAnimHandler = new ALTK.StaticAnimHandler(Game);
51            StaticAnimHandler.Initialize();
52            Game.Components.Add(StaticAnimHandler);
53
54            Cursor = new Cursor(Game);
55            Cursor.Initialize();
56            Cursor.Visible = false;
57            Game.Components.Add(Cursor);
58
59            ExitWindow = new GUI.Dialogs.ExitWindow(Game);
60            ExitWindow.Initialize();
61            ExitWindow.Visible = false;
62            ExitWindow.Enabled = false;
63            Game.Components.Add(ExitWindow);
64
65            MessageDisplay = new GUI.AMessageDisplay(Game);
66            MessageDisplay.backgroundTextureColor = new Color(0, 192, 0, 128);
67            MessageDisplay.Width = ALTKConstants.WindowWidth;
68            MessageDisplay.TextColor = Color.Blue;
69            MessageDisplay.FontPath = "aMainFont";
70            MessageDisplay.UpdateFont("");
71            MessageDisplay.Initialize();
72            MessageDisplay.CreateBackgroundTexture(ALTKConstants.WindowWidth);
73            Game.Components.Add(MessageDisplay);
74
75            HealthBars.Add(CreateHealthBar(new Vector2(ALTKConstants.WindowWidth - 36.0f, ALTKConstants.WindowHeight - 110.0f)));
76            HealthBars.Add(CreateHealthBar(new Vector2(10.0f, ALTKConstants.WindowHeight - 110.0f)));
77            Game.Components.Add(HealthBars[0]);
78            Game.Components.Add(HealthBars[1]);
79
80            ScoreDisplayers.Add(CreateScoreDisplayer(new Vector2(ALTKConstants.WindowWidth - 105.0f, 5.0f)));
81            ScoreDisplayers.Add(CreateScoreDisplayer(new Vector2(5.0f, 5.0f)));
82            ScoreDisplayers.Add(CreateScoreDisplayer(new Vector2((ALTKConstants.WindowWidth / 2.0f) - 50.0f, 5.0f)));
83            ScoreDisplayers[2].Color = Color.Gold;
84            Game.Components.Add(ScoreDisplayers[0]);
85            Game.Components.Add(ScoreDisplayers[1]);
86            Game.Components.Add(ScoreDisplayers[2]);
87
88            ScoreRatioDisplayers.Add(CreateScoreRatioDisplayer(new Vector2(ALTKConstants.WindowWidth - 145.0f, 5.0f)));
89            ScoreRatioDisplayers.Add(CreateScoreRatioDisplayer(new Vector2(105.0f, 5.0f)));
90            Game.Components.Add(ScoreRatioDisplayers[0]);
91            Game.Components.Add(ScoreRatioDisplayers[1]);
92
93            MusicPlayer = new Audio.MusicPlayer(Game);
94            MusicPlayer.Initialize();
95            MusicPlayer.LoadTrack("YAG2DSS", true);
96
97            SoundPlayer = new Audio.SoundPlayer(Game);
98            SoundPlayer.Initialize();
99        }
100
101        private GUI.AScoreRatioDisplay CreateScoreRatioDisplayer(Vector2 position)
102        {
103            GUI.AScoreRatioDisplay ScoreRatioDisplayer = new GUI.AScoreRatioDisplay(Game);
104            ScoreRatioDisplayer.Position = position;
105            ScoreRatioDisplayer.Value = 1.0;
106            ScoreRatioDisplayer.Size = new Vector2(40.0f, 30.0f);
107            ScoreRatioDisplayer.Color = Color.Pink;
108            ScoreRatioDisplayer.Initialize();
109            return ScoreRatioDisplayer;
110        }
111
112        private GUI.AScoreDisplay CreateScoreDisplayer(Vector2 position)
113        {
114            GUI.AScoreDisplay ScoreDisplayer = new GUI.AScoreDisplay(Game);
115            ScoreDisplayer.Position = position;
116            ScoreDisplayer.Value = 0;
117            ScoreDisplayer.Size = new Vector2(100.0f, 30.0f);
118            ScoreDisplayer.Color = Color.Purple;
119            ScoreDisplayer.Initialize();
120            return ScoreDisplayer;
121        }
122
123        private GUI.ALineBar CreateHealthBar(Vector2 position)
124        {
125            GUI.ALineBar returnValue = new GUI.ALineBar(Game);
126            returnValue.Position = position;
127            returnValue.Value = 100;
128            returnValue.Enabled = true;
129            returnValue.Initialize();
130            return returnValue;
131        }
132
133        public static Vector2 AdjustJypeliVectorToXna(double x, double y)
134        {
135            return CreateXNAVectorFromDoubles(x * ALTKConstants.JypeliToXNARatioX, y * ALTKConstants.JypeliToXNARatioY);
136        }
137
138        private static Vector2 CreateXNAVectorFromDoubles(double x, double y)
139        {
140            return new Vector2(Convert.ToSingle(x), Convert.ToSingle(y));
141        }
142
143        /// <summary>
144        /// Allows the game component to update itself.
145        /// </summary>
146        /// <param name="gameTime">Provides a snapshot of timing values.</param>
147        public override void Update(GameTime gameTime)
148        {
149            // TODO: Add your update code here
150
151            base.Update(gameTime);
152        }
153    }
154}
Note: See TracBrowser for help on using the repository browser.