-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameStateMainMenu.cs
executable file
·142 lines (117 loc) · 3.94 KB
/
GameStateMainMenu.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
using System;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Media;
namespace TheGame
{
public class GameStateMainMenu : GameState
{
private List<Sprite> buttons;
private int buttonCursor;
private InputHandler inputHandler;
private Game1 game;
private ContentManager Content;
private Menu m;
private TextWindow tw;
private Sprite bg;
public GameStateMainMenu (ContentManager c, Game1 g)
{
Content = c;
inputHandler = new InputHandler ();
buttons = new List<Sprite> ();
game = g;
m = new Menu(new Vector2(10, 10), new String[] { "NEW GAME", "CREDITS", "QUIT" }, new Menu.menuAction[] { playerCount, showCredits, quitGame }, 3, 1, "test-semifont.png", Content);
bg = new Sprite("title-bg.png", Content, new Vector2(0, 0));
}
public void playerCount()
{
m = new Menu(new Vector2(10, 10), new String[] { "ONE PLAYER", "TWO PLAYERS" }, new Menu.menuAction[] { startOneP, startTwoP }, 2, 1, "test-semifont.png", Content);
}
public void startOneP()
{
startGame(1);
}
public void startTwoP()
{
startGame(2);
}
private void startGame(int nPlayers)
{
m = new Menu(new Vector2(10, 10), new String[] { "NEW GAME", "CREDITS", "QUIT" }, new Menu.menuAction[] { playerCount, showCredits, quitGame }, 3, 1, "test-semifont.png", Content);
game.doStateTransition(new GameStateMap(Content, game, nPlayers));
}
private void showCredits()
{
m = null;
tw = new TextWindow(new string[] { "DEVELOPED BY\\n\\2ANDREW BARRY" }, Content, new Vector2(25,25), new Vector2(200,50));
}
private void quitGame()
{
m = null;
game.Exit();
}
public void update(double dt)
{
if (tw != null)
{
tw.update(dt);
}
else if (m != null)
{
m.update(dt);
}
}
public void draw(SpriteBatch spriteBatch)
{
bg.draw(spriteBatch);
if (tw != null)
{
tw.draw(spriteBatch);
}
else if (m != null)
{
m.draw(spriteBatch);
}
}
public void handleInput()
{
inputHandler.update (Keyboard.GetState ());
if (m != null)
{
m.handleInput(inputHandler);
}
else if (inputHandler.allowSinglePress(Keys.Down) && buttonCursor != 2) {
buttons [buttonCursor].animHandler.setAnimation (0,false);
buttonCursor++;
buttons [buttonCursor].animHandler.setAnimation (1,false);
}
else if (inputHandler.allowSinglePress(Keys.Up) && buttonCursor != 0) {
buttons [buttonCursor].animHandler.setAnimation(0,false);
buttonCursor--;
buttons[buttonCursor].animHandler.setAnimation(1,false);
}
if (inputHandler.allowSinglePress(Keys.Enter) && tw != null)
{
if (tw != null)
{
if (tw.waitingForContinue)
{
tw.advanceLine();
}
else
{
tw.fastForward();
}
if (tw.done)
{
tw = null;
m = new Menu(new Vector2(10, 10), new String[] { "NEW GAME", "CREDITS", "QUIT" }, new Menu.menuAction[] { playerCount, showCredits, quitGame }, 3, 1, "test-semifont.png", Content);
}
}
}
}
}
}