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