1 using System;
2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Content;
4 using Microsoft.Xna.Framework.Graphics;
5 using DreamLibrary;
6 using Microsoft.Xna.Framework.GamerServices;
7
8 namespace DreamBuildPlay {
9 public class GamePlayScreen : Screen {
10 ContentManager content;
11 SpriteBatch spriteBatch;
12 Level level;
13 bool winTest;
14 int currentLevel;
15 //double timeToFinish;
16
17 public GamePlayScreen() {
18 TransitionOnTime = TimeSpan.FromSeconds(1.5);
19 TransitionOffTime = TimeSpan.FromSeconds(0.5);
20 }
21
22 public override void LoadContent() {
23 spriteBatch = ScreenManager.SpriteBatch;
24
25 if (content == null)
26 content = new ContentManager(ScreenManager.Game.Services, "Content");
27
28 level = new Level(ScreenManager);
29
30 if(currentLevel == 2)
31 level.Load(ScreenManager.Game, "", "TestLevel2");
32 else
33 level.Load(ScreenManager.Game, "", "TestLevel");
34
35 SoundManager.PlaySound("PlayerStart", 2.0f);
36
37 // Stop currently playing music
38 SoundManager.StopMusic();
39 // Play game music
40 SoundManager.PlayMusic("GameBackgroundMusic", 1.0f);
41 SoundManager.Update(); // update soundmanager
42 }
43
44 public override void UnloadContent() {
45 level.Unload();
46 }
47
48 public override void HandleInput(GameInput input) {
49 PlayerIndex playerIndex;
50 float moveX = input.LeftThumbstickX(ControllingPlayer, out playerIndex) * 30 * level.Player.SpeedModifier;
51 float moveY = input.LeftThumbstickY(ControllingPlayer, out playerIndex);
52 if (input.IsMoveLeft(ControllingPlayer, out playerIndex))
53 moveX -= 30 * level.Player.SpeedModifier;
54 if (input.IsMoveRight(ControllingPlayer, out playerIndex))
55 moveX += 30 * level.Player.SpeedModifier;
56
57 if (level.tallyFinished && input.IsButtonA(ControllingPlayer, out playerIndex))
58 LoadingScreen.Load(ScreenManager, false, new BackgroundScreen(), new MainMenuScreen());
59
60 // If player DIES
61 if (!level.Player.IsAlive)
62 // Play death sound
63 SoundManager.PlaySound("PlayerDeath2", 1.0f);
64
65 // If player is NOT DYING
66 if (!level.Player.isDying)
67 {
68 // If player is NOT currently attacking
69 if (!level.Player.PlayerArm.attacking)
70 {
71 //this needs to be uncommented before submittal
72 if (/*!input.GamePadIsConnected ||*/ input.IsPause(ControllingPlayer) && !winTest)
73 {
74 SoundManager.PlaySound("Pause", 0.7f);
75 SoundManager.MusicVolume(0.5f); // turn down music for menu
76 ScreenManager.AddScreen(new SidePauseMenuScreen());
77 }
78 // If player is moving in any direction
79 if (moveX != 0 || moveY != 0)
80 {
81 // If player is moving LEFT
82 if (moveX < 0)
83 {
84 level.Player.PlayerArm.attDir = Arm.AttackDirection.Left;
85 level.Player.eDirection = Entity.Direction.Left;
86 }
87 // If player is moving RIGHT
88 else if (moveX > 0)
89 {
90 level.Player.PlayerArm.attDir = Arm.AttackDirection.Right;
91 level.Player.eDirection = Entity.Direction.Right;
92 }
93 // If player is pressing UP
94 if (moveY < -0.6f)
95 level.Player.PlayerArm.attDir = Arm.AttackDirection.Up;
96 // If player is pressing DOWN
97 else if (moveY > 0.6f)
98 level.Player.PlayerArm.attDir = Arm.AttackDirection.Down;
99 // Apply movement force accordingly
100 level.Player.AddForce(new Force(moveX, 0));
101 }
102 else // If player is NOT MOVING
103 {
104 if (level.Player.eDirection == Entity.Direction.Left)
105 level.Player.PlayerArm.attDir = Arm.AttackDirection.Left;
106 else if (level.Player.eDirection == Entity.Direction.Right)
107 level.Player.PlayerArm.attDir = Arm.AttackDirection.Right;
108 }
109 // If player presses the JUMP BUTTON
110 if (input.IsButtonA(ControllingPlayer, out playerIndex) && (level.Player.eState == Entity.State.OnGround))
111 {
112 // Apply jump force and update state
113 level.Player.AddForce(new Force(450.0, 90));
114 level.Player.eState = Entity.State.Jumping;
115
116 // Play jump sound
117 SoundManager.PlaySound("Jump", 0.9f);
118 }
119 // If player presses the USE BUTTON
120 if (input.IsButtonB(ControllingPlayer, out playerIndex) && level.Player.SpeedBoostAvailable)
121 {
122 // Use player power up
123 level.Player.UseSpeedBoost = true;
124 SoundManager.PlaySound("UsePower", 1.0f);
125 }
126 // If player is pressing the ATTACK BUTTON
127 if (input.IsButtonX(ControllingPlayer, out playerIndex) || input.IsNewKey(Microsoft.Xna.Framework.Input.Keys.Enter, ControllingPlayer, out playerIndex))
128 {
129 // Update player state to ATTACKING
130 level.Player.eState = Entity.State.Attacking;
131 // If player is moving analogue stick in Y AXIS
132 if (moveY != 0)
133 {
134 // If player is pressing UP
135 if (moveY < -0.5f)
136 level.Player.PlayerArm.attDir = Arm.AttackDirection.Up;
137 // If player is pressing DOWN
138 else if (moveY > 0.5f)
139 {
140 level.Player.PlayerArm.attDir = Arm.AttackDirection.Down;
141 // Apply downward force
142 level.Player.AddForce(new Force(150.0, -90));
143 }
144 }
145 else // if player is NOT pressing UP or DOWN
146 {
147 // If player is NOT doing air attack
148 if (!level.Player.PlayerArm.allowAirAttack)
149 {
150 if (level.Player.eDirection == Entity.Direction.Left)
151 {
152 level.Player.PlayerArm.attDir = Arm.AttackDirection.Left;
153 level.Player.AddForce(new Force(100.0, 180)); // apply LEFT force
154 }
155 else if (level.Player.eDirection == Entity.Direction.Right)
156 {
157 level.Player.PlayerArm.attDir = Arm.AttackDirection.Right;
158 level.Player.AddForce(new Force(100.0, 0)); // apply RIGHT force
159 }
160 }
161 else // If player IS doing air attack
162 {
163 if (level.Player.eDirection == Entity.Direction.Left)
164 {
165 level.Player.PlayerArm.attDir = Arm.AttackDirection.Left;
166 level.Player.AddForce(new Force(350.0, 180)); // apply LEFT force
167 }
168 else if (level.Player.eDirection == Entity.Direction.Right)
169 {
170 level.Player.PlayerArm.attDir = Arm.AttackDirection.Right;
171 level.Player.AddForce(new Force(350.0, 0)); // apply RIGHT force
172 }
173 }
174 }
175 }
176 }
177 else // Else, if player IS currently attacking
178 {
179 level.Player.AddForce(new Force(moveX, 0));
180 // If the attack sound is allowed to be played
181 if (level.Player.PlayerArm.playAttackSound)
182 // Play attack sound
183 SoundManager.PlaySound("AttackWhip", 0.9f);
184 }
185 }
186
187 // If the player has LANDED from a jump
188 if (level.Player.hasLanded)
189 if (!SoundManager.IsCuePlaying("Land"))
190 // Play LAND sound
191 SoundManager.PlaySound("Land", 0.9f);
192
193 // If the player IS HURT
194 if (level.Player.eState == Entity.State.Hurting)
195 // Play HURT sound
196 SoundManager.PlaySound("PlayerHurt", 0.9f);
197
198 // If the player has PICKED UP the powerup
199 if (level.Player.PlayerFace.playPickupSound)
200 // Play PICK UP sound
201 SoundManager.PlaySound("Pickup", 0.9f);
202
203 // If enemy is ATTACKING
204 if (level.EnemyAttack)
205 if (!SoundManager.IsCuePlaying("Spit"))
206 // Play enemy attack sound
207 SoundManager.PlaySound("Spit", 0.9f);
208
209 if (level.LevelIsDone && !winTest && level.Player.Health > 0)
210 {
211 SoundManager.PlaySound("TubeSuck", 1.0f); // play ending sound
212 winTest = true;
213 }
214
215 if (level.DisplayMessage)
216 {
217 ScreenManager.AddScreen(new TextScreen(level.sMessage, TextScreen.TransitionType.FromGame));
218 level.DisplayMessage = false;
219 }
220 }
221
222 public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) {
223 base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
224
225 SoundManager.Update(); // update soundmanager
226 if (IsActive) {
227 SoundManager.MusicVolume(1.0f); // turn music back up
228 level.Update(gameTime);
229 }
230
231 if (level.Restart) {
232 ScreenManager.AddScreen(new MessageBoxScreen(level.sMessage, true));
233 level.Restart = false;
234 }
235 }
236
237 public override void Draw(GameTime gameTime) {
238 level.Draw(gameTime, spriteBatch);
239 }
240 }
241 }