-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSceneGameplay.cs
280 lines (226 loc) · 9.29 KB
/
SceneGameplay.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using TexturePackerLoader;
namespace BCEngine
{
public class SceneGameplay : Scene
{
private KeyboardState oldKBState;
private GamePadState oldPadState;
private Song music;
private SoundEffect sfxExplode;
private PlayerInput playerInput;
private Rectangle World;
private SpriteSheetLoader spriteSheetLoader;
private SpriteSheet heroSpriteSheet;
private Hero MyHero;
private Texture2D Background;
public SceneGameplay(MainGame pGame) : base(pGame)
{
}
public override void Load()
{
World.Width = 1000;
World.Height = mainGame.Screen.Height;
// Input state
oldKBState = Keyboard.GetState();
oldPadState = GamePad.GetState(PlayerIndex.One);
playerInput = new PlayerInput();
spriteSheetLoader = new SpriteSheetLoader(mainGame.Content, mainGame.GraphicsDevice);
heroSpriteSheet = spriteSheetLoader.Load("Robot 1.png");
// Hero
// Anim Idle
Anim HeroIdle = new Anim("idle", 10, true);
for (int i = 0; i < 9; i++)
{
HeroIdle.addFrame(heroSpriteSheet.Sprite("R1_Idle/idle_00" + i));
}
// Anim Run
Anim HeroRun = new Anim("run", 10, true);
for (int i = 0; i < 12; i++)
{
if (i < 10)
{
HeroRun.addFrame(heroSpriteSheet.Sprite("R1_Run/Run_00" + i));
}
else
{
HeroRun.addFrame(heroSpriteSheet.Sprite("R1_Run/Run_0" + i));
}
}
MyHero = new Hero();
MyHero.Height = 150;
MyHero.addAnim(HeroIdle);
MyHero.addAnim(HeroRun);
MyHero.playAnim("run");
MyHero.Position = new Vector2(40, mainGame.Screen.Height - MyHero.Height - 20);
Debug.WriteLine(MyHero.Position);
listActor.Add(MyHero);
// Meteors
// AssetManager.LoadTexture2D(mainGame.Content, "meteor");
// for (int i = 0; i < 10; i++)
// {
// Meteor m = new Meteor(AssetManager.GetTexture2D("meteor"));
// m.Position = new Vector2(Util.GetInt(1, mainGame.Screen.Width - m.Texture.Width), Util.GetInt(1, mainGame.Screen.Height - m.Texture.Height));
// listActor.Add(m);
// }
// Music
// AssetManager.LoadSong(mainGame.Content,"techno");
// music = AssetManager.GetSong("techno");
// MediaPlayer.Play(music);
// MediaPlayer.IsRepeating=true;
// Sfx
// AssetManager.LoadSoundEffect(mainGame.Content,"explode");
// sfxExplode = AssetManager.GetSoundEffect("explode");
// Background
AssetManager.LoadTexture2D(mainGame.Content, "War2");
Background = AssetManager.GetTexture2D("War2");
base.Load();
}
public override void Unload()
{
base.Unload();
}
public override void Update(GameTime gameTime)
{
// Debug.WriteLine("Updating Scene Gameplay...");
// Mouse
// MouseState mouseState = Mouse.GetState();
// Debug.WriteLine(mouseState.X+", "+mouseState.Y+", "+mouseState.LeftButton);
/**
Controlls
*/
playerInput.reset();
// Pad
GamePadCapabilities capabilities = GamePad.GetCapabilities(PlayerIndex.One);
if (capabilities.IsConnected)
{
GamePadState newPadState = GamePad.GetState(PlayerIndex.One, GamePadDeadZone.IndependentAxes);
if (newPadState.IsButtonDown(Buttons.LeftThumbstickLeft) || newPadState.IsButtonDown(Buttons.DPadLeft))
playerInput.Left = true;
if (newPadState.IsButtonDown(Buttons.LeftThumbstickDown) || newPadState.IsButtonDown(Buttons.DPadDown))
playerInput.Down = true;
if (newPadState.IsButtonDown(Buttons.LeftThumbstickRight) || newPadState.IsButtonDown(Buttons.DPadRight))
playerInput.Right = true;
if (newPadState.IsButtonDown(Buttons.LeftThumbstickUp) || newPadState.IsButtonDown(Buttons.DPadUp))
playerInput.Up = true;
if (newPadState.IsButtonDown(Buttons.A))
playerInput.A = true;
if (newPadState.IsButtonDown(Buttons.B) && !oldPadState.IsButtonDown(Buttons.B))
playerInput.B = true;
oldPadState = newPadState;
}
// Keyboard
KeyboardState newKBState = Keyboard.GetState();
if ((newKBState.IsKeyDown(Keys.Left) || newKBState.IsKeyDown(Keys.A)))
playerInput.Left = true;
if ((newKBState.IsKeyDown(Keys.Down) || newKBState.IsKeyDown(Keys.S)))
playerInput.Down = true;
if ((newKBState.IsKeyDown(Keys.Right) || newKBState.IsKeyDown(Keys.D)))
playerInput.Right = true;
if ((newKBState.IsKeyDown(Keys.Up) || newKBState.IsKeyDown(Keys.W)))
playerInput.Up = true;
if (newKBState.IsKeyDown(Keys.Space) && !oldKBState.IsKeyDown(Keys.Space))
{
Debug.WriteLine("Space on the menu");
mainGame.gameState.changeScene(GameState.SceneType.Menu);
}
if (newKBState.IsKeyDown(Keys.I))
{
Debug.WriteLine("Fire !");
}
// Handle inputs
// if (playerInput.Up && MyHero.Position.Y > 0)
// {
// MyHero.Move(3 * 0, 3 * -1);
// }
// if (playerInput.Down && MyHero.Position.Y < World.Height - MyHero.Height)
// {
// MyHero.Move(3 * 0, 3 * 1);
// }
// if (playerInput.Left && MyHero.Position.X > 0)
// {
// MyHero.Move(3 * -1, 3 * 0);
// MyHero.effect = SpriteEffects.FlipHorizontally;
// }
// if (playerInput.Right && MyHero.Position.X < World.Width - MyHero.Width)
// {
// MyHero.Move(3 * 1, 3 * 0);
// MyHero.effect = SpriteEffects.None;
// }
if (playerInput.A)
{
}
if (playerInput.B)
{
}
if (playerInput.X)
{
}
if (playerInput.Y)
{
}
// /**
// Meteors
// */
// foreach (IActor Actor in listActor)
// {
// if (Actor is Meteor m)
// {
// if (m.Position.X < 0)
// {
// m.Position = new Vector2(0, m.Position.Y);
// m.vx = -m.vx;
// }
// if (m.Position.X > mainGame.Screen.Width - m.Texture.Width)
// {
// m.Position = new Vector2(mainGame.Screen.Width - m.Texture.Width, m.Position.Y);
// m.vx = -m.vx;
// }
// if (m.Position.Y < 0)
// {
// m.Position = new Vector2(m.Position.X, 0);
// m.vy = -m.vy;
// }
// if (m.Position.Y > mainGame.Screen.Height - m.Texture.Height)
// {
// m.Position = new Vector2(m.Position.X, mainGame.Screen.Height - m.Texture.Height);
// m.vy = -m.vy;
// }
// if (Util.CollideByBox(m, MyHero))
// {
// MyHero.TouchedBy(m);
// m.TouchedBy(MyHero);
// m.ToRemove = true;
// // sfxExplode.Play();
// }
// }
// }
listActor.RemoveAll(item => item.ToRemove == true);
/**
Ship
*/
// if (MyHero.Energy <= 0)
// {
// MediaPlayer.Stop();
// mainGame.gameState.changeScene(GameState.SceneType.Gameover);
// }
oldKBState = newKBState;
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
// Debug.WriteLine("Drawing Scene Gameplay...");
mainGame.spriteBatch.Begin();
mainGame.spriteBatch.Draw(Background, Vector2.Zero, Color.White);
// mainGame.spriteBatch.DrawString(AssetManager.MainFont, "Ship Energy : " + MyHero.Energy, new Vector2(20, 50), Color.Wheat);
mainGame.spriteBatch.DrawString(AssetManager.MainFont, "This is the Gameplay", new Vector2(100, 10), Color.Red);
mainGame.spriteBatch.End();
base.Draw(gameTime);
}
}
}