-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.cs
88 lines (71 loc) · 2.58 KB
/
Menu.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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Connect4
{
public class Menu : Game
{
KeyboardState ks1, ks2;
Texture2D menu;
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private SpriteFont menuFont;
int width = 700;
int height = 800;
public Menu()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
_graphics.PreferredBackBufferWidth = width;
_graphics.PreferredBackBufferHeight = height;
_graphics.ApplyChanges();
this.Window.Title = "Connect 4";
this.Window.AllowUserResizing = false;
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
menu = Content.Load<Texture2D>("Menu");
menuFont = Content.Load<SpriteFont>("MenuFont");
}
protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
ks1 = Keyboard.GetState();
if (ks1.IsKeyDown(Keys.Enter) && ks2.IsKeyUp(Keys.Enter))
{
using var game = new Connect4.Game1();
Exit();
game.Run();
}
ks2 = ks1;
// Credit to Pixi91 for the fix on constant push of keys found here -> https://community.monogame.net/t/delay-after-keyboard-input/10999/2
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Blue);
// TODO: Add your drawing code here
_spriteBatch.Begin();
_spriteBatch.Draw(menu, new Vector2(0, 0), Color.White);
_spriteBatch.DrawString(menuFont, "Press ENTER to play", new Vector2(225, 300), Color.Yellow);
_spriteBatch.DrawString(menuFont, "Press ESCAPE to exit", new Vector2(225, 400), Color.Red);
_spriteBatch.End();
base.Draw(gameTime);
}
}
}