]>
Commit | Line | Data |
---|---|---|
1 | using System; | |
2 | using System.Collections.Generic; | |
3 | using System.Linq; | |
4 | using System.Text; | |
5 | using Microsoft.Xna.Framework; | |
6 | using Microsoft.Xna.Framework.Graphics; | |
7 | using Microsoft.Xna.Framework.Audio; | |
8 | using Microsoft.Xna.Framework.Media; | |
9 | using Microsoft.Xna.Framework.Input; | |
10 | ||
11 | namespace SuperPolarity | |
12 | { | |
13 | ||
14 | using MediaPlayer = Microsoft.Xna.Framework.Media.MediaPlayer; | |
15 | ||
16 | class GameScreen : Screen | |
17 | { | |
18 | public GameScreen(SuperPolarity newGame) : base(newGame) {} | |
19 | ||
20 | protected List<BasicGenerator> Generators; | |
21 | ||
22 | protected int LivesRate; | |
23 | protected int CurrentLivesRate; | |
24 | protected int BombRate; | |
25 | protected int CurrentBombRate; | |
26 | protected SoundEffect BombSound; | |
27 | protected SoundEffect LifeSound; | |
28 | ||
29 | protected bool Flashing; | |
30 | ||
31 | protected bool IsPaused; | |
32 | protected Texture2D PauseScreen; | |
33 | ||
34 | public override void Initialize() | |
35 | { | |
36 | Generators = new List<BasicGenerator>(); | |
37 | ||
38 | CurrentBombRate = 1; | |
39 | BombRate = 10000; | |
40 | ||
41 | LivesRate = 19000; | |
42 | CurrentLivesRate = 1; | |
43 | ||
44 | InputController.RegisterEventForButton("changePolarity", Buttons.B); | |
45 | InputController.RegisterEventForKey("changePolarity", Keys.Z); | |
46 | ||
47 | InputController.RegisterEventForButton("shoot", Buttons.A); | |
48 | InputController.RegisterEventForKey("shoot", Keys.X); | |
49 | ||
50 | InputController.Bind("pause", HandlePause); | |
51 | ||
52 | PauseScreen = Game.Content.Load<Texture2D>("Graphics\\pause-screen"); | |
53 | } | |
54 | ||
55 | protected void HandlePause(float value) | |
56 | { | |
57 | Console.WriteLine("Paused"); | |
58 | IsPaused = !IsPaused; | |
59 | ||
60 | if (IsPaused) | |
61 | { | |
62 | MediaPlayer.Volume = 0.05f; | |
63 | } | |
64 | else | |
65 | { | |
66 | MediaPlayer.Volume = 1; | |
67 | } | |
68 | } | |
69 | ||
70 | public override void LoadContent() | |
71 | { | |
72 | CreateGenerators(); | |
73 | ||
74 | Vector2 playerPosition = new Vector2(Game.GraphicsDevice.Viewport.TitleSafeArea.X + Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.TitleSafeArea.Y + Game.GraphicsDevice.Viewport.TitleSafeArea.Height / 2); | |
75 | ||
76 | BombSound = Game.Content.Load<SoundEffect>("Sound\\bomb"); | |
77 | LifeSound = Game.Content.Load<SoundEffect>("Sound\\life"); | |
78 | ||
79 | Renderer.CheckIn(ActorFactory.CreateMainShip(playerPosition)); | |
80 | ||
81 | Game.PlaySong("game"); | |
82 | } | |
83 | ||
84 | protected void CalculateBomb() | |
85 | { | |
86 | if (Game.Player.Score >= BombRate * CurrentBombRate) | |
87 | { | |
88 | ActorManager.Bomb(); | |
89 | Flashing = true; | |
90 | BombSound.Play(); | |
91 | CurrentBombRate = CurrentBombRate + 1; | |
92 | } | |
93 | } | |
94 | ||
95 | protected void CalculateLife() | |
96 | { | |
97 | if (Game.Player.Score >= LivesRate * CurrentLivesRate) | |
98 | { | |
99 | Game.Player.Lives = Game.Player.Lives + 1; | |
100 | LifeSound.Play(); | |
101 | CurrentLivesRate = CurrentLivesRate + 1; | |
102 | } | |
103 | } | |
104 | ||
105 | public override void Update(GameTime gameTime) | |
106 | { | |
107 | CalculateBomb(); | |
108 | CalculateLife(); | |
109 | InputController.UpdateInput(IsPaused); | |
110 | if (IsPaused) | |
111 | { | |
112 | return; | |
113 | } | |
114 | ActorManager.Update(gameTime); | |
115 | ||
116 | foreach (BasicGenerator generator in Generators) | |
117 | { | |
118 | generator.Update(gameTime); | |
119 | } | |
120 | } | |
121 | ||
122 | public override void Draw(SpriteBatch spriteBatch) | |
123 | { | |
124 | Renderer.Draw(spriteBatch); | |
125 | Game.Player.Draw(spriteBatch); | |
126 | ||
127 | if (IsPaused) | |
128 | { | |
129 | spriteBatch.Draw(PauseScreen, new Vector2(0, 0), Color.White); | |
130 | } | |
131 | ||
132 | if (Flashing) | |
133 | { | |
134 | Game.GraphicsDevice.Clear(Color.Black); | |
135 | Flashing = false; | |
136 | } | |
137 | } | |
138 | ||
139 | protected void CreateGenerators() | |
140 | { | |
141 | // The basic ship generators. | |
142 | var gen = new BasicGenerator(); | |
143 | gen.Initialize(Game, new Vector2(-50, -50), BasicGenerator.Ships.Ship, 3000, 0); | |
144 | Generators.Add(gen); | |
145 | ||
146 | gen = new BasicGenerator(); | |
147 | gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0); | |
148 | Generators.Add(gen); | |
149 | ||
150 | gen = new BasicGenerator(); | |
151 | gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, -50), BasicGenerator.Ships.Ship, 3000, 0); | |
152 | Generators.Add(gen); | |
153 | ||
154 | gen = new BasicGenerator(); | |
155 | gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0); | |
156 | Generators.Add(gen); | |
157 | ||
158 | // After 1.5k liberate some sporadic Scouts, and add two more ship generators. | |
159 | gen = new BasicGenerator(); | |
160 | gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 3000, 1500); | |
161 | Generators.Add(gen); | |
162 | ||
163 | gen = new BasicGenerator(); | |
164 | gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 1500); | |
165 | Generators.Add(gen); | |
166 | ||
167 | gen = new BasicGenerator(); | |
168 | gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500); | |
169 | Generators.Add(gen); | |
170 | ||
171 | gen = new BasicGenerator(); | |
172 | gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500); | |
173 | Generators.Add(gen); | |
174 | ||
175 | ||
176 | // After 3k add more scouts. | |
177 | gen = new BasicGenerator(); | |
178 | gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Scout, 3000, 3000); | |
179 | Generators.Add(gen); | |
180 | ||
181 | gen = new BasicGenerator(); | |
182 | gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Scout, 3000, 5000); | |
183 | Generators.Add(gen); | |
184 | ||
185 | // After 5k release more ships and a cruiser. | |
186 | gen = new BasicGenerator(); | |
187 | gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 1500, 5000); | |
188 | Generators.Add(gen); | |
189 | ||
190 | gen = new BasicGenerator(); | |
191 | gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 1500, 5000); | |
192 | Generators.Add(gen); | |
193 | ||
194 | gen = new BasicGenerator(); | |
195 | gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000); | |
196 | Generators.Add(gen); | |
197 | ||
198 | gen = new BasicGenerator(); | |
199 | gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000); | |
200 | Generators.Add(gen); | |
201 | } | |
202 | ||
203 | public override void CleanUp() | |
204 | { | |
205 | base.CleanUp(); | |
206 | Generators.Clear(); | |
207 | InputController.Unbind("pause", HandlePause); | |
208 | Renderer.Empty(); | |
209 | ActorManager.Empty(); | |
210 | } | |
211 | } | |
212 | } |